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
fix(pi): a non-prefix text revision must not paint the answer twice
richard-epsillac53d9a95c96a
diff --git a/runner/server.py b/runner/server.pyindex d2619af7..e90ea83d 100644--- a/runner/server.py+++ b/runner/server.py@@ -1269,10 +1269,17 @@ def _pi_to_claude(obj: dict, state: dict) -> list[dict]:if full:state["final"] = fullif full and full != streamed:- # self-healing tail: with no deltas the tail is the whole text; a non-prefix- # revision re-emits in full (duplicate beats missing)- tail = full[len(streamed):] if streamed and full.startswith(streamed) else full- return [{"type": "assistant", "message": {"content": [{"type": "text", "text": tail}]}}]+ if not streamed:+ # no deltas arrived — emit the whole text once (the no-streaming path)+ return [{"type": "assistant", "message": {"content": [{"type": "text", "text": full}]}}]+ if full.startswith(streamed):+ # normal self-healing: emit only the un-streamed tail+ return [{"type": "assistant", "message": {"content": [{"type": "text", "text": full[len(streamed):]}]}}]+ # Non-prefix revision (seen live: a kimi channel whose deltas and final text+ # disagree). The streamed text is already on the user's screen — re-emitting the+ # full text painted the whole answer twice. Emit nothing: the result event and+ # state["final"] already carry the authoritative text.+ return []return []if t == "tool_execution_start":return [{"type": "assistant", "message": {"content": [diff --git a/runner/tests/test_pi_normalize.py b/runner/tests/test_pi_normalize.pyindex 3da1c1d9..f438393a 100644--- a/runner/tests/test_pi_normalize.py+++ b/runner/tests/test_pi_normalize.py@@ -227,3 +227,22 @@ def test_build_vision_default_keeps_image_input(tmp_path):model="moonshotai/kimi-k3")mj = json.loads((tmp_path / "home" / ".pi" / "agent" / "models.json").read_text())assert mj["providers"]["hr"]["models"][0]["input"] == ["text", "image"]+++def test_non_prefix_revision_does_not_duplicate():+ """When the final text is NOT an extension of what streamed (a kimi channel did this live),+ re-emitting the full text paints the answer twice in the transcript. The deltas stay, the+ re-emit is suppressed, and the result event carries the authoritative final text."""+ stream = [+ {"type": "session", "id": "s3", "cwd": "/ws"},+ {"type": "message_start", "message": {"role": "assistant", "content": []}},+ {"type": "message_update", "assistantMessageEvent": {"type": "text_delta", "contentIndex": 0, "delta": "Thinking aloud…"}},+ {"type": "message_end", "message": _ok_msg("The real answer.", {"input": 1, "output": 1})},+ {"type": "agent_end"},+ ]+ chunks, state = _run(stream)+ texts = [c["text"] for e in _flat(chunks) if e.get("type") == "assistant"+ for c in e["message"]["content"] if c.get("type") == "text"]+ assert texts == ["Thinking aloud…"] # no duplicate paint+ result = next(e for e in _flat(chunks) if e.get("type") == "result")+ assert result["result"] == "The real answer." # the authoritative text still lands