Repository navigation
Conversation
Streamed tool-call deltas are parsed speculatively so a UI can render a call before it is complete. That parse was also what the finished call kept, so a stream that ended inside the arguments left a call the model never wrote: a write cut off at the output token limit reached the filesystem as a truncated file instead of failing. A finished call now carries only what the provider completed. `parseFinalToolArguments` still repairs invalid escapes, which restores the encoding the model meant without inventing structure, but it never fills in missing structure. When the arguments cannot be read the block keeps empty `arguments` and an `argumentsError`, and `validateToolArguments` refuses it, so the call comes back to the model as a tool error it can re-issue. Two provider gaps that let an unfinished call look finished are closed with it: an Anthropic stream that stops after `message_delta` without closing a tool block, and a block whose scratch buffer survived finalization, are both reported instead of being executed on the last streamed preview.
…o act on A provider that reported `length` with no visible text and no tool call ended the run as if it had finished. Nothing was recorded, nothing was retried, and the turn read as ordinary completion even though the model had spent its whole output budget and produced no work. The turn is now classified as `truncated_without_output` and reported as the run's failure on `agent_settled`, so print, JSON, subagent lanes and goal continuation all see it. It does not enter the empty-turn recovery loop: a recovery prompt would resend whatever filled the budget, which is how a degenerate reply becomes the input for the next one. A truncated turn that did produce text or a tool call keeps its existing handling — compaction owns that case, and `isRecoverableLength` still decides whether a compact-and-retry is worth asking for.
…view A reply that filled its whole output budget with a degenerate loop stays in the transcript, and every later request resends it. That makes one bad reply the input for the next one, so a single failure can seed a series of them. The cap is a size bound, not a repetition detector. Judging whether text looks repetitive needs a threshold that misfires on legitimate long output — a generated table, a file listing, a detailed report. The size of one reply is a fact, so the bound is derived from what the model could actually have written: its output limit priced at four characters a token, with a 400,000-character floor. An answer the model could legitimately emit is never shortened. Only the request view changes. The transcript, the session file and compaction boundaries keep the original, the most recent reply is left alone because it is the current turn, and the rewrite is deterministic so a shortened prefix stays byte-identical and the provider cache stays warm.
A model can keep issuing one call — reading the same file, running the same command — and nothing in the loop notices. The signal is deliberately exact: tool name plus canonical arguments, compared by length and a digest so a written file body never has to be held in memory. That is a fact about the request the client sent, not a guess about how repetitive the wording looks, so no ordinary answer can trip it. Three consecutive successful identical calls add one hidden notice to the next request. Ten stop the call and end the turn. Stopping is far from the reminder because repeats can be legitimate, and blocking is only for a loop that already ignored the notice. At most one notice joins a request, so a stuck run cannot spend prompt space on repeating it. A failed or blocked call resets the streak, because a retry after an error is not a repetition, and a new user message starts a new count.
liuedcson
requested review from
MelodyVAR,
Uking-xxx and
ZouR-Ma
as code owners
December 2, 2026 03:44
…igurable The repeat guard recognised one call repeating. A run that alternates between two or three calls — read, test, read, test — never extended a same-call streak, so it went unnoticed however long it ran. A cycle is now detected as the shortest period of 2 to 4 calls that repeats three times in a row, compared with the same key the streak uses: tool name plus the complete arguments. That comparison is what keeps ordinary work out of it. An `edit` that changes something followed by a `test` is keyed by different arguments, so a real edit/test cycle is `ABCB`, not `ABAB`, and does not match. Only a cycle reissuing the exact same calls does. The cycle is reported, never stopped. A repeat cycle can be a legitimate retry loop over external state, and a notice costs a few lines while a stop costs the run. One call repeating keeps its own limits — reported at three, stopped at ten — and is excluded from the cycle check so `AAAAAA` is not reported twice. Both are now controlled by `[tools] repeat_call_guard` (JSON config: `tools.repeatCallGuard`), default on. It is read on every call, so a reload takes effect without a new session.
…-tool-arguments # Conflicts: # packages/providers/src/api/anthropic-messages.ts # packages/providers/src/api/openai-completions.ts
Every configurable top-level key needs a row in the settings table, and the guard added one without it.
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.
Problem
A provider can cut a reply off in the middle of a tool call. The best-effort streaming parser filled in whatever arguments had arrived, so the call ran with arguments the model never finished writing: a
writetruncated at the output token limit reached the filesystem as a truncated file. The same reply then stayed in the transcript and was resent as history on every later request, so one bad turn could seed the next.Three separate gaps made that possible, a purely empty truncated turn had no handling at all, and a run stuck reissuing the same calls was never noticed.
Changes
A call whose arguments never arrived whole is refused (
providers)Streamed deltas are still parsed speculatively so a UI can render a call in progress. A finished call now carries only what the provider completed:
parseFinalToolArgumentsrepairs invalid escapes, which restores the encoding the model meant, but never fills in missing structure. When the arguments cannot be read, the block keeps emptyargumentsand anargumentsError, andvalidateToolArgumentsrefuses it, so the model gets a tool error it can re-issue.Two provider gaps that let an unfinished call look finished close with it: a stream that stops after
message_deltawithout closing a tool block, and a block whose scratch buffer survived finalization, are reported rather than executed on the last streamed preview.A turn that hit the output limit with nothing to act on ends the run (
coding-agent)A
lengthstop with no visible text and no tool call used to end as if it had finished. It is nowtruncated_without_outputand reported as the run's failure onagent_settled, so print, JSON, subagent lanes and goal continuation all see it. It does not enter the empty-turn recovery loop: a recovery prompt would resend whatever filled the budget.isRecoverableLengthis unchanged. It answers "is a compact-and-retry worth asking for", which is a different question from "was this truncated": a reply that spent its whole budget cannot be helped by compacting, so flipping its comparison would make every max-output stop trigger a retry it cannot fix.An oversized historical reply is bounded in the request view (
agent-core)The cap is a size bound, not a repetition detector. Repetition needs a threshold that misfires on a generated table, a file listing or a detailed report; the size of one reply is a fact. The bound follows what the model could actually have written — its output limit at four characters a token, with a 400,000-character floor — so a legitimate answer is never shortened.
A repeated or cycling tool call is noticed, and an unrecoverable repeat is stopped (
coding-agent)Two shapes are recognised, both keyed by tool name and the complete arguments:
ABAB,ABCABC) is reported once. It is never stopped: a cycle can be a legitimate retry loop over external state, and a notice costs a few lines while a stop costs the run.Comparing the complete arguments is what keeps ordinary work out. An
editthat changes something followed by atestis keyed by different arguments, so a real edit/test cycle isABCB, notABAB, and does not match. Only a cycle reissuing the exact same calls does.At most one notice joins a request, so a stuck run cannot spend prompt space repeating it. A failed or blocked call resets both counters — a retry after an error is not a repetition — and a new user message starts a new count.
Both guard shapes are controlled by
[tools] repeat_call_guard(JSON config:tools.repeatCallGuard), default on, read on every call so a reload takes effect without a new session.Behavior and compatibility
lengthstop with no output now fails the run instead of ending quietly.argumentsErroron a tool-call block and a thirdincompletevalue. Readers that ignore unknown fields are unaffected; a stored call withargumentsErroris refused again on replay rather than executed.[tools] repeat_call_guard = falseturns both the notice and the stop off. One switch covers both shapes; there is no finer split.Validation
pnpm run check— clean, including the regenerated config schema.packages/providers527 passed / 6 skipped;packages/agent-core583 passed / 1 skipped;packages/coding-agent5801 passed / 59 skipped.mainand passes here: truncated arguments, the unclosed-tool-block cases for two dialects, thetruncated_without_outputclassification, the repeat limits, cycle detection, the guard switch in TOML and JSON, and the reply cap.Limitations
main:json-mode-durability(three, from a stale localdistbuilt before a later export existed) andsubagent-invocation(one, a unix socket path over the macOS length limit). None of the files they exercise are touched here.