Skip to content

perf(session): keep the tail of a spilled tool result, not just its head - #478

Merged
mrnasil merged 1 commit into
mainfrom
perf/spill-keeps-tail
Nov 25, 2026
Merged

mrnasil merged 1 commit into
mainfrom
perf/spill-keeps-tail

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 25, 2026

Copy link
Copy Markdown
Member

What

When an old tool result is spilled to disk (spill_old_tool_results), the transcript stand-in keeps 160 chars of the head and 240 of the tail around the pointer line, instead of the first 400 chars only:

warning: unused variable: `cache_depth`
  --> crates/cache/src/depth.rs:17:13
[27963 more chars; full output saved: .whycodes/scratch/artifacts/call_5.txt]
error: could not compile `bench` (lib) due to 1 previous error; 120 warnings emitted
(exit code: 101)

The tail starts on a whole line when it contains a line break.

Why

In the dev token workload the failed build's spilled stand-in showed the sandbox notice and the first warning — nothing about why it failed. Build and test output ends with what matters (the error, test result:, the exit code); cap_tool_text_to already keeps head + tail for fresh results for the same reason.

Cost

Same 400-char budget (SPILL_HEAD_CHARS → SPILL_KEEP_CHARS, plus SPILL_TAIL_CHARS = 240), still under the shake cap, so token use and the shrink-batch accounting are unchanged.

Tests

  • New spilled_build_output_keeps_its_last_whole_lines: head kept, tail starts on a line and ends with the error and exit code, omitted count right, under the shake cap; a body with no line break keeps a raw 240-char tail.
  • Existing spill_old_tool_results_keeps_head_and_pointer unchanged and passing (same omitted count).
  • session lib tests, agent spill/compact/turn tests, fmt, clippy, budgets; session line coverage measured locally (only the 3 pre-existing misses remain).

🤖 Generated with Claude Code

An old tool result moved to disk kept its first 400 chars and a pointer.
For a failed build that is the first warnings; the error and exit code
at the end were gone, so the model had to read the file back or rerun
the build to recall why it failed. The same 400 chars now split into a
160-char head and a 240-char tail (starting on a whole line when it
can), around the pointer line. The stand-in stays under the shake cap
and costs the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil
mrnasil merged commit 1d60ef8 into main Nov 25, 2026
7 checks passed
@mrnasil
mrnasil deleted the perf/spill-keeps-tail branch November 25, 2026 12:25
@mrnasil mrnasil mentioned this pull request Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant