Skip to content

perf(runtime): compaction writes a short narrative; QQ renders the exact record (CX0+CX1) - #239

Merged
lg2m merged 5 commits into
mainfrom
perf/eng-994-cx1-compaction-summary
Oct 5, 2026
Merged

lg2m merged 5 commits into
mainfrom
perf/eng-994-cx1-compaction-summary

Conversation

@lg2m

@lg2m lg2m commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

CX0 + CX1: compaction writes a short narrative; QQ renders the exact record

Spec: docs/plans/compaction.md (CX0, CX1) · ADR-0056 (Proposed) · Linear: ENG-992 (plan), ENG-993, ENG-994

Why

On the live store, compaction takes 110–390 s. Most of that time is the model retyping stored data: every user message, error and file list. Summaries are 20–36 KB. The Anthropic route always hits the 8 192-token cap and needs a continuation turn, and Codex takes up to 389 s. Retyped user messages are only "near-verbatim", and they degrade on every fold. The baseline is in docs/plans/progress/compaction.md.

What changed

  • The model writes a narrative only. It has five sections: Intent; Decisions and constraints; Work state; Open problems; Next step. The target is about 1 200 words, and the model is told not to restate the record.

  • QQ renders the record. It is built from stored rows in the commit transaction and stored after the narrative in the same session_compactions.summary row. It holds:

    • every user message and applied steering message, verbatim, newest kept first; older prompts are listed by ordinal for search_history;
    • the last assistant reply;
    • files modified and read, with paths taken from tool_calls arguments in SQL;
    • failed calls, first non-empty line.

    The record is bounded to 64 KiB, or an eighth of a declared window. It is rebuilt from rows at every compaction, so it stays exact however many times a session folds.

  • Migration always succeeds. Between runs, shrinkage is required of the narrative only, and the record is a bounded cost. So a stored six-section summary always folds into the new format, even when the record makes the assembly larger. In-run steps still count the record toward shrinkage.

  • Output cap. The summarizer uses the run's resolved cap, held to an eighth of a declared window and never below 8 192. This replaces the fixed 8 192 clamp.

  • Live equals replay. The in-run commit returns the stored text, so the live splice and replay render the same bytes.

  • Echoed records are dropped. If a reply echoes a record (a header at the start of a line), it is cut there, so the stored record is always QQ's.

How verified

  • cargo test --workspace after the rebase: 2 089–2 090 passed, 13 ignored. Two unrelated timeout tests (steering_during_a_slice_report_lands_before_the_continuation_notice, shutdown_settles_a_running_parent_and_its_in_flight_child) each failed once under full-workspace load and pass on re-run; the minimal qq-provider profile passes too.
    • headless::tests::turn_budget_cancels_before_a_silent_over_budget_turn_can_hang failed once with a 1 s timeout under full-workspace load.
    • It passes 6/6 alone on main and 3/3 alone on this branch, and the full suite re-run was green. It doesn't touch compaction.
  • cargo fmt --all -- --check and cargo clippy --workspace --all-targets --all-features -- -D warnings are clean.
  • New tests in sessions/tests/compaction.rs:
    • the_compaction_record_is_exact_bounded_and_cites_what_it_omits
    • an_in_run_record_holds_the_replaced_turns_steering_files_and_failures: uses a turn-ordinal gap and a case with no kept turn, and checks that the steering dropped by replay equals the steering in the record.
    • small_records_stay_within_budget_and_end_on_a_line: sweeps windows from 0 to 1M tokens.
    • the_summarizer_output_cap_is_the_run_cap_bounded_by_the_window
    • a_summary_that_echoes_a_record_keeps_only_its_narrative
    • repeated_compactions_keep_every_user_message_verbatim_without_the_model_retyping_them: five folds with a summarizer that never repeats a user message.
    • an_old_format_summary_folds_into_the_new_format_even_when_the_record_is_larger
    • an assertion that the live in-run splice equals replay.
  • Independent read-only review: no blockers. All should-fix items are resolved; the list is in the ledger entry.

Measurements

context_assembly at 10 000 archived runs, release, 300 iterations, A/B/C × 3. The stored summary length was varied through a temporary bench-only change, which is not committed.

Stored summary assemble
22 B (fixture) 57–71 µs
30 KB (typical six-section summary today) 61–78 µs
94 KB (worst case: 30 KB plus a full record) 104–124 µs

The record is rendered only at the compaction commit, never during assembly. The live latency win (CX5) will be measured after CX2/CX3 land.

Compatibility

  • PROTOCOL_VERSION, DESCRIPTOR_VERSION and the store schema are unchanged.
  • SessionCompacted.summary now includes the record (still truncated to 16 KiB).
  • Old summaries replay unchanged. The new preamble costs one cache miss per session.

Coordination

Deviation

The first commit is docs, not the failing test. Tests and implementation are in the CX1 commit.

Follow-ups

CX2 (cache-aligned summarizer), CX3 (prune watermark), CX4 (RunActivity::Compacting), CX5 (live qualification).

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

lg2m added 4 commits October 4, 2026 20:23
Plan docs/plans/compaction.md (CX0-CX5), ledger with the live-store
baseline (110-390 s per compaction, cold cache), and Proposed ADR-0055:
the summarizer writes a short narrative and QQ renders the exact record
from stored rows. Reserves ADR-0055 in progress/root.md (0054 is taken by

Refs: ENG-992, ENG-993
…act record (CX1)

The summarizer now writes five short sections (Intent; Decisions and
constraints; Work state; Open problems; Next step) instead of retyping
user messages, errors and file lists. At commit, in the same transaction,
QQ renders a bounded record from stored rows and stores it after the
narrative: every user message and applied steering verbatim (older
prompts listed by ordinal for search_history), the last reply, files
modified and read, and failed calls. The record is rebuilt from rows at
every compaction, so it stays exact across any number of folds.

- Between runs, shrinkage is required of the narrative; the record is a
  bounded cost, so a stored six-section summary always folds into the
  new format. In-run steps count the record too.
- The summarizer uses the run's resolved output cap, held to an eighth of
  a declared window (never below 8 192), instead of a fixed 8 192 clamp.
- The in-run commit returns the stored text, so the live splice and
  replay render the same bytes.
- No schema or protocol change.

Refs: ENG-992, ENG-994
@lg2m
lg2m force-pushed the perf/eng-994-cx1-compaction-summary branch from 7c4d4b6 to e0fd1a0 Compare October 5, 2026 03:36
@lg2m
lg2m added this pull request to stack #251 October 5, 2026 06:32
@lg2m
lg2m merged commit d3de299 into main Oct 5, 2026
3 of 4 checks passed
@lg2m
lg2m deleted the perf/eng-994-cx1-compaction-summary branch October 5, 2026 07:05
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.

1 participant