Elpida Deploy Bot commited on
Commit
258cdab
Β·
1 Parent(s): 53c947e

deploy: 28bf7ff HF Space outbound TLS reachability diagnostic

Browse files
Files changed (2) hide show
  1. app.py +12 -0
  2. elpidaapp/diagnose_outbound.py +139 -0
app.py CHANGED
@@ -71,6 +71,18 @@ logging.basicConfig(
71
  )
72
  logger = logging.getLogger(__name__)
73
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  def run_background_worker():
75
  """
76
  I PATH: Process consciousness dilemmas from S3 every 6 hours.
 
71
  )
72
  logger = logging.getLogger(__name__)
73
 
74
+ # One-shot outbound TLS reachability diagnostic β€” runs once at HF Space
75
+ # startup, prints results to logs. Lets us see immediately whether HF
76
+ # Space's outbound is selectively filtering specific destinations
77
+ # (Telegram, Discord) or under blanket egress restriction. Stdlib only,
78
+ # ~10 seconds total runtime, no behavior change.
79
+ try:
80
+ from elpidaapp.diagnose_outbound import diagnose_outbound
81
+ diagnose_outbound()
82
+ except Exception as _diag_err:
83
+ logger.warning("Outbound diagnostic failed to run: %s", _diag_err)
84
+
85
+
86
  def run_background_worker():
87
  """
88
  I PATH: Process consciousness dilemmas from S3 every 6 hours.
elpidaapp/diagnose_outbound.py ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ HF Space outbound TLS reachability diagnostic.
3
+
4
+ Tests TCP+TLS handshakes against a list of representative external hosts
5
+ to identify whether outbound filtering is selective (deny-list against
6
+ specific destinations like Telegram/Discord) or blanket egress
7
+ restriction. Prints one line per host with status. Stdlib only.
8
+
9
+ Result patterns:
10
+ - Some OK, some TLS-failed β†’ SELECTIVE egress filtering. Specific
11
+ destinations are throttled while others work. Consistent with
12
+ abuse-flag deny-list applied to this Space.
13
+ - All failed β†’ general network problem or complete egress block.
14
+ - All OK β†’ no current restriction; original failure was transient.
15
+ """
16
+
17
+ import logging
18
+ import socket
19
+ import ssl
20
+ import time
21
+
22
+ logger = logging.getLogger("elpida.diagnose")
23
+
24
+ # (host, port, label) β€” pick destinations across the categories that matter
25
+ # to Elpida. Order from "should work" toward "currently broken" so reading
26
+ # the log top-to-bottom shows the contrast.
27
+ HOSTS_TO_TEST = [
28
+ ("api.github.com", 443, "GitHub API"),
29
+ ("api.openai.com", 443, "OpenAI API"),
30
+ ("api.anthropic.com", 443, "Anthropic API"),
31
+ ("api.mistral.ai", 443, "Mistral API"),
32
+ ("api.perplexity.ai", 443, "Perplexity API"),
33
+ ("s3.eu-north-1.amazonaws.com", 443, "AWS S3 eu-north-1"),
34
+ ("api.telegram.org", 443, "Telegram Bot API"),
35
+ ("discord.com", 443, "Discord"),
36
+ ("httpbin.org", 443, "httpbin (neutral)"),
37
+ ]
38
+
39
+
40
+ def _test_host(host: str, port: int, label: str, timeout: float = 8.0) -> dict:
41
+ """Test TCP connect + TLS handshake. Return a result dict."""
42
+ result = {
43
+ "host": host,
44
+ "port": port,
45
+ "label": label,
46
+ "tcp_ok": False,
47
+ "tls_ok": False,
48
+ "duration_s": 0.0,
49
+ "error": None,
50
+ }
51
+ start = time.monotonic()
52
+ try:
53
+ sock = socket.create_connection((host, port), timeout=timeout)
54
+ result["tcp_ok"] = True
55
+ try:
56
+ ctx = ssl.create_default_context()
57
+ tls_sock = ctx.wrap_socket(
58
+ sock, server_hostname=host, do_handshake_on_connect=True
59
+ )
60
+ result["tls_ok"] = True
61
+ tls_sock.close()
62
+ finally:
63
+ try:
64
+ sock.close()
65
+ except Exception:
66
+ pass
67
+ except socket.gaierror as e:
68
+ result["error"] = f"DNS: {e}"
69
+ except (socket.timeout, TimeoutError) as e:
70
+ result["error"] = f"timeout: {e}"
71
+ except ssl.SSLError as e:
72
+ result["error"] = f"TLS: {e}"
73
+ except OSError as e:
74
+ result["error"] = f"OSError: {e}"
75
+ except Exception as e:
76
+ result["error"] = f"{type(e).__name__}: {e}"
77
+ result["duration_s"] = round(time.monotonic() - start, 2)
78
+ return result
79
+
80
+
81
+ def diagnose_outbound() -> list:
82
+ """Run all host tests and log results."""
83
+ logger.warning("=" * 78)
84
+ logger.warning("ELPIDA DIAGNOSE β€” HF Space outbound TLS reachability")
85
+ logger.warning("=" * 78)
86
+ logger.warning(
87
+ "%-8s %-8s %-37s %s", "Status", "Time", "Host:Port", "Notes"
88
+ )
89
+ logger.warning("-" * 78)
90
+
91
+ results = []
92
+ for host, port, label in HOSTS_TO_TEST:
93
+ r = _test_host(host, port, label)
94
+ if r["tls_ok"]:
95
+ status = "OK"
96
+ elif r["tcp_ok"]:
97
+ status = "TLS_FAIL"
98
+ else:
99
+ status = "TCP_FAIL"
100
+ line = "%-8s %-8s %-37s %s" % (
101
+ status,
102
+ f"{r['duration_s']}s",
103
+ f"{host}:{port}",
104
+ label + (f" [{r['error']}]" if r["error"] else ""),
105
+ )
106
+ logger.warning(line)
107
+ results.append(r)
108
+
109
+ logger.warning("-" * 78)
110
+ n_ok = sum(1 for r in results if r["tls_ok"])
111
+ n_tls_fail = sum(1 for r in results if r["tcp_ok"] and not r["tls_ok"])
112
+ n_tcp_fail = sum(1 for r in results if not r["tcp_ok"])
113
+ logger.warning(
114
+ "Summary: %d/%d OK, %d TLS-failed, %d TCP-failed",
115
+ n_ok, len(results), n_tls_fail, n_tcp_fail,
116
+ )
117
+
118
+ if n_ok == 0:
119
+ logger.warning(
120
+ "β†’ All destinations failed. General network problem or complete egress block."
121
+ )
122
+ elif n_tls_fail == 0:
123
+ logger.warning(
124
+ "β†’ All destinations working. Current failure window is transient or already past."
125
+ )
126
+ elif n_tls_fail > 0:
127
+ logger.warning(
128
+ "β†’ Mixed result indicates SELECTIVE egress filtering: specific "
129
+ "destinations throttled while others work. Consistent with abuse-flag "
130
+ "deny-list applied to this Space (H1)."
131
+ )
132
+
133
+ logger.warning("=" * 78)
134
+ return results
135
+
136
+
137
+ if __name__ == "__main__":
138
+ logging.basicConfig(level=logging.WARNING, format="%(levelname)s: %(message)s")
139
+ diagnose_outbound()