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.

CheetahClaws: the verdict counts completions, not positions; console: a failure line stays last (#289)

github-actions[bot]36653c5d70f3
diff --git a/runner/cheetahclaws_driver.py b/runner/cheetahclaws_driver.py
index c3cb04af..0fe278b9 100644
--- a/runner/cheetahclaws_driver.py
+++ b/runner/cheetahclaws_driver.py
@@ -217,14 +217,18 @@ class Pairing:
return f"cc{self.n}"
-def verdict(messages: list, start: int, notices: list[str], budget_hit: bool) -> dict:
+def verdict(messages: list, completions: int, notices: list[str], budget_hit: bool) -> dict:
"""How the turn ended, read off the history the loop left behind.
- `start` is the index of the user message this turn appended. The loop appends an assistant
- message only for a completion that came back, and its own loop guards append one of their own
- whose text is the guard's notice; anything else that ends the loop (a failed provider call, an
- open circuit breaker) leaves the history ending on the user's message or on a tool result."""
- last = messages[-1] if len(messages) > start else None
+ `completions` is how many assistant messages the loop appended this turn (its TurnDone events).
+ The loop appends one only for a completion that came back, and its own loop guards append one
+ of their own whose text is the guard's notice; anything else that ends the loop (a failed
+ provider call, an open circuit breaker) leaves the history ending on the user's message or on
+ a tool result. The history is read from its end and never by position: the loop compacts
+ and REPLACES `state.messages` when the context is full (agent.py maybe_compact and
+ _force_compact), so an index taken before the turn points nowhere after it; a muse-spark turn
+ that answered in full was reported as "no completion" that way (hr-test, 2026-09-27)."""
+ last = messages[-1] if completions and messages else None
role = (last or {}).get("role")
content = (last or {}).get("content")
text = content if isinstance(content, str) else ""
@@ -332,7 +336,6 @@ def main() -> int:
calls = {"n": 0}
pairing = Pairing()
notices: list[str] = []
- start = len(state.messages)
try:
with contextlib.redirect_stdout(sys.stderr):
events = run(job["prompt"], state, config, system_prompt,
@@ -373,7 +376,7 @@ def main() -> int:
budget_hit = bool(budget) and calls["n"] >= budget and (
not state.messages or state.messages[-1].get("role") != "assistant"
or bool(state.messages[-1].get("tool_calls")))
- out = verdict(state.messages, start, notices, budget_hit)
+ out = verdict(state.messages, calls["n"], notices, budget_hit)
_save(cc_session, state, config)
_emit("__hr_result", {**out, "session_id": sid, "calls": calls["n"],
"seconds": round(time.time() - _T0, 2)})
diff --git a/runner/tests/test_cheetahclaws_backend.py b/runner/tests/test_cheetahclaws_backend.py
index 21eecedf..815c33e5 100644
--- a/runner/tests/test_cheetahclaws_backend.py
+++ b/runner/tests/test_cheetahclaws_backend.py
@@ -101,23 +101,31 @@ def test_a_hint_that_names_the_clis_slash_commands_is_cut_from_the_reason():
def test_the_verdict_is_the_historys_shape_not_the_text():
user = {"role": "user", "content": "hi"}
- # a model that WRITES a failure line is still an answer
+ # a model that WRITES a failure line is still an answer (one completion came back)
said = [user, {"role": "assistant", "content": "[Failed — AuthenticationError: quoted]"}]
- assert drv.verdict(said, 0, [], False)["ok"] is True
- # a call that never came back leaves the history on the user's message
+ assert drv.verdict(said, 1, [], False)["ok"] is True
+ # a call that never came back leaves the history on the user's message, no completion counted
v = drv.verdict([user], 0, ["[Failed — APIConnectionError: Connection error.. Hint: x]"], False)
assert v["ok"] is False and v["reason"].startswith("Failed — APIConnectionError")
- # or on a tool result, when the call after a tool failed
+ # or on a tool result, when the call after a tool failed (one completion, then nothing)
tool = [user, {"role": "assistant", "content": "", "tool_calls": [{"id": "1", "name": "Bash", "input": {}}]},
{"role": "tool", "tool_call_id": "1", "content": "x"}]
- assert drv.verdict(tool, 0, [], False)["ok"] is False
+ assert drv.verdict(tool, 1, [], False)["ok"] is False
# the loop guard's own message is the CLI stopping the model, not an answer
lg = [user, {"role": "assistant", "content": "[Loop guard] Same tool call repeated 3 times — stopping."}]
- v = drv.verdict(lg, 0, [], False)
+ v = drv.verdict(lg, 1, [], False)
assert v["ok"] is False and v["reason"].startswith("Loop guard")
- # a resumed history's earlier answer is not this turn's answer
+ # a resumed history's earlier answer is not this turn's answer: no completion this turn
resumed = [{"role": "user", "content": "a"}, {"role": "assistant", "content": "old answer"}, user]
- assert drv.verdict(resumed, 2, [], False)["ok"] is False
+ assert drv.verdict(resumed, 0, [], False)["ok"] is False
+ # the loop compacted and REPLACED the history during the turn (agent.py maybe_compact /
+ # _force_compact): the list is shorter than it was when the turn began, and its last message
+ # is this turn's answer all the same. Read by position it looked like no completion; a
+ # muse-spark turn on hr-test that answered in full was failed that way (2026-09-27).
+ compacted = [{"role": "assistant", "content": "Understood. I have the context from the previous conversation. Let's continue."},
+ user, {"role": "assistant", "content": "Updated the deck with the refined text style."}]
+ v = drv.verdict(compacted, 2, [], False)
+ assert v["ok"] is True and v["final"].startswith("Updated the deck")
def test_the_step_budget_ends_the_turn_as_max_turns():
diff --git a/ui/src/lib/conversation.ts b/ui/src/lib/conversation.ts
index fe0ae19f..9becdab5 100644
--- a/ui/src/lib/conversation.ts
+++ b/ui/src/lib/conversation.ts
@@ -36,15 +36,30 @@ export interface UserMsg { role: 'user'; text: string; attachments?: { name: str
export interface ToolStep { name: string; args: string; result?: string; callId?: string }
// An assistant turn is an ORDERED list of blocks appended as events arrive, so tool activity is
// interleaved with prose in real time (not all tools hoisted to the top).
-export type Block = { kind: 'text'; text: string } | { kind: 'tools'; reasoning: string; steps: ToolStep[] };
+export type Block = { kind: 'text'; text: string; error?: true } | { kind: 'tools'; reasoning: string; steps: ToolStep[] };
-// The failure sentence reaches a message on two paths, the turn's own stream and the settled
-// read of the turns feed, and the second arrival must not print it twice: a message that already
-// ends with this exact error keeps it once (seen as "Error: X Error: X" under a refused turn).
-function withError(blocks: Block[], msg: string): Block[] {
+// The failure sentence is its own block, marked, and it stays LAST. It reaches a message on two
+// paths, the turn's own stream and the settled read of the turns feed, and the second arrival must
+// not print it twice (seen as "Error: X Error: X" under a refused turn). And a turn's text and tool
+// steps can still arrive after the failed event (the trace chunk that carries them lands after
+// the status): appended blindly they glued onto the error line and the feed then wrote the error
+// again ("...from the provider20pt", a CheetahClaws turn on 2026-09-27), so every append below
+// goes in front of a trailing error block.
+const isErrorBlock = (b: Block | undefined): boolean => !!b && b.kind === 'text' && b.error === true;
+function beforeError(blocks: Block[], apply: (rest: Block[]) => Block[]): Block[] {
const last = blocks[blocks.length - 1];
- if (last && last.kind === 'text' && last.text.trimEnd().endsWith('Error: ' + msg)) return blocks;
- return withText(blocks, '\n\nError: ' + msg);
+ return isErrorBlock(last) ? [...apply(blocks.slice(0, -1)), last as Block] : apply(blocks);
+}
+const addText = (blocks: Block[], d: string): Block[] => beforeError(blocks, (r) => withText(r, d));
+const addReasoning = (blocks: Block[], d: string): Block[] => beforeError(blocks, (r) => withReasoning(r, d));
+const addStep = (blocks: Block[], step: ToolStep): Block[] => beforeError(blocks, (r) => withStep(r, step));
+const addResult = (blocks: Block[], callId: string, output: string): Block[] => beforeError(blocks, (r) => withResult(r, callId, output));
+function errorBlock(blocks: Block[], msg: string): Block {
+ return { kind: 'text', text: (blocks.length ? '\n\n' : '') + 'Error: ' + msg, error: true };
+}
+function withError(blocks: Block[], msg: string): Block[] {
+ if (blocks.some((b) => isErrorBlock(b) && b.kind === 'text' && b.text.trimEnd().endsWith('Error: ' + msg))) return blocks;
+ return [...blocks, errorBlock(blocks, msg)];
}
export interface AsstMsg { role: 'assistant'; blocks: Block[]; files: RespFile[]; status: 'running' | 'done' | 'failed' | 'cancelled' | 'incomplete';
/** Why an incomplete turn is incomplete (max_steps | timeout | interrupted) — from the
@@ -78,7 +93,7 @@ export function msgsFromTurns(turns: SessionTurn[]): { msgs: Msg[]; running: boo
if (t.assistant) blocks.push({ kind: 'text', text: t.assistant });
// a failed turn's reason, the line the live stream appended as its error event
const why = (t as { error?: string }).error;
- if (why && (t.status === 'failed' || t.status === 'error')) blocks.push({ kind: 'text', text: (t.assistant ? '\n\n' : '') + 'Error: ' + why });
+ if (why && (t.status === 'failed' || t.status === 'error')) blocks.push(errorBlock(blocks, why));
const st: AsstMsg['status'] = t.status === 'failed' || t.status === 'error' ? 'failed'
: t.status === 'cancelled' ? 'cancelled'
: (t.status === 'incomplete' || t.status === 'max_turns' || t.status === 'timeout') ? 'incomplete'
@@ -225,19 +240,19 @@ function applyBusEvent(sid: string, responseId: string, ev: Record<string, unkno
break;
}
case 'response.reasoning_summary_text.delta':
- busUpdateLast(sid, (a) => { a.blocks = withReasoning(a.blocks, ev.delta as string); }); break;
+ busUpdateLast(sid, (a) => { a.blocks = addReasoning(a.blocks, ev.delta as string); }); break;
case 'response.output_item.added': {
const item = ev.item as Record<string, unknown>;
if (item?.type === 'function_call') _busFn[`${sid}:${ev.output_index}`] = { name: item.name as string, callId: (item.call_id as string) || '' };
- else if (item?.type === 'function_call_output') busUpdateLast(sid, (a) => { a.blocks = withResult(a.blocks, (item.call_id as string) || '', String(item.output ?? '')); });
+ else if (item?.type === 'function_call_output') busUpdateLast(sid, (a) => { a.blocks = addResult(a.blocks, (item.call_id as string) || '', String(item.output ?? '')); });
break;
}
case 'response.function_call_arguments.done': {
const fn = _busFn[`${sid}:${ev.output_index}`] || { name: 'tool', callId: '' };
- busUpdateLast(sid, (a) => { a.blocks = withStep(a.blocks, { name: fn.name, args: (ev.arguments as string) || '', callId: fn.callId }); }); break;
+ busUpdateLast(sid, (a) => { a.blocks = addStep(a.blocks, { name: fn.name, args: (ev.arguments as string) || '', callId: fn.callId }); }); break;
}
case 'response.output_text.delta':
- busUpdateLast(sid, (a) => { a.blocks = withText(a.blocks, ev.delta as string); }); break;
+ busUpdateLast(sid, (a) => { a.blocks = addText(a.blocks, ev.delta as string); }); break;
case 'response.output_text.annotation.added': {
const a = ev.annotation as Record<string, unknown>;
if (a?.type === 'container_file_citation') busUpdateLast(sid, (m) => { m.files = withFile(m.files, { container_id: a.container_id as string, file_id: a.file_id as string, filename: a.filename as string }); });
@@ -527,10 +542,10 @@ export function useConversationTurn({ harnessId, sessionId, target, onRan, onSes
}
onSession?.(sid);
},
- onReasoningDelta: (d) => updateLast((a) => { a.blocks = withReasoning(a.blocks, d); }),
- onToolCall: (name, args, callId) => updateLast((a) => { a.blocks = withStep(a.blocks, { name, args, callId }); }),
- onToolResult: (callId, output) => updateLast((a) => { a.blocks = withResult(a.blocks, callId, output); }),
- onTextDelta: (d) => updateLast((a) => { a.blocks = withText(a.blocks, d); }),
+ onReasoningDelta: (d) => updateLast((a) => { a.blocks = addReasoning(a.blocks, d); }),
+ onToolCall: (name, args, callId) => updateLast((a) => { a.blocks = addStep(a.blocks, { name, args, callId }); }),
+ onToolResult: (callId, output) => updateLast((a) => { a.blocks = addResult(a.blocks, callId, output); }),
+ onTextDelta: (d) => updateLast((a) => { a.blocks = addText(a.blocks, d); }),
onFile: (f) => updateLast((a) => { a.files = withFile(a.files, f); }),
onError: (msg) => updateLast((a) => { a.blocks = withError(a.blocks, msg); }),
onDone: (status, response) => {