Repository navigation
feat(tools): spill store and read_tool_result for cut tool outputs (T4) - #36
Merged
Merged
Conversation
When bounding cuts a tool result, the complete text (unmasked, up to 8 MiB) now travels with the result to the session store, which writes it to a new tool_spills table in the same transaction as the tool_calls row (schema 27 -> 28). The marker changes from `; not stored]…` to `; full output t:<tool>:<call8>:<digest8>; read_tool_result offset=N]…` where the call prefix is the tool call id and the digest is the SHA-256 of the stored bytes; direct runs keep no store and their markers still say not stored. The turn-budget re-cut points its marker at the same handle. read_tool_result pages (offset/limit, line-numbered like read_file) or searches (query, regex) within a stored output. Explicit reads return exact bytes: the model asked for a range of something it already produced, and masking there would make .env debugging impossible; the inline preview stays masked. Handles are session-scoped: another session reads handle_foreign_session, never data. Typed failures: handle_invalid, spill_missing, spill_evicted, handle_foreign_session, invalid_regex, invalid_offset, invalid_limit, range_out_of_bounds. Bounds: 8 MiB per item, 64 MiB per session with oldest-finished-run eviction that nulls content but keeps the row so the handle answers spill_evicted rather than spill_missing. Rows delete with the session. Declared only for session runs (ToolHost::ReadToolResult, installed by SessionSpillReader); prunable; TUI row `Recall <handle> L…`.
This was referenced Sep 14, 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.
T4: spill store and
read_tool_result— a cut result is a pointer, not a lossSpec: docs/plans/tool-layer.md § D4 Linear: ENG-774 ADR: docs/adr/0019-spill-handles.md Follows: #35 (T3)
What changed
User-visible
…[qq: 41,207 bytes / 1,142 lines omitted; full output t:shell:9f3a2c1d:b7e0d4a2; read_tool_result offset=213]…instead of
…; not stored]…. Direct runs (qq runwithout a session) have no store and keepnot stored.read_tool_result(session runs only):offset/limitpage the stored output line-numbered likeread_file;query(+regex) returns matching lines asL<n>: text. Pages stop on a whole line at 32 KiB and namenext=..envdebugging impossible. The inline preview stays masked (tested both ways in one flow).handle_foreign_session, never data.turn budget reached) points its marker at the same handle.handle_invalid,spill_missing(no row, or digest disagrees),spill_evicted,handle_foreign_session,invalid_regex,invalid_offset,invalid_limit,range_out_of_bounds.read_tool_resultpath; TUI rowRecall <handle> L1000-1002 of 1501 lines/2/3 hits;read_tool_resultis prunable and in the config vocabulary.Store (the part that needs the second reviewer)
tool_spills(tool_call_id PK, session_id, run_id, tool, digest, content BLOB, content_bytes, omitted_from_line, created_at_ms, evicted_at_ms)+ index on(session_id, created_at_ms). Created by the schema-28 step with ahas_tableguard; 22 existing migration tests bumped to"28", one new test for 28.finish_tool_callinserts the spill between the resultUPDATEandappend_event, in the samebegin_unittransaction — replay and crash recovery see both or neither. The event envelope does not carry the spill (would blowMAX_PERSISTED_EVENT_BYTES).SUM(content_bytes)for the session exceeds 64 MiB, the oldest rows of runsNOT IN ('running','preparing')havecontentset to NULL andevicted_at_msstamped. Rows are kept so the handle answersspill_evicted, notspill_missing. The running run's own spills are never evicted.read_tool_spillruns onPriority::AwaitControl(same reasoning assearch_history): prefix range scan on the PK, digest prefix must agree, session must match.delete_idle_sessiondeletestool_spillsbysession_idbeforetool_calls.qq sessions pruneonly touches sessions with no runs, which have no spills.Runtime / boundary
ToolOutput::boundedclones the text only whenlen() > max_bytes || len() > max_lines(a length compare on the common path), before masking, and keeps it asSpillRecord { text, digest, omitted_from_line }when the cut actually happened and the text ≤ 8 MiB.bound_textwrites the marker provisionally (not stored) and recordsomitted_from_line; the runtime'scite_spillfinalizes it with the handle before the yield, only when aSpillReaderis installed. The digest is of the complete text, so it is known at the boundary; the store trusts it.RuntimeEvent::ToolCallFinishedgainsspill: Option<SpillRecord>;execution.rspasses it tofinish_tool_call.ToolHost::ReadToolResult,StaticFilter.read_tool_result,SessionSpillReader(mirrorsSessionHistorySearcher),runtime/spill.rs(spec, handle parser, renderer).MARKER_RESERVE_BYTES160 → 224 to fit the handle and offset within the bound.How verified
cargo test --workspace: 1363 passed / 0 failed; provider minimal profile 162; fmt andclippy -D warningsclean.a_cut_result_names_a_handle_the_model_can_page_and_search_exactlyruns a realshellproducing 90 KiB, asserts the 16 KiB inline result carriest:shell:<this call's id8>:…, masksAKIA…, and that the next turn'sread_tool_result offset=1000 limit=3returns line 1000 exact and unmasked withL1000-1002/1501 next=1003. Store tests cover same-transaction commit, exact read, digest mismatch → missing, foreign session, 3×30 MiB eviction keeping rows, schema migration, and session deletion emptying the table.not stored, turn-budget marker carries the handle.Measurements
tool_dispatchA/B (pinned core, 10 pairs, median)store_output_batch(fairness gate)Evidence:
target/qq-perf/t4-2026-09-14/(untracked).Docs
docs/adr/README.md,root.mdADR row → written.docs/design/tools.md: § Output Bounding marker updated; § Spilled Outputs (new).Compatibility
read_tool_resultis a session-only static tool likesearch_history).not storedmarkers replay as-is.Deviations from the plan (in the ledger)
bound_text, so direct runs stay honest.querymode has nocontextargument (fixed at 0 as the plan states).search_historydoes not yet search spills.Follow-ups