Repository navigation
fix(offload): cache_aware_summarizer cut every span at quoted marker text - #705
Conversation
…text The span trim asked skipReduce, so expand.HasPlaceholder stopped the span at the first message whose text holds `<<cg:...>>`. A session that reads this repo's docs carries that text from an early tool result on. On a live 900k-token thread, every one of 30 commissions covered 4 of about 2,200 messages. The trim now asks only kept-verbatim and restored content, as summarize does. Every decline path now records a gate (summary_span_empty, summary_span_empty_after_expand_trim, summary_span_below_min_tokens, no_model), and a started commission records summary_started. /stats gains prefix_stash_oversized: bodies the proxy did not stash because they were over maxSentBody. That cap is why all 30 commissions on the same thread failed as no_prefix. Refs #703 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
It sits with the other PrefixAsk counters, which are not on Prometheus either. Refs #703 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
maxSentBody was 1.5 MB. A thread near a 1M-token window is about 4 MB of request JSON, so it was never stashed, and every summary at the 0.9 trigger ended as ErrNoPrefix (30 of 30 on the live proxy). The cap is now 8 MB per body and 320 MB for the whole stash, as the owner decided. Worst case: one entry holds 2 bodies of up to 8 MB, and the stash is capped at 320 MB. A shared proxy is the case to monitor (#704). Fixes #703 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 003837ff48dd |
approve |
Verdict: approve
Findings
No blocking issues found.
Non-blocking
- proxy/prefixask.go:46-58 — Documentation clarity
- The comment block explaining the new 8 MB cap is thorough, but the phrase "MUST HOLD A FULL-WINDOW BODY" could be misread as a hard requirement rather than a design goal. Consider: "SHOULD HOLD A FULL-WINDOW BODY to avoid ErrNoPrefix on large threads."
- Impact: Documentation only, no functional issue.
What I checked
-
Core fix correctness (cache_aware_summarizer.go:639-644): The change from
skipReduceto onlyisKeptVerbatimis correct. The old code usedexpand.HasPlaceholder, which matches marker TEXT (e.g.,<<cg:HASH>>in documentation) as well as real markers. This caused spans to stop at the first message containing marker text, even when that text was just documentation content. The fix correctly distinguishes between:- Marker TEXT in content (safe to summarize, as the whole span gets stashed)
- Actually expanded content (must not be re-summarized, checked by
isKeptVerbatim)
-
Reversibility preserved: When a real marker exists inside a span being summarized, the entire span (including that marker) is stashed under the summary's own marker. The nested marker resolves through the same content-hash keys after expansion, so reversibility is maintained.
-
Test coverage (cache_aware_span_test.go): Two new tests cover the fix:
TestCacheAwareSpanIsNotCutByMarkerTextInAnEarlyMessage: Verifies that marker text in docs doesn't truncate the span. The test creates a message with both marker text and an actual marker, confirms the span covers the expected message count, and verifies the summary is commissioned and later spliced.TestCacheAwareEveryDeclineRecordsAGateOrEvent: Ensures every decline path records a gate or event. This addresses the observability gap where 1,030 runs declined with no gate recorded.
-
Prefix stash cap increase (prefixask.go:63-75): The increase from 1.5 MB to 8 MB is justified. A 1M-token window produces about 4 MB of request JSON, and the summarizer triggers at 90% of capacity. At the old 1.5 MB cap, threads above ~375k tokens were never stashed, causing every summary to fail as
ErrNoPrefix. The new 8 MB cap provides 2x headroom. The worst-case memory bound (320 MB total) is explicitly documented. -
Observability improvements:
- New
prefix_stash_oversizedcounter tracks bodies refused for exceeding the cap, distinguishing this from first-turnno_prefixcases. - New gates added:
summary_span_empty,summary_span_empty_after_expand_trim,summary_span_below_min_tokens,no_model. - New event
summary_startedrecords when a summary is commissioned asynchronously.
- New
-
Fail-open behavior: All changes maintain fail-open guarantees. When a body exceeds the cap, it is not stashed (rather than evicting others), and the next turn's prefix ask returns
ErrNoPrefix, causing a decline. This is a forgone opportunity, not a wrong answer. -
Data dependence: No change to data dependence. The component still requires stored content (summaries are model-generated text that differs each time).
-
Wire-group alignment: The fix does not affect wire-group handling. The
trimSpanForKeptVerbatimfunction is called aftersummarizeSpancomputes boundaries, and both respect tool-pairing atomicity. -
Metrics wiring: The new
PrefixStashOversizedcounter is correctly wired throughproxy.go:2347to the/statsendpoint and documented inpromexport_coverage_test.go:189as not yet exported to Prometheus. -
Test for full-window body (prefixask_test.go:364-376): Verifies that a 4.5 MB body (representing a full 1M-token window) is successfully stashed under the new 8 MB cap.
-
Documentation updates:
docs/components/advanced-offload.mdadds the newprefix_stash_oversizedcounter and explains the gate sequence for declined summaries.- Comments in the code clearly explain the reasoning for each change, including the #703 issue reference.
-
Backward compatibility: The changes are backward compatible. Existing configurations continue to work, and the new behavior only affects sessions with large request bodies or marker text in content.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 003837ff48dd |
approve |
Verdict: approve
Findings
None. The PR correctly fixes issue #703 and adds proper observability.
Non-blocking
- The fix is well-targeted: it removes the false-positive check (
expand.HasPlaceholder) that treated marker TEXT in docs as real markers, while keeping the actual expanded-content check (isKeptVerbatim). - The comment at lines 640-643 clearly explains why marker text inside a span is safe to summarize (the whole span is stashed, so reversibility is preserved).
- The pattern now matches
summarize.go's own span trimming (line 530), which already used onlyisKeptVerbatim+restoredSpanGuard. - The
maxSentBodyincrease from 1.5 MB to 8 MB is justified: a 1M-token window is about 4 MB of JSON, and the old cap refused every thread above ~375k tokens. The new cap holds a full window with room to spare. - The new
PrefixStashOversizedcounter properly distinguishes refused bodies from first-turnno_prefix, fixing the observability gap where 30 of 30 summaries on a 900k-token thread failed asno_prefixwith no way to see the cap was the cause. - Gate coverage is complete: every decline path now records a gate or event, addressing the #703 finding of 1,030 runs with no explanation.
- Test coverage is good:
TestCacheAwareSpanIsNotCutByMarkerTextInAnEarlyMessagereproduces the exact bug (docs with marker text → 4-message span) and verifies the fix (span covers the full fixture).
What I checked
- Read the full diff and the code around each change
- Verified the fix removes only the false-positive check while preserving the actual expanded-content guard
- Confirmed the pattern matches
summarize.go's existing implementation - Checked that
skipReduceitself is unchanged, so other components are unaffected - Verified the
maxSentBodyincrease is bounded (320 MB total cap) and justified (holds a full 1M-token window) - Confirmed all new gates and events are properly named and documented
- Reviewed test coverage for both the span-trimming fix and the gate-coverage requirement
- Checked that the new counter integrates correctly with
/statsand the Prometheus export coverage test
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 2 of 2 | 003837ff48dd |
approve |
Verdict: approve
Findings
None. Nothing changed since round 1: no new commit, no new comment, no author reply.
Non-blocking
- proxy/prefixask.go:46-49 — the round-1 doc note stands, unaddressed. "MUST HOLD A FULL-WINDOW BODY" reads as a hard requirement where it states a design goal. "SHOULD HOLD ... to avoid ErrNoPrefix on large threads" would be clearer. Not addressed because the head did not move. Still documentation only.
What I checked
- Last review: round 1, 003837f, 2026-10-25T17:09:18Z
- New commits read: 0.
git log --stat 003837ff..HEADprinted nothing (rc=0). The head is the same as round 1, as expected. - Read in full: 2 reviews, 0 comments, 0 inline comments (from the three saved files)
- New items since my last review: none. Both round-1 reviews (reviewer 1 and reviewer 2) approved; no person commented on the PR.
Earlier findings, this round:
- Reviewer 1, round 1, non-blocking (the "MUST HOLD" phrasing): not fixed, not rejected — no commit and no reply. It stays non-blocking; see above.
- Reviewer 2, round 1: no findings. Nothing to track.
Because my context is fresh, I re-verified the round-1 claims myself against the head, not against the round-1 text:
- Span trim fix.
skipReduce(state.go:434-444) returns skip whenexpand.HasPlaceholder(content)is true, and that matches marker TEXT quoted in docs, not only real markers. The change at cache_aware_summarizer.go:644-645 drops that half and keepsisKeptVerbatim || restoredSpanGuard. That predicate is byte-for-byte the one summarize.go:529-530 already uses for the same trim. Confirmed correct. - Reversibility with a real marker inside the span. The whole span is marshalled and stashed under
hashKey(spanJSON)(cache_aware_summarizer.go:924-931, cache_aware_async.go:232-237, and the checkpoint refreshes at cache_aware_summarizer.go:1105-1110). The inner marker's own stash keys are untouched, so expand still resolves them. Confirmed reversible. - Gate coverage. I walked every return path in
Offload(cache_aware_summarizer.go:610-983). Each decline now records a gate or an event:summary_span_empty,summary_span_empty_after_expand_trim,below_request_trigger,window_not_exact,cache_state_declined_*,summary_span_below_min_tokens,request_over_max_tokens,no_messages_model/no_model,thinking_would_be_stripped, the role gates,no_stash_room,cold_commission_deferred, or the newsummary_startedevent. I found no silent decline left. - Stash cap. One entry holds two bodies of up to 8 MB, so 16 MB;
maxSentBytes(320 MB) is the outer bound and evicts oldest first (prefixask.go:177-186). An oversized put deletes the old entry and countsprefix_stash_oversized(prefixask.go:157-165). Fail-open holds: the next ask returns ErrNoPrefix, which callers handle. - Wiring and tests.
PrefixStashOversizedreaches/stats(proxy.go:2347), the golden list, and the not-exported-yet map. Tests cover the marker-text span bug, the gate coverage, the oversized refusal count, and the full-window stash. - Data dependence. No change. The stash is host memory, not the Store, and no component's data dependence moved.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 2 of 2 | 003837ff48dd |
approve |
Verdict: approve
Findings
None. Round 2 found no defect.
Earlier findings
- Reviewer 1, round 1 (doc wording, "MUST HOLD" → "SHOULD HOLD"): not addressed, no author reply. I checked it myself. The comment states an invariant the cap must satisfy for the prefix ask to work at all, not a rule for a caller. "MUST" is defensible. Non-blocking either way.
- My round 1 raised no blocking finding. Nothing to re-check as fixed.
Non-blocking
docs/components/advanced-offload.md:1054— the new gate-order sentence omits two real decline gates:wire_groups_stale(cache_aware_summarizer.go:623) andside_request_read_only(line 704). A reader auditing "acted: 0" turns can still hit a gate the list does not name. Doc completeness only.cache_aware_summarizer.go:644— the trim runs beforetryReuse, whilesummarize.go:517-523moved its own trim belowtryReusebecause a loweredendcan turn a reusable checkpoint into a full-transcript send. Pre-existing order, not this PR. This PR only narrows the trim's predicate, so it lowersendin fewer cases than before — the risk shrinks. Worth aligning in a follow-up, not a blocker here.
What I checked
- Last review: round 1, 003837f, 2026-10-25T17:10:03Z
- New commits read: 0.
git log --stat 003837ff..HEADis empty; the head is the same as round 1, as the brief said to expect. - Read in full: 2 reviews, 0 comments, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt) - New items since my last review: none. Both round-1 reviews predate my LAST_TIME (17:09:18 and 17:10:03). No issue comments, no inline comments, no author replies exist on the PR.
- Re-read the full diff (
0a22b9ca..HEAD, 10 files) and the code around each change, with fresh eyes:- Core fix (cache_aware_summarizer.go:644-646): the trim now asks only
isKeptVerbatim || restoredSpanGuard. Verifiedsummarize.go:529-530already uses exactly that pair — the change removes the one half (expand.HasPlaceholderviaskipReduce) thatsummarizenever had, and that matched marker TEXT in ordinary content. - Reversibility: a real marker inside the span stays reversible.
commitAsyncSummarystashes the whole span under the summary's own key in full mode (cache_aware_async.go:231-241), so expanding the summary restores the inner marker, which then resolves as before.summary/offmodes are operator-opted lossy drops and already behaved this way insummarize.go. - Gate coverage: walked every return path in
Offload. Each decline now records a gate or event:summary_span_empty,summary_span_empty_after_expand_trim,side_request_read_only,below_request_trigger/window_not_exact,cache_state_declined_*,summary_span_below_min_tokens,request_over_max_tokens,no_messages_model/no_model,thinking_would_be_stripped,system_role_unsupported_via_prefix_ask,unverified_system_role,no_stash_room,!phased(gate raised at line 731),cold_commission_deferred, and the newsummary_started. The only gateless return is thejson.Marshalerror path (line 925), which returns an error the pipeline reverts — fail open, not a silent decline. summary_startedevent:startAsyncSummaryreturns""only after the detached goroutine is launched (cache_aware_async.go:124-203), so the event never fires on an in-flight or concurrency refusal — those return their own gates.- Stash caps (prefixask.go): 8 MB per body, 16 MB per entry (2 bodies), 320 MB total — the math in the comment checks out, and the byte cap binds before the 256-entry bound for full-window bodies. The
put/evict logic is unchanged; only the constants moved. No stale1.5 MB/96 MBreference remains in code or docs. - New counter:
sentStashOversizedincrements only on the oversized refusal path; wired to/stats(proxy.go:2347), the golden list, and the promexport not-yet-exported map. Consistent. - Tests: all helpers the new tests use exist (
caFixture,caToolPair,WaitForSummaryForTest,loadCheckpoint). The span test assertsCoveredCountequals the untrimmed span, which the oldskipReducetrim would have cut to nothing — the PR body's mutation runs confirm both directions. The oversized-turn integration test now sizes its payload frommaxSentBodyinstead of a hardcoded 1.6 MB, so it cannot silently go under the cap again. - Data dependence: PR body states it — no change in kind, sizes only,
docs/data-dependence.mdrow unchanged. No new component registered, sodatadep_test.gois unaffected.
- Core fix (cache_aware_summarizer.go:644-646): the trim now asks only
- Live tests were not approved; this review is code-reading only, as the brief requires.
…ion (#725) fix(cheapmodel): move the trailing breakpoint onto the appended question Claude Code 2.1.310 ends each request with a system message that holds the last cache_control breakpoint. The prefix ask kept it there and appended the bridge and the ask with none. The provider then missed the turn's cache entry and the question rewrote the conversation. The sweep gate refused every answer. - insertAskMessage moves the last message's breakpoint (same object, ttl kept) onto the bridge, or onto the ask when there is no bridge. It adds none when the last message has none. - The sweep write gate refuses a write only when it is larger than the tokens the question appended, plus a named margin. - The ping candidate scan skips only real markers. Text that quotes marker syntax is a candidate (same fault as #705). Fixes #721 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]> fix(offload): judge a prefix-ask answer by its read, behind one function The provider never reads a cache entry that ends at a text turn, so a correct question always rewrites that turn's tail. A write limit would still refuse most questions. prefixAskCacheOK is now the one decision. It refuses a read of 0 and a read below the last real turn's read. An optional write cap (min of 2 percent of the prefix and 2,000 tokens) is off until the owner decides. The keeper passes the turn's cache_read to the sweep through SweepPingWait. The old "write > appended tokens" allowance is removed. Refs #721 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]> fix(offload): ship the prefix-ask write cap on, as one constant The owner has not chosen the cap yet. prefixAskWriteCapEnabled is one constant, so the cap can go without a rewrite. Adds table rows for a typed-prompt tail write, and a test that the shipped switch is on. Refs #721 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]> fix(cheapmodel): keep the breakpoint off the ask, one rule for the marker check Review round 1 of #725. - A trailing user message that carries a breakpoint now also gets the "Understood." bridge, and the breakpoint moves onto the bridge. The ask stays fresh input. Before, the breakpoint sat on the ask and the cache write held the whole ask (about 1,000 to 1,400 tokens), so the write cap refused every question in that shape. - The cold apply and the replay use carriesRealMarker, the same rule as the ping's candidate scan. A drop on an output that only quotes marker text now applies. A skip on a real marker is counted (sweep_apply_already_marked). - Docs: the read rules in advanced-offload, the Store presence read in data-dependence. Refs #721 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]> fix(offload): ship the prefix-ask write cap off The owner chose the read rule only (2026-10-26). The cap code and its constants stay behind prefixAskWriteCapEnabled, now false. One constant turns it on. Refs #721 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Summary
The cache-aware summarizer never acted on a live
xhighproxy: 0 of 2,597 runs. Two separate causes block it on long threads. This PR fixes both. Also, every decline path now records a gate.What we found
Live proxy, port 8789, preset
xhigh, one Opus 5.5 thread with 2,169 to 2,231 messages and 901k to 925k billed tokens:covered_messages=430 times)no_prefixWhy it happens
skipReduce. That also asksexpand.HasPlaceholder, which matches any<<cg:...>>text. The thread's 7th and 9th entries are file reads of this repo's docs, and they quote<<cg:HASH>>. So the span stopped there, and every summary covered 4 messages.summarizedoes not have this fault: it asks only for kept-verbatim and restored content.sentStash.putrefuses a body overmaxSentBody(1,500,000 bytes,proxy/prefixask.go). A thread near a 1M-token window is several MB. So the thread was never stashed, and the summary call found nothing to ask over (ErrNoPrefix)./statsreported this the same way as a first turn.keep_last_turns, a span belowmin_tokens, and no model. A turn that started a summary also recorded nothing.What changed
cache_aware_summarizer: the span trim asks only for kept-verbatim and restored content, assummarizedoes. A real marker inside the span is safe to summarize, because the span is stashed whole under the summary's own marker.summary_span_empty,summary_span_empty_after_expand_trim,summary_span_below_min_tokens,no_model. New event:summary_started.maxSentBodygoes from 1.5 MB to 8 MB per body.maxSentBytesgoes from 96 MB to 320 MB for the whole stash. A 1M-token window is about 4 MB of request JSON, so 8 MB leaves twice that room.proxy/prefixask.gosays this./statsgainsprefix_stash_oversized: the count of bodies the proxy did not stash because of the cap. It is not exported to Prometheus yet, the same as the other PrefixAsk counters.docs/components/advanced-offload.mdlists the new counter and the gates.How it was tested
All runs are on the eval box.
TestCacheAwareSpanIsNotCutByMarkerTextInAnEarlyMessageorigin/main+ testturn 1 started no summary: gates map[], events map[](as on the live proxy)TestCacheAwareEveryDeclineRecordsAGateOrEvent(4 cases)origin/main+ testgates map[]skipReduceback in the trimgates map[summary_span_empty_after_expand_trim:1]TestAnOversizedBodyIsNotStashed(asserts the new counter)TestAFullWindowBodyIsStashed(4.5 MB body)maxSentBodyback to 1.5 MBa 4500000-byte full-window body was not stashed (cap 1500000)TestCacheAwareStalePrefixThroughARealOversizedTurn(payload nowmaxSentBody+ 100 KB)go test -race ./components/...go test -race ./proxy/...go test ./metrics/...,go vet,gofmt -lData dependence
No change in kind. The PR stores no new kind of data and reads nothing new. The body stash already held full request bodies (
docs/data-dependence.md, Body stash row, unchanged). It can now hold larger bodies, up to 320 MB in total, in memory only. The new counter is a count only.Follow-up
Fixes #703
Technical notes
0c21eade) and the cap with feat(extract_llm)!: extract_llm_sweep — adjudicate spent tool outputs over the model's cached transcript #118 (d6efefec). Both are older than refactor(offload): one helper for the role and opening of an appended question #507, feat(sweep): ask at the keep-alive ping, hold the answer, recheck, shadow mode #508, feat(keepalive): follow the cache TTL each session was billed at #512 and feat(keepalive): share the ping with the summary call (#404 point 10) #688, and both are in v0.5.3 and v0.5.4.summary_span_empty.🤖 Generated with Claude Code