Repository navigation
fix(offload): cover the last tool exchange in an OpenAI summary - #732
Merged
Merged
Conversation
The summary span stopped before the last tool exchange so the host could anchor a cache breakpoint on it (#727). OpenAI takes no explicit breakpoint, so the retreat only cost savings there. - Add Ctx.NoCacheBreakpoint, set from the provider by the host. - cache_aware_summarizer retreats the span only when a breakpoint can be written (Anthropic, Bedrock, Vertex). - Fix the stale "300 s - 270 s" text in keepalive/substitute.go and keepalive/openaiphase_test.go. Assisted-By: Claude Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
commented
Oct 26, 2026
amiddavid
left a comment
Collaborator
Author
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 | 1 of 2 | 0c90804f5e91 |
blocking |
Verdict: blocking
Findings
- apply/responses.go:568 — the Responses route never sets
NoCacheBreakpoint, so OpenAI Responses traffic still keeps the last tool exchange verbatim.- What fails: a request with
API: "responses"(always OpenAI-shaped, nocache_controlon that wire) andcache_aware_summarizerin the pipeline gets itsCtxfrombodyResponsesOpts, which leavesNoCacheBreakpointat the zero valuefalse.Offloadthen still runsretreatPastLastToolExchange(components/offload/cache_aware_summarizer.go:745-747), so the last function-call exchange stays out of the summary — and nothing marks it, because the Responses rebuild path never callsanchorCacheBreakpoint. That is the exact waste #730 describes, on the proxy's other OpenAI wire. - Proof: apply/apply.go:396-398 routes
o.API == "responses"tobodyResponsesOptsbefore theCtxat apply/apply.go:666 that sets the flag; theCtxat apply/responses.go:568-591 sets noNoCacheBreakpoint; the route runscache_aware_summarizerend to end (apply/responses_test.go:543,TestResponsesCacheAwareOneMessageSpliceIsWritten); the Responses wire normalizesfunction_call/function_call_outputinto assistant/tool messages (apply/responses.go:71-78), so the retreat finds an exchange there; and apply/apply.go:787's own anchor gate already treats OpenAI as breakpoint-less, while responses.go has no anchor call at all. - Fix: set
NoCacheBreakpoint: trueinbodyResponsesOpts(that wire is always OpenAI-shaped). Add a Responses-route test that the lastfunction_call_outputis summarized away, mirroringTestTheSummaryCoversTheLastToolExchangeOnlyOnOpenAI.
- What fails: a request with
Non-blocking
- adapters/bifrost/plugin.go:51 builds its
Ctxwithout the flag too. Today it is latent: with the defaultmin_request_frac0.9 and noCtxWindowExacton that host, the summarizer declines atwindow_not_exactbefore the retreat.chat.Provideris at hand there if you want the hint set anyway, so a later config change cannot revive the gap. - apply/cache_anchor_test.go:229 —
TestTheSummaryCoversTheLastToolExchangeOnlyOnOpenAIchecks only the OpenAI half at the apply level. The Anthropic half ("the exchange stays") is covered at the unit level only (components/offload/summary_anchor_test.go). The name promises more than the test asserts.
What I checked
- The full diff
06b40ed2..HEAD, every hunk, and the code around each change. - The retreat gate:
summarizeSpan's ownadvanceSpanBoundarykeeps the tail start safe without the retreat, so the splice andemitCheckpointnever begin a kept tail mid-exchange. CoveredCountconsistency:end-startflows unchanged throughregisterKeepAliveCandidate,deferSummary,startAsyncSummary, and back asboundary = start + CoveredCountintryReuse/replayStale. A checkpoint frozen before this change (retreated count) is reused as-is after it, and a retreated boundary is still a safe tail start.CacheAnchorToolID: apply/apply.go:792 is the only consumer and it is gated onexplicitBreakpointProvider, so skipping the retreat on OpenAI cannot strand an anchor.- The keepalive hunks are comment-only, and the new numbers check out:
DefaultKeepAliveIdle = 240(config/config.go:197),cacheLifetime(Anthropic, false) = 300 s,tick = 2 s, so the widened default window is 64 s. The test keeps its 270 s idle and its 60 s expectation, which still holds (slack 34 s < 60 s). - Providers:
explicitBreakpointProvider(Anthropic, Bedrock, BedrockMantle, Vertex) matches the anchor gate at apply/apply.go:787. Gemini and unknown providers getNoCacheBreakpoint = true, which only drops the retreat — no fail-open path is affected. - The new tests' helpers all exist (
pipe,recordingModel,caCtx,caTurn,caFixture,caToolPair,WaitForSummaryForTest,WaitForAllSummariesForTest,convKey,loadCheckpoint) and the imports are present. I did not run them: live tests are not approved, and Go is not installed here. - Data dependence: unchanged. The span extent changes, but the stash and marker machinery is untouched, and docs/data-dependence.md has no row that describes the retreat.
amiddavid
commented
Oct 26, 2026
amiddavid
left a comment
Collaborator
Author
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 | 1 of 2 | 0c90804f5e91 |
blocking |
Verdict: blocking
Findings
- apply/responses.go:568 — the OpenAI Responses route does not set
NoCacheBreakpoint, so fix #730 does not reach it.- What fails: an OpenAI
/v1/responsesrequest with client-held history (inputis an array, noprevious_response_id) runscache_aware_summarizerthrough thisCtx. The field's zero value isfalse, soOffloadstill callsretreatPastLastToolExchange(components/offload/cache_aware_summarizer.go:746). The last tool exchange stays verbatim although no breakpoint can mark it: the route hardcodesProvider: bschemas.OpenAI(apply/responses.go:559), and its rebuildrebuildResponsesCountChanged(apply/responses.go:273) never callsanchorCacheBreakpoint— that call exists only on the Messages route (apply/apply.go:792). This is the exact "kept for nothing" behavior the PR removes on the Chat Completions route, so every summarized Responses turn leaves those tokens unsummarized, and the PR summary line "OpenAI summaries now cover the last tool exchange" is wrong for this route. - Proof:
TestResponsesCacheAwareOneMessageSpliceIsWritten(apply/responses_test.go:543) shows the summarizer runs and splices on the Responses route, andTestResponsesSetsRawInputBeforeThePipelineRewrites(apply/responses_test.go:513) showsfunction_call_outputitems normalize torole:toolmessages, which is what the retreat keys on.grep anchorCacheBreakpoint apply/returns only apply.go:792, so the Responses rebuild writes no anchor. - Fix: add
NoCacheBreakpoint: trueto theCtxliteral inapply/responses.go(the route is always OpenAI, so!explicitBreakpointProvider(bschemas.OpenAI)is a constanttruethere). Add a Responses-route test that the summary covers the last function-call exchange, mirroringTestTheSummaryCoversTheLastToolExchangeOnlyOnOpenAI.
- What fails: an OpenAI
Non-blocking
- A conversation that switches provider mid-thread can replay an OpenAI-commissioned checkpoint (exchange covered) on an Anthropic turn. The anchor is recomputed from the spliced output at replay time (
lastKeptToolResultID), so it still lands on a kept tool result when the tail holds one; only a text-only tail loses the #723 read. Fail-open, cost only, and rare. No action needed now. - Gemini wires get the new behavior too (
NoCacheBreakpointtrue) with no test. The component test covers OpenAI and Anthropic only. Low risk, since Gemini is not an explicit-breakpoint provider. - The two keepalive comment fixes are correct:
config.DefaultKeepAliveIdle = 240(config/config.go:197), so the Anthropic slack is 300 s − 240 s = 60 s andsubstituteWindowreturns 64 s. The old "270 s" text did not match the code.
What I checked
- Read the full diff (7 files) and the code around each change:
apply/apply.go(BodyOpts Ctx),components/component.go(new field),components/offload/cache_aware_summarizer.go(the gated retreat),keepalive/substitute.goand its test (comment-only). - Traced every constructor of
components.Ctx:apply/apply.go:666(sets the field fromexplicitBreakpointProvider),apply/responses.go:568(does not — the finding),adapters/bifrost/plugin.go:51(zero value keeps the old retreat, fail-safe), test-only constructors. - Verified the gated retreat stays consistent with its consumers:
tryReuse/replayStalecomparestart + CoveredCountagainst the pre-retreatend, so the larger OpenAICoveredCountstill passes; the commission, deferral (ResolveDeferredCacheAwareSummary), and keep-alive substitute paths all freeze the span andcoveredCountat commission time, so none re-derives the retreat later. - Verified reversibility: the span including the exchange is stashed under the summary's marker (
markerFulldefault, stash-room check before the call), andsplice+advanceSpanBoundarykeep the cut on a safe boundary, so no orphaned tool result is created by covering the exchange. - Verified the anchor path is untouched for Anthropic:
anchorCacheBreakpointstill runs only underexplicitBreakpointProvider, and an emptyCacheAnchorToolIDis a no-op (apply/metawrite.go:239). - Checked both new tests against their helpers (
caFixture,caToolPair,caCtx,WaitForSummaryForTest,recordingModel): the index arithmetic gives CoveredCount 17 (OpenAI) vs 15 (Anthropic, equal to the retreat) as the test asserts. - Checked the PR description's data-dependence statement: metadata only (provider name), no storage change,
docs/data-dependence.mdunchanged — consistent with the diff. - Live tests were not run (not approved); the PR reports them passing on the eval box.
…reakpoint flag (#730) The Responses route is always OpenAI. It built its Ctx without NoCacheBreakpoint, so it still retreated the summary span. - Set NoCacheBreakpoint on the Responses Ctx. - Set it on the bifrost adapter Ctx, which never writes the anchor. - Add a Responses test: the summary covers the last function_call_output. - Rename the apply-level OpenAI test to say what it checks. Assisted-By: Claude Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Collaborator
Author
|
Fixed in the new head.
Tests: |
amiddavid
commented
Oct 26, 2026
amiddavid
left a comment
Collaborator
Author
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 | resumed | 1 of 2 | 2 of 2 | 290802fe29b4 |
approve |
Verdict: approve
Findings
None.
Earlier findings
- Mine, round 1 — Responses route missing
NoCacheBreakpoint(blocking): fixed.apply/responses.go:571now setsNoCacheBreakpoint: !explicitBreakpointProvider(bschemas.OpenAI), a constanttrueon that route. The newTestResponsesSummaryCoversTheLastToolExchange(apply/responses_test.go:570) covers it: I traced the indices — 7 normalized messages,end = 7 - keep_last_turns(2) = 5, so the spanmsgs[1:5]folds in thefunction_call_output(index 4). With the flag back atfalse, the retreat movesendto 3 andLASTEXCHANGEstays in the body, so the test fails. The test discriminates. - Mine, round 1, non-blocking — bifrost adapter without the flag: fixed.
adapters/bifrost/plugin.go:58setsNoCacheBreakpoint: trueunconditionally. That is right for every provider on that host: the adapter runs the pipeline in place and has no anchor-writing path at all, so the retreat's premise ("the host marks the exchange") never holds there. No Anthropic-via-bifrost regression: that host never had the #723 mark. - Mine, round 1, non-blocking — test name promised an Anthropic half: fixed. Renamed to
TestTheOpenAISummaryCoversTheLastToolExchange, and the comment now points at the tests that hold the Anthropic half. - Reviewer 2, round 1, finding 1 — same defect as my finding 1: fixed (checked myself, see item 1; I add no new proof beyond it).
- Reviewer 2, round 1, non-blocking items (mid-thread provider switch, Gemini untested, keepalive comment check): all marked "no action needed" by reviewer 2 themselves. The author left them; I agree that is fine.
Non-blocking
- The bifrost flag has no test. A cheap one exists: run
PreRequestHookwith a probe component that readsNoCacheBreakpointoff theCtx. Low value, since the adapter'sCtxsets the flag literally; note it only if you want every host hint pinned.
What I checked
- Last review: round 1, 0c90804, 2026-10-26T09:57:36Z.
- New commits read: 1 —
290802fe"fix(apply): give the Responses route and the bifrost adapter the no-breakpoint flag (#730)". - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt; the inline file is empty). - New items since my last review: the fix commit above; the author's comment at 2026-10-26T10:11:35Z ("Fixed in the new head", with a mutation check on the Responses test and a
-racetest report). Both read and checked against the code. - The full new diff:
adapters/bifrost/plugin.go,apply/cache_anchor_test.go(rename only),apply/responses.go,apply/responses_test.go. explicitBreakpointProvideris package-local toapply, so the newresponses.goexpression compiles in that package;bschemas.OpenAIyieldsfalse, so the field istrueon that route.- The new test's body shape:
function_call/function_call_outputitems match whatnormalizeResponsesmaps (apply/responses.go:71-78); imports (strings,offload,time,context,gjson,recordingModel) are all already used by the neighboring test at apply/responses_test.go:543. - I did not run the tests: live runs are not approved and Go is not installed here. The author reports
-racepassing on./apply/... ./adapters/... ./components/... ./keepalive/....
amiddavid
commented
Oct 26, 2026
amiddavid
left a comment
Collaborator
Author
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 | resumed | 2 of 2 | 2 of 2 | 290802fe29b4 |
approve |
Verdict: approve
Findings
None.
Earlier findings
- Mine, round 1 — Responses route missing
NoCacheBreakpoint(blocking): fixed.apply/responses.go:571now setsNoCacheBreakpoint: !explicitBreakpointProvider(bschemas.OpenAI)— a constanttrue, matching the route's hard-coded OpenAI provider (apply/responses.go:559) and its rebuild that never writes an anchor.- New test
TestResponsesSummaryCoversTheLastToolExchange(apply/responses_test.go:571) drives the route end to end and asserts the lastfunction_call_outputtext is gone after the splice. I traced the indices: 7 input items normalize to 7 messages,keep_last_turns: 2gives end = 5, the old retreat would have moved it to 3, and the span [1, 5) now covers the exchange at 3–4. The test would fail under the old behavior, which the author's mutation check also shows.
- Reviewer 1, round 1, finding 1 — same Responses-route defect: fixed by the same change. I checked it myself; my proof above stands on its own.
- Reviewer 1, round 1, non-blocking — bifrost adapter leaves the flag unset: addressed.
adapters/bifrost/plugin.go:59now setsNoCacheBreakpoint: true. The author's reason is right: that host runs the pipeline in place and never writes theCacheAnchorToolIDmark for any provider, so the retreat buys nothing there. Unconditionaltrueis more correct than a provider check, because the anchor write is a host capability, not a provider fact. Today the value is latent anyway (the summarizer declines atwindow_not_exacton that host), so no behavior change now. - Reviewer 1, round 1, non-blocking — apply test name promised more than it asserted: addressed. Renamed to
TestTheOpenAISummaryCoversTheLastToolExchange, with the comment pointing at the Anthropic-half tests above it. - My round-1 non-blocking notes (cross-provider replay edge, no Gemini test): not acted on. Both were marked "no action needed now" / low risk. I accept that.
Non-blocking
apply/responses.go:571writes!explicitBreakpointProvider(bschemas.OpenAI), a constanttrue. A plaintruewith the comment would read the same. Style only; no action needed.
What I checked
- Last review: round 1, 0c90804, 2026-10-26T09:59:19Z.
- New commits read: 1 —
290802fe"fix(apply): give the Responses route and the bifrost adapter the no-breakpoint flag (#730)". The worktree is checked out at that head. - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files).
- New items since my last review: the commit above and the author's comment at 2026-10-26T10:11:35Z (fix summary). Both read in full and checked against the code.
- Read the full new diff (4 files) and the code around each change: the Responses
Ctxliteral, the bifrostCtxliteral, the renamed apply test, the new Responses test. - Verified the new test's helpers and imports already exist in
apply/responses_test.go(pipe,recordingModel,offload.WaitForAllSummariesForTest,strings,time). - Traced the new test's span arithmetic (see finding 1) and the splice path: count change 7 → 4 goes through
rebuildResponsesCountChanged, which the existingTestResponsesCacheAwareOneMessageSpliceIsWrittenalready exercises on this route. - Confirmed the bifrost change cannot break Anthropic traffic through that adapter: the flag's only consumer is the summarizer's retreat, tail-start safety stays guaranteed by
advanceSpanBoundary, and reversibility is untouched. - Confirmed nothing else in the round-1 diff changed:
git diff 0c90804f..HEADtouches only the four files above. - Live tests were not run (not approved). The author reports
-racepassing on./apply/... ./adapters/... ./components/... ./keepalive/...and a cleango vet.
This was referenced Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #730.
What changed
components.Ctx.NoCacheBreakpoint: new field. The host sets it from the provider (!explicitBreakpointProvider).cache_aware_summarizer: skipsretreatPastLastToolExchangewhen the field is true. Anthropic, Bedrock and Vertex behave as before.keepalive/substitute.go,keepalive/openaiphase_test.go: comment text now matches the 240 s default idle.apply/apply.go: one line added to theCtxliteral. The rest of the diff there is gofmt realignment.Fail-open is unchanged. The zero value of the new field keeps the old retreat.
How it was tested
On the eval box, with
-race:./apply/... ./components/... ./keepalive/...: all pass.go vet ./...: clean.New tests:
TestSummarySpanRetreatsOnlyWhereABreakpointCanBeWritten(offload): OpenAI covers more than the retreated span, Anthropic covers exactly it.TestTheSummaryCoversTheLastToolExchangeOnlyOnOpenAI(apply): the spliced OpenAI body holds no last-exchange text.Mutation checks:
false: the apply test fails.Data dependence
docs/data-dependence.mddoes not change.🤖 Generated with Claude Code