Repository navigation
fix(agent-loop): one invariant for the five ways a turn dies silently (supersedes #869 #872 #873 #874 #876 #879) - #880
Open
leonsong09 wants to merge 6 commits into
Conversation
added 6 commits
November 14, 2026 10:46
…ing-only reply as failure
leonsong09
force-pushed
the
fix/silent-truncation-umbrella
branch
from
November 14, 2026 02:46
49ef32e to
825d3e5
Compare
This was referenced Nov 14, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #863, #860, #866, #875, #877.
Why one PR
These five reports looked unrelated when I filed them, but they are one failure mode wearing five masks: the loop treats "nothing happened" as "the model finished". A reply that hit a wall — truncated mid-stream, empty, cut off before the tool call, or a tool call emitted as plain text — all end up in the same place: no error, no retry, task quietly over.
Splitting them into #869 / #872 / #873 / #874 / #876 / #879 made each diff small, but it also meant a reviewer had to hold five interlocking invariants in their head to judge any one of them. This branch merges all six in that order, and the tests for the merged result are the deliverable: every shape from #863 plus the retry paths play through one code state.
Merged cleanly, no conflicts.
pytest tests/test_text_tool_call.py tests/test_stream_retry.py -q→ 8 passed.The invariant
_has_usable_output()andtextual_tool_residue()are two halves of that sentence. Everything else follows.What's in it
1.
llmcore.py— pseudo-XML tool calls are reconstructed, never half-executed_parse_text_tool_callsonly understood a trailingtool_useJSON array plus<tool_use>/<tool_call>wrappers. Every spelling that upstreams actually emit fell through todo_no_tool, where no guard matched, so the turn ended silently.<code_run><script>…<parameter name="script"><file_read">(stray quote)<type>-wrapped parameters||DSML||invoke<function=code_run><parameter=script></code_run><code_run></code_run>H is the reason the guard sits inside
_parse_text_tool_callsrather than indo_no_tool: once a truncated call becomes a realtool_call, the normal response path executes it anddo_no_toolis never reached. Two cases pinned — the cut that leaves a syntax error, and the cut that happens to leave valid Python.Argument names are parsed independently of the tool tag (
<parameter name="k">,<parameter=k>,||DSML||prefix all share one expression), so shape C no longer producesdsml_parameter.textual_tool_residue()returnsunclosed/empty/orphan/invalid;do_no_toolretries on any of them.2.
ga.py— truncation markers only match at the taildo_no_tool()fired on a marker appearing anywhere in the trailing window. So a reply that merely quoted[!!! 流异常中断 ...]— which happens whenever the model debugs this check, documents it, or writes a regression test for it — was discarded wholesale. The failure is self-triggering: the more thoroughly the model explains the mechanism, the more reliably it trips.llmcorealways appends these markers at the very end, so anchoring to$is both sufficient and precise. Two markers thatllmcoredoes emit were also missing from the check.3.
llmcore.py— never replay what the caller already saw_stream_with_retryretried onTimeout / ConnectionError / ChunkedEncodingErrorregardless of whether it had already yielded, so the consumer receivedAAABBBthree times.MixinSessiondid the same at channel level. Now: ifstreamed, don't retry — append the interruption marker (same convention as the existing generic branch) and leave the next call pointed at a different channel.4.
llmcore.py— empty / thinking-only replies are failuresThe emptiness test was
not e.value and not streamed, which only requiresblocksto be non-empty. A response with athinkingblock and no text and notool_callis non-empty — so it was reported as success, and the user got a blank screen with the system insisting all was well._has_usable_output()now requires non-blanktextor atool_use(a pure tool-call response still counts, so nothing is over-rejected).5.
llmcore.py— emptytool_use_idresults keep their orderMockToolCallreconstructs from text withid='', and that branch prepends, so three results arrived asR3, R2, R1— the opposite of theappend-based path used when ids exist. Collected in order intoorphan_tails, appended after the loop. Byte-identical when all ids are present — that path is untouched.6.
ga.py—code_runno longer sleeps a flat secondtime.sleep(1)before joining the reader thread. Replaced witht.join(0.05), plus aprocess.wait(timeout=5)fallback — because the reader exiting does not mean the process was reaped, andpoll()returnsNone, losing the exit code. That regression is in the diff because the first version of this patch had it.Medians from 5,187 recorded response gaps: 1.000s exactly, 2,012 of them,
code_runresponsible for 1,912.7.
agentmain.py—--no-reply-wait--taskwaits 600s for a follow-up round, which is right for supervised sessions and pure idle for schedulers. Report written at 20:41, process killed at 21:00 withrc=-999, three days running. Opt-in flag; default unchanged.Scope
agentmain.py+9,ga.py+64/-8,llmcore.py+324, and two new test files (351 lines). No frontend, no channel config, no schedule changes.Nothing here touches files outside the agent loop, so it can be reviewed and landed independently of the TUI perf series (#870 / #871, merged separately).
Verification
Both suites are offline and deterministic —
test_stream_retry.pydrives a localThreadingHTTPServerfake SSE, no network.