Skip to content

feat(config): switch the xhigh preset to cache_aware_summarizer - #414

Merged
amiddavid merged 2 commits into
mainfrom
feat/xhigh-cache-aware
Oct 11, 2026
Merged

amiddavid merged 2 commits into
mainfrom
feat/xhigh-cache-aware

Conversation

@amiddavid

@amiddavid amiddavid commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The xhigh preset uses a summarizer component called summarize. This component writes a new
prompt 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 conversation
itself, 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 xhigh from summarize to cache_aware_summarizer. It does not change any
other preset.

Today vs. with this PR, for an xhigh user

Today With this PR
Summary call cost Full price for the whole conversation, every time Full price for one short instruction; the rest reads from cache
When it fires Once the context is nearly full The same point, unchanged
Config needed None None — the new component's own defaults are used as is

Nothing else about xhigh changes. The components around the summarizer, and the order they run
in, stay the same.

Why this does not change high too

high also uses summarize. It stays on summarize in this PR.

cache_aware_summarizer needed three separate fixes before it could do anything useful on real
Anthropic 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 of summarize never needed any of these — summarize works the same way it
always 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_summarizer
does 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):

go build ./...
go vet ./...
go test ./config/... ./components/offload/... ./proxy/... ./context-guru-plugin/...
go test -race ./config/... ./components/offload/...
make lint

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 tables
in the docs against config.go (TestPresetDocsDoNotDrift). The full plugin test suite shows the
same 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

  • high also uses summarize, and keeps using it after this PR, by design — see "Why this does
    not change high too" above.
  • Nobody has measured cache_aware_summarizer against the housellm offloaders it now runs
    alongside in xhigh, the same way nobody had measured summarize there either. The component
    is placed first in the pipeline on the same precedent summarize was, not on a measured order.

@amiddavid
amiddavid force-pushed the feat/xhigh-cache-aware branch from 2d6a348 to 4d81a92 Compare October 7, 2026 19:06
@amiddavid
amiddavid force-pushed the feat/xhigh-cache-aware branch from 4d81a92 to b972379 Compare October 8, 2026 09:29
@amiddavid
amiddavid force-pushed the feat/cache-aware-summarizer-trigger branch from b001c92 to 8365907 Compare October 8, 2026 09:59
@amiddavid
amiddavid force-pushed the feat/xhigh-cache-aware branch 2 times, most recently from 4940fca to 090edb1 Compare October 8, 2026 10:39
@amiddavid
amiddavid force-pushed the feat/xhigh-cache-aware branch 4 times, most recently from 8001c54 to 82ead0d Compare October 8, 2026 17:30
@amiddavid
amiddavid changed the base branch from feat/cache-aware-summarizer-trigger to main October 8, 2026 21:17

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. cache_aware_summarizer is first in the xhigh pipeline. It hashes its own input: the messages as the client sent them.
  2. The components after it (textclean, format, dedup, extract, …) rewrite tool output in those same messages. In this test, textclean removed the ANSI codes in 14 of 14 forwarded bodies.
  3. The proxy stores the forwarded body. sentStash.CoversSpan hashes 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 put time the proxy also has the incoming request. Store its normalized message count plus SpanHash (or per-message hashes) next to the forwarded body, and let CoversSpan compare 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_use ids, 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 ./... and go vet ./...: pass.
  • go test -race -count=1 ./config/... ./components/offload/...: pass.
  • go test -count=1 ./...: pass, except 4 context-guru-plugin tests:
    • TestInstallRefusesAnUnverifiedDownload and TestInstallReportsPATHFromTheSourceFallbackToo: the known box defect. They also fail on origin/main.
    • TestUninstallDropsAStaleRecordEvenWhenNothingElseChanged and TestUserScopeThenProjectKeepsTwoPorts: pass 3 of 3 when run alone on both this PR and main, so they are flaky under load.
  • TestPluginPresetPipelinesAgreeWithConfig and TestPresetDocsDoNotDrift: pass.

Smaller points

  • The config.go comment 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.md says xhigh uses the same thresholds as high. That is correct, but keep_last_turns (10) differs from summarize's keep_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

amiddavid added a commit that referenced this pull request Oct 11, 2026
…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]>
@amiddavid
amiddavid force-pushed the feat/xhigh-cache-aware branch from 82ead0d to bb9ce5d Compare October 11, 2026 11:25
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Re-check after #431: xhigh now commits a summary

Result: with #431 merged, the shipped xhigh preset commits a cache-aware summary. Rebased onto main as bb9ce5d.

What changed

How it was tested (eval box, CGO_ENABLED=1)

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 amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. TestXHighPresetCommitsACacheAwareSummary does not check the preset's own cache_aware_summarizer settings. The test gives its own cache_aware_summarizer block. applyPreset replaces the preset's block with the user's block as a whole (merged[k] = v). It does not merge the fields. So the shipped model.source: incoming never gets to the test.
    • Mutation: I removed model.source: incoming from the xhigh preset. 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 checks model.source at 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.
  2. config/config.go:527-529: the new comment is wrong. It says keep_last_turns (default 10) matches "summarize's own keep_last tuning". The default of summarize's keep_last is 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.
  3. config/config.go:516 says "(#413)" for the swap. The swap is this PR. #413 is the prefix-ask insertion fix. #456 also removes this line.
  4. The message of commit 7836726 says it fixes the docs/components.md row. 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.

@amiddavid
amiddavid merged commit bfdc2ba into main Oct 11, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 11, 2026
@amiddavid
amiddavid deleted the feat/xhigh-cache-aware branch October 11, 2026 14:45
amiddavid added a commit to AIMikav/context-guru that referenced this pull request Nov 9, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant