Repository navigation
fix(cachesplit): keep the Converse cachePoint entry after the stable half - #755
Merged
Merged
Conversation
…half (#45) On Bedrock Converse, cachePoint is its own system array entry after the block it ends. The split put the volatile half before that entry, so the breakpoint still covered the churn while the split reported Changed. The split now keeps a standalone cachePoint entry directly after the stable half and puts the volatile half after it. The Anthropic field-on-block case is unchanged. The docs state that the -34.1% figure is an Anthropic measurement. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
amiddavid
commented
Oct 27, 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.311 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 2d0c1b078ffa |
approve |
Verdict: approve
Findings
None. The fix is correct. I traced every path I could construct against it.
Non-blocking
apply/prefixsplit_test.go:501— the new test callssplitTaildirectly. It does not go throughBodyFullon the Converse shape. The gate (apply/apply.go:478) and the splice are shared with the Anthropic path, whichTestSplitAppliedThroughBodyFullcovers. Risk is low. A wiring test per provider shape would close it.apply/apply.go:1239—hasCacheBreakpointqueriessystem.#.cache_controlbut notsystem.#.cachePoint. A Converse body whose only breakpoint is a standalone system entry reads as "no breakpoint". Today this changes nothing: Converse bodies go to Bedrock, andresolveCacheAwarereturns true for Bedrock by provider name (apply/apply.go:979). Pre-existing, not this PR.docs/components/caching.md:70— the doc still says the component'sReformat"always reportsSkipped".apply/apply.go:705sets the flag before the run, andTestSplitIsReportedAgainstCachesplitasserts the opposite. The line is stale. Pre-existing, but this PR edits the same file, so it was cheap to fix here.apply/prefixsplit.go:191—e.Get("cachePoint").Exists()is true for a JSONnullvalue.{"cachePoint":null}would count as standalone and move after the stable half. That input is invalid on the Converse wire, and the entry is moved, not lost. No action needed.
What I checked
- Full diff
245982d7..HEAD(one commit, three files) and the code around each change. - The reorder logic: on Converse, a
cachePointentry ends the cached prefix at the block before it. Output[stable, cachePoint, volatile]keeps the churn outside the hashed prefix. The old code emitted[stable, volatile, cachePoint], which covered the churn — the defect named indocs/results/improvement-plan.md(§F, "the split on Bedrock Converse") and issue #45. - Loop bounds: the inner
i++fires at most once, because the marker search is gated on!split. Only the cachePoint entry is skipped, and it is appended verbatim. No block is lost or duplicated. Blocks after a non-split block keep their own cachePoint neighbours in place. - Breakpoint count, both spellings:
CountBreakpoints/elemMarks(apply/metawrite.go:161-211) count the standalone entry as 1. The split block in Converse carries no inline mark, so the count stays 1 -> 1. A block with an inline mark plus a standalone follower also stays 2 -> 2 (inline stays on the stable half, standalone is appended, both are deleted from the volatile half). - Fail-open and losslessness: the consumed entry is copied from
blocks[i+1].Rawbefore any body rewrite. Error paths return the input untouched. Text concatenation is unchanged; the new test asserts both halves and the preserved count. - Byte-shift bookkeeping:
shiftAt/shiftcome from the wholesystemsplice (prefixsplit.go:185), not from entry order, so the reorder cannot corrupt the message writeback. - Ordering against neighbours:
headTTLruns before the split and only edits existing marks; nothing after the split rewritessystem(onlyprefixsplit.go:177does). - The test itself: traced
blockWithGitTail(6000)through the split.atlands after the newline, both halves pass the token floor, and the assertions match the code's output for Bedrock and BedrockMantle. docs/data-dependence.md:184— thecachesplitrow still holds; the PR changes no data dependence, and the PR body says so.- The doc edit in
caching.mdis honest: the −34.1% figure is Anthropic-only, the Converse path has no cost measurement.
amiddavid
commented
Oct 27, 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.311 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 2d0c1b078ffa |
approve |
Verdict: approve
Findings
None. The fix is correct and lossless. Details of what I verified are under "What I checked".
Non-blocking
apply/prefixsplit.go:191—isStandaloneCachePointdoes not check the provider. On an Anthropic- or Vertex-shaped wire, a standalonecachePointentry is invalid input. If a client sends one after a block that splits, this code reorders it. The entry is broken either way, and the reorder keeps the count. No action needed.apply/prefixsplit.go:155— The skip consumes exactly one standalone entry. Two back-to-backcachePointentries after the split block would leave the second one after the volatile half. The Converse API allows this shape but it is pointless on the wire, so I do not expect it. Aforloop instead of the singleifwould cover it.apply/prefixsplit_test.go:501— The new test does not cover the combined shape: a split block with an inlinecachePointplus a standalone entry after it. I traced that path by hand: the stable half keeps the inline mark, the standalone entry is consumed, and the total count stays 2. A test would pin this down.
What I checked
- The reorder is semantically right. A Converse breakpoint covers everything before it. Input
[block, {cachePoint}]becomes[stable, {cachePoint}, volatile], so the hashed prefix ends at the stable half. Before the fix, the output was[stable, volatile, {cachePoint}]— the breakpoint still covered the churn, and the split reported success while buying nothing. The fix matches its claim. - Text seen by the model is unchanged. A
cachePointentry carries no text, so the concatenation of system text is the same in both orders. - The consumed entry survives verbatim.
apply/prefixsplit.go:156appendsblocks[i+1].Rawunmodified. Thei++plus the loop increment skips exactly that entry; I traced the index arithmetic for the entry last in the array and for entries after it. - The
!e.Get("text").Exists()guard is needed and correct. A block that carries an inlinecachePointplus text must not be consumed as standalone — its text would be dropped. With the guard, such a block keeps its inline mark on the stable half through the field copy atapply/prefixsplit.go:129-132, and thedelete(volatile, ...)at line 142-143 keeps the cap-safe count. The guard also passesguardContent-only entries through untouched. - Breakpoint count stays within the cap of four.
CountBreakpoints(apply/metawrite.go:161) counts acachePointfield on any system element, wherever it sits. The move changes order, not count. The new test asserts this (wireBreakpointsbefore == after), and I checkedwireBreakpointsandblockMarksinmetawrite.go:109-118count the standalone spelling. - The byte-shift contract still holds. The writeback uses
shiftAt = sys.Index + len(sys.Raw)andshift = len(next) - len(body)(apply/prefixsplit.go:185). The reorder happens inside the re-marshaledsystemvalue;sjson.SetRawBytesstill splices one range, so bytes aftersystemkeep moving by a uniform shift. The caller atapply/apply.go:478-481is unaffected. - The loop rewrite is behavior-identical for input without a standalone entry. Existing tests (
TestSplitsGitTailOffStableBodyand the rest ofprefixsplit_test.go) cover those paths. - The test is real.
blockWithGitTail(6000)clears both thelen(txt)/4 >= 1024andat/4 >= 1024floors. The assertions check the order, both halves' text, thecachePointposition, and the count, forBedrockandBedrockMantle. Both constants exist (apply/prefixsplit.go:212). - Fail-open paths are untouched. Every error branch still appends the original raw block and continues; the marshal failure and no-split returns are unchanged.
- The doc change is accurate.
docs/components/caching.mdnow says the Converse path has no cost measurement. That matches the code: the −34.1% figure came from Anthropic-shaped traffic.
This was referenced Oct 27, 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
The volatile-tail split now works on the Bedrock Converse shape. Before, it reported a split that did not help.
What changed
cachePointis its own entry after the block. The split now keeps that entry right after the stable half. The volatile half goes after it.docs/components/caching.mdnow says the -34.1% figure is an Anthropic measurement. The Converse path has no cost measurement.How it was tested
gofmt -l,go vet ./applygo test -race ./apply/...Data dependence
None changes. The split reads request structure and the system text, as before. No stored customer data.
docs/data-dependence.mdneeds no change.Open questions
Closes #45
🤖 Generated with Claude Code