Repository navigation
feat(config): switch the xhigh preset to cache_aware_summarizer - #414
Conversation
2d6a348 to
4d81a92
Compare
4d81a92 to
b972379
Compare
b001c92 to
8365907
Compare
4940fca to
090edb1
Compare
8001c54 to
82ead0d
Compare
amiddavid
left a comment
There was a problem hiding this comment.
Summary
Do not merge yet. With this PR, xhigh makes no summaries at all. The preset change itself is correct, and the docs and plugin tables match config.go. But in xhigh, components after cache_aware_summarizer rewrite the body before the proxy sends it. The stale-prefix guard from #402 then declines every commission as stale_prefix. Today xhigh uses summarize, which works, so this PR removes compaction from xhigh.
What we found
Live traffic (aws/claude-sonnet-5 through the plain gateway). The script sends 7 Claude-Code-shaped turns, each a Bash tool_use plus a tool_result with ANSI-coloured test output. Both configs are preset: xhigh, with a lower trigger so the summarizer fires on a small conversation.
PR (cache_aware_summarizer) |
main (summarize) |
|
|---|---|---|
| Summary attempts | 5 | 2 |
stale_prefix declines |
5 | n/a |
| Summaries committed | 0 | 2 |
| Turn with a splice | none | 1 turn, saved=1574 |
The same result through serve() with a mock upstream (14 turns, the same shape):
| Pipeline | Summary calls | stale_prefix |
|---|---|---|
[cache_aware_summarizer] (control) |
2 | 2 (early turns, before the stash catches up) |
[cache_aware_summarizer, textclean] |
0 | 12 |
preset: xhigh |
0 | 12 |
Why it happens
cache_aware_summarizeris first in thexhighpipeline. It hashes its own input: the messages as the client sent them.- The components after it (
textclean,format,dedup,extract, …) rewrite tool output in those same messages. In this test,textcleanremoved the ANSI codes in 14 of 14 forwarded bodies. - The proxy stores the forwarded body.
sentStash.CoversSpanhashes that body and compares the two hashes. They can never match on any turn where a later component changed a message inside the span. Changing those messages is what the later components are for.
The guard is too strict for a mixed pipeline. The summary model reads the forwarded body, which is a compacted copy of the same messages, so a summary of it is still valid for the span. Issue #429 has the same cause (the hash covers bytes that do not change what the model reads), but this case is much more serious, because it affects the default xhigh pipeline.
Proposal
Fix the guard first, in its own PR. Then merge this one. Options:
- Store the pre-pipeline identity with the stashed body. At
puttime the proxy also has the incoming request. Store its normalized message count plusSpanHash(or per-message hashes) next to the forwarded body, and letCoversSpancompare against those. This keeps the guard's protection against an old body (#402, Finding 1) and ignores what later components rewrote. - Or compare structure only. Use message count, roles and
tool_useids, not content. This is simpler, but a little weaker.
The fix also needs a test that runs preset: xhigh through serve() and checks that a summary is committed. With that test, this problem cannot come back without a failing test.
What I ran
Eval box, head 82ead0d (1 commit on main, mergeable):
go build ./...andgo vet ./...: pass.go test -race -count=1 ./config/... ./components/offload/...: pass.go test -count=1 ./...: pass, except 4context-guru-plugintests:TestInstallRefusesAnUnverifiedDownloadandTestInstallReportsPATHFromTheSourceFallbackToo: the known box defect. They also fail onorigin/main.TestUninstallDropsAStaleRecordEvenWhenNothingElseChangedandTestUserScopeThenProjectKeepsTwoPorts: pass 3 of 3 when run alone on both this PR andmain, so they are flaky under load.
TestPluginPresetPipelinesAgreeWithConfigandTestPresetDocsDoNotDrift: pass.
Smaller points
- The
config.gocomment says the swap needs #402, #406 and #413. All 3 are merged now, so the "Merge order" section of the PR description is out of date. presets.mdsaysxhighuses the same thresholds ashigh. That is correct, butkeep_last_turns(10) differs fromsummarize'skeep_last(3). A short note would help readers compare the two tiers.
Technical notes
Probe test (not committed): proxy/review414_probe_test.go
// 14 turns: assistant tool_use (Bash) + user tool_result with 60 lines of
// "\x1b[31mFAIL\x1b[0m test_i_j: expected j got j+1 \r\n".
// Override: cache_aware_summarizer {keep_last_turns: 4, trigger: {min_request_frac: 0, min_request_tokens: 1}}
// Counts upstream bodies that contain "Output ONLY the summary", plus the
// cache_aware_summarizer_stale_prefix counter.
// [cache_aware_summarizer] calls=2 stale=+2
// [cache_aware_summarizer, textclean] calls=0 stale=+12, ANSI stripped in 14/14 forwarded bodies
// preset: xhigh calls=0 stale=+12…ker and the pipeline order PR #402 added a guard that declines a cache_aware_summarizer commission (gate stale_prefix) when the stashed forwarded body does not cover the span the commission is about to claim as summarized. Two re-reviews found that the guard's own hash was wrong in two separate ways. What we found. 1. The guard's hash included each message's cache_control marker. A client that moves a single cache breakpoint to the last message every turn (Claude Code does this) resends an earlier message with the marker gone. The content is the same; only the marker moved. At keep_last_turns 2 or less, the summarized span reached that message on every turn, so the hash never matched and the guard declined every commission. Live: 3 of 3 commissions declined, 0 summaries. 2. extract_llm_sweep reads the same host stash through the same PrefixAsker construction, with no coverage check of its own. 3. A second review (of PR #414, which switches the xhigh preset to cache_aware_summarizer) found that a pipeline component downstream of cache_aware_summarizer rewrites a message before the request is forwarded. The guard compared the summarizer's own span - computed from the message set the pipeline first received - against the FORWARDED body, which a later component may have already rewritten. The two bodies disagreed on every turn such a component acted. Live xhigh: 5 of 5 commissions declined, 0 summaries; through [cache_aware_summarizer, textclean], 12 of 12 declined. What we changed. - components.SpanHash now strips cache_control before hashing a message, on both sides of every comparison that uses it. A moved marker no longer looks like a content change. - extract_llm_sweep gained the same stale-prefix guard cache_aware_summarizer already had, scoped to candidates the component believes already sit inside the cached prefix (i <= MaxCachedIdx). A candidate in the turn's own new, not-yet-cached tail is a separate, already-tracked gap (#122), not this guard's job - checking it there would decline a normal turn's own newest content, not only a stale one. - proxy's sentStash now keeps two bodies per session: the one actually forwarded (what Ask appends its question to, because that is what the provider's cache holds) and the one the pipeline received before any component ran. The stale-prefix guard, on both callers, now checks coverage against the PRE-pipeline body, so a downstream component's rewrite can no longer make the guard see a stale prefix that was never stale. How it was tested. Eval box, CGO_ENABLED=1: go build ./... pass go vet ./... pass gofmt -l . no files go test ./components/offload/... ./proxy/... pass go test -race ./components/offload/... ./proxy/... pass New tests, each confirmed to fail without its matching fix and pass with it, through the real serve() path: - TestCacheAwareClaudeCodeStyleMovingCacheControlIsNotStale: three turns with the marker moving to the last message each turn, keep_last_turns 2. Fails without the SpanHash fix (0 ask calls); passes with it (1). - TestCacheAwareRealContentChangeInsideSpanStillDeclines: same shape, but a real text change inside the span. Still declines either way, so the SpanHash fix does not blind the guard to an actual change. - TestCacheAwarePipelineOrderMinimalTextCleanCase and TestCacheAwarePipelineOrderXHighEquivalent: [cache_aware_summarizer, textclean] and the full pipeline PR #414 switches xhigh to (spelled out in the test; #414 is not merged yet). Both fail without the pre/post pipeline stash split (0 ask calls, reproducing the live finding) and pass with it (1). Unit tests in components/offload: TestSweepDeclinesOnAStalePrefix, TestSweepAsksNormallyWhenPrefixCovers, TestSweepStaleGuardStaysOutOfTheWayWithNoKnownBoundary. References #402 (its own re-review found finding 1) and #414 (its review found finding 3; this change unblocks it). Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
xhigh used summarize for its summarizer. summarize builds a new prompt for its summary call. This prompt does not reuse the cached conversation. Every summary call pays full price. cache_aware_summarizer does the same job a different way. It sends the conversation itself, plus one short instruction at the end. This lets the call reuse the cache the agent's own turn already wrote. The call pays full price only for the one short instruction, not for the whole conversation. This commit swaps summarize for cache_aware_summarizer in the xhigh preset only. high keeps summarize unchanged. cache_aware_summarizer's own default trigger (fire at 90% of the context window, on any cache state) is used as is. No trigger values are pinned in the preset. high was left alone on purpose. cache_aware_summarizer needed three separate fixes before it could do anything on real Anthropic traffic: a working trigger and keep-alive integration (#402), a header-size fix for its side call (#406), and a message-order fix for the same call (#413). high's own use of summarize never needed any of these. Moving both presets at once would have mixed two unrelated changes into one commit. Also updated: the preset's own comments in config/config.go, the preset tables in docs/reference/presets.md and docs/components.md, the plugin's own copy of the preset pipeline table (context-guru-plugin/scripts/insights.py, pinned against config.go by TestPluginPresetPipelinesAgreeWithConfig) and its component description table (context-guru-plugin/skills/insights-components/ SKILL.md). docs/components.md's own description of cache_aware_summarizer said it declines without a MessagesModel; that sentence was already stale after #402 added the prefix-ask fallback, so it is corrected here too. This PR must merge after #402, #406 and #413, in that order. It is based on #402's branch so its own diff shows only the preset change. It needs to be retargeted to main once all three are merged. Assisted-By: Claude Sonnet 5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
The xhigh test from #431 spelled out the pipeline by hand, because #414 was not merged then. It now loads `preset: xhigh` by name. Only the summarizer's trigger is lowered, so a three-turn fixture reaches it. - With this PR, the test passes: 1 summary call, covering turn 2. - With main's xhigh (summarize), it fails: 0 calls. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
82ead0d to
bb9ce5d
Compare
Re-check after #431: xhigh now commits a summaryResult: with #431 merged, the shipped What changed
How it was tested (eval box,
|
| Summary calls | |
|---|---|
This PR (preset: xhigh) |
1, covering turn 2 |
Control: main's xhigh (summarize) |
0 (the test fails, as expected) |
go build ./...,go vet,gofmt -l: clean.- Preset and drift tests pass:
TestPresetDocsDoNotDrift,TestPluginPresetPipelinesAgreeWithConfig,TestEveryPresetOfferedIsOneInsightsCanExplain. go test -race ./config/... ./components/offload/...: pass.
amiddavid
left a comment
There was a problem hiding this comment.
Review round 2: the blocker is fixed. OK to merge.
Result: with #431 merged, xhigh commits cache-aware summaries on live traffic. The stale_prefix declines from round 1 are gone. I found no new blocking problems.
Round-1 findings
| Round-1 finding | Status |
|---|---|
xhigh made 0 summaries (every commission declined as stale_prefix) |
Fixed by #431. Live run below: 3 summaries committed, 0 stale_prefix declines. |
| The "Merge order" section of the description was out of date | Fixed. |
Add a note that keep_last_turns (10) differs from keep_last (3) |
Added, but the new comment is wrong. See point 2 below. |
What I ran
On the eval box, at head bb9ce5d:
go build ./...,go vet,gofmt -l: clean.go test -race -count=1 ./config/... ./components/offload/...: pass.TestXHighPresetCommitsACacheAwareSummary,TestCacheAwarePipelineOrderMinimalTextCleanCase,TestEveryPresetBuilds,TestPresetDocsDoNotDrift,TestPluginPresetPipelinesAgreeWithConfig,TestEveryPresetOfferedIsOneInsightsCanExplain: pass.
Live traffic. I used aws/claude-sonnet-5 through the plain gateway, not Context Guru. The script is the same as in round 1: 7 Claude-Code-shaped turns with ANSI test output, preset: xhigh, and a lower trigger (keep_last_turns: 4, min_request_frac: 0).
Round 1 (82ead0d) |
Now (bb9ce5d) |
|
|---|---|---|
| Summary calls | 5 | 3 |
stale_prefix declines |
5 | 0 |
| Summaries committed | 0 | 3 |
| Tokens saved on the last 3 turns | none | 3200, 3840, 4480 |
| Cache read across the 3 summary calls | n/a | 35,745 tokens |
Non-blocking points
TestXHighPresetCommitsACacheAwareSummarydoes not check the preset's owncache_aware_summarizersettings. The test gives its owncache_aware_summarizerblock.applyPresetreplaces the preset's block with the user's block as a whole (merged[k] = v). It does not merge the fields. So the shippedmodel.source: incomingnever gets to the test.- Mutation: I removed
model.source: incomingfrom thexhighpreset. The test still passes. - The pipeline order does come from the preset, and that is the property this test is for. #456 adds
TestPresetLadderSummarizerModes, which checksmodel.sourceat the config level. So this is only a note: the test comment says "every other component's settings come from the preset", and that is not fully true for the summarizer.
- Mutation: I removed
config/config.go:527-529: the new comment is wrong. It sayskeep_last_turns(default 10) matches "summarize's own keep_last tuning". The default ofsummarize'skeep_lastis 3 (components/offload/summarize.go:1057). It also counts messages, not turns. #456 rewrites this comment and removes the wrong part, so you can also leave it to #456.config/config.go:516says "(#413)" for the swap. The swap is this PR. #413 is the prefix-ask insertion fix. #456 also removes this line.- The message of commit
7836726says it fixes thedocs/components.mdrow. This PR does not change that file. The row is already correct, so only the commit message is wrong. If you squash on merge, drop that sentence.
…igh (any) The picker ladder now uses cache_aware_summarizer from medium up (rossoctl#417): - medium: cache_state: pre_expiry. The summary is prepared in the background, in place of one keep-alive ping, and kept in reserve. It is used only when the user comes back after the cache expired. - high: cache_state any (the default). The summary is made at 90% of the window and used on the next request. - xhigh: high plus extract_llm_sweep (unchanged from rossoctl#414). summarize is no longer in any picker tier. It stays available by name. User-facing text updated: plugin.json, settings.py, README, the preset-picker and insights-components skills, insights.py, and docs/reference/presets.md. Tests: - TestPresetLadderSummarizerModes: medium pins pre_expiry; high and xhigh use the default; none runs summarize; each preset builds. - TestHighPresetCommitsACacheAwareSummary: 1 summary call through serve(). It fails on rossoctl#414's high (summarize): 0 calls. - TestMediumPresetDoesNotSummarizeOnAWarmTurn: 0 calls on warm turns. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Summary
The
xhighpreset uses a summarizer component calledsummarize. This component writes a newprompt for its summary call every time. The new prompt does not match the cache the agent's own
turn wrote. Every summary call pays full price for the whole conversation.
A different component,
cache_aware_summarizer, does the same job. It sends the conversationitself, plus one short instruction at the end. The call can then reuse the cache the agent's own
turn already wrote. It pays full price only for the one short instruction.
This PR switches
xhighfromsummarizetocache_aware_summarizer. It does not change anyother preset.
Today vs. with this PR, for an
xhighuserNothing else about
xhighchanges. The components around the summarizer, and the order they runin, stay the same.
Why this does not change
hightoohighalso usessummarize. It stays onsummarizein this PR.cache_aware_summarizerneeded three separate fixes before it could do anything useful on realAnthropic traffic: a working trigger and a connection to the idle keep-alive ping (#402), a
header-size fix for its own call (#406), and a message-order fix for the same call (#413).
high's own use ofsummarizenever needed any of these —summarizeworks the same way italways has, on every provider. Moving both presets at once would mix two separate changes into
one.
Merge order
#406 and #413 are merged into
main. This PR still needs #402 first —cache_aware_summarizerdoes nothing useful on Anthropic traffic without it. It is based on #402's branch so this PR's own
diff shows only the preset change, not everything #402 already added. Once #402 merges, this PR
should be retargeted to
main.How it was tested
Run on the shared eval box, in the foreground (Go is not available on this machine):
All pass, including the test that pins the plugin's own copy of the preset table against
config.go(TestPluginPresetPipelinesAgreeWithConfig) and the test that pins the preset tablesin the docs against
config.go(TestPresetDocsDoNotDrift). The full plugin test suite shows thesame two failures this box already has on an unmodified checkout — a root-owned proxy binary on
this shared box, unrelated to this change.
Open questions
highalso usessummarize, and keeps using it after this PR, by design — see "Why this doesnot change
hightoo" above.cache_aware_summarizeragainst thehousellmoffloaders it now runsalongside in
xhigh, the same way nobody had measuredsummarizethere either. The componentis placed first in the pipeline on the same precedent
summarizewas, not on a measured order.