Repository navigation
perf(agent): stop doubling failed tool output in context - #418
Merged
Merged
Conversation
A failed tool call put its output in context twice. The tool result was capped at 32 KiB, but the recovery note copied the raw output, uncapped, into a user-role message that truncate/spill/prune never touch, so it rode every later step until compaction. A red test run measured 11.9k tokens of result plus a 23.9k-token note. The cap also kept only the head. The shell already keeps the tail of long output, so the model saw the middle of a test run: neither the start nor the `failures:` verdict, which only reached it through the note. - The recovery note now names the failed tool in one line and points at its result. - A fresh tool result over the cap keeps its first 8 KiB and its tail, with `[N chars omitted]` between them. Older results still shrink from the head as before. Measured on a captured request for one failing `cargo test`-shaped run: 35,790 -> 11,928 tokens, and the failure line is now in the result. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 7, 2026
This was referenced Nov 7, 2026
Merged
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.
First of four token-efficiency PRs. The findings come from requests captured with a scripted OpenAI-compatible mock server, counted with the o200k tokenizer.
Problem
When a tool call failed, its output went into the context twice:
The tool failed with error: {full output}. Please correct your approach.This copied the raw output with no cap, into aRole::Usermessage. Truncate, spill, prune and shake only touchRole::Toolmessages, so the note stayed in context and was re-sent on every step until compaction.The cap also kept only the head of the output. The shell layer already keeps the tail of long output, so for a long test run the model saw only the middle. Neither the start nor the
failures:line was in the tool result; the verdict only reached the model through the oversized note.Change
`bash` failed; its output is in the tool result above. Correct your approach.[N chars omitted]between them (cap_tool_text_head_tail). The result stays at or underTOOL_RESULT_MAX_CHARS, so the per-step head-only passes leave it alone until it is old.Measured
One
cargo test-shaped run: 4,000 lines,failures:as the last line, exit 101.failures:linefailures:and the exit codeThe saving repeats on every later step of the session until compaction.
Checks
whycodes-agent --lib764 passed;whycodes-session --lib171 passeddocs/internals/turn-loop.mdandcompaction.mdare updated🤖 Generated with Claude Code