Skip to content

perf(runtime): compaction requests share the session's prompt cache (CX2) - #250

Merged
lg2m merged 2 commits into
perf/eng-994-cx1-compaction-summaryfrom
perf/eng-995-cx2-cache-aligned-summarizer
Oct 5, 2026
Merged

lg2m merged 2 commits into
perf/eng-994-cx1-compaction-summaryfrom
perf/eng-995-cx2-cache-aligned-summarizer

Conversation

@lg2m

@lg2m lg2m commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

CX2: compaction requests share the session's prompt cache

Spec: docs/plans/compaction.md § CX2 · ADR-0056 § 5 · Linear: ENG-995 (plan ENG-992)
Stacked on #239: review and merge that first; this PR's base is its branch.

Why

Compaction sent a cold request: no system prompt and no tools. It therefore shared no prefix with the session's prompt runs, and turn-1 cache reads were 0 on 152k–365k-token inputs (CX0 baseline).

What changed

  • Same prefix as the prompt runs. The summarizer request carries the same system prompt, tool list and reasoning effort as the session's prompt runs, built from the same PromptPrefixKey.
    • Between runs, the new RunCapabilities::summarizer(key) replaces without_tools. The key comes from the session (execution::session_prompt_prefix_key): depth, purpose, approval mode and delegation depth.
    • Context sources and output contracts are not applied to the summarizer.
  • In-run. The summarizer gets the run's live system prompt, its tools, and the full message prefix through the cut, so it is a prefix of the run's own last request.
    • It falls back to the run alone (the shape before this PR) when the loop's own estimate says the full prefix won't fit, or right after the provider rejected that estimate.
  • Tools are declared, never run.
    • Every call is answered with a rejection result. In-run, the retry includes the turn's replay data, which Anthropic thinking requires.
    • Everything the summarizer wrote up to that turn is discarded.
    • A second turn with a call fails the step (ProviderProtocol).
  • Soak fixture. It now detects summarizers by their instruction, since they no longer have an empty tool list.

What is and isn't cached (ADR-0056 § Consequences)

  • Tool block: always matches.
  • System prompt: matches unless the session uses context sources, a /skill invocation or an output contract, which are per-run suffixes.
  • Messages: extend the prompt run's last request unless assembly pruned results since then. CX3 fixes that divergence. In-run, the messages are always a prefix of the run's own last request.

How verified

  • cargo test --workspace: 2 099 passed, 13 ignored.
    • Two wall-clock-timeout tests failed once under load and pass 3/3 alone: hard_cost_budget_cancels_an_unmetered_looping_child and wall_clock_budget_settles_a_hanging_provider_without_a_final_response.
  • Minimal qq-provider profile: 210 passed. fmt and clippy -D warnings are clean.
  • New tests:
    • a_between_run_summarizer_request_extends_the_prompt_request_it_follows
    • an in-run prefix assertion in one_run_spanning_several_windows…
    • an_in_run_summarizer_keeps_the_session_context_before_its_prompt (fails with the full-prefix path disabled)
    • a_summarizer_run_sends_the_prompt_runs_system_prompt_and_tools_without_context_sources
    • a_child_sessions_summarizer_uses_the_childs_own_prompt_prefix (fails with a wrong child key)
    • a_summarizer_that_calls_a_tool_is_answered_once_and_its_reply_text_is_dropped
    • a_rejected_call_turn_after_a_cut_reply_drops_the_abandoned_fragment (fails without the fix)
    • a_summarizer_that_calls_tools_on_two_turns_fails_closed
    • two Runtime::summarize unit tests: rejected-call turn with replay, second call turn, and cut call turn
  • Independent review: no blockers. All should-fix items are resolved (the list is in the ledger entry).

Measurements (same host, against the CX1 tip)

Gate Base CX2
context_assembly assemble @ 10 000 archived (A/B/A/B) 63.6 / 58.6 µs 58.3 / 62.3 µs
turn_overhead median @ 10 / 100 / 1 000 turns (B/A/B, host under load) 74.9 / 73.0 / 68.3 ms 69.3 / 72.4 / 68.5 and 71.6 / 68.1 / 67.9 ms

Both are within noise. The live cache-read share is measured in CX5.

Compatibility

Follow-ups

  • CX3: a durable prune watermark, so the between-run messages extend too (schema 41 → 42).
  • CX4: RunActivity::Compacting.
  • CX5: live qualification.

lg2m added 2 commits October 4, 2026 23:31
…CX2)

The compaction summarizer now sends the system prompt, tool list and
reasoning effort of the session's prompt runs, built from the same
PromptPrefixKey, so it reads the provider cache those runs wrote instead
of a cold, tool-less prefix. Context sources and an output contract are
not applied to it.

- Between runs: RunCapabilities::summarizer(key) replaces without_tools;
  the key is derived from the session (depth, purpose, approval mode,
  delegation depth) to match its prompt runs.
- In-run: the summarizer gets the run's live system prompt, tools and full
  message prefix through the cut, falling back to the run alone when the
  loop's estimate says it would not fit or the provider just rejected it.
- Declared tools are never run. Each call is answered with a rejection
  (with the turn's replay data), everything written so far is discarded,
  and a second call turn fails the step closed.

No schema, protocol or descriptor change. context_assembly and
turn_overhead are within noise.

Refs: ENG-992, ENG-995
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-05T06:33:30.728191Z d0c1b8a PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lg2m
lg2m added this pull request to stack #251 October 5, 2026 06:32
@lg2m
lg2m merged commit c37afe2 into main Oct 5, 2026
4 checks passed
@lg2m
lg2m deleted the perf/eng-995-cx2-cache-aligned-summarizer 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