Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

relay: a stream is forwarded as it arrives, and keep-alive lines are not an answer (#381)

github-actions[bot]d257219281ef
diff --git a/runner/dsh_driver.py b/runner/dsh_driver.py
index 0bf7ed1f..49efb6c0 100644
--- a/runner/dsh_driver.py
+++ b/runner/dsh_driver.py
@@ -18,6 +18,7 @@ credential never enters the dsh process env, its session log, or anything it cou
"""
from __future__ import annotations
+import http.client
import http.server
import json
import re
@@ -25,9 +26,24 @@ import os
import pathlib
import sys
import threading
+import time
import urllib.request
UPSTREAM_BASE = "" # set in main() from HR_DSH_BASE_URL, then scrubbed from the env
+
+
+def _upstream_wait() -> float:
+ """How long this relay waits on the provider: for the answer to begin, and in a stream for the
+ next EVENT. The runner's own figure (HR_RELAY_UPSTREAM_TIMEOUT_S, handed over by _build_dsh),
+ 600 s when it is absent or not a positive number."""
+ try:
+ v = float(os.environ.get("HR_RELAY_UPSTREAM_TIMEOUT_S") or 600)
+ except ValueError:
+ return 600.0
+ return v if v > 0 else 600.0
+
+
+UPSTREAM_WAIT_S = _upstream_wait()
UPSTREAM_KEY = ""
@@ -302,7 +318,7 @@ class _Relay(http.server.BaseHTTPRequestHandler):
req = urllib.request.Request(UPSTREAM_BASE.rstrip("/") + tail,
data=body, method="POST", headers=headers)
try:
- resp = urllib.request.urlopen(req, timeout=600)
+ resp = urllib.request.urlopen(req, timeout=UPSTREAM_WAIT_S)
break
except urllib.error.HTTPError as e:
data = e.read()
@@ -345,19 +361,50 @@ class _Relay(http.server.BaseHTTPRequestHandler):
self.send_header("transfer-encoding", "chunked")
self.end_headers()
buf = b""
+ # The same two rules as the runner's relay (server.py, _forward), for the same reason.
+ # read1 forwards what has arrived: `read(4096)` waits for 4096 bytes or the end of the
+ # stream, so a short event sat here until the block filled. And an EVENT is the measure
+ # of a live provider, not bytes: an aggregator trickles comment lines while its own
+ # upstream says nothing, which keeps the socket from ever timing out, and the turn hung
+ # until its cap with nothing delivered.
+ last_event = time.monotonic()
+ stopped = ""
while True:
- chunk = resp.read(4096)
+ try:
+ chunk = resp.read1(65536)
+ except (http.client.HTTPException, TimeoutError, OSError) as e:
+ stopped = f"{type(e).__name__}: {e}"[:300]
+ break
if not chunk:
break
buf += chunk
while b"\n" in buf:
line, buf = buf.split(b"\n", 1)
+ if line.strip() and not line.lstrip().startswith(b":"):
+ last_event = time.monotonic()
if google:
for cid, sig in _google_signatures_in_line(line.strip()):
_google_sigs[cid] = sig
out = (_rewrite_sse_line(line.rstrip(b"\r")) if rewrite else line.rstrip(b"\r")) + b"\n"
self.wfile.write(f"{len(out):x}\r\n".encode() + out + b"\r\n")
self.wfile.flush()
+ if time.monotonic() - last_event > UPSTREAM_WAIT_S:
+ stopped = f"no data for {UPSTREAM_WAIT_S:g} s, only keep-alive lines"
+ break
+ if stopped:
+ # Said in the stream, and the body left unterminated with the connection closed: a
+ # zero chunk here would hand the runtime a complete answer missing its last events.
+ print(f"[dsh relay] upstream stopped mid-answer on {tail}: {stopped}", flush=True)
+ ev = ("data: " + json.dumps({"error": {
+ "message": f"the provider stopped answering mid-stream: {stopped}",
+ "type": "upstream_unavailable", "code": "upstream_unavailable"}}) + "\n\n").encode()
+ try:
+ self.wfile.write(f"{len(ev):x}\r\n".encode() + ev + b"\r\n")
+ self.wfile.flush()
+ except OSError:
+ pass
+ self.close_connection = True
+ return
if buf:
out = _rewrite_sse_line(buf) if rewrite else buf
self.wfile.write(f"{len(out):x}\r\n".encode() + out + b"\r\n")
diff --git a/runner/server.py b/runner/server.py
index f3c98911..9a81cd63 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -2452,6 +2452,8 @@ def _build_dsh(provider: str, auth: Auth, model: str, prompt: str, cwd: str, env
# a loopback relay URL and a placeholder key — the credential never enters its environment.
env["HR_DSH_BASE_URL"] = base
env["HR_DSH_API_KEY"] = auth.api_key or ""
+ # The driver's own relay waits on the provider as long as this one does (dsh_driver._upstream_wait).
+ env["HR_RELAY_UPSTREAM_TIMEOUT_S"] = f"{HR_RELAY_UPSTREAM_TIMEOUT_S:g}"
# No system_prompt in the job: harness instructions land in AGENTS.md (dsh reads it via
# its dsh-agent-instructions loader), same mechanism as codex/hermes/pi.
job = {"prompt": prompt, "model": model, "cwd": cwd,
@@ -3524,7 +3526,9 @@ def _aws_eventstream_frames(resp):
import struct
buf = b""
while True:
- chunk = resp.read(65536)
+ # read1, for the reason _forward reads that way: `read(65536)` waits for 64 KB or the end
+ # of the stream, so an answer shorter than that reached the client all at once at the end.
+ chunk = resp.read1(65536)
buf += chunk
while len(buf) >= 16:
total = struct.unpack(">I", buf[:4])[0]
@@ -4350,37 +4354,53 @@ class _HermesRelayHandler(http.server.BaseHTTPRequestHandler):
carry = b"" # tail of the previous chunk, so a split "model":"…" is still seen
fcarry = b"" # tail of the previous chunk, for the finish_reason field
call_usage: dict = {} # what this call's events said about tokens, unioned
+
+ def _stopped(why: str) -> None:
+ # The answer began and then stopped: the provider went silent past the socket's
+ # timeout, dropped the connection mid-stream, or kept the socket warm and sent no
+ # event. The status line is long gone, so the reason travels as the stream's own
+ # error event (the shape of the API being spoken) and the chunked body is then left
+ # UNTERMINATED with the connection closed. Ending it with the zero chunk would hand
+ # the client a well-formed, complete answer that merely lacks its last events —
+ # measured at a stub: one event, a stall, and the client read 200 with nothing wrong.
+ print(f"[relay] upstream stopped mid-answer on {tail} model={_body_model}: {why}",
+ flush=True)
+ msg = f"the provider stopped answering mid-stream: {why}"
+ if "/messages" in tail:
+ ev = "event: error\ndata: " + json.dumps(
+ {"type": "error", "error": {"type": "api_error", "message": msg}}) + "\n\n"
+ else:
+ ev = "data: " + json.dumps({"error": {
+ "message": msg, "type": "upstream_unavailable",
+ "code": "upstream_unavailable"}}) + "\n\n"
+ call_usage.update(_usage_in_sse_line(pending.strip()))
+ _usage_add(flags, call_usage)
+ try:
+ raw = ev.encode()
+ self.wfile.write(f"{len(raw):x}\r\n".encode() + raw + b"\r\n")
+ self.wfile.flush()
+ except OSError:
+ pass
+ self.close_connection = True
+
+ # When the provider last sent an EVENT (or the answer began). Bytes are not the measure:
+ # an aggregator trickles comment lines (": OPENROUTER PROCESSING") for as long as its own
+ # upstream says nothing, so the socket never goes quiet and its timeout never fires.
+ last_event = time.monotonic()
while True:
try:
- chunk = resp.read(4096)
+ # read1: what has arrived, as it arrives. `read(4096)` on an HTTP response waits
+ # for 4096 BYTES or the end of the stream, so a short first event sat here until
+ # the rest of the answer filled the block (an answer under 4 KB reached the client
+ # all at once, at its end), and a provider that sent a little and then stalled,
+ # or only kept the connection warm, delivered nothing at all and was never timed
+ # out. Both reproduced at a stub (runner/tests/test_relay_upstream_failure.py);
+ # neither has been caught on a live provider, where the long turns looked at so
+ # far were a model streaming reasoning without end, which is an answer arriving
+ # and is rightly left alone here.
+ chunk = resp.read1(65536)
except (http.client.HTTPException, TimeoutError, OSError) as e:
- # The answer began and then stopped: the provider went silent past the socket's
- # timeout, or dropped the connection mid-stream. The status line is long gone, so
- # the reason travels as the stream's own error event (the shape of the API being
- # spoken) and the chunked body is then left UNTERMINATED with the connection
- # closed. Ending it with the zero chunk would hand the client a well-formed,
- # complete answer that merely lacks its last events — measured at a stub: one
- # event, a stall, and the client read 200 with nothing wrong.
- why = f"{type(e).__name__}: {e}"[:300]
- print(f"[relay] upstream stopped mid-answer on {tail} model={_body_model}: {why}",
- flush=True)
- msg = f"the provider stopped answering mid-stream: {why}"
- if "/messages" in tail:
- ev = "event: error\ndata: " + json.dumps(
- {"type": "error", "error": {"type": "api_error", "message": msg}}) + "\n\n"
- else:
- ev = "data: " + json.dumps({"error": {
- "message": msg, "type": "upstream_unavailable",
- "code": "upstream_unavailable"}}) + "\n\n"
- call_usage.update(_usage_in_sse_line(pending.strip()))
- _usage_add(flags, call_usage)
- try:
- raw = ev.encode()
- self.wfile.write(f"{len(raw):x}\r\n".encode() + raw + b"\r\n")
- self.wfile.flush()
- except OSError:
- pass
- self.close_connection = True
+ _stopped(f"{type(e).__name__}: {e}"[:300])
return
if not chunk:
break
@@ -4392,12 +4412,14 @@ class _HermesRelayHandler(http.server.BaseHTTPRequestHandler):
# A read boundary can fall inside the field, and a miss here is silent:
# served_model stays empty and the turn is simply not substitution-checked.
# 256 bytes covers the longest id this can carry (the regex caps at 200).
- carry = chunk[-256:]
+ # The tail of the STREAM, not of the last read: a read returns whatever has
+ # arrived, so the field can span three of them.
+ carry = (carry + chunk)[-256:]
# the last finish_reason, across read boundaries (64 bytes covers the field)
fr = _finish_reason_in(fcarry + chunk)
if fr:
flags["last_finish"] = fr
- fcarry = chunk[-64:]
+ fcarry = (fcarry + chunk)[-64:]
# usage (and Google's tool-call signatures) live on whole SSE lines, so the
# stream is line-buffered as it passes; the bytes still go through untouched
pending += chunk
@@ -4409,6 +4431,8 @@ class _HermesRelayHandler(http.server.BaseHTTPRequestHandler):
if out_lines is not None:
out_lines.append(_usage_without_nulls(line) + b"\n")
line = line.strip()
+ if line and not line.startswith(b":"):
+ last_event = time.monotonic() # an event's line; a comment is not one
call_usage.update(_usage_in_sse_line(line))
if sigs is not None:
for cid, sig in _google_signatures_in_line(line):
@@ -4418,6 +4442,11 @@ class _HermesRelayHandler(http.server.BaseHTTPRequestHandler):
if chunk:
self.wfile.write(f"{len(chunk):x}\r\n".encode() + chunk + b"\r\n")
self.wfile.flush()
+ if time.monotonic() - last_event > HR_RELAY_UPSTREAM_TIMEOUT_S:
+ # No event for the whole of the relay's wait, only lines that keep the connection
+ # open: the same silence the socket's timeout reports, by another door.
+ _stopped(f"no data for {HR_RELAY_UPSTREAM_TIMEOUT_S:g} s, only keep-alive lines")
+ return
call_usage.update(_usage_in_sse_line(pending.strip()))
_usage_add(flags, call_usage)
if flags.get("usage_no_nulls") and pending:
@@ -4601,9 +4630,10 @@ def _adapt_custom_auth(auth):
return auth.model_copy(update={"base_url": base, "api_key": tok})
-# How long the relay waits for the provider on ONE upstream call, and how long a stalled READ of an
-# answer already begun may block (it is the socket's timeout: connect, the wait for the status line,
-# and every later read). It must stay BELOW the turn cap above it, or a provider that accepts a
+# How long the relay waits for the provider on ONE upstream call, and how long an answer already
+# begun may go without an EVENT (it is the socket's timeout: connect, the wait for the status line,
+# and every later read; and, in a stream, the longest run of keep-alive lines with no event between
+# them, since those keep the socket from ever timing out). It must stay BELOW the turn cap above it, or a provider that accepts a
# request and then goes silent is indistinguishable from a working turn: the cap fires first and the
# turn is cancelled with no served model, no tool call and no reason. The default is the 600 s this
# relay has always waited, far under MAX_TURN_SECONDS: a reasoning model answering a non-streaming
diff --git a/runner/tests/test_dsh_driver_stream_liveness.py b/runner/tests/test_dsh_driver_stream_liveness.py
new file mode 100644
index 00000000..1a547249
--- /dev/null
+++ b/runner/tests/test_dsh_driver_stream_liveness.py
@@ -0,0 +1,118 @@
+"""The DeepSeek Harness driver's own relay forwards a stream as it arrives and ends one that only
+keeps the connection warm. It is a second copy of the runner's relay loop (it holds the key in the
+driver's process), and it had the same read: `resp.read(4096)`, which waits for 4096 bytes or the end
+of the stream. See runner/tests/test_relay_upstream_failure.py for the measurement."""
+import http.client
+import http.server
+import json
+import pathlib
+import socket
+import sys
+import threading
+import time
+
+sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
+import dsh_driver # noqa: E402
+
+
+class _Upstream:
+ def __init__(self, mode: str):
+ self.mode = mode
+ self.sock = socket.socket()
+ self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ self.sock.bind(("127.0.0.1", 0))
+ self.sock.listen(4)
+ self.port = self.sock.getsockname()[1]
+ self.stop = threading.Event()
+ threading.Thread(target=self._serve, daemon=True).start()
+
+ def _serve(self):
+ while not self.stop.is_set():
+ try:
+ conn, _ = self.sock.accept()
+ except OSError:
+ return
+ try:
+ conn.recv(65536)
+ conn.sendall(b"HTTP/1.1 200 OK\r\ncontent-type: text/event-stream\r\n"
+ b"transfer-encoding: chunked\r\n\r\n")
+ if self.mode == "keepalive_forever":
+ line = b": PROCESSING\n\n"
+ while not self.stop.wait(0.1):
+ conn.sendall(b"%x\r\n" % len(line) + line + b"\r\n")
+ else:
+ first = b'data: {"choices":[{"delta":{"content":"first"}}]}\n\n'
+ rest = b'data: {"choices":[{"delta":{"content":" second"}}]}\n\ndata: [DONE]\n\n'
+ conn.sendall(b"%x\r\n" % len(first) + first + b"\r\n")
+ self.stop.wait(1.5)
+ conn.sendall(b"%x\r\n" % len(rest) + rest + b"\r\n0\r\n\r\n")
+ conn.close()
+ except OSError:
+ pass
+
+ def close(self):
+ self.stop.set()
+ try:
+ self.sock.close()
+ except OSError:
+ pass
+
+
+def _relay(monkeypatch, upstream_port: int, wait_s: float):
+ monkeypatch.setattr(dsh_driver, "UPSTREAM_BASE", f"http://127.0.0.1:{upstream_port}/v1")
+ monkeypatch.setattr(dsh_driver, "UPSTREAM_KEY", "sk-real")
+ monkeypatch.setattr(dsh_driver, "UPSTREAM_WAIT_S", wait_s)
+ srv = http.server.ThreadingHTTPServer(("127.0.0.1", 0), dsh_driver._Relay)
+ threading.Thread(target=srv.serve_forever, daemon=True).start()
+ return srv
+
+
+def _post(srv, timeout_s: float):
+ conn = http.client.HTTPConnection("127.0.0.1", srv.server_address[1], timeout=timeout_s)
+ conn.request("POST", "/v1/chat/completions",
+ body=json.dumps({"model": "m", "messages": [], "stream": True}),
+ headers={"authorization": "Bearer placeholder", "content-type": "application/json"})
+ return conn, conn.getresponse()
+
+
+def test_an_event_is_forwarded_when_it_arrives(monkeypatch):
+ up = _Upstream("first_event_then_pause"); srv = _relay(monkeypatch, up.port, 30.0)
+ try:
+ t0 = time.time()
+ conn, resp = _post(srv, 10)
+ first = resp.read1(4096)
+ waited = time.time() - t0
+ rest = resp.read()
+ conn.close()
+ finally:
+ up.close(); srv.shutdown()
+ assert b'"first"' in first and waited < 1.0, (waited, first[:80])
+ assert b"second" in rest and b"[DONE]" in rest
+
+
+def test_keep_alive_lines_alone_end_the_call_with_the_reason(monkeypatch):
+ up = _Upstream("keepalive_forever"); srv = _relay(monkeypatch, up.port, 1.0)
+ try:
+ t0 = time.time()
+ conn, resp = _post(srv, 15)
+ try:
+ body = resp.read()
+ ended = "complete"
+ except http.client.IncompleteRead as e:
+ body, ended = e.partial, "incomplete"
+ took = time.time() - t0
+ conn.close()
+ finally:
+ up.close(); srv.shutdown()
+ assert took < 6 and ended == "incomplete", (took, ended)
+ assert b'"code": "upstream_unavailable"' in body and b"no data" in body
+
+
+def test_the_wait_is_the_runners_figure_and_600_without_it(monkeypatch):
+ monkeypatch.delenv("HR_RELAY_UPSTREAM_TIMEOUT_S", raising=False)
+ assert dsh_driver._upstream_wait() == 600
+ monkeypatch.setenv("HR_RELAY_UPSTREAM_TIMEOUT_S", "180")
+ assert dsh_driver._upstream_wait() == 180
+ for junk in ("", "0", "-1", "soon"):
+ monkeypatch.setenv("HR_RELAY_UPSTREAM_TIMEOUT_S", junk)
+ assert dsh_driver._upstream_wait() == 600, junk
diff --git a/runner/tests/test_relay_upstream_failure.py b/runner/tests/test_relay_upstream_failure.py
index 85c60737..29afd7d2 100644
--- a/runner/tests/test_relay_upstream_failure.py
+++ b/runner/tests/test_relay_upstream_failure.py
@@ -67,6 +67,39 @@ class _Upstream:
self.stop.wait(30) # one event, then nothing and no end
conn.close()
continue
+ if self.mode == "keepalive_forever":
+ # what an aggregator sends while ITS upstream says nothing: comment lines, on
+ # and on. The socket is never silent and no answer ever comes.
+ conn.sendall(b"HTTP/1.1 200 OK\r\ncontent-type: text/event-stream\r\n"
+ b"transfer-encoding: chunked\r\n\r\n")
+ line = b": PROCESSING\n\n"
+ while not self.stop.wait(0.1):
+ conn.sendall(b"%x\r\n" % len(line) + line + b"\r\n")
+ conn.close()
+ continue
+ if self.mode == "first_event_then_pause":
+ first = b'data: {"choices":[{"delta":{"content":"first"}}]}\n\n'
+ rest = (b'data: {"choices":[{"delta":{"content":" second"},"finish_reason":"stop"}]}\n\n'
+ b'data: [DONE]\n\n')
+ conn.sendall(b"HTTP/1.1 200 OK\r\ncontent-type: text/event-stream\r\n"
+ b"transfer-encoding: chunked\r\n\r\n"
+ + b"%x\r\n" % len(first) + first + b"\r\n")
+ self.stop.wait(1.5) # the model is still writing
+ conn.sendall(b"%x\r\n" % len(rest) + rest + b"\r\n0\r\n\r\n")
+ conn.close()
+ continue
+ if self.mode == "split_fields":
+ # one event, written in pieces that cut the model name and the finish reason
+ conn.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
+ conn.sendall(b"HTTP/1.1 200 OK\r\ncontent-type: text/event-stream\r\n"
+ b"transfer-encoding: chunked\r\n\r\n")
+ for piece in (b'data: {"id":"c","mo', b'del":"served/', b'in-three-reads","choices":[{"delta":'
+ b'{"content":"OK"},"finish_', b'reason":"st', b'op"}]}\n\ndata: [DONE]\n\n'):
+ conn.sendall(b"%x\r\n" % len(piece) + piece + b"\r\n")
+ self.stop.wait(0.08)
+ conn.sendall(b"0\r\n\r\n")
+ conn.close()
+ continue
if self.mode == "stall_mid_body":
conn.sendall(b"HTTP/1.1 200 OK\r\ncontent-type: application/json\r\n"
b"content-length: 500\r\n\r\n" + b'{"id":')
@@ -205,3 +238,71 @@ def test_a_body_that_stops_arriving_is_a_provider_failure_not_an_empty_200(monke
up.close()
assert status == 504, (status, body[:200])
assert json.loads(body)["error"]["code"] == "upstream_unavailable"
+
+
+def test_keep_alive_lines_alone_are_a_provider_that_stopped_answering(monkeypatch):
+ """An aggregator trickles comment lines while its own upstream says nothing. The socket never
+ goes quiet, so the socket's timeout never fires, and a read that waits for 4096 bytes never
+ returns either: the client got nothing at all and nothing ended the call but the turn's cap.
+ Reproduced here at a stub; not caught on a live provider (the long turns that prompted the look,
+ 2026-10-04, turned out to be a model streaming reasoning without end, which sends events and is
+ not this). No EVENT for the relay's wait is the provider having stopped, whatever else arrives."""
+ import time
+ monkeypatch.setattr(rs, "HR_RELAY_UPSTREAM_TIMEOUT_S", 1.0)
+ up = _Upstream("keepalive_forever")
+ t0 = time.time()
+ try:
+ status, body = _relay_call(up.port, timeout_s=15)
+ finally:
+ up.close()
+ assert time.time() - t0 < 6, "the relay must end the call itself, near its own wait"
+ assert status == 200
+ assert body.endswith(b"<<INCOMPLETE>>"), body[-160:]
+ assert b'"code": "upstream_unavailable"' in body and b"no data" in body
+ assert up.requests == 1
+
+
+def test_an_event_reaches_the_client_when_it_arrives_not_when_4096_bytes_have(monkeypatch):
+ """The stream is forwarded as it is read. A read for 4096 bytes held a short first event in the
+ relay until the rest of the answer filled the block, so a person watched nothing and then
+ everything, and a first event followed by a stall never arrived at all."""
+ import time
+ up = _Upstream("first_event_then_pause")
+ base = f"http://127.0.0.1:{up.port}/v1"
+ relay_base, tok = rs._hermes_relay_route(base, "sk-real")
+ conn = http.client.HTTPConnection(relay_base.removeprefix("http://").removesuffix("/v1"), timeout=10)
+ try:
+ t0 = time.time()
+ conn.request("POST", "/v1/chat/completions",
+ body=json.dumps({"model": "m", "messages": [], "stream": True}),
+ headers={"authorization": f"Bearer {tok}", "content-type": "application/json"})
+ resp = conn.getresponse()
+ first = resp.read1(4096)
+ waited = time.time() - t0
+ rest = resp.read()
+ finally:
+ conn.close(); up.close(); rs._HERMES_RELAY["routes"].pop(tok, None)
+ assert b'"first"' in first and waited < 1.0, (waited, first[:80])
+ assert b"second" in rest and b"[DONE]" in rest
+
+
+def test_a_field_cut_across_several_reads_is_still_read_off_the_stream():
+ """The relay reads the served model and the finish reason off the bytes as they pass. Forwarding
+ what has arrived means a read can be a few bytes, so the field is looked for in the tail of the
+ stream so far, not in the tail of the one read before."""
+ up = _Upstream("split_fields")
+ base = f"http://127.0.0.1:{up.port}/v1"
+ relay_base, tok = rs._hermes_relay_route(base, "sk-real")
+ conn = http.client.HTTPConnection(relay_base.removeprefix("http://").removesuffix("/v1"), timeout=10)
+ try:
+ conn.request("POST", "/v1/chat/completions",
+ body=json.dumps({"model": "m", "messages": [], "stream": True}),
+ headers={"authorization": f"Bearer {tok}", "content-type": "application/json"})
+ resp = conn.getresponse()
+ body = resp.read()
+ flags = rs._HERMES_RELAY["routes"][tok][2]
+ assert b'"model":"served/in-three-reads"' in body and body.endswith(b"data: [DONE]\n\n")
+ assert flags.get("served_model") == "served/in-three-reads"
+ assert flags.get("last_finish") == "stop"
+ finally:
+ conn.close(); up.close(); rs._HERMES_RELAY["routes"].pop(tok, None)