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.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
runner: pi's agent_end that will retry is not the end of the turn (#285)
Hao Lu2cc485153b7b
diff --git a/runner/server.py b/runner/server.pyindex 72df7317..93fa180f 100644--- a/runner/server.py+++ b/runner/server.py@@ -2603,6 +2603,16 @@ def _pi_to_claude(obj: dict, state: dict) -> list[dict]:{"type": "tool_result", "tool_use_id": obj.get("toolCallId") or "tool","is_error": bool(obj.get("isError")), "content": content}]}}]if t == "agent_end":+ if obj.get("willRetry"):+ # pi retries a retryable provider error itself (settings.retry: three attempts by+ # default), a reply stream cut mid-message among them, and says so on the agent_end it+ # emits before retrying. That agent_end is not the end of the turn: the attempt's error+ # and its half-streamed text give way to the retry's. Taking it as the end failed a+ # GDPval turn whose relay cut the last line of its reply (2026-09-26) while pi retried+ # and finished; the error also outlived a successful retry, so the true end failed too.+ state.pop("_pi_error", None)+ state["_pi_text"] = ""+ return []err = state.get("_pi_error")usage = dict(state.get("_pi_usage") or {})usage = {k: v for k, v in usage.items() if v}diff --git a/runner/tests/fixtures/pi_retry_after_stream_cut.jsonl b/runner/tests/fixtures/pi_retry_after_stream_cut.jsonlnew file mode 100644index 00000000..24decfd3--- /dev/null+++ b/runner/tests/fixtures/pi_retry_after_stream_cut.jsonl@@ -0,0 +1,25 @@+{"type": "session", "version": 3, "id": "01a0de42-e1f0-7251-9392-892edec68750", "timestamp": "2026-09-26T15:08:40.305Z", "cwd": "/tmp/tmpbe4srrt2"}+{"type": "agent_start"}+{"type": "turn_start"}+{"type": "message_start", "message": {"role": "user", "content": [{"type": "text", "text": "Say where the file is."}], "timestamp": 1790435320345}}+{"type": "message_end", "message": {"role": "user", "content": [{"type": "text", "text": "Say where the file is."}], "timestamp": 1790435320345}}+{"type": "message_start", "message": {"role": "assistant", "content": [{"type": "text", "text": "The file is saved as Rep"}], "api": "openai-completions", "provider": "hr", "model": "test-model", "usage": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "stopReason": "pending", "timestamp": 1790435320353, "responseId": "x"}}+{"type": "message_update", "usage": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "assistantMessageEvent": {"type": "text_start", "contentIndex": 0}}+{"type": "message_update", "usage": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "assistantMessageEvent": {"type": "text_delta", "contentIndex": 0, "delta": "The file is saved as Rep"}}+{"type": "message_update", "usage": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "assistantMessageEvent": {"type": "text_end", "contentIndex": 0, "content": "The file is saved as Rep"}}+{"type": "message_end", "message": {"role": "assistant", "content": [{"type": "text", "text": "The file is saved as Rep"}], "api": "openai-completions", "provider": "hr", "model": "test-model", "usage": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "stopReason": "error", "timestamp": 1790435320353, "responseId": "x", "errorMessage": "Stream ended without finish_reason"}}+{"type": "turn_end", "message": {"role": "assistant", "content": [{"type": "text", "text": "The file is saved as Rep"}], "api": "openai-completions", "provider": "hr", "model": "test-model", "usage": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "stopReason": "error", "timestamp": 1790435320353, "responseId": "x", "errorMessage": "Stream ended without finish_reason"}, "toolResults": []}+{"type": "agent_end", "messages": [{"role": "user", "content": [{"type": "text", "text": "Say where the file is."}], "timestamp": 1790435320345}, {"role": "assistant", "content": [{"type": "text", "text": "The file is saved as Rep"}], "api": "openai-completions", "provider": "hr", "model": "test-model", "usage": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "stopReason": "error", "timestamp": 1790435320353, "responseId": "x", "errorMessage": "Stream ended without finish_reason"}], "willRetry": true}+{"type": "auto_retry_start", "attempt": 1, "maxAttempts": 3, "delayMs": 2000, "errorMessage": "Stream ended without finish_reason"}+{"type": "agent_start"}+{"type": "turn_start"}+{"type": "message_start", "message": {"role": "assistant", "content": [], "api": "openai-completions", "provider": "hr", "model": "test-model", "usage": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "stopReason": "pending", "timestamp": 1790435322378}}+{"type": "message_update", "usage": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "totalTokens": 0, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "assistantMessageEvent": {"type": "text_start", "contentIndex": 0}}+{"type": "message_update", "usage": {"input": 20, "output": 5, "cacheRead": 0, "cacheWrite": 0, "reasoning": 0, "totalTokens": 25, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "assistantMessageEvent": {"type": "text_delta", "contentIndex": 0, "delta": "The file is saved as Rep"}}+{"type": "message_update", "usage": {"input": 20, "output": 5, "cacheRead": 0, "cacheWrite": 0, "reasoning": 0, "totalTokens": 25, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "assistantMessageEvent": {"type": "text_delta", "contentIndex": 0, "delta": "ort.pdf"}}+{"type": "message_update", "usage": {"input": 20, "output": 5, "cacheRead": 0, "cacheWrite": 0, "reasoning": 0, "totalTokens": 25, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "assistantMessageEvent": {"type": "text_end", "contentIndex": 0, "content": "The file is saved as Report.pdf"}}+{"type": "message_end", "message": {"role": "assistant", "content": [{"type": "text", "text": "The file is saved as Report.pdf"}], "api": "openai-completions", "provider": "hr", "model": "test-model", "usage": {"input": 20, "output": 5, "cacheRead": 0, "cacheWrite": 0, "reasoning": 0, "totalTokens": 25, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "stopReason": "stop", "timestamp": 1790435322378, "responseId": "x", "rawStopReason": "stop"}}+{"type": "auto_retry_end", "success": true, "attempt": 1}+{"type": "turn_end", "message": {"role": "assistant", "content": [{"type": "text", "text": "The file is saved as Report.pdf"}], "api": "openai-completions", "provider": "hr", "model": "test-model", "usage": {"input": 20, "output": 5, "cacheRead": 0, "cacheWrite": 0, "reasoning": 0, "totalTokens": 25, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "stopReason": "stop", "timestamp": 1790435322378, "responseId": "x", "rawStopReason": "stop"}, "toolResults": []}+{"type": "agent_end", "messages": [{"role": "assistant", "content": [{"type": "text", "text": "The file is saved as Report.pdf"}], "api": "openai-completions", "provider": "hr", "model": "test-model", "usage": {"input": 20, "output": 5, "cacheRead": 0, "cacheWrite": 0, "reasoning": 0, "totalTokens": 25, "cost": {"input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0, "total": 0}}, "stopReason": "stop", "timestamp": 1790435322378, "responseId": "x", "rawStopReason": "stop"}], "willRetry": false}+{"type": "agent_settled"}diff --git a/runner/tests/test_pi_normalize.py b/runner/tests/test_pi_normalize.pyindex 7cd308a3..1bba6338 100644--- a/runner/tests/test_pi_normalize.py+++ b/runner/tests/test_pi_normalize.py@@ -108,6 +108,17 @@ def test_final_is_last_message_not_a_concatenation():assert state["final"] == "Done. One file."+def test_an_agent_end_that_will_retry_is_not_the_end():+ """A VERBATIM capture of `pi -p --mode json` (0.85.1) against a provider that closed the first+ reply stream mid-message and answered the second: pi emits agent_end with willRetry, retries+ and finishes. One result, the retry's, with the retry's text alone."""+ events = [json.loads(line) for line in+ (pathlib.Path(__file__).parent / "fixtures" / "pi_retry_after_stream_cut.jsonl").read_text().splitlines()]+ chunks, state = _run(events, model="test-model")+ results = [e for e in _flat(chunks) if e["type"] == "result"]+ assert [(r["subtype"], r["result"]) for r in results] == [("success", "The file is saved as Report.pdf")]++def test_tool_events_map_to_tool_use_and_tool_result():chunks, _ = _run(HAPPY)evs = _flat(chunks)