Repository navigation
fix(apply): report a head-TTL relabel as a change on the messages path (#1354) - #1356
Merged
Merged
Conversation
#1354) BodyOpts set Result.Changed from the head-TTL relabel on two return paths. The messages-array path left it out. When the count-changing rebuild declined, the body held the 1h label but Changed was false. The fix adds `|| headTTL1h` to that path, as on its two siblings. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
amiddavid
commented
Nov 24, 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.331 | offload-review skill, @amiddaid's session | fresh | 1 of 2 | 1 of 2 | 34c8fdd3ca77 |
blocking |
Verdict: blocking
Findings
- apply/apply.go:931 — the equal-count path still drops a head-TTL-only relabel from
Changed- What fails: a tenant opts into
HeadTTL1h; the request passes the byte gate and holds head breakpoints; the pipeline changes no message and no other envelope rewrite fires.Result.Bodythen carries"ttl":"1h", butResult.Changedis false. A caller that gates onChanged— the impact named in #1354 — still reads "not applied". - Proof: line 498 relabels
bodybefore any path choice. Line 931:changed := systemSplit || toolSchema || filteredDecls > 0— noheadTTL1h. Line 1122:res.Body, res.Changed = out, changed. The flag is in scope and unused on this path. Lines 507 and 548 include it, and this PR adds it at line 922. The omission exists on the base8f67d0c7too, so it is pre-existing — but this PR claims to fix "a head-TTL relabel reported as a change on the messages path", and the equal-count writeback is the messages path most requests take. Issue #1354 lists threeChangedsites; there are four. - Fix: add
|| headTTL1hat line 931. Add one test: the same head-TTL opts with a pipeline whose component declines (for examplemidsumon a transcript under its threshold), assertingChangedis true.
- What fails: a tenant opts into
Non-blocking
- The new test uses the
midsumcomponent, whichops_splice_test.goregisters in the same package. Fine as is. A one-line comment in the test naming that file would help the next reader. - The fix changes reporting only. The wire body is the same before and after: on a declined rebuild,
rebuildCountChangedreturns the already-relabelledbody, and the proxy forwardsres.Bodyregardless ofChanged. So no human-permission rule for behavior changes is triggered.
What I checked
- Read the full diff:
apply/apply.go:922and the newapply/headttl_changed_test.go. - Traced
headTTL1hfromupgradeHeadTTL(apply.go:496-500) through every site that setsres.Changed: 442, 467, 507, 548, 919, 922, 1122, 2424, 2427, and apply/responses.go:515. All include the flag or cannot relabel, except line 931/1122 (finding 1). - Traced
rebuildCountChanged(apply.go:1992-2005): on decline it returns the inputbody, which is the relabelled one. Sores.Bodywas already correct; only the flag was wrong. The fix restores the documented contract "Changed is false when Body is the untouched input" (apply/opts.go:151-152) on this path. - Verified the test reaches the fixed line:
midsumneeds 4+ normalized messages and replaces messages 1..2, so the count changes and line 899 enters the rebuild. Therole:123message failsUnmarshalJSON, gets no slot (apply.go:1897-1898), solen(covered) != len(orig)and the rebuild declines. The pipeline[midsum]has notoolschema,toolfilter,cachesplitorcacheinject, soheadTTL1his the only true term at line 922 — the test fails on the base and passes on the head. - Verified the test's relabel preconditions: Anthropic provider, body over 200,000 bytes (the pad is 240,000),
cache_controlobjects present intoolsandsystem. - Checked
Result.Changedconsumers: no reader in this repo's hosts.proxy/modes.go:79-82forwardsres.Bodyunconditionally. The reader is a downstream library caller, as #1354 says. - Checked rules: no wire behavior change, no data-dependence change (the relabel is metadata-only), the test waits on no clock, no binaries added.
amiddavid
commented
Nov 24, 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.331 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 34c8fdd3ca77 |
blocking |
Verdict: blocking
Findings
- apply/apply.go:931 — the equal-count path still omits
headTTL1h, so the fix is incomplete- What fails: a request where only the head-TTL relabel fires and no component changes a message leaves
Changed = falsewhileBodycarries the relabel. This is the same defect as #1354, on the other messages-path return — and the busier one: it is the path every request takes when the pipeline changes nothing (a warm, cache-frozen session). - Proof: trace the code.
apply/apply.go:497-499—upgradeHeadTTLrelabels the head,headTTL1h = true,bodynow differs from the input.- The pipeline changes no message and no count, so
apply/apply.go:899(len(chat.Input) != len(norm) || summaryStructureChanged(...)) is false and the count-changed block the PR fixed is skipped. apply/apply.go:931—changed := systemSplit || toolSchema || filteredDecls > 0. NoheadTTL1h. All three flags are false when the pipeline holds nocachesplit/toolschema/toolfilteror when they decline.apply/apply.go:1071—out := body, the relabeled body, no edits to splice.apply/apply.go:1122—res.Body, res.Changed = out, changed→ the relabeled body goes out withChanged = false.- This breaks the contract at
apply/opts.go:151: "Changed is false when Body is the untouched input." The three sibling returns already honor it: lines 507 and 548 (from #86) and line 922 (this PR) all include|| headTTL1h. Line 931 is the one left behind. - Consumers read the flag:
cmd/cg-transcript-replay/main.go:180records it per call, andBodyFull(apply/apply.go:343) returns it to library importers. The proxy wires the relabel on the live path (proxy/modes.go:55-63), so the scenario is production traffic, not a corner.
- Fix:
changed := systemSplit || toolSchema || filteredDecls > 0 || headTTL1hatapply/apply.go:931. Add a test like the new one, but with a pipeline that declines (or a body midsum leaves alone), assertingres.Changed.
- What fails: a request where only the head-TTL relabel fires and no component changes a message leaves
Non-blocking
apply/headttl.go:116-120— a head mark that already carriesttl: "1h"setsupgraded = truewithout changing any byte.Changedis then true on all return paths whileBodyequals the input. The PR extends this to line 922. Pre-existing from #86 on lines 507/548, so not this PR's defect, but the contract sentence atopts.go:151reads false in that case too.apply/headttl_changed_test.gorelies onmidsum, a component another test file registers ininit()(apply/ops_splice_test.go:33). This works, because one test binary holds all files ofapply_test. It is fragile if that file ever moves. The existingtraceOftests already do this, so it follows the local pattern.
What I checked
- The full diff (one line in
apply/apply.go, one new test) and the code around each return path ofBodyOpts. - The fix itself is correct for the path it touches: with
ok = false,rebuildCountChangedreturns the input body (apply/apply.go:2003-2005), which holds the relabel, and line 922 now reports it. - The new test reaches line 922: normalize skips the
{"role":123}message (apply/apply.go:1897-1898), midsum changes the count, the rebuild declines because message 4 has no slot (apply/apply.go:2003), and the relabel fires (Anthropic, 240 KB pad over the 200,000-byte gate, marks ontoolsandsystem). - Every assignment to
res.Changedinapply/apply.goandapply/responses.go, and every reader ofResult.Changedin the repo (proxy forwardsres.Bodyand ignores the flag;cg-transcript-replayand the publicBodyFullAPI read it). apply/headttl.goin full: the gate, the fail-open returns, the byte format the test asserts.git log -S "headTTL1h": #86 added the flag to lines 507 and 548 but not to 922 or 931; this PR fixes 922 only.- Repo rules: no new data dependence (the relabel works from metadata only, and no feature row changes); no wire-behavior change, only the reported flag; fail-open untouched.
- Live tests were not run (not approved for this review).
The equal-count path set `changed` without the head-TTL flag. Most requests take this path: no component changes a message. The body held the 1h label, but Changed was false. Add `|| headTTL1h` there. Add a test for it. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Collaborator
Author
|
Round 1, both reviewers: the equal-count path ( |
amiddavid
commented
Nov 24, 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.331 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 8d72023ff654 |
approve |
Verdict: approve
Findings
None.
Earlier findings
- My round-1 finding (apply/apply.go:931, equal-count path omits
headTTL1h) — fixed. Commit8d72023fadds|| headTTL1hat line 931, exactly as proposed. The newTestHeadTTLRelabelCountsAsChangedOnTheEqualCountPathcovers it: 3 messages, somidsumdeclines under its 4-message threshold, the count stays equal, and the equal-count path runs. The pipeline[midsum]has notoolschema,toolfilter,cachesplitorcacheinject, so the relabel is the only true term — the test fails on34c8fdd3and passes on the head. - Reviewer 2's round-1 finding (same defect) — fixed by the same commit. I checked it myself; the proof above is mine. I add nothing to reviewer 2's trace.
Non-blocking
- Reviewer 2's note stands and I agree with it: a head mark that already carries
ttl: "1h"setsupgraded = truewithout changing a byte (apply/headttl.go, theAlready 1hbranch), soChangedcan be true whileBodyequals the input. Pre-existing from #86, on lines 507 and 548 as well. Not this PR's defect. - The new test also relies on
midsumfromops_splice_test.go. Same minor note as round 1; it follows the local pattern.
What I checked
- Last review: round 1, 34c8fdd, 2026-11-24T12:31:04Z.
- New commits read: 1 —
8d72023f"fix(apply): count a head-TTL relabel on the equal-count path too (#1354)". - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files).
- New items since my last review: reviewer 2's round-1 review (same finding as mine, checked, agreed); the author's comment naming the fix commit and test (verified against the code); the new commit itself (reviewed below).
- The new commit's full diff: one line in
apply/apply.goand one new test. Read both, plus the code around them. - Traced the new test's path through
BodyOpts: normalize gives 3 slots (or 2 if the last message fails bifrost's unmarshal — either way under midsum's threshold),midsumreturns nil,len(chat.Input) == len(norm)and the structure is unchanged, so line 899 skips the rebuild and control reaches line 931.out := bodyholds the relabel, no edits splice, sochangedis exactlyheadTTL1h. - Checked the side effects of
changed = trueon this path: line 1105 (dumpPathis empty) and line 1115 (breakpoint recount — the relabel adds no breakpoint, and the test body has 4 marks against a cap of 4, son > maxWireBreakpointsandn > c.ExistingBreakpointsare both false). No new log, no wire change. - Re-checked every site that sets
res.Changed(apply.go:442, 467, 507, 548, 919, 922, 931/1122, 2424, 2427; responses.go:515): all now includeheadTTL1hor cannot relabel. - Repo rules: reporting-only change, no wire behavior, no data-dependence change, no clock waits, no binaries. Commit carries
Signed-off-byandAssisted-By. - Live tests were not run (not approved for this review).
amiddavid
commented
Nov 24, 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.331 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 8d72023ff654 |
approve |
Verdict: approve
Findings
None. My round-1 finding is fixed, and the new commit adds no defect.
Round-1 findings
- apply/apply.go:931 — equal-count path omitted
headTTL1h— fixed in8d72023f. Line 931 now readschanged := systemSplit || toolSchema || filteredDecls > 0 || headTTL1h. All fourChangedsites on the messages path (507, 548, 922, 931) now include the flag, so the contract atapply/opts.go:151holds on each of them. - Reviewer 1 raised the same finding (their finding 1). I checked it myself in round 1 and agree; the same commit fixes it.
Non-blocking
- Both round-1 non-blocking notes stand, unchanged and accepted: an already-1h head mark sets
Changed = truewith byte-identical body (pre-existing from #86), and the tests rely onmidsumfromops_splice_test.go'sinit(). - The new test repeats the 240 KB pad and body shape from the first test instead of sharing a helper. Style only.
What I checked
- Last review: round 1,
34c8fdd3ca77795d8588b272a482abbd118e49fc, 2026-11-24T12:33:06Z. - New commits read: 1 —
8d72023f"fix(apply): count a head-TTL relabel on the equal-count path too (#1354)". - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review: the fix commit, the author's comment naming the fix, and reviewer 1's round-1 review (now readable). The author's comment states the test fails without the fix and passes with it; my own trace agrees (below).
- The full new diff (
git diff 34c8fdd3..HEAD): one line inapply/apply.go, one new test inapply/headttl_changed_test.go. - The new test reaches the fixed line: 3 messages, all with string roles, so normalize slots all of them;
midsumneeds 4+ messages (apply/ops_splice_test.go:23) and declines, so the count stays equal andsummaryStructureChangedis false (apply/summaryshape.go:14-25) — the equal-count path runs. Nocachesplit,toolschemaortoolfilterin the pipeline, soheadTTL1his the only true term. Without the fix line,Changedis false and the test fails. - The relabel preconditions hold: Anthropic provider, 240 KB pad over the 200,000-byte gate,
cache_controlmarks ontoolsandsystem(apply/headttl.go:94-136). - Side effects of
changedturning true on this path: the breakpoint-cap recount (apply/apply.go:1115) cannot false-alarm, because the relabel adds no breakpoint, son > c.ExistingBreakpointsstays false.dumpChanges(apply/apply.go:1105) matches the existing behavior for envelope-only rewrites.finishRestoreand the defers (OneHourFirst, tail mark) do not interfere: no restore plan on an empty store, and neither feature is configured. - The commit message follows the repo rules: conventional title,
Signed-off-by,Assisted-Byfor AI attribution. - Live tests were not run (not approved for this review).
amiddavid
pushed a commit
that referenced
this pull request
Nov 24, 2026
fix(pi): a Pi window open during an uninstall no longer fails Pi reads models.json at start and on /model only. A window opened while context-guru routed Pi kept the proxy URL in memory. After an uninstall, every request of that window failed with ECONNREFUSED on 127.0.0.1:8787, 3 retries each (#1341). The files were right. - Extension: on each prompt (input, before_agent_start), when the session's model is context-guru's route and the install record is gone, it reads models.json again and switches the session to the same model at its real endpoint (modelRegistry.refresh, find, pi.setModel). It says so once. Fail open: a removed context-guru must not break Pi. While the record exists, nothing changes. - The extension keeps the last routed install record, so an uninstall from this same window recovers too. - Installer: before uninstall, and before a re-run turns context-guru off, it names the open Pi windows (pgrep) and asks "Go on anyway? [y/N]": windows with an older package cannot switch by themselves. After an install it says that windows open before use context-guru only after a restart. Tested: 65 installer tests (5 new), 57 extension tests (5 new). Real Pi 1.6.0: a window opened while routed, then the uninstall while it stays open. main: no answer, 4 ECONNREFUSED. Fix: answer ok, 0 errors, one notice naming the endpoint. pgrep finds a real Pi. Behavior change: Pi users who uninstall or re-run the installer with Pi windows open. Old: the installer went on; those windows failed until restarted. New: the installer asks first (default no); a window with this package switches to the real endpoint by itself. To skip the question, answer y. Data dependence: none. Process ids and the install record only. Fixes #1341 fix(pi): the review findings on #1342 - A window that took the route after it started (/model) recovers too: each prompt reads the record once and keeps a record that routes this window's URL. A record on a new port does not hide the old URL, and the window moves to the new port ("context-guru moved to ..."). - "Still installed" now means: the current record routes this window's URL, not just that a record exists. - Wiring tests (tests/recover.test.ts): the real extension, with its state folder in a temporary place, through its own handlers: the switch after an uninstall, one notice only, an uninstall from the same window, a late route, the moved port, and a setModel that throws (the prompt goes on). - Installer: pgrep -u <uid>; the question only when context-guru routes Pi; the re-run refusal says "context-guru was not turned off" (Pi and the package may have changed); the line after an install has the right plural, and says to restart a window if it started before context-guru was on. - The ChatGPT comment is back above before_provider_request. - Docs: the how-to page and the design name the question. test(pi): the recovered window keeps the same model, only its address The owner asked whether the recovery after an uninstall changes the model. It does not: it asks Pi for the same provider and id, and only the baseUrl is read again from models.json. The wiring test now asserts the provider and the id, not only the address. Real Pi 1.6.0 (get_state after the prompt): provider anthropic, id aws/claude-opus-5-5, the real endpoint; answer ok, 0 ECONNREFUSED. Pi behavior change: Vitaly gave his yes on the PR; Pi changes are FYI to the owner. Round 3 (owner granted) re-checked the merge of main and the post-approval commit. Integrator check on current main + #1356 + #1342: the Pi unittest suites and go test ./pi-package/... pass. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
This was referenced Nov 24, 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.
Behavior change
None. Every host that sends the body reads
res.Body, notres.Changed. The proxy already sent the 1-hour relabel on this path. Only a flag changes. No off-switch is needed.Summary
apply.BodyOptsdid not count a head-TTL relabel inResult.Changedon 2 of its 4 return sites: the messages-array path (line 922) and the equal-count path (line 931, the path most requests take). The 2 early-return paths already did.What we found
res.Bodyholds the 1h label.res.Changedwas false.Result.Changed:apply.BodyFullreturns it. No non-test code callsBodyFull,BodyWithModelWindoworBody.cmd/cg-transcript-replay/main.go:180-181writes it to its report and skips a branch on it. Replay tool only.proxy/modes.go,proxy/proxy.go,dash/adaptcompaction.goreadres.Body,res.Traceorres.Changes. They never readChanged.What changed
apply/apply.go: add|| headTTL1hat 2 sites: the messages path and the equal-countchanged :=.apply/headttl_changed_test.go: 2 new tests, one per site.Changedsites checked: 442 and 467 (true already), 507 and 548 (haveheadTTL1h), 919 and finishRestore (true already).How it was tested
macOS, Go 1.27.4.
gofmt,go vet ./...,CGO_ENABLED=0 go build ./...: clean.CGO_ENABLED=1 go test -race ./apply/...: pass.go test -race -run 'HeadTTL|OneHour|Relabel|1h' ./proxy/: pass.Data dependence
None. The change reads a flag only. No stored customer data. No row in
docs/data-dependence.mdchanges.Fixes #1354