Repository navigation
feat(runtime): compact proactively near the window; stub stale reads mid-run (C2) - #58
Conversation
…ds mid-run (C2) Proactive: an eligible prompt run whose estimate enters the last tenth of the model window compacts before it sends, while the summarizer still has room, instead of waiting for the estimate to cross the window. Every other disposition is still judged at the window itself. In-run: mid-run overflow was a hard failure (`BetweenRunsOnly`). Before a later turn is refused for the window, the run now stubs its own read-only results older than the recency window in the live transcript, the same rewrite assembly applies between runs, then re-plans. Stored rows are untouched; the compatible-occupancy chain is dropped for the rewritten request. Full mid-run summarization stays deferred (needs a store cutoff inside a run). Tests: planner headroom by disposition; a run of eight 8 KiB reads on a 16k window completes with stubs (fails on the parent with the user's error class); a prompt inside the headroom compacts before it sends.
b966791 to
42c6f78
Compare
|
Main supersedes this PR. I did not push the merge of main 5893573; the head stays at 2612786. What happened. Main's
Why I stopped. Merged locally, the diff against main reduces to that single Recommendation: close as superseded by 🤖 Generated with Claude Code |
C2: proactive compaction at 90 % of the window; in-run stale-read stubbing
Spec: docs/plans/context-usability.md § C2. Follows #56 (C1, merged). Rebased on
mainafter #55.User-visible behavior
read_file/search/treeresults) no longer fails with "compaction is only available between model runs". Read-only results older than the last 4 model turns are stubbed in memory ([pruned: read_file … returned N bytes; call it again if needed], header kept) and the turn proceeds. Stored rows keep the verbatim result.What changed
sessions/context.rs:PROACTIVE_COMPACTION_HEADROOM_DIVISOR = 10;Eligibleruns with reducible history planCompactwhenrequired > window − window/10. All other dispositions (already attempted, mid-run, summarizer,qq ask) are unchanged so exact-fit requests still send.lib.rsexecute loop: records this run's admitted call effects by provider call id; on turn ≥ 2, ifestimate(bytes) + max_output > window, builds the(message, block) → effectmap fix(runtime): preserve turn-scoped tool results and pruning (F01) #55 introduced and calls the existingprune_stale_tool_resultson the live transcript, re-measures, and clears the compatible-occupancy chain (rewrite).transcript::prune_stale_tool_resultsispub(crate).Deferred, recorded in the ledger: true mid-run summarization. It needs a compaction cutoff that lands inside a run in the store; stubbing recovers the common case with no schema change.
How verified
cargo test --workspacegreen (qq-core 603 passed / 3 ignored); fmt; strict all-target clippy.context::tests::eligible_runs_compact_proactively_inside_the_last_tenth_of_the_window;compaction::a_run_that_outgrows_the_window_stubs_its_stale_reads_instead_of_failing(verified to fail without thelib.rschange withPolicy: context is estimated at 16016 input tokens … over the selected model's 16384-token window);compaction::a_prompt_inside_the_last_tenth_of_the_window_compacts_before_it_sends.Measurements
None: the in-run prune runs only on the overflow branch; the proactive check is two integer ops per turn.
Docs
docs/design/architecture.md§ run loop step 3; ledger.