Repository navigation
fix(runtime): decide in-run context recovery on the measured estimate - #195
Merged
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This was referenced Sep 26, 2026
… (ENG-940) The run loop triggered stale-result stubbing and in-run compaction from the raw bytes/4 estimate while the session admission guard judged the prepared weight by the calibrated measured chain. On code-heavy transcripts (~3 B/t) the two diverge by a third: the loop said the request fit, skipped recovery, and the guard failed the run closed. Eight production runs on 2026-09-25 failed this way with `context_compaction_attempted = 0` after 21–1,091 completed turns; the reported request was 968,606 bytes / 256,359 tokens against a 272,000 window. One `estimate_input_tokens` closure now produces the figure every decision on the turn shares: the stub trigger, the compaction trigger, and the `compatible_input_tokens` handed to admission. The chain is passed by value so clearing it after an in-run summary is visible to the next estimate. Regression: `a_dense_tokenizer_compacts_in_run_instead_of_failing_at_the_guard` uses a new `Measured` harness wrapper that reports usage at 2 B/t over 24 mutating turns in a 16k window. It fails on the previous code with the exact production message and passes with at least one in-run compaction and every prompt-run request under the window by the provider's own ratio. No schema or protocol change. `plan_compile` benchmark unchanged.
lg2m
force-pushed
the
fix/eng-940-measured-context-recovery
branch
from
September 26, 2026 19:03
a7d22f5 to
dff7485
Compare
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.
Fixes ENG-940.
User-visible behavior
Long code-heavy runs no longer die with
context is estimated at N input tokens (B bytes) plus a 16384-token output reserve, over the selected model's window; no earlier history remains to compactwhen in-run compaction could have saved them. Eight production runs failed this way on 2026-09-25, all withcontext_compaction_attempted = 0after 21–1,091 completed turns; the reported request was 968,606 bytes / 256,359 tokens against a 272,000-token window.Cause
The run loop in
qq-core/src/lib.rstriggered stale-result stubbing and in-run compaction from the rawestimate_tokens(input_bytes)(bytes/4), while the session admission guard judged thePreparedweight bycompatible_input_tokens: the calibrated measured chain from RR7. On code-heavy transcripts (~3 B/t) the two diverge by a third. The loop said "fits", skipped recovery, and the guard failed the run closed.Design
One
estimate_input_tokensclosure computes the measured-chain figure (or the byte ratio when no compatible measurement covers the request) and every decision on the turn uses it: the stub trigger, the compaction trigger, and the weight handed to admission. The loop and the guard can no longer disagree. The chain is passed by value so clearing it after an in-run summary is visible to the next estimate. No schema or protocol change.Verification
a_dense_tokenizer_compacts_in_run_instead_of_failing_at_the_guard: aMeasuredharness wrapper reports usage at 2 B/t over 24 mutating turns in a 16k window. Fails onmainwith the exact production message; passes here with ≥1 in-run compaction and every prompt-run request under the window by the provider's own ratio.cargo test --workspace: all green (735 qq-core, 0 failures workspace-wide).cargo clippy --workspace --all-targets --all-features -- -D warningsclean;cargo fmt --checkclean.Performance
Hot path unchanged: the same arithmetic runs once per turn instead of twice (the
compatible_input_tokenscomputation moved earlier and is reused).cargo bench -p qq-core --bench plan_compileunchanged (compile 23,756 ns/op, digest 2,292 ns/op).Follow-up
ENG-952: an empty completed turn with no usage settles
completedinstead of retrying as a provider fault. Stacked on this branch next.