Skip to content

fix(cheapmodel): the prefix question keeps the turn's breakpoint (#776) - #777

Merged
amiddavid merged 3 commits into
mainfrom
fix/ping2-reads-prefix
Oct 30, 2026
Merged

amiddavid merged 3 commits into
mainfrom
fix/ping2-reads-prefix

Conversation

@amiddavid

@amiddavid amiddavid commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Ping 2 after a sweep question now reads the prefix instead of writing it again, on tool_result turns. The sweep question at ping 1 moved the turn's last cache breakpoint away. That let the turn's own cache entry expire 5 minutes after the turn. The question now leaves the breakpoint where it is.

  • Live, same session shape, ping 2 after the question:
    • Sonnet 5.5: read 13,487 / wrote 18,053 before; read 31,542 / wrote 0 after.
    • Opus 5.5: read 13,371 / wrote 18,214 before; read 31,599 / wrote 0 after.
  • In the laptop data this shape is 58 of the 80 ping-2 misses ($47.79 of $97.97).
  • Not fixed: 22 misses ($50.18) after a turn that ends at a text turn. Live, every variant still misses there. See Open questions.

Fixes #776

What we found

From a copy of the laptop dashboard DB (port 8789), metadata columns only, rows after the #712 merge:

Ping 1 was Ping 2 hit Ping 2 missed
A plain ping 146 0
The sweep question (sent in place of the ping) 120 80
  • Every one of the 80 misses follows a sweep question, not a plain ping. The "6 tokens" written by ping 1 is the sweep question's write on its "Understood." bridge.
  • By model, after a sweep question: Opus 5.5, 99 hit / 19 missed; Sonnet 5.5, 21 hit / 61 missed.
  • The real turn before ping 1 made the difference:
Real turn Message breakpoints Hit Missed
Ends at a tool_result, Sonnet 1 0 58
Ends at a tool_result, Sonnet 2 19 0
Ends at a tool_result, Opus 1 or 2 69 0
Ends at a text turn, both models 1 or 2 32 22

Live reproduction (proxy built from origin/main, a capture forwarder in front of the gateway, a Claude Code sandbox session on Sonnet 5.5). Bodies were compared as metadata: roles, breakpoint positions, hashes.

Request Messages Last message breakpoint Read Wrote
Real turn 17, ends tool_result, then a system reminder on message 16 (the reminder) 21,159 10,386
Ping 1 = the sweep question 19 moved to message 17 ("Understood.") 31,545 6
Ping 2 = plain ping 17 on message 16 13,487 18,058
  • Ping 2's system, tools and all 17 messages are byte-identical to the real turn. Only max_tokens and stream differ.

Why it happens

  • Prefix questions (sweep, summary substitute) miss the cache: the breakpoint stays on Claude Code's trailing system message #721 moved the turn's last breakpoint onto the question's "Understood." bridge, so the question reads the whole turn.
  • The question reads the turn's entry by lookback (the provider searches back from the breakpoint for an earlier entry). Only the entry the question names gets a new 5-minute lifetime. The turn's own entry is not refreshed.
  • Ping 2 is the turn's body again. It asks for the turn's entry, which expired 5 minutes after the turn. So it reads system + tools only and writes the rest again.
  • With a second message breakpoint earlier in the conversation (interactive sessions), ping 2 falls back to that one, which is why those hit.

What changed

  • cheapmodel/anthropic.go insertAskMessage: the last message keeps its breakpoint. The bridge gets a copy of it only while the request stays at or under the provider's cap of 4 breakpoints. At the cap the bridge gets none.
  • The question still reads the turn's entry, and now also keeps that entry alive. Every byte before the appended messages is as sent.
  • countBreakpoints: a small local counter with the same rule as apply.CountBreakpoints (both mark spellings, tools, system, messages and blocks). cheapmodel cannot import apply.
  • No plain ping byte changes. fix(keepalive): never send two identical pings in a row #712 is untouched: pings still differ in max_tokens.
  • The same function serves the summarizer's keep-alive substitute, so it gets the same fix.
  • docs/components/advanced-offload.md: one paragraph.

How it was tested

Unit tests (cheapmodel/anthropic_prefixed_test.go). All 3 new ones fail on origin/main:

  • TestInsertAskMessageCopiesTheTrailingBreakpoint (replaces the Prefix questions (sweep, summary substitute) miss the cache: the breakpoint stays on Claude Code's trailing system message #721 "moves" test): the last message is unchanged, and the bridge carries the same cache_control (ttl included).
  • TestInsertAskMessageLeavesThePrefixByteIdentical: system and every original message are byte-identical.
  • TestInsertAskMessageNeverExceedsTheBreakpointCap: 3 marks gives a bridge copy; 4 marks (on system, tools, a message, or a trailing user message) gives none, and the total stays at 4 or fewer.
  • TestCountBreakpointsMatchesTheCapRule: both spellings and every location count; text that only names the field does not.

Mutations, each on a copy of the fix, all killed:

Mutation Killed by
Strip the last message's breakpoint (the old behavior) 3 tests, 12 cases
No cap check cap test, 3 cases
Cap check > instead of >= cap test, 3 cases
Never copy to the bridge copy test + cap test, 6 cases
Counter skips system / tools / message-level / blocks cap test, 1 to 4 cases each
Counter skips cachePoint count test
Counter matches a substring instead of a field count test

Box: go vet ./... and gofmt -l clean. -race passed on ./cheapmodel/... ./keepalive/... ./components/offload/... ./proxy/.... Non-race passed on ./apply/... ./components/... ./cmd/....

Live runs on the laptop. Each run used its own proxy (pipeline [extract_llm_sweep], idle 200 s, 2 pings) and a capture forwarder. All runs went through the ANTHROPIC_UPSTREAM gateway. Rows are from each proxy's own DB, metadata only. "Q" is the sweep question at ping 1. "Ping 2" is the plain ping after it.

Run Build / variant Model Last turn Q read / write Ping 2 read / write Spend
run2 main Sonnet 5.5 tool_result 31,545 / 6 13,487 / 18,058 $0.15
s-main main Sonnet 5.5 tool_result 31,540 / 6 13,487 / 18,053 $0.15
s-moved experiment, as main Sonnet 5.5 tool_result 31,393 / 6 13,487 / 17,906 $0.15
s-keep keep + bridge copy Sonnet 5.5 tool_result 31,550 / 6 31,550 / 0 $0.11
s-keeponly keep, no bridge copy Sonnet 5.5 tool_result 31,542 / 0 31,542 / 0 $0.07
s-keepcap keep + copy, drop an early mark at the cap Sonnet 5.5 tool_result 31,408 / 6 31,408 / 0 $0.07
s-anchor mark on last tool_result Sonnet 5.5 tool_result 31,405 / 1,727 31,338 / 67 $0.11
s-cs-main main + cachesplit Sonnet 5.5 tool_result 31,555 / 6 13,487 / 18,068 $0.12
s-cs-keepcap keepcap + cachesplit Sonnet 5.5 tool_result 31,402 / 6 31,402 / 0 $0.06
o-main main Opus 5.5 tool_result 31,585 / 6 13,371 / 18,214 $0.31
o-keeponly keep, no bridge copy Opus 5.5 tool_result 31,592 / 0 31,592 / 0 $0.22
t-main main Sonnet 5.5 text 31,713 / 30 13,487 / 18,251 $0.12
t-keeponly keep, no bridge copy Sonnet 5.5 text 31,654 / 24 13,487 / 18,192 $0.12
t-keepcap keepcap Sonnet 5.5 text 31,645 / 30 13,487 / 18,183 $0.12
t-moved as main Sonnet 5.5 text 31,627 / 30 13,487 / 18,165 $0.12
ot-main main Opus 5.5 text 31,593 / 173 13,371 / 18,390 $0.32
ot-keeponly keep, no bridge copy Opus 5.5 text 31,578 / 189 13,371 / 18,397 $0.32
F-o-fix this PR Opus 5.5 tool_result 31,599 / 6 31,599 / 0 $0.21
F-s-cs-fix this PR + cachesplit Sonnet 5.5 tool_result 31,542 / 6 31,542 / 0 $0.11
F-s-main, F-s-fix main, this PR Sonnet 5.5 tool_result no question (no candidate) 24,097 / 0 and 24,366 / 0 $0.17
run1 main, xhigh Sonnet 5.5 tool_result no question (no candidate) none ~$0.19
  • Total live spend: about $3.30 on the laptop, plus under $1 for the owner's gateway replays.
  • The "experiment" builds were a throwaway copy with an env switch, used only to choose the shape. They are not in this PR.
  • Not done: a Sonnet run with a prefix above 200k. It costs about $3 a pair, which is over the $5 limit. The fix does not depend on prefix size. The F-s runs tried a larger prefix, but Claude Code shortened the big tool outputs, so the sweep had no candidate.
    Direct gateway replays (the owner ran them). Input: the captured real-turn body (17 messages, 3 breakpoints, last message role: system). Each run has its own nonce, so the runs share no cache entry.
  • Step 1: a plain ping at 0 s.
  • Step 2: the variant at about 250 s.
  • Step 3: a plain ping at about 490 s.
  • Step 3 is the test: does the plain ping after step 2 still read the whole prefix?
Variant at step 2 Model Step 2 read / write (bps) Step 3 read / write
plain (control) Sonnet 5.5 31,599 / 0 (3) 31,599 / 0
plain (control) Opus 5.5 31,602 / 0 (3) 31,602 / 0
moved (origin/main) Sonnet 5.5 31,599 / 6 (3) 13,541 / 18,058
moved (origin/main) Opus 5.5 31,601 / 6 (3) 13,543 / 18,058
keep (this PR, under the cap) Sonnet 5.5 31,598 / 6 (4) 31,598 / 0
keep (this PR, under the cap) Opus 5.5 31,600 / 6 (4) 31,600 / 0
anchor (mark on the last tool_result) Sonnet 5.5 31,598 / 27 (4) 31,531 / 67
anchor (mark on the last tool_result) Opus 5.5 31,601 / 27 (4) 31,534 / 67
  • moved reproduces the miss on both models, and keep matches the control on both.
  • Spend: 24 requests of about 31.6k tokens, under $1, on top of the laptop runs.

At the 4-breakpoint cap, the fix drops the bridge's copy, never one of the client's breakpoints.

  • The question then reads the turn's entry through the last message's own breakpoint, and keeps that entry alive.
  • Live, this shape ("keep, no bridge copy"): ping 2 read the full prefix and wrote 0, on Sonnet (s-keeponly) and Opus (o-keeponly). The question itself wrote 0 instead of 6.
  • Dropping an earlier client breakpoint instead (s-keepcap) also passed. It was not chosen, because it changes a byte of the client's prefix.
  • Unit test: TestInsertAskMessageNeverExceedsTheBreakpointCap. Mutations: no cap check, and > instead of >=.

Data dependence

No change. The fix edits where one cache_control mark sits in a request the sweep already sends. It reads no new data and stores nothing. Each storage level (off, metadata only, everything) works as before. docs/data-dependence.md needs no update.

Behavior change

  • Before: the sweep question (and the summarizer's keep-alive substitute) moved the turn's last breakpoint onto its "Understood." bridge.
  • After: the breakpoint stays on the turn's last message. The bridge gets a copy only under the 4-breakpoint cap.
  • What users see: ping 2 after a sweep question on a tool_result turn reads instead of writing the conversation again. The question costs the same, or 6 tokens less. No ping is added.

Open questions

  • Text-turn misses (22 of 80, $50.18). After a real turn that ends at a text turn, ping 2 misses with every variant (live: Sonnet and Opus, main and fix). This is the provider rule from v0.6.0: no later request reads an entry that ends at a text turn. One option is to send a plain ping instead of the sweep question when the turn ended at a text turn. That changes when the sweep runs and what pings cost, so it needs the owner's decision. Not in this PR.
  • The ping limit decision in Keep-alive: measure again after #712, then decide the ping time and the ping limit #716 can use the post-fix rate once this ships.

Technical notes

🤖 Generated with Claude Code

amiddavid and others added 2 commits October 30, 2026 01:22
The sweep question at a keep-alive ping moved the turn's last
breakpoint onto its "Understood." bridge (#721). The question read the
turn's cache entry, but only the entry it named got a new lifetime. The
turn's own entry expired 5 minutes after the turn, so the plain ping 2
after the question wrote the whole conversation again.

The last message now keeps its breakpoint. The bridge gets a copy only
while the request stays at or under the provider's 4 breakpoints.

Live, ping 2 after the question, Sonnet 5.5: read 13,487 / write 18,053
before, read 31,542 / write 0 after. Opus 5.5: 13,371 / 18,214 before,
31,592 / 0 after.

Fixes #776

Assisted-By: Claude
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
Refs #776

Assisted-By: Claude
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.312 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 1d32a460affc blocking

Verdict: blocking

Findings

  1. cheapmodel/anthropic.go:223 — the doc comment on CompletePrefixed still states the old #721 contract this PR reverses
    • What fails: a maintainer reads CompletePrefixed to reason about the cache key, and lines 219-225 tell them "The only existing byte it changes is the last message's cache_control, which moves onto the appended message (#721)". After this PR no byte before the appended messages changes. The comment states the exact opposite of the change's own guarantee, in the same file the PR edits.
    • Proof: cheapmodel/anthropic.go:223-224 versus the rewritten insertAskMessage comment at anthropic.go:380-381 ("every byte before the appended messages is untouched") and the new test TestInsertAskMessageLeavesThePrefixByteIdentical, which asserts that guarantee.
    • Fix: update that paragraph. Two smaller spots carry the same stale "moves" wording and should go in the same edit: anthropic.go:417 ("and the breakpoint lands on it" — at the 4-mark cap it does not) and askBridgeFor's comment at anthropic.go:503-506 ("whether a breakpoint moves with it … a breakpoint to move").

Non-blocking

  • At the cap, a trailing user message with a breakpoint still gets a bridge that carries nothing (insertAskMessage passes cc.Exists() to askBridgeFor, not bridgeCC.Exists(), anthropic.go:488). For that shape the bridge's only job was to host the copy. It is harmless — the ask stays fresh input, and the PR's live "keep, no bridge copy" rows read the full prefix and wrote 0 — but the extra "Understood." turn serves no purpose there. Worth a sentence in the comment, or dropping the bridge in that case, in a later change.
  • countBreakpoints duplicates apply.CountBreakpoints's rule by hand. The layering reason is fair, and TestCountBreakpointsMatchesTheCapRule pins the rule, so drift has a tripwire. No change needed.

What I checked

  • The full diff of both commits (697f93d9, 1d32a460): cheapmodel/anthropic.go, cheapmodel/anthropic_prefixed_test.go, docs/components/advanced-offload.md, plus the code around each change.
  • Every insertAskMessage shape, traced by hand: last role system / user / assistant / empty, breakpoint present or absent, count at 3 / 4 marks. No behavioral defect found. The copy is added only when the body holds 3 or fewer marks, so the total never passes the provider's cap of 4. The copied cache_control keeps its ttl verbatim (marshalAppended splices cc.Raw).
  • countBreakpoints against apply.CountBreakpoints (apply/metawrite.go:161): both mark spellings, marks on tools, system, message level (Anthropic spelling only) and content blocks. The rules match.
  • Fail-open: no new error paths. countBreakpoints cannot fail; an insertAskMessage error still returns from CompletePrefixed and the caller declines to the plain ping. The sweep gate (components/offload/prefixask_gate.go) judges usage numbers only, so it does not depend on where the breakpoint sits.
  • Callers of CompletePrefixed / the bridge shape: proxy/prefixask.go, cmd/cg-selarm/main.go, the summarizer paths, and the sweep gate tests. None depends on the old "moved" shape.
  • Repo rules: the PR names the behavior change at the top (old and new behavior, what users see) and states its data dependence (no change, no new data read or stored) — both sections are present and correct for a mark-only edit.
  • Tests were NOT run: live tests are not approved and Go is not on this machine. I read the tests and traced them against the code instead; the three new tests and the rewritten copy test match the new behavior.
  • I read the PR title and description only. I read no other review or comment before posting this one.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.312 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 1d32a460affc blocking

Verdict: blocking

Findings

  1. cheapmodel/anthropic.go:224 — CompletePrefixed's doc comment still describes the removed #721 behavior
    • What fails: a reader of CompletePrefixed is told "The only existing byte it changes is the last message's cache_control, which moves onto the appended message (#721); everything before that message is byte-identical." After this PR, insertAskMessage changes no existing byte: lastBreakpoint only reads the mark, and the copy lands on the appended bridge. The comment states the opposite of the invariant this PR exists for (#776: every byte before the appended messages is untouched). The doc comments in this package are the design record — the PR's own test (TestInsertAskMessageLeavesThePrefixByteIdentical) pins the opposite of what this comment claims.
    • Proof: cheapmodel/anthropic.go:219-226 (the "THE ASK IS NOT ALWAYS THE ONLY THING APPENDED" bullet) against the new insertAskMessage at cheapmodel/anthropic.go:477-494, which never edits parts[len(parts)-1].
    • Fix: replace that sentence with: insertAskMessage changes no existing byte; it copies the last message's breakpoint onto the appended bridge only while the request stays at or under the provider's cap (#776).

Non-blocking

  • cheapmodel/anthropic.go:415-417 — the "#725" paragraph still says of a trailing user message with a breakpoint that "the breakpoint lands on it" (the bridge). After this PR it is a copy that lands there, and only below the 4-mark cap. Same stale-wording class as the finding.
  • cheapmodel/anthropic.go:503-506 — askBridgeFor's comment still says "a breakpoint to move". Nothing moves now.
  • components/offload/prefixask_gate.go:17-19 — the (off-by-default) write-cap comment says "the cap assumes the question's breakpoint sits on the short bridge". With #776 the question's breakpoint sits on the last message, copied onto the bridge. The magnitude reasoning still holds (the write stays a few tokens), and the switch is off, so this is a wording fix only.
  • countBreakpoints does not count a cache_control nested inside a tool_result's array-form content. apply.CountBreakpoints has the same limit, the stash body was accepted by the provider under the same rule, and a miss only skips the bridge copy (the safe direction). Noting for symmetry with the "same rule as apply" claim, not asking for a change.

What I checked

  • Read CLAUDE.md and docs/design.md; read the full diff of both commits (697f93d9, 1d32a460) and the code around every change.
  • Traced insertAskMessage end to end: no existing message is edited (the old sjson.Delete strip is gone), the copy is verbatim (ttl survives), and the ask never carries a mark.
  • Verified the cap guard: the bridge copy is added only when countBreakpoints(prefixBody) < maxBreakpoints, so the sent body stays at or under 4 marks. The guard's premise holds because prefixBody comes from the sent stash (proxy/prefixask.go:315-322, sentStash), the body the provider already accepted.
  • Compared cheapmodel.countBreakpoints against apply.CountBreakpoints (apply/metawrite.go:161-211) rule by rule: message-level marks count only the cache_control spelling; tools, system and content blocks count both spellings; all checks are structural (IsObject). apply's mayHold/strings.Contains guards are perf prefilters only, so the rules match. Checked gjson ForEach on non-array system/tools values is a no-op or safe.
  • Hand-traced every test in the diff against the new code (no Go on this machine, live tests not approved): the five copy cases, the byte-identity test, the four cap cases, the count-rule test, and the unchanged tests (TestInsertAskMessage, TestInsertAskMessageAddsNoBreakpointWhenTheLastHasNone, TestInsertAskMessageBridgeOnlyWhereABreakpointMoves, the CompletePrefixed HTTP tests) — all assertions hold under the new behavior.
  • Checked fail-open: an error or a provider 400 on the question returns an error from CompletePrefixed; the sweep declines and the ordinary ping goes out. No path loses data or blocks a request.
  • Confirmed strconv had no remaining use in anthropic.go, and no other code references takeLastBreakpoint or depends on the moved-breakpoint behavior (components/offload and cheapmodel/zz_live_trailing_system_test.go only reference the shape, not the move).
  • Data dependence: unchanged — the question still reads only the stashed sent body, which existed before this PR. No docs/data-dependence.md update needed.
  • Per round-1 independence I did not read the PR body or any comments on it, so I did not verify the PR's own behavior-change naming; the change itself (copy-and-keep instead of move) is the PR's stated purpose in the code and docs.

Review round 1 of #777 found doc comments that still described the
#721 move. CompletePrefixed, the #725 paragraph, askBridgeFor and the
write-cap note in prefixask_gate.go now say the question changes no
existing byte and copies the breakpoint onto the bridge only below the
provider's 4-breakpoint cap. One test is renamed to match. No code
change.

Refs #776

Assisted-By: Claude
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 1 replies. Fixed in 9826d89 (doc comments and one test name; no code change). Unit tests and -race passed again on the box: ./cheapmodel/... and ./components/offload/.... go vet and gofmt are clean.

Reviewer 1 and 2, finding 1 (blocking): CompletePrefixed's doc, anthropic.go:219-226. Fixed. It now says insertAskMessage changes no existing byte. It copies the last message's breakpoint onto the appended bridge only while the request stays at or under the 4-breakpoint cap (#776).

The #725 paragraph, anthropic.go:415-417. Fixed. A copy lands on the bridge, below the cap only. At the cap the bridge is still sent, with no breakpoint.

askBridgeFor's comment, anthropic.go:503-506. Fixed. It no longer says "move". I also renamed TestInsertAskMessageBridgeOnlyWhereABreakpointMoves to ...WhereABreakpointIsCopied.

prefixask_gate.go:17-19, the write cap that is off. Fixed, wording only. The question's breakpoints sit on the turn's last message and on its copy on the bridge, never on the ask.

The empty bridge at the cap for a trailing user message (non-blocking). Left as is, on purpose.

  • The change is one line (bridgeCC.Exists()). But it changes the request shape for a trailing user message at the cap: no bridge, and the ask straight after the user message.
  • The live "keep, no bridge copy" rows had a trailing system message, which always gets a bridge. So the user-message-at-cap shape without a bridge is not proven live.
  • The current shape is harmless: the ask stays fresh input, and the bridge costs a few tokens.

countBreakpoints duplicating apply.CountBreakpoints, and a cache_control nested inside a tool_result's content (non-blocking). No change, as both reviewers said. The rule is pinned by TestCountBreakpointsMatchesTheCapRule. A miss skips only the bridge copy, which is the safe direction.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.312 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 9826d8923045 approve

Verdict: approve

Findings

None. The round-1 finding is fixed, and the one new commit changes comments only.

Non-blocking

  • components/offload/prefixask_gate.go:17-20 — the write-cap note now says the question's breakpoints "sit on the turn's last message and on its copy on the short bridge". At the cap (4 marks) there is no copy on the bridge. The conclusion the note draws (small write, ask stays fresh input) still holds there — the write is even smaller — so this is wording precision only, not a defect.
  • The author's choice to keep the empty bridge for a trailing user message at the cap is accepted. The reason is right: dropping the bridge there changes the request shape, that shape is not proven live, and the current shape is harmless.

What I checked

  • Last review: round 1, 1d32a460affca3d21510e813c9189fef3c96e3d1, 2026-10-29T23:59:34Z.
  • New commits read: 1 — 9826d892 "docs(cheapmodel): say the breakpoint is copied, not moved (#776)".
  • Read in full: 2 reviews, 1 comment, 0 inline comments (.review-in-inline.txt is empty).
  • New items since my last review, and what I did about each:
    • Reviewer 2's round-1 review (posted before mine; read now per round-2 rules). Its finding matches my round-1 finding. I checked it myself against the code: confirmed then, fixed now.
    • The author's round-1 reply comment. Every claim in it matches the diff.
    • Commit 9826d892. Reviewed in full below.
  • My round-1 finding 1 (cheapmodel/anthropic.go:224, CompletePrefixed doc said the breakpoint "moves"): fixed. The bullet now says insertAskMessage "changes no existing byte" and copies the breakpoint onto the bridge only at or under the 4-breakpoint cap (anthropic.go:224-226). Checked against the code at anthropic.go:477-494: the wording is accurate.
  • My round-1 non-blocking items: the #725 paragraph (anthropic.go:417-419) fixed — "a copy of the breakpoint lands on it, below the cap only. At the cap the bridge is still sent, with no breakpoint", which matches the guard. askBridgeFor's comment fixed, and the test renamed to TestInsertAskMessageBridgeOnlyWhereABreakpointIsCopied (body unchanged, still passes by hand-trace). prefixask_gate.go fixed (wording). The nested tool_result mark note: no change, as I suggested.
  • Reviewer 2's non-blocking items: the empty bridge at the cap — the author rejected a change with a reason (unproven live shape, harmless as is); I checked the reason and accept it. The countBreakpoints duplication note needed no change, as both reviews said.
  • The new commit in full: git diff 1d32a460..9826d892 touches only doc comments in cheapmodel/anthropic.go, one test name in cheapmodel/anthropic_prefixed_test.go, and the comment in components/offload/prefixask_gate.go. No code change. I read each new sentence against the code it describes; each is accurate. The renamed test's body and its own comment still match the behavior.
  • No new behavior, no new data dependence, fail-open untouched (nothing executable changed since round 1).
  • Tests were not run by me: live tests are not approved and Go is not on this machine. The author reports ./cheapmodel/... and ./components/offload/... passed with -race on the box; the change is comment-only, so this claim is consistent with the diff.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.312 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 9826d8923045 approve

Verdict: approve

Findings

None. The new commit is docs-only and every comment it touches now matches the code I traced in round 1.

Earlier findings

  1. My finding 1 (blocking), CompletePrefixed's doc stated the old #721 "moves" contract — fixed. anthropic.go:224-226 now says the question changes no existing byte and copies the breakpoint onto the bridge only at or under the 4-mark cap. That is what the code does. Reviewer 1 raised the same finding; I checked the fix myself and agree.
  2. My non-blocking notes, same wording class — fixed. The #725 paragraph (anthropic.go:418-420) now says a copy lands on the bridge, below the cap only, and that the bridge is still sent at the cap with no breakpoint. askBridgeFor's comment (anthropic.go:505-509) says "carries" and "copy", not "move". prefixask_gate.go:17-20 now names both of the question's breakpoints (last message and its bridge copy). The test rename (...WhereABreakpointIsCopied) matches; its body and assertions are unchanged and still hold.
  3. My non-blocking note, the empty bridge at the cap for a trailing user message — rejected by the author, and I accept the reason. The no-bridge shape for a user message at the cap is not proven live (the live "keep, no bridge copy" rows all had a trailing system message, which always gets a bridge), and the current shape is harmless: the ask stays fresh input and the bridge costs a few tokens. Shipping an unproven request shape to save a few tokens is the worse trade. The new #725-paragraph wording documents the behavior, which is what I asked for.
  4. Reviewer 1's non-blocking note, countBreakpoints does not count a cache_control nested inside a tool_result's array-form content — no change, agreed. I checked the same limit in apply.CountBreakpoints in round 1: arrayMarks walks messages.#.content blocks but not a tool_result block's own nested content. Both counters share the rule, a miss only skips the bridge copy (the safe direction), and TestCountBreakpointsMatchesTheCapRule pins it.

Non-blocking

  • anthropic.go:228-229 still says "every byte before the appended message is prefix", singular, where the question appends two messages (bridge plus ask). The meaning is clear from the fixed bullet above it. Wording only; not worth a commit.

What I checked

  • Last review: round 1, 1d32a460affca3d21510e813c9189fef3c96e3d1, 2026-10-29T23:59:03Z.
  • New commits read: 1 — 9826d892 "docs(cheapmodel): say the breakpoint is copied, not moved (#776)". Docs-only: three comment blocks and one test name; no code change, confirmed by reading the full diff 1d32a460..HEAD.
  • 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: reviewer 1's round-1 review (same finding as mine plus two non-blocking notes — checked both, see items 2 and 4); the author's round-1 reply at 2026-10-30T00:08:21Z (claims each fix — verified each against the code at HEAD; claims tests and -race passed on the box — not run by me, see below).
  • Verified each rewritten comment against the behavior I traced in round 1: the copy goes on the bridge only when the body holds 3 or fewer marks; the last message keeps its mark; the bridge is still sent at the cap; the ask never carries a mark. All four comment blocks now state exactly that.
  • Confirmed the renamed test's body and assertions are unchanged, so the rename cannot hide a behavior change.
  • Tests were NOT run by me: live tests are not approved and Go is not on this machine. The commit touches no executable code path, so my round-1 hand-trace of the tests still covers the behavior.

@amiddavid
amiddavid merged commit 8fbc19c into main Oct 30, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 30, 2026
amiddavid added a commit that referenced this pull request Oct 30, 2026
Owner decision 2026-10-30: the sweep must not contradict the caching
strategy. Where the question cannot renew the cache, it runs as an extra
request after the strategy's last ping.

- After a turn that ends at a text turn (the last non-system message
  is not a tool_result; roles and block types only), every planned ping
  is plain. The question goes out once at the slot after the last
  planned ping, 30 s before the hold ends. No ping follows it, and it
  sends nothing if the copy is gone or there is no candidate.
- After a tool_result turn the question may take ping 1, as on main:
  it renews the entry (#777).
- This replaces the "plain ping 1, question on the last ping" rule of
  the first commit, which is reverted.

New counters: keepalive_sweep_extra_asked, keepalive_sweep_extra_skipped.

Refs #776

Assisted-By: Claude
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Oct 30, 2026
…776) (#779)

fix(keepalive): the sweep question takes the last ping, never ping 1 (#776)

The sweep question took ping 1 of an idle span. It reads the turn's
cache entry but does not renew one that ends at a text turn. After a
text turn the entry then expired, and the plain ping 2 wrote the whole
conversation again: 22 of the 80 misses in #776 ($50.18 in 3.9 days on
one laptop), which #777 could not fix.

Ping 1 is now always plain. The question takes the last planned ping of
the span. A one-ping plan (the 1-hour tier's default) sends no question,
so the question is never the only ping.

The summarizer's substitute, the already_asked latch, the cost ceiling
and the batch rules are unchanged.

Owner decision 2026-10-30.

Fixes #776

Assisted-By: Claude
Signed-off-by: DAVID AMID <[email protected]>
fix(keepalive): after a text turn the sweep question comes third (#776)

Owner decision 2026-10-30: the sweep must not contradict the caching
strategy. Where the question cannot renew the cache, it runs as an extra
request after the strategy's last ping.

- After a turn that ends at a text turn (the last non-system message
  is not a tool_result; roles and block types only), every planned ping
  is plain. The question goes out once at the slot after the last
  planned ping, 30 s before the hold ends. No ping follows it, and it
  sends nothing if the copy is gone or there is no candidate.
- After a tool_result turn the question may take ping 1, as on main:
  it renews the entry (#777).
- This replaces the "plain ping 1, question on the last ping" rule of
  the first commit, which is reverted.

New counters: keepalive_sweep_extra_asked, keepalive_sweep_extra_skipped.

Refs #776

Assisted-By: Claude
Signed-off-by: DAVID AMID <[email protected]>
docs: keep-alive never shortens the cache strategy (#776)

The owner asked for the rule in the development docs, so a later change
that breaks it is caught.

- docs/design.md: a new section, "Keep-alive: the cache strategy comes
  first". It names the summarizer's substitute as a known gap.
- CLAUDE.md, Hard boundaries: one bullet that points at it.
- RELEASING.md, Part B: the live check confirms that after a text turn
  every planned ping is plain and reads the full prefix.
- A guard test for the sweep on 1-, 2- and 3-ping plans.

Refs #776

Assisted-By: Claude
Signed-off-by: DAVID AMID <[email protected]>
fix(keepalive): the summarizer follows the cache strategy too (#776)

Owner decisions 2026-10-30: "summerizer as well so a)" and "a1 it is".

- After a text turn the summarizer's keep-alive substitute no longer
  takes a planned ping. Every planned ping is plain, and the summary
  goes out once as the extra request after the last one.
- A cache_state any summary uses the sweep's slot: 30 s before the
  normal hold deadline.
- A cache_state pre_expiry summary (the medium preset) runs only in its
  pre-expiry window. Its slot is the middle of that window: 268 s
  after the last ping at the 5-minute defaults, 32 s before expiry.
- The one exception to the hold limit: only for a span that ended at a
  text turn and still has a pre_expiry summary waiting, the deadline
  timer re-arms once, to 15 s past the slot (43 s longer at the
  defaults), never past the cache expiry. Every other span keeps the
  limit. Counted as keepalive_hold_extensions.
- One request in the extra slot. The summary owns it before the sweep.
  A declining pre_expiry summary is not followed by the sweep.
- A missed extra slot is never sent late.
- OpenAI is out of scope: its cache has no text-turn rule.
- docs/design.md: the known gap is gone. The guard covers every
  substitute kind.

Refs #776

Assisted-By: Claude
Signed-off-by: DAVID AMID <[email protected]>
test(proxy): the summary-at-a-ping tests use a tool_result turn (#776)

After a text turn the summary now waits for the extra slot after the
last planned ping. These two tests are about a planned ping dispatching
the summary, so their last real turn now ends at a tool_result.

Refs #776

Assisted-By: Claude
Signed-off-by: DAVID AMID <[email protected]>
fix(keepalive): the summary uses the 210 s slot, no hold extension (#776)

Owner decision 2026-10-30: "give it more time, it can run on the 210
sec mark".

- The hold extension is removed: the re-armed timer,
  keepalive_hold_extensions and its tests. Every span keeps today's
  hold limit.
- One extra slot for every substitute: 30 s before the normal hold
  deadline (210 s after the last ping at the 5-minute defaults).
- For the summary's extra request only, the pre-expiry window widens to
  cover that slot (94 s at the defaults: 90 s left plus two ticks).
  Planned-ping summaries keep the #715/#717 window.
- The summary goes first. The sweep question goes only if the summary
  declines, in the same slot. Nothing after it.
- Kept: a missed slot is never sent late; OpenAI is out of scope.

Refs #776

Assisted-By: Claude
Signed-off-by: DAVID AMID <[email protected]>
fix(keepalive): only the summary takes a summary's slot; extra re-checks the breaker (#776)

Owner rule 2026-10-30: "as for sweep after summary. dont do that. it can
probably have the sweep question pay a cache write like the problem with
the ping... so we should probably just do summary at that point".

- When a summary is due in the extra slot, only the summary goes, even
  if it declines. The sweep question takes the slot only when no
  summary is registered for the thread.

Review round 1 on #779:
- The extra slot now runs the same route-breaker and dead-credential
  re-check as a planned ping. On a trip it sends nothing and stops the
  span.
- A short Idle: the slot is at least two ticks after the last ping, and
  the extra waits until that ping's response is in (pingRunning).
- SweepExtraSkipped: the doc names every case it counts.
- docs/design.md: endsAtTextTurn is an internal flag, not a metric.
- RELEASING.md: the Part B check is numbered like its siblings.

Refs #776

Assisted-By: Claude
Signed-off-by: DAVID AMID <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(keepalive): ping 2 re-writes the whole prefix after a ping 1 that wrote 6 tokens

1 participant