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.

dsh: the relay reads a tool-call delta on an SSE line with no space after the colon (#572)

Rudy Mizrahi Celekli268674149ae4
diff --git a/runner/dsh_driver.py b/runner/dsh_driver.py
index 5ee8cde2..83c30e57 100644
--- a/runner/dsh_driver.py
+++ b/runner/dsh_driver.py
@@ -54,11 +54,20 @@ UPSTREAM_KEY = ""
def _rewrite_sse_line(line: bytes) -> bytes:
- """Drop empty-string id/name from tool_call deltas in one `data:` SSE line."""
- if not line.startswith(b"data: {"):
+ """Drop empty-string id/name from tool_call deltas in one `data:` SSE line.
+
+ The space after the field's colon is OPTIONAL in the SSE spec, so a provider that writes
+ `data:{...}` is conformant and its deltas must be rewritten too — welding the prefix to
+ `data: {` turned this whole function into a pass-through against such an upstream, which is
+ exactly the UNKNOWN_TOOL failure it exists to prevent. Every other SSE reader in this tree
+ tests `data:`; so does this one, with the JSON-object check kept but separate."""
+ if not line.startswith(b"data:"):
+ return line
+ payload = line[5:].removeprefix(b" ")
+ if not payload.startswith(b"{"):
return line
try:
- obj = json.loads(line[6:])
+ obj = json.loads(payload)
for ch in obj.get("choices") or []:
for tc in (ch.get("delta") or {}).get("tool_calls") or []:
if tc.get("id") == "":
diff --git a/runner/tests/test_dsh_normalize.py b/runner/tests/test_dsh_normalize.py
index 025ba66a..e40eb40b 100644
--- a/runner/tests/test_dsh_normalize.py
+++ b/runner/tests/test_dsh_normalize.py
@@ -150,6 +150,21 @@ def test_relay_drops_empty_id_and_name_only():
def test_relay_leaves_non_data_lines_alone():
assert dsh_driver._rewrite_sse_line(b"data: [DONE]") == b"data: [DONE]"
assert dsh_driver._rewrite_sse_line(b"") == b""
+ assert dsh_driver._rewrite_sse_line(b"event: delta") == b"event: delta"
+ assert dsh_driver._rewrite_sse_line(b"data:[DONE]") == b"data:[DONE]"
+
+
+def test_relay_rewrites_a_data_line_with_no_space_after_the_colon():
+ """The space after an SSE field's colon is optional, so `data:{...}` is a conformant
+ delta and its empty id/name must be stripped exactly as the spaced form's are."""
+ cont = (b'{"choices":[{"delta":{"tool_calls":[{"index":0,"id":"","type":"function",'
+ b'"function":{"name":"","arguments":"{\\"command\\""}}]},"finish_reason":null,"index":0}]}')
+ spaced = dsh_driver._rewrite_sse_line(b"data: " + cont)
+ tight = dsh_driver._rewrite_sse_line(b"data:" + cont)
+ assert tight == spaced
+ tc = json.loads(tight[6:])["choices"][0]["delta"]["tool_calls"][0]
+ assert "id" not in tc and "name" not in tc["function"]
+ assert tc["function"]["arguments"] == '{"command"'
# ── builder ─────────────────────────────────────────────────────────────────────────