Skip to content

Commit 661f2d3

Browse files
1 parent 02e3035 commit 661f2d3

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎.github/security/ai_security_review.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
REVIEW_CONTACTS = ("runpod/security",)
5959

6060
MAX_OUTPUT_TOKENS = 8192
61+
# Socket timeout for the model call. A full prompt on a busy pod can take over
62+
# a minute to stream its first byte; the pod proxy drops an idle response at ~100s.
63+
MODEL_TIMEOUT_S = 95
6164

6265
# Context lines either side of a detection.
6366
WINDOW_LINES = 20
@@ -454,7 +457,8 @@ def call_kimi(prompt_system: str, prompt_user: str, api_key: str) -> str | None:
454457

455458
# `raw` buffers the whole event stream; the proxy stays open while events arrive.
456459
status, raw = request(f"{LITELLM_BASE}/v1/chat/completions", headers,
457-
data=json.dumps(body).encode(), raw=True)
460+
data=json.dumps(body).encode(), raw=True,
461+
timeout=MODEL_TIMEOUT_S)
458462
if status == 400:
459463
# Bounded: the server may echo the request back.
460464
log(f"::warning::model rejected the request (400): {str(raw)[:200]}")

‎.github/security/ghapi.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ def log(msg: str) -> None:
2424

2525

2626
def request(url: str, headers: dict, data: bytes | None = None,
27-
raw: bool = False, method: str | None = None):
27+
raw: bool = False, method: str | None = None,
28+
timeout: float = HTTP_TIMEOUT_S):
2829
"""Minimal HTTP helper. Returns (status, body) and never raises on 4xx/5xx."""
2930
req = urllib.request.Request(url, data=data, headers=headers, method=method)
3031
if data is not None:
3132
req.add_header("Content-Type", "application/json")
3233
try:
33-
with urllib.request.urlopen(req, timeout=HTTP_TIMEOUT_S) as resp:
34+
with urllib.request.urlopen(req, timeout=timeout) as resp:
3435
body = resp.read()
3536
return resp.status, (body if raw else json.loads(body or b"{}"))
3637
except urllib.error.HTTPError as exc:

‎.github/security/test_secret_gate.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def _stub_stream(monkeypatch, events):
342342
urls = []
343343

344344
def fake_request(url, *a, **k):
345-
urls.append(url)
345+
urls.append((url, k.get("timeout")))
346346
return 200, b"".join(b"data: " + e + b"\n\n" for e in events)
347347

348348
monkeypatch.setattr(air, "request", fake_request)
@@ -361,7 +361,7 @@ def test_streamed_reply_is_reassembled_from_litellm(monkeypatch):
361361
_delta('{"verdicts":'), _delta(" []}", "stop"), b"[DONE]"])
362362

363363
assert air.call_kimi("sys", "user", "key") == '{"verdicts": []}'
364-
assert urls == [f"{air.LITELLM_BASE}/v1/chat/completions"]
364+
assert urls == [(f"{air.LITELLM_BASE}/v1/chat/completions", air.MODEL_TIMEOUT_S)]
365365

366366

367367
@pytest.mark.parametrize("bad", [b'{"error": {"message": "overloaded"}}',

0 commit comments

Comments
 (0)