Repository navigation
perf(runtime): prune at seams so each run extends the last request (CX3) - #254
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f5fda8e3ac
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The re-stub guard matched any result whose last line began with "[pruned: ", so a large read-only result ending that way was never pruned. Now content is skipped only when it is exactly the stub this call would produce (an optional header line, then the stub line with this call's name, arguments and hint). Addresses Codex review on #254. Refs: ENG-992, ENG-996
95e81f1 to
d9feda8
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9feda8188
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The re-stub guard matched any result whose last line began with "[pruned: ", so a large read-only result ending that way was never pruned. Now content is skipped only when it is exactly the stub this call would produce (an optional header line, then the stub line with this call's name, arguments and hint). Addresses Codex review on #254. Refs: ENG-992, ENG-996
d9feda8 to
3812ce1
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3812ce17fc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The re-stub guard matched any result whose last line began with "[pruned: ", so a large read-only result ending that way was never pruned. Now content is skipped only when it is exactly the stub this call would produce (an optional header line, then the stub line with this call's name, arguments and hint). Addresses Codex review on #254. Refs: ENG-992, ENG-996
3812ce1 to
a143e6e
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…ffect The live overflow prune knew effects only for this run's calls, so an earlier run's read-only result outside the built-in names (load_skill, spawn_agent, select_tools) stayed verbatim live but was stubbed on replay, breaking the cross-run extension at that seam. Assembly now also returns stored effects in result order; the claim and every reload carry them into the run, and the live prune classifies inherited results by them exactly as assembly does. Addresses the third Codex review on #254. Refs: ENG-992, ENG-996
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a9d4561f5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The re-stub guard matched any result whose last line began with "[pruned: ", so a large read-only result ending that way was never pruned. Now content is skipped only when it is exactly the stub this call would produce (an optional header line, then the stub line with this call's name, arguments and hint). Addresses Codex review on #254. Refs: ENG-992, ENG-996
…ffect The live overflow prune knew effects only for this run's calls, so an earlier run's read-only result outside the built-in names (load_skill, spawn_agent, select_tools) stayed verbatim live but was stubbed on replay, breaking the cross-run extension at that seam. Assembly now also returns stored effects in result order; the claim and every reload carry them into the run, and the live prune classifies inherited results by them exactly as assembly does. Addresses the third Codex review on #254. Refs: ENG-992, ENG-996
4a9d456 to
22f4104
Compare
…t a prompt - The re-stub guard's optional header must pass the same bounded header_line check the stub is built with, and the size must be a u64; a large first line before a stub-shaped line no longer escapes pruning. - A summarizer's live prune is not a seam (its request is not a transcript), and advance_prune_watermark fails instead of silently succeeding for a run with no prompt row. Addresses the fourth Codex review on #254. Refs: ENG-992, ENG-996
Assembly used to stub every stale read-only result between runs while a live run stubbed only on overflow, so a run's first request rewrote the middle of the previous run's last request and missed the provider cache. - Store schema 41 -> 42: sessions.prune_through_ordinal/_turn, a durable prune watermark. Assembly stubs as if the context ended at that turn; between seams each request extends the last one byte for byte. - Seams: the live overflow prune (RuntimeEvent::ContextPruned, committed before the stubbed request is sent) and the proactive threshold, which now moves the watermark and reassembles once before it compacts; if the stubbed context fits, no summarizer runs. - Fix: a live run re-stubbed its own stubs on later overflowing turns, so the stub named the previous stub's size and disagreed with replay. - Upgraded sessions start at their newest turn and assemble as before. context_assembly is within noise against the CX4 tip. Refs: ENG-992, ENG-996
The re-stub guard matched any result whose last line began with "[pruned: ", so a large read-only result ending that way was never pruned. Now content is skipped only when it is exactly the stub this call would produce (an optional header line, then the stub line with this call's name, arguments and hint). Addresses Codex review on #254. Refs: ENG-992, ENG-996
…window Codex flagged that a new session's unset watermark would leave a windowless model unstubbed until the 4 MiB backstop refused it. The backstop plans Compact, which runs the threshold seam; this end-to-end test pins that (it fails at run 156 with the seam disabled). tools.md names the backstop as part of the seam. Refs: ENG-992, ENG-996
…ffect The live overflow prune knew effects only for this run's calls, so an earlier run's read-only result outside the built-in names (load_skill, spawn_agent, select_tools) stayed verbatim live but was stubbed on replay, breaking the cross-run extension at that seam. Assembly now also returns stored effects in result order; the claim and every reload carry them into the run, and the live prune classifies inherited results by them exactly as assembly does. Addresses the third Codex review on #254. Refs: ENG-992, ENG-996
…t a prompt - The re-stub guard's optional header must pass the same bounded header_line check the stub is built with, and the size must be a u64; a large first line before a stub-shaped line no longer escapes pruning. - A summarizer's live prune is not a seam (its request is not a transcript), and advance_prune_watermark fails instead of silently succeeding for a run with no prompt row. Addresses the fourth Codex review on #254. Refs: ENG-992, ENG-996
main's AP4.2 (#257) took schema 42 (child_reports). The prune watermark is now step 43; step 42 accepts 43, every version list gains it, and the migration test upgrades from 42. The live-seam test's window grows with the larger tool block so its second prompt is not itself a seam, and it now asserts the watermark held still between the runs. Refs: ENG-992, ENG-996
2c48484 to
ee55433
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee5543345b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let mut ordered = Vec::new(); | ||
| for (message_index, message) in context.iter().enumerate() { | ||
| for (block_index, block) in message.content().iter().enumerate() { | ||
| if matches!(block, ContentBlock::ToolResult { .. }) { | ||
| ordered.push(effects.get(&(message_index, block_index)).copied()); |
There was a problem hiding this comment.
Exercise effect collection in the assembly benchmark
Production claims now use load_model_context_with_effects, so sessions with many tool results pay this additional full-context traversal and Vec allocation before their first request. However, the context_assembly benchmark still enters through bench_support::assemble, which calls load_model_context and skips this new work; consequently the ledger's within-noise result does not measure the changed production hot path. Update the benchmark entry point to collect effects as claims do.
AGENTS.md reference: AGENTS.md:L153-L154
Useful? React with 👍 / 👎.
| ### CX3 — Durable prune watermark | ||
| **Inputs:** CX2 | ||
| **Owned paths:** `crates/qq-core/src/sessions/{transcript,context}.rs`, schema (41 → 42), `crates/qq-core/src/lib.rs` (live overflow prune) | ||
| **Owned paths:** `crates/qq-core/src/sessions/{transcript,context}.rs`, schema (42 → 43; main took 42 for AP4.2), `crates/qq-core/src/lib.rs` (live overflow prune) |
There was a problem hiding this comment.
Declare the files CX3 actually owns
The slice still declares only transcript.rs, context.rs, the schema, and lib.rs as owned, but this commit also changes runtime/events.rs and the session claim, compaction, execution, settlement, store, and test modules. docs/plans/workflow.md makes edits outside a slice's owned paths blocking during review, so the plan must expand and coordinate this ownership or the out-of-scope edits must be removed before merge.
AGENTS.md reference: AGENTS.md:L14-L19
Useful? React with 👍 / 👎.
CX3: prune at seams so each run extends the last request
Spec:
docs/plans/compaction.md§ CX3 · ADR-0056 § 6 · Linear: ENG-996 (plan ENG-992)Stacked on #252 (CX4): merge that first.
Why
Between runs, assembly stubbed every read-only result older than 4 turns, but a live run stubbed only on overflow. Each run's first request therefore rewrote the middle of the previous run's last request: 6 of 18 Anthropic follow-ups within 5 minutes mostly missed the cache in the CX0 baseline.
What changed
sessions.prune_through_ordinalandsessions.prune_through_turn. Assembly stubs as if the context ended at that turn. Between seams, every request extends the last one byte for byte.RuntimeEvent::ContextPruned. The session commits the watermark before the stubbed request is sent, so the next run replays the same stubs.ContextPlan::Compact, the prompt first moves the watermark to the newest prior turn and reassembles, once per run. If the result fits, no summarizer runs, which is cheaper than compacting. Otherwise it compacts as before.prunable_stubnow never stubs a stub.Verification
cargo test --workspace: 2 105 passed, 13 ignored. Soak: 7 passed.fmtandclippy -D warningsare clean.each_run_extends_the_previous_runs_last_request_until_a_seam: the golden test that each run's first request extends the previous run's last one.a_live_prune_moves_the_watermark_and_the_next_run_extends_itthe_proactive_threshold_stubs_stale_reads_before_it_compactsversion_forty_one_gains_the_prune_watermark_at_the_newest_turn: the schema upgrade from 41.mark_prune_seam.Performance
context_assemblyassemble times, paired against the CX4 tip on the same host. They are within noise.The change costs one extra row read per assembly and one write per seam.
Compatibility
Next
CX5 is live qualification: re-run the CX0 query 7 days after this merges.