Skip to content

feat(runtime): compact proactively near the window; stub stale reads mid-run (C2) - #58

Merged
lg2m merged 1 commit into
mainfrom
fix/context-usability-2-in-run-compaction
Sep 17, 2026
Merged

lg2m merged 1 commit into
mainfrom
fix/context-usability-2-in-run-compaction

Conversation

@lg2m

@lg2m lg2m commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

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 main after #55.

User-visible behavior

  • A long session no longer waits until its estimate crosses the window: once a new prompt's estimate is inside the last 10 % of the window, QQ compacts first and then runs the prompt (Codex compacts at 90 %, fx at 80 %).
  • A run that grows past the window during its own tool loop (many read_file/search/tree results) 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; Eligible runs with reducible history plan Compact when required > window − window/10. All other dispositions (already attempted, mid-run, summarizer, qq ask) are unchanged so exact-fit requests still send.
  • lib.rs execute loop: records this run's admitted call effects by provider call id; on turn ≥ 2, if estimate(bytes) + max_output > window, builds the (message, block) → effect map fix(runtime): preserve turn-scoped tool results and pruning (F01) #55 introduced and calls the existing prune_stale_tool_results on the live transcript, re-measures, and clears the compatible-occupancy chain (rewrite). transcript::prune_stale_tool_results is pub(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 --workspace green (qq-core 603 passed / 3 ignored); fmt; strict all-target clippy.
  • New: 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 the lib.rs change with Policy: 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.

…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.
@lg2m
lg2m force-pushed the fix/context-usability-2-in-run-compaction branch from b966791 to 42c6f78 Compare September 17, 2026 01:50
@lg2m
lg2m merged commit 3446c54 into main Sep 17, 2026
4 checks passed
@lg2m
lg2m deleted the fix/context-usability-2-in-run-compaction branch September 17, 2026 01:51
@integrate-your-mind

Copy link
Copy Markdown
Collaborator

Main supersedes this PR. I did not push the merge of main 5893573; the head stays at 2612786.

What happened. Main's f110e29 ("fix(ci): reconcile TypeScript catalog lockfile") fixed the same frozen-install break the other way round:

  • It set nub.lock's sdk/typescript specifier to the literal 5.9.3, matching main's sdk/typescript/package.json.
  • This PR instead changes that package.json entry to typescript: "catalog:".

Why I stopped. Merged locally, the diff against main reduces to that single package.json line, while the lock keeps main's specifier: 5.9.3. That pair is inconsistent, and nub install --frozen-lockfile would refuse it. That's the failure this PR existed to fix. Read from the files, not run.

Recommendation: close as superseded by f110e29. If the catalog form is preferred, the change has to set the lock specifier back to 'catalog:' in the same commit. That decision is for the manager or Romy.

🤖 Generated with Claude Code

https://claude.ai/code/session_011YSSvkVJ34kvxKGsmK71uZ

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.

2 participants