Repository navigation
refactor(schema): one canonical form of a message for cross-request comparison (#783) - #787
Conversation
…omparison (#783) Add schema.CanonicalMessage (bifrost schema) and schema.CanonicalWireMessage (wire JSON). Both remove cache_control and read a list of one plain text block as its string. The wire form also sorts keys and keeps numbers as literal text. - components.SpanHash and expand.Fingerprint use the canonical form. - A stored hash is compared through SpanHashMatches / fingerprintMatches, which also accept the hash the old rule gives the same message. Nothing stored before the upgrade reads as new. - A message with no one-text-block content hashes byte for byte as before. - internal/thread keeps its own streaming hash (its ids key stored checkpoints); a shared table test holds every caller to one equality. Assisted-By: Claude Opus 5.5 <[email protected]> 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 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.316 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | d6c99955bf66 |
blocking |
Verdict: blocking
Both findings are the same class: the "stored before the upgrade" fallback does not try
every form the canonical rule now treats as one message. Fail-open holds in both. No wrong
content goes out. The cost is a lost reuse, once, per stored record that straddles the
upgrade. Severity is low, but both contradict the PR's own claim ("Nothing stored before
the upgrade reads as new"), and finding 1 hits the exact configuration (small
keep_last_turns) where this bug class was first found (#402).
Findings
-
components/component.go:207 — the legacy fallback misses a pre-#783 checkpoint whose covered span held the then-newest message
- What fails: a deployment runs
keep_last_turns: 0(allowed:Min: 0,
components/offload/cache_aware_summarizer.go:431). Thenend = len(msgs) - keepLast(components/offload/summarize_pairing.go:150), so the covered span
includes the request's newest message. Claude Code sends that message as one text
block withcache_controlon that turn, and as a string on every later turn. A
checkpoint written before the upgrade storesLegacySpanHashof the block form. On
the next turn the span carries the string form.SpanHash(msgs)is the canonical
(string) hash;LegacySpanHash(msgs)is the old rule over the string form. Neither
equals the stored old-rule hash of the block form. SoSpanHashMatchesreturns
false,tryReusedeclines (components/offload/summarize.go:819), and a fresh
summary is commissioned. The fallback is dead code for this configuration: the first
read after the write already sees the string form. - Proof:
LegacySpanHashstripscache_controlonly (components/component.go:198,
222-247); it does not collapse a one-text-block to its string, so old-rule(block) ≠
old-rule(string). The anchor side solves exactly this transition by reconstructing
the block form (asTextBlock, expand/anchor.go:126) before hashing under the old
rule;SpanHashMatcheshas no such reconstruction. The new tests cover the legacy
fallback only with the span in the same form it was stored in
(components/spanhash_canon_test.go:288-309,
components/offload/spanhash_upgrade_test.go:158-186). No test covers legacy-stored
plus form transition. - Fix: in
SpanHashMatches, also comparewantwith the legacy hash of the span
rewritten so each plain-string content message becomes its one-text-block form (the
inverse ofschema.CanonicalMessage's collapse). Or state the limit in the
SpanHashMatchesdoc and accept the one-time decline. Bounded either way: one extra
summary commission per straddling checkpoint, then the new checkpoint is canonical
and stable.
- What fails: a deployment runs
-
expand/anchor.go:104 — the legacy fallback does not reconstruct a
tool_resultblock's content- What fails: an anchor recorded before the upgrade over a user message whose
tool_resultcontent is[{"type":"text","text":"out","cache_control":…}]. After
the upgrade the client sends that content as the string"out"— the transition
CanonicalWireMessageitself unifies (schema/canon.go:88-93).Fingerprint(msg)
collapses thetool_resultcontent to the string, so it cannot equal the stored
old-rule hash, which keeps the block form.legacyCanonical(msg.Raw)keeps the
string.asTextBlockrewrites only a top-level stringcontent
(expand/anchor.go:126-135); here the top-level content is thetool_resultarray,
so it returns "". No path matches,Usablereturns false, and the anchor stays
unusable forever — the expanded original is never restored for it. - Proof: the three values
fingerprintMatchestries areFingerprint(msg),
legacyCanonical(msg.Raw)andlegacyCanonical(asTextBlock(msg))
(expand/anchor.go:93-108); none writes atool_resultblock's string content back
as one text block. The canonical rule says the two forms are one message
(schema/canon_callers_test.go:701-703, pair "tool_result content, string vs one
text block"), butTestAnAnchorRecordedByTheOldRuleStillMatches
(expand/anchor_test.go:468-497) has notool_resultcase. As with finding 1, this
anchor was already lost before the upgrade, so it is a gap in the fix, not a
regression. - Fix: in the fallback, also try the message with each
tool_resultblock's string
contentwritten as one text block. Or name the limit in the
fingerprintMatchescomment.
- What fails: an anchor recorded before the upgrade over a user message whose
Non-blocking
- The two canonical forms disagree on one shape: a text block with a field bifrost does
not model. The wire form requires exactlytype+text
(schema/canon.go:622-634,len(blk) != 2); the struct form drops unknown fields and
collapses (schema/canon.go:45-47,plainText). No caller compares a struct hash with
a wire hash, and the struct path cannot see the extra field anyway. Not reachable from
a schema-valid client. - A message that carries both
ContentStrandContentBlocksmakes bifrost's
MarshalJSONerror, so it adds empty bytes to both hashes
(components/component.go:211-219,b, _ := json.Marshal). Two different such
messages are legacy-equal but not canonical-equal, so the "fallback never accepts a
span SpanHash would reject" claim (components/component.go:205-206) does not hold
there. Invalid state, unreachable from the wire (see schema/schema.go:104-110). - dash/toolinventory.go:675-678 hashes the raw last tool-using message,
cache_control
included. That is the same false-mismatch class this PR removes elsewhere. The cost is
only a recount of used tools. Suggest its own issue rather than a change here. - I could not run the tests (live tests not approved; Go is not on this laptop). CI
puregopassed;build-testwas still pending when I posted.
What I checked
- Full diff 1ce2d4c..d6c9995, and the code around every hunk: components/component.go,
the fourspanHashMatchescall sites, state.go, summarize.go's
summaryCoveredHashMatches, extract_sweep_recheck.go, expand/anchor.go, schema/canon.go. - Every store site and every compare site of a stored hash or fingerprint:
sumCheckpoint.CoveredHash (4 readers, all through the new Matches), heldOutput.Hash
(recheck), Anchor.Fp (Usable), the async and inline writers, the keepalive checkpoint
writer,summarize.go:635's marker-full hash (it equalssummaryCoveredHash, because
spanJSONcomes fromsummaryStashJSON, which is the same payload function). - The proxy's
sentStash(proxy/prefixask.go): it recomputes both sides from in-memory
bytes, so==there is safe across this change; nothing persisted compares a
SpanHashwith==outside the Matches wrappers. - The safety claims: canonical form is a function of the legacy form, so a legacy
fallback match implies a canonical match — holds for both the struct and the wire path,
except the degenerate both-fields case noted above. - Mutation safety:
CanonicalMessagecopies before it clears or collapses; confirmed by
reading the code and by TestSpanHashDoesNotTouchTheMessage. - Import graph:
schemaimports only stdlib and bifrost, socomponents→schemaand
expand→schemaadd no cycle. Test-helper names collide with nothing in their
packages. - internal/thread.Fingerprint already unifies string and one-text-block (its own canon),
so the shared caller table's expectations hold for it.
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.316 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | d6c99955bf66 |
approve |
Verdict: approve
Findings
None. Every defect candidate I chased survived neither a line-level proof nor a trace. Details of
what I proved are under "What I checked".
Non-blocking
components/offload/summarize.go:350— on the Responses route, the covered hash stays
representation-sensitive.summaryCoveredHashhashes the stash payload, which
apply/responses.go:248builds from raw wire bytes. ThespanHashhalf is now flip-insensitive,
but the payload half is not. So on Responses, a string-against-block flip still declines checkpoint
reuse. The fail direction is safe (a fresh summary, never a wrong reuse), no known Responses client
flips, and it is pre-existing. Worth a line in the PR if Responses flips are ever observed.schema/canon.go:66andschema/canon.go:623— the struct form and the wire form can disagree
on a block with an extra key.plainTextworks from the bifrost struct, which drops unknown wire
fields, so[{type,text,unknown}]collapses underSpanHash.collapseTextContentneeds exactly
2 keys, so it does not collapse underFingerprint. Each hash space is internally consistent, so
this can only miss an equivalence, never invent one.- Responses
input_textblocks do not collapse. Onlytype:"text"collapses, so a
string-against-input_textflip on Responses is not recognized. Fail-safe direction (anchor
skipped, checkpoint not reused). expand/anchor.go:126— the legacy fallback rewrites only the message's owncontent. A
pre-upgrade anchor over atool_resultwhose block content now arrives as a string is skipped:
asTextBlockdoes not reach inside atool_result. The old rule missed this case too, so it is
not a regression, and the anchor's fallback is fail-open (kept-verbatim in place).components/component.go:207— the decline path pays two hash passes. When the primary hash
does not match,SpanHashMatchesalso computesLegacySpanHashover the whole span. One extra
marshal pass per declined checkpoint per turn. Acceptable; drop the legacy fallbacks when the
pinned pre-upgrade values age out (the PR's own open question).
What I checked
- Read the full diff (13 files) and the code around every hunk. One commit,
d6c99955. - The legacy rule is byte-identical to the old one. I diffed
legacyStripCacheControlagainst
the pre-PRstripCacheControl(identical body), andlegacyCanonical+fingerprintOfagainst
the oldFingerprint(same decode, samestripCacheControl, same marshal, same truncation, same
"" on unparseable input). So a pre-upgrade stored hash recomputes exactly. - The fallbacks cannot accept what the new rule rejects. Trace: if two forms are equal under the
legacy rule, they are equal after the one extra equivalence the canonical rule adds (blocks to
string), so they are equal under the canonical rule. The same holds for theasTextBlockbranch:
it only rebuilds the block form of the same text. Checked bothSpanHashMatchesand
fingerprintMatches. plainTextcovers every fieldChatContentBlockcarries.schema/schema.go:118documents
the full set (Type/Text/Refusal/ImageURLStruct/InputAudio/File plus CacheControl, Citations,
CachePoint).plainTextchecks all of them except CacheControl, which is set aside on purpose.
ChatMessageContenthas onlyContentStrandContentBlocks, so the collapse drops nothing.- Every comparison against a stored hash goes through a
...Matcheshelper. I grepped the repo
for stored-hash equality and read each site:tryReuse(both summarizers),
checkpointRefreshOpportunity,dispatchDeferred,recheckHeld,Anchor.Usable. The two
proxy/prefixask.gosites compare hashes computed live on the same turn (current request against
the stash, both normalized by this binary), so plain==is right there. The dash, keepalive and
modes packages hold no span hashes.thread.Fingerprintalready collapsed string against block
and is unchanged, so no thread id moves. - Write and read sides stay paired. The plain summarizer writes a payload-aware covered hash and
reads withsummaryCoveredHashMatches; the cache-aware writers write a barespanHashand read
withspanHashMatches. The legacy paths recompute the exact pre-PR formulas, including
hashKey(payload + ":" + hash). - The collapse cannot merge two messages the model reads differently. A block collapses only
when it istype: "text"plustextplus optionalcache_control, which is what a provider
renders as the bare string. Blocks with citations, cache_point, or any other field stay blocks. CanonicalMessagecopies, never mutates. The collapse and the strip both build newContent
values; the caller's message keeps its breakpoint (the new test asserts this too).- The new tests are sound and should pass. I traced each pair in
schema/canon_callers_test.go
through all four callers (includingthread.canonAt's synthetic block form for a string content,
andattachToolUsekeeping large integers exact inToolCalls.Arguments), and each stored-value
test's precondition, positive and negative cases. No test-helper name collisions in the
components,schema_test,offloadorexpandpackages; no import cycle from
components/expandtoschema. - Repo rules. The PR names the behavior change at the top, with old and new behavior and who it
affects. Data dependence is stated (none: a hash over in-request data, nothing new stored), and no
docs/data-dependence.mdrow changes. No proxy import from a library package. Live tests were
not run (not approved); this is a code-only review.
…783) Review round 1 of #787 found two stored values that still read as new: - A summary checkpoint stored over the block form of the then-newest message (keep_last_turns: 0). SpanHashMatches now also tries the old hash with the last message, and with every message, written back as one text block (LegacySpanHashes). summaryCoveredHashMatches uses the same list. - An expand anchor over a tool_result whose content was one text block. fingerprintMatches now also tries the old hash with the tool_result string content written back as one text block (the last one, and all of them). Each extra form is the same message under the canonical rule, so the fallback never accepts a pair the canonical rule rejects. Tests cover both changes and the negative cases. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
|
Reply to reviewer 2, round 1, finding 1 (
|
|
Reply to reviewer 2, round 1, finding 2 (
|
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.316 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 954b64be4b4a |
approve |
Verdict: approve
Both round-1 findings are fixed, and I verified the fixes by hand. No new finding.
Round-1 findings
-
SpanHashMatchesmissed a checkpoint stored over the block form — FIXED (954b64b,
components/component.go:213).LegacySpanHashesnow tries three old-rule hashes: the span as it is, the span with
the last message's string content as one text block (thekeep_last_turns: 0case),
and the span with every string content as one text block.- I traced the case that failed: a checkpoint stored as
LegacySpanHash([strings…, block "go"]), read on the next turn as[strings…, "go"]. Form 2 rewrites the last
message back to a block and matches. The reverse direction (stored over strings, now
a block) already matched through the primarySpanHash, because canonical(block) ==
canonical(string) == legacy(string). - The dedup is right: form 3 is skipped when it would equal form 2 (one flip, at the
last message) or form 1 (no flips). Themsgs[len(msgs)-1]index is guarded by
flipped == 1, so an empty span cannot panic. - The safety claim holds: every form differs from
msgsonly by a string written as
one plain text block, andCanonicalMessagecollapses that block back to the same
string. So any form that matches a stored hash is a span the canonical rule accepts. summaryCoveredHashMatches(components/offload/summarize.go:357) walks the same
list and keeps the exact old payload formula,hashKey(payload + ":" + hash). The
recheck, keepalive and cold-deferral readers get the new forms for free through
SpanHashMatches.- Tests:
TestSpanHashMatchesAcceptsAnOldHashAcrossTheBlockToStringChangeand
TestASummaryCheckpointOverTheBlockFormIsReusedOnTheStringForm. I traced every case,
positive and negative (other text, other role, two blocks, shorter span, different
span at the summarizer). Each fails without the fix and passes with it.
-
fingerprintMatchesdid not rebuild atool_resultblock's content — FIXED
(954b64b, expand/anchor.go:143).fingerprintMatchesnow also tries the old-rule hash of the message with each
tool_resultblock's stringcontentwritten as one text block: the last such block
only, and all of them.- I traced the case that failed: an anchor stored over
[t0:"first", t1:[text "out"]],
read as[t0:"first", t1:"out"]. The last-only form matches (flipping both would
breakt0, which the stored hash keeps as a string — the test covers exactly this). - The rewrite is safe:
CanonicalWireMessagecollapses atool_resultblock's
one-plain-text-block content back to the string (schema/canon.go:88-93), so every
tried form is the same message under the canonical rule. Atool_resultwhose stored
block form had more than a plain text block cannot match the reconstruction, so no
wrong accept. gjson.Array()on a non-array returns the result itself, so a message with string
content cannot be misread as a block list; the guard holds. Thesjsonpath
content.<i>.contentindexes the same arraygjsonwalked.- Test:
TestAnOldAnchorOverAToolResultBlockMatchesItsStringForm, both recorded forms
and three negatives (other text, othertool_use_id, two text blocks). I traced each;
none matches.
Non-blocking
LegacySpanHashestries three of the 2^k possible string/block mixes: none, the last
message, all. A middle-only flip is not tried. No known client produces it (a block
form exists only to carrycache_controlon the newest message), the doc names the
three forms and why, and a miss costs one declined reuse, fail-open. Fine as is.- On the mismatch path
SpanHashMatchesnow computes up to four hash passes over the span
(one canonical, three legacy). Bounded to the decline path, once per eligible turn.
Acceptable; drop the legacy forms when pre-upgrade values age out. - The degenerate both-content-fields message from round 1 (bifrost
MarshalJSONerrors,
unreachable from the wire) is unchanged. Still not reachable.
What I checked
- Last review: round 1, d6c9995, 2026-11-01T09:28:11Z.
- New commits read: 1 — 954b64b "fix(schema): old-rule fallbacks try every form of a
changed message (#783)". Full diff read; each changed file read around the change
(components/component.go, components/offload/summarize.go,
components/offload/spanhash_upgrade_test.go, components/spanhash_canon_test.go,
expand/anchor.go, expand/anchor_test.go). - Read in full: 2 reviews, 2 comments, 0 inline comments (from the three saved files).
- New items since my last review:
- Reviewer 1's round-1 review (approve, no findings; non-blocking notes overlap my
round-1 items — thetool_resultfallback gap and the struct/wire divergence). I
checked the two fixes above against the shared concern; nothing new to add. - Author's two replies to my findings (both "fixed in 954b64b"): verified each claim
against the code — the three-form list, the payload-prefix formula, the two
tool_resultforms, the tests, and the mutation claims. The author reports
go test -racegreen on the eval box; I could not run tests myself (not approved),
but CIpuregopasses on 954b64b (build-testpending at posting).
- Reviewer 1's round-1 review (approve, no findings; non-blocking notes overlap my
- No new commits beyond 954b64b; no inline comments exist.
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.316 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 954b64be4b4a |
approve |
Verdict: approve
Findings
None in the new commit. Both round-1 findings are fixed correctly, and the fix adds no defect
I could prove. Trace-level detail under "What I checked".
Earlier findings
- Reviewer 2, finding 1 (SpanHashMatches misses a checkpoint stored over the block form):
fixed.LegacySpanHashes(components/component.go:213) now also tries the span with the
last message's string content written as one text block, and with every string content so
written. I verified the gating (flipped > 1 || flipped == 1 && last is not the string)
adds no duplicate and cannot index an empty span.summaryCoveredHashMatches
(components/offload/summarize.go:357) applies the same list under the stash-payload prefix,
and stays byte-identical to the round-1 behavior for the no-payload, no-flip case. - Reviewer 2, finding 2 (fingerprintMatches does not rebuild a tool_result's content):
fixed.toolResultsAsTextBlocks(expand/anchor.go:143) rewrites each tool_result block's
string content as one text block, in two forms: all of them, and the last one only. I traced
both new test cases throughfingerprintMatchesby hand: the "last block" recording matches
through the last-only form, the "every block" recording through the all form. The negative
cases (other text, othertool_use_id, two text blocks) match no form. - Reviewer 2's non-blocking items: not addressed, and I agree they stay non-blocking. The
both-fieldsContentstate is unreachable from the wire (bifrost'sMarshalJSONerrors on
it, so neither side of a stored comparison can be written from it). The
dash/toolinventory.goraw-message hashing deserves its own issue, as reviewer 2 said. - My round-1 non-blocking notes: the tool_result fallback gap (my note 4) is now fixed by
this commit. The others (Responses payload sensitivity, struct-against-wire disagreement on
extra block keys,input_textnot collapsing) are unchanged and still non-blocking.
Non-blocking
components/component.go:251— the decline path now pays up to 4 marshal passes. A
typical all-string span triggers every form: canonical, legacy as-is, last-flipped,
all-flipped. That is one extra pass over the covered span per declined checkpoint per turn,
on top of round 1's two. Correct, just cost. The PR's own open question (dropping the legacy
fallbacks later) is the remedy.components/offload/spanhash_upgrade_test.go:53— the stash-payload test uses a constant
payload. In production the payload is the raw wire bytes of the span
(apply/responses.go:248), which differ across a string-against-block flip. So on the
Responses route the new forms 2 and 3 are inert: an identical payload implies an identical
normalized span, which form 1 already matched. Fail-safe, and no known Responses client
flips. My round-1 note stands.components/component.go:202— the form list is 3 of the 2^n string/block assignments.
It covers the known clients: only-the-newest-as-block (Claude Code) and all-blocks. A client
flipping some other subset still reads as new, once, fail-safe. The doc comment enumerates
the three forms honestly, so nothing overclaims.- Carried from reviewer 2, round 1: a message with both
ContentStrandContentBlocks
breaks the "every form is the same span under the canonical rule" argument, because
CanonicalMessagecollapses to the block's text whileasTextBlockusesContentStr.
Invalid state, unreachable from the wire, and the stored side cannot be written from it
either. Agree: non-blocking.
What I checked
- Last review: round 1, d6c9995, 2026-11-01T09:28:35Z.
- New commits read: 1 —
954b64befix(schema): old-rule fallbacks try every form of a changed
message (#783). - Read in full: 2 reviews, 2 comments, 0 inline comments (from
.review-in-reviews.txt,
.review-in-comments.txt,.review-in-inline.txt). - New items since my last review: reviewer 2's round-1 review (same head as mine, posted 24
seconds earlier — I read it in full now, as round 2 requires), the author's two replies
(09:39:02Z, 09:39:03Z), and commit954b64be. I checked each reply's claims against the
code; both hold. - The safety invariant of the new forms. Each form rewrites a string content as exactly
{type: "text", text: X}with every other field nil, whichCanonicalMessage'splainText
collapses back to the string X. SoSpanHash(form) == SpanHash(msgs), and a legacy match on
any form implies the stored span canonicalizes equal tomsgs. The same holds on the wire
side:toolResultsAsTextBlocksbuilds the exact two-key block that
CanonicalWireMessage's tool_result collapse inverts. The one exception is the invalid
both-fields state, noted above and already flagged by reviewer 2. toolResultsAsTextBlocksedge cases. A non-arraycontent(including gjson's
single-elementArray()on a string) is caught by the finalIsArrayguard after the loop,
so the sjson rewrite on a degenerate object is discarded, not returned. A string content
re-embeds asc.Raw, so escapes stay valid. Indices stay stable because only values are
replaced.LegacySpanHashesedge cases. Empty span: one hash, no index access. One string
message: no duplicate of the last-flipped form. Mutation safety:asTextBlockbuilds a new
Contenton a copy of the message; the caller's span is untouched.- The new tests. I traced every positive and negative case by hand:
TestSpanHashMatchesAcceptsAnOldHashAcrossTheBlockToStringChange(the string-against-block
direction needs no new form — a legacy hash over an all-string span equals its canonical
hash, so the primary check already matches; the block-against-string and all-blocks cases
need forms 2 and 3),TestASummaryCheckpointOverTheBlockFormIsReusedOnTheStringForm(with
and without payload), andTestAnOldAnchorOverAToolResultBlockMatchesItsStringForm
(last-only form covers the "last block" recording, all-form covers "every block"). - No caller drift. All stored-hash comparisons still go through
SpanHashMatches/
summaryCoveredHashMatches/fingerprintMatches; the newLegacySpanHasheshas exactly
one production caller besidesSpanHashMatches(the summarizer). No name collisions for the
new functions in their packages;strconvis the only new import. - Repo rules. No behavior change beyond what round 1 already named: the fix widens when a
stored pre-upgrade value matches, which is the PR's stated intent. Data dependence unchanged
(nothing new stored). Live tests were not run (not approved); I read the author's report
that-racepasses on the eval box, and my own traces agree with the test outcomes.
Behavior change (a human developer must confirm before merge)
summarize,cache_aware_summarizer), and held sweep answers (extract_llm_sweep).internal/threadalready treats a string and a one-text-block list as equal. Its hash bytes are unchanged, so no thread id moves.Summary
schema.CanonicalMessage(bifrost schema) andschema.CanonicalWireMessage(wire JSON) define it:cache_controlremoved, and a list of one plain text block read as its string. The wire form also sorts keys and keeps numbers as their literal text.What we found
cache_controlexpand.Fingerprint(expand/anchor.go)cg:rst:(pinned)fingerprintMatchescomponents.SpanHash(components/component.go)CoversSpan, checkpointscg:sum:CoveredHashContentStrandContentBlocksapart)SpanHashMatchesoffload.outputHash(extract_sweep_hold.go)cg:swh:SpanHashMatchesoffload.summaryCoveredHash(summarize.go)summaryCoveredHashMatchesthread.canonAt(internal/thread/thread.go)apply.NormalizeMessages(apply/apply.go)offload.msgPrint(extract_sweep_apply.go)MessageText)components.reformatKeys(pipeline.go)MessageText)proxy/prefixask.go(sentStash.CoversSpan,snapshotCovering) comparesSpanHashvalues computed on the same turn. They are not stored across an upgrade, so plain==stays.Why it happens
cache_controlmarks where the provider's cache breaks. Claude Code puts it on the newest message, so it moves every turn.missed=1).apply.normalizekeeps the two forms apart in the bifrost schema, soSpanHashsaw two messages.What changed
schema/canon.go: the canonical form.type: "text"andtextcollapses. A block with citations, an image or any other field stays a list.tool_resultblock's owncontent(one level down).components.SpanHashusesschema.CanonicalMessage.LegacySpanHashandSpanHashMatcheskeep stored hashes valid.expand.Fingerprintusesschema.CanonicalWireMessage.Anchor.UsableusesfingerprintMatches. It accepts the new hash, the old hash of the message, and the old hash of its block form....Matchesfunction:tryReuse(both summarizers),checkpointRefreshOpportunity,dispatchDeferred,recheckHeld.internal/threadis not changed. It hashes in one streaming pass for speed, and its ids are content-derived keys. Its key order is wire order on purpose, so the table test exempts it from the key-order pairs only.How it was tested
schema/canon_callers_test.go: one table, 11 same-message pairs and 6 different-message pairs, run against 4 callers (CanonicalWireMessage,expand.Fingerprint,SpanHashoverapply.NormalizeMessages,thread.Fingerprint).tool_result,tool_resultstring vs block.TestTheFingerprintIsUnchangedWithoutAOneTextBlockContent,TestSpanHashIsUnchangedWithoutAOneTextBlockContent(byte-identical hashes),TestAnAnchorRecordedByTheOldRuleStillMatches,TestSpanHashMatchesAcceptsAHashStoredByTheOldRule,TestASummaryCheckpointStoredByTheOldRuleIsStillReused.CanonicalMessage; no collapse inCanonicalWireMessage; notool_resultcollapse; no legacy fallback infingerprintMatches,SpanHashMatches,summaryCoveredHashMatches.go test -raceon the eval box:./components/... ./expand/... ./schema/... ./internal/... ./adapters/... ./config/... ./apply/... ./proxy/... ./proxyapp/... ./cmd/..., all pass.go vetclean.Data dependence
None. It is a hash over a message already in the request. Nothing new is stored, at any storage level.
docs/data-dependence.mdneeds no change: no component is added and none changes what it stores.Open questions
cg:rst:/cg:sum:/cg:swh:values from before the upgrade have aged out?Technical notes
fingerprintMatchesalso tries the old hash of the message with its string content written as a block. That matches an anchor recorded before the upgrade over the block form, when the client now sends the string: the exact toolfilter: defer unused tool declarations at session start, by history (was: remove at cold moments) #485 case.#784(sibling PR) touchesexpand/response.goandapply/metawrite.go. This PR changes onlyFingerprintand its helpers inexpand/anchor.go.Closes #783.
🤖 Generated with Claude Code