Skip to content

fix(cheapmodel): move the trailing breakpoint onto the appended question - #725

Merged
amiddavid merged 5 commits into
mainfrom
fix/prefix-ask-breakpoint
Oct 26, 2026
Merged

amiddavid merged 5 commits into
mainfrom
fix/prefix-ask-breakpoint

Conversation

@amiddavid

@amiddavid amiddavid commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Sweep questions now hit the cache, and the sweep gate accepts a correct answer.

Fixes #721. Blocks v0.6.0.

What we found

  • The provider never reads a cache entry that ends at a text turn (Prefix questions (sweep, summary substitute) miss the cache: the breakpoint stays on Claude Code's trailing system message #721 update). A question after a typed prompt always rewrites that turn's tail, so a write limit cannot judge it.
  • Claude Code 2.1.310 ends each request with a role: system message. It holds the last cache_control breakpoint.
  • insertAskMessage kept that breakpoint there and appended the bridge and the ask with none.
  • The provider then missed the turn's cache entry. The question rewrote the conversation (12,142 tokens written).
  • The sweep gate refused any write, so it refused every answer.

What changed

  • F1. insertAskMessage moves the last message's breakpoint onto the "Understood." bridge. A trailing user message with a breakpoint now gets the bridge too, so the breakpoint never sits on the ask (the cache write would hold the whole ask, 1,000 to 1,400 tokens).
    • It copies the cache_control object as is, so ttl stays.
    • It works for string content (on the message) and array content (on the last block).
    • It adds no breakpoint if the last message has none. The count never goes up.
    • It changes no other byte of the earlier messages.
  • F2 (revised, after the text-turn finding in Prefix questions (sweep, summary substitute) miss the cache: the breakpoint stays on Claude Code's trailing system message #721). The provider never reads a cache entry that ends at a text turn, so a correct question rewrites that turn's tail and a write limit cannot tell good from bad. The sweep now judges the READ.
    • One function decides: prefixAskCacheOK (components/offload/prefixask_gate.go).
    • Refuse a read of 0 (sweep_prefix_cache_read_ZERO).
    • Refuse a read below the last real turn's read (new gate sweep_prefix_cache_read_below_turn).
    • Write cap, min(2% of prefix, 2,000 tokens), constants prefixAskWriteCapFrac and prefixAskWriteCapMax, behind the constant prefixAskWriteCapEnabled. Off as shipped. The owner chose the read rule only, on 2026-10-26. The code and constants stay; set the constant true to turn the cap on. A refusal by the cap uses sweep_prefix_cache_write.
    • The turn's read comes from the keeper entry (turnRead, set at record time) through SweepPingWait.LastTurnRead. No DB read. Unknown (0) means only the read-of-0 rule applies.
    • The earlier "write > appended tokens" allowance is removed.
  • Marker quote. One function, carriesRealMarker, decides on the ping side AND the cold apply and replay. A skip on a real marker in the apply is counted (sweep_apply_already_marked). The ping candidate scan skips only real markers: the summary sentinel, or a <<cg:HASH>> whose HASH is in the store. Text that only quotes marker syntax is a candidate. Same fault as fix(offload): cache_aware_summarizer cut every span at quoted marker text #705.
  • Doc comments on insertAskMessage and CompletePrefixed are corrected.

How it was tested

All on eval box 1, -count=1. Full go test ./... passes. -race passes on cheapmodel, components/offload, keepalive and proxy. No known flake hit. No live model calls.

New tests, each failing on main a0e5f9e5:

  • TestInsertAskMessageMovesTheTrailingBreakpoint (4 cases): fails on main, the old message keeps cache_control and the carrier has none.
  • TestInsertAskMessageAddsNoBreakpointWhenTheLastHasNone: guards against adding a breakpoint.
  • TestPrefixAskCacheOK (15 table rows): A5 passes, model switch refused, read 0 refused, a typed-prompt tail write of 300 passes (the case the old rule got wrong), large write refused only with the cap on.
  • TestPrefixAskCacheOKShipsWithTheCapOff: the shipped constant is off, a large write with a good read is accepted, and the read rule still refuses a model switch. The cap rows force it on through prefixAskJudge.
  • TestThePingGateJudgesTheReadAgainstTheLastTurn: end to end through the sweep. On main the A5 rows (small write) are refused.
  • TestSweepWaitCauseCarriesTheTurnsRead: the keeper passes the turn's read.
  • TestSweepPrefixWriteTripsTheCounterEvenOnAPartialHit was rewritten: the partial hit is now caught by its low read.
  • TestThePingOffersAnOutputThatOnlyQuotesAMarker: on main, no question is offered (no_inventory).

Mutations, each killed by its test:

  1. Keep the old breakpoint on the last message.
  2. Drop the ttl when moving.
  3. Add a breakpoint when there is none.
  4. Marker scan back to expand.HasPlaceholder.
  5. Real marker no longer detected.
  6. Gate: read of 0 allowed.
  7. Gate: read below the turn allowed.
  8. Gate: off by one on the comparison.
  9. Gate: write cap ignored.
  10. Gate: 2,000 ceiling ignored.
  11. Gate: any write refused.
    11a. Bridge: breakpoint back on the ask; no bridge for a user message; bridge for every user message; touch an assistant-last message.
    11a2. Shipped cap constant flipped on.
    11b. Apply side: bare marker rule; apply never skips; replay with the bare rule.
    12a. Gate: shipped cap switch off.
  12. Sweep ignores LastTurnRead.
  13. Keeper does not pass turnRead.

One more mutation survives and is equivalent: dropping the lastTurnRead > 0 guard. A read is never below 0, so the guard is redundant. It stays for clarity.

Two existing tests used a marker with no stashed original. They now stash it, as a real marker has one.

Review round 1 (#725)

  • R2, apply side: the cold apply and the replay now use carriesRealMarker. Tests: a quoting output is dropped on a cold request and replayed on a warm one; a real marker is skipped and counted.
  • R1, no-bridge shape: fixed with option (a). A trailing user message with a breakpoint gets the bridge, and the breakpoint moves onto it. The made-up 300-token row is replaced by a test built from the real ask (TestThePingGateWriteExcludesTheRealAsk).
  • Non-blocking items: struct comment, cap comment, docs and data-dependence updated.

Other gates (F2 scope)

  • keeper.go ~1436 (CacheWrite > CacheRead || CacheRead == 0): no change. This judges the ordinary ping, not a prefix-ask answer. It already allows a small write. A question that reads 25,588 and writes 20 passes.
  • keepalive/substitute.go ~385 (CacheWrite > CacheRead): stop rule for the sweep substitute. Left as is. It stops only when the write exceeds the read, which a question that read the prefix never does. It is not a refusal of the answer.
  • cache_aware_ (summarizer substitute):* no write gate. It books the usage and does not refuse on a write. No change.
  • extract_sweep_ping.go ~564 (Substituted = read > 0 || write > 0): not a refusal. No change.

Open questions

Technical notes

Assisted-By: Claude Opus 5.5

  • A live measure of the bridge shape against the no-bridge shape is not done. No live call runs on this PR.
  • A zero read with a write now records only sweep_prefix_cache_read_ZERO, not also sweep_prefix_cache_write. This is intended: it is one failure.
  • A ⟪cg⟫ sentinel quoted in a tool output is still skipped as a candidate. It has no key to check. Safe direction.

Claude Code 2.1.310 ends each request with a system message that holds the
last cache_control breakpoint. The prefix ask kept it there and appended the
bridge and the ask with none. The provider then missed the turn's cache entry
and the question rewrote the conversation. The sweep gate refused every
answer.

- insertAskMessage moves the last message's breakpoint (same object, ttl
  kept) onto the bridge, or onto the ask when there is no bridge. It adds
  none when the last message has none.
- The sweep write gate refuses a write only when it is larger than the
  tokens the question appended, plus a named margin.
- The ping candidate scan skips only real markers. Text that quotes marker
  syntax is a candidate (same fault as #705).

Fixes #721

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
The provider never reads a cache entry that ends at a text turn, so a
correct question always rewrites that turn's tail. A write limit would
still refuse most questions.

prefixAskCacheOK is now the one decision. It refuses a read of 0 and a
read below the last real turn's read. An optional write cap (min of 2
percent of the prefix and 2,000 tokens) is off until the owner decides.
The keeper passes the turn's cache_read to the sweep through
SweepPingWait. The old "write > appended tokens" allowance is removed.

Refs #721

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
The owner has not chosen the cap yet. prefixAskWriteCapEnabled is one
constant, so the cap can go without a rewrite. Adds table rows for a
typed-prompt tail write, and a test that the shipped switch is on.

Refs #721

Assisted-By: Claude Opus 5.5
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.310 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 86e92f336a07 blocking

Verdict: blocking

Findings

  1. components/offload/extract_sweep_apply.go:797 — a quoted-marker output is offered and judged, but its drop can never be applied
    • What fails: a tool output that only QUOTES marker syntax now enters the sweep at the ping
      (carriesRealMarker, extract_sweep_ping.go:475, returns false when the hash is not in the
      Store). The question is asked and paid for. The model's drop verdict is held. On the next cold
      request, applyHeld re-checks the verdict, then skips the output, because line 797 still tests
      the bare expand.HasPlaceholder(content) — which is true for a quoted marker too. The skip
      records no gate and no counter. So the new candidate class this PR adds can never produce a
      saving, and nothing in /stats shows that.
    • Proof: trace. Ping side: collect (extract_sweep_ping.go:475) admits the output, because
      carriesRealMarker (line 621) finds no store key for the quoted hash. ask stores the verdict
      through buildHeld/putHeld (lines 584-591). Apply side: recheckHeld
      (extract_sweep_recheck.go:91) has no marker test, so the output lands in res.Valid. The apply
      loop at extract_sweep_apply.go:797 then hits expand.HasPlaceholder(content) == true on the
      same quoted text and continues before applySweepDrop. No rep.Gate or event fires on that
      path — contrast applySweepDrop failing, which counts eventApplyDeclined. The PR's own test
      (TestThePingOffersAnOutputThatOnlyQuotesAMarker) covers the offer only. No test covers the
      apply of a quoted-marker verdict.
    • Fix: at extract_sweep_apply.go:797, replace expand.HasPlaceholder(content) with
      carriesRealMarker(c, content) (the function already takes the *components.Ctx that
      applyHeld holds), so the apply side and the offer side use one rule. Count the skip when it
      does fire. Add a test that a held drop on a quoting output applies on a cold request.

Non-blocking

  • components/offload/extract_sweep_ping.go:77 — the struct comment says "Never read to decide
    anything here." The new LastTurnRead field is read to decide the cache gate. The field's own
    comment says so. Update the struct comment; it now states something false.
  • components/offload/prefixask_gate.go:19-20 — the comment says "The owner has not chosen the
    cap yet (#721)", but the cap ships on and TestPrefixAskCacheOKShipsWithTheCapOn asserts that.
    The comment will mislead the next reader into thinking the shipped value is unsettled.
  • docs/components/advanced-offload.md:466-475 — the section "When the cache read does not
    happen" still describes only the zero-read and the write rules. The new below-turn rule appears
    only in the gate list at line 578. Add one sentence there.
  • docs/data-dependence.md — the candidate gate now reads Store key-presence
    (carriesRealMarker). It is presence only, and a nil Store keeps the old answer, so it likely
    sits inside the existing extract_llm_sweep row. But CLAUDE.md asks each PR to state a change of
    dependence; the diff does not touch this file. Say it in the PR text or the row.
  • keepalive/keeper.go:828 — turnRead is copied from u.CacheRead even when usageOK is
    false. This matches how prefix is built on the line above, so it is consistent; noting it only.

What I checked

  • Read CLAUDE.md and docs/design.md, then the full diff of all three commits and the code
    around each change: cheapmodel/anthropic.go (insertAskMessage, takeLastBreakpoint,
    marshalAppended, CompletePrefixed, thinkingAdjustedMaxTokens), components/offload/ extract_sweep.go (adjudicateWith and its one caller), extract_sweep_ping.go (collect,
    ask, carriesRealMarker), extract_sweep_apply.go (applyHeld, replayDrops),
    extract_sweep_recheck.go, prefixask_gate.go, keepalive/keeper.go (Record),
    keepalive/substitute.go (sweepWaitCause, fireSweepSubstitute), and every changed test file.
  • Verified adjudicateWith has exactly one production caller (the ping path), and that
    SweepPingWait is built in production only by sweepWaitCause, which sets LastTurnRead.
  • Verified all prefix asks route through cheapmodel.Anthropic.CompletePrefixed →
    insertAskMessage, so the breakpoint move covers every asker; the OpenAI CompletePrefixedResponses
    path is untouched and carries no cache_control.
  • Checked the breakpoint move for the shapes I could think of: string and block content, message-level
    and block-level cache_control, ttl preserved verbatim, count preserved (no new 4-breakpoint
    400), sjson.Delete failure leaves the message untouched (fail open, plain ping), and no
    breakpoint is added when the last message has none.
  • Checked the gate change for regressions in the unknown-turn case (lastTurnRead == 0): the write
    cap (2% of read+write, ceiling 2000) still refuses a rebuild, e.g. read 13,440 / write 12,000.
    Checked the keeper's own stop guard (CacheWrite > CacheRead, substitute.go:385) stays valid
    under the new rule.
  • Checked carriesRealMarker against expand.HasPlaceholder, ParseMarkers, and the Store Get
    contract (two-value return; sliding-TTL refresh on a real marker is benign). A quote whose hash
    collides with a real marker id is skipped — the safe direction.
  • Did not run builds or tests (not approved). Findings rest on code reading only.

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

Verdict: blocking

Findings

  1. components/offload/prefixask_gate.go:49 — the write cap refuses every real question in the no-bridge shape, because the question's own text sits inside the write
    • What fails: a thread whose last sent message is not role: system and carries cache_control (the placement Anthropic's own docs recommend for the final message). The question reads the full entry, so the read rule passes. But the write contains the whole ask prompt, so the cap refuses it. The sweep pays for every question on that thread and discards every answer. The persisted rejection says "re-created the agent's prefix instead of reading it". That is false.
    • Proof:
      • insertAskMessage (cheapmodel/anthropic.go:461-473) puts the moved breakpoint on the bridge, or on the ask when there is no bridge. marshalAppended (cheapmodel/anthropic.go:507-522) puts cache_control on the ask's own text block. So the cache write covers everything from the read boundary to that block — the whole ask text.
      • The ask text is large. It is the adjudication contract (482 words, internal/extract/adjudicate.go:139-180), the evidence section (254 words, :198-215, on by default — extract_sweep.go:292), up to 12 inventory lines with 90-char heads and evidence (:229-255, maxAskItems = 12, extract_sweep.go:163), plus the opening line (ask_role.go:15). That is about 1,400 tokens; the smallest real ask is about 1,000.
      • The cap (prefixask_gate.go:49-56) passes only when write <= 0.02 x (read+write), so a write of ~1,500 needs a read of ~73,500. On a 25,000-token prefix the limit is ~512. The ask alone is ~3x over it.
      • The PR's own test contradicts itself here: "typed prompt: a 300-token tail write passes" (extract_sweep_ping_test.go:1074) reports write = 300 for the no-bridge shape. In that shape the write cannot be 300. The ask alone is ~1,400. The row passes only because the fake asker reports an invented number.
      • The live replays in the comment (read 25,588, wrote 6 and 20) are all bridge-shape, where the ask sits after the breakpoint and is fresh input, not a write. They do not cover the no-bridge shape. The "wrote 20" replay also used a stub ask, not the real ~1,400-token prompt.
    • Fix: keep the ask out of the write the cap judges. Either (a) put the breakpoint on a short synthetic assistant message in the no-bridge case too, so the ask stays after it (same as the bridge case, write ~6); or (b) pass the ask's own token count to the gate and judge write - askTokens against the cap. A true rebuild writes the whole prefix, so it stays far above either cap.

Non-blocking

  • components/offload/extract_sweep.go:856 — a zero read with a write used to record both sweep_prefix_cache_read_ZERO and sweep_prefix_cache_write. Now the switch records only the first. A dashboard trending sweep_prefix_cache_write will see those cases leave it. Say in the PR if this drop is intended.
  • keepalive/keeper.go:828 — no test covers that Record sets turnRead from the turn's CacheRead. TestSweepWaitCauseCarriesTheTurnsRead builds the kaEntry by hand, so a mutation of the turnRead: u.CacheRead assignment survives.
  • components/offload/extract_sweep_ping.go:625 — carriesRealMarker treats any ⟪cg⟫ as real. A tool output that greps this repo quotes that sentinel (expand/expand.go:29) and is skipped as a candidate. Safe direction, but it is the same fault #705 fixed for <<cg:HASH>>. The summary sentinel carries no key, so the store cannot confirm it.
  • docs/data-dependence.md — carriesRealMarker adds a new read of the Store (key existence, extract_sweep_ping.go:630-633). The sweep's row there does not mention it. CLAUDE.md asks for that update when a feature's data dependence changes. The PR body states "only key names and token counts", which covers the intent; the row should still say it.

What I checked

  • The full diff a0e5f9e5..86e92f33, all three commits, and the code around every change.
  • insertAskMessage, takeLastBreakpoint, marshalAppended, lastBridge and their one caller CompletePrefixed; the ask prompt assembly (internal/extract/adjudicate.go, ask.go, ask_role.go).
  • adjudicateWith and its single caller (the ping path); the gate change and the new prefixask_gate.go; carriesRealMarker against expand.HasPlaceholder, ParseMarkers, and the #705 fix (2e29045).
  • The keeper side: Record, kaEntry.turnRead, sweepWaitCause, fireSweepSubstitute, and every construction of SweepPingWait (one, in production code).
  • Arithmetic traces: cap limit for read 25,516 with a 1,400-token ask; the read rule against the entry the last real turn wrote; both bridge and no-bridge shapes.
  • All new and changed tests, and the gate names against docs/components/advanced-offload.md.
  • No tests were run. Live tests are not approved and Go is not on this machine.

…rker check

Review round 1 of #725.

- A trailing user message that carries a breakpoint now also gets the
  "Understood." bridge, and the breakpoint moves onto the bridge. The ask
  stays fresh input. Before, the breakpoint sat on the ask and the cache
  write held the whole ask (about 1,000 to 1,400 tokens), so the write cap
  refused every question in that shape.
- The cold apply and the replay use carriesRealMarker, the same rule as the
  ping's candidate scan. A drop on an output that only quotes marker text now
  applies. A skip on a real marker is counted (sweep_apply_already_marked).
- Docs: the read rules in advanced-offload, the Store presence read in
  data-dependence.

Refs #721

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 1 fixes are in the new head.

  1. Reviewer 2, the apply side. The cold apply and the replay now call carriesRealMarker, the same function the ping scan calls. A real-marker skip raises the gate sweep_apply_already_marked. Tests: a quoting output is dropped on a cold request and replayed byte for byte on a warm one. An output that gained a real marker after the ping is skipped and counted. Three mutations are killed.
  2. Reviewer 1, the no-bridge shape. Fixed with option (a). A trailing user message that carries a breakpoint gets the "Understood." bridge, and the breakpoint moves onto it. The ask is never the carrier, so it stays fresh input. The made-up 300-token row is gone. TestThePingGateWriteExcludesTheRealAsk counts the real ask and checks the gate accepts a bridge-sized write and refuses an ask-sized one. Five mutations are killed.
  3. Non-blocking. The struct comment, the cap comment, advanced-offload.md and data-dependence.md are updated. The zero-read gate change is stated in the PR body. The keeper turnRead test and the ⟪cg⟫ quote are left as they are, and the body says so.

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

Verdict: approve

Findings

None. Both round-1 findings are fixed, and I found no new defect in the fix commit.

Earlier findings

  1. Mine, round 1 — the write cap refused every question in the no-bridge shape. Fixed, with my option (a). insertAskMessage (cheapmodel/anthropic.go:454-487) now gives a trailing user message that carries a breakpoint the "Understood." bridge, and the breakpoint moves onto the bridge. The ask is always built with marshalAppended("user", ask, gjson.Result{}), so no shape ever puts a breakpoint on the ask. The write is now the bridge plus the turn's tail, never the ~1,400-token ask. I traced every shape:
    • system last: bridge always, breakpoint moved onto it (the measured shape, read 25,588 / wrote 6).
    • user last with a breakpoint: bridge added, breakpoint moved onto it. Write = tail + bridge.
    • user last without a breakpoint: no bridge, ask appended directly. Legal shape, no breakpoint added.
    • assistant last: untouched, ask follows directly. The breakpoint stays on the assistant message; the bridge measurement shows a breakpoint on a non-last assistant message still reads the entry, and the ask after it is fresh input, so the write is 0.
    • empty messages: ask only.
      The invented 300-token test rows are gone from both gate test files. TestThePingGateWriteExcludesTheRealAsk counts the tokens of the real ask (asserts at least 300), then checks the gate accepts a bridge-sized write and refuses an ask-sized one. That is the right test.
  2. Reviewer 2, round 1 — a quoted-marker output was offered but its drop could never apply. Fixed, and I checked it myself. applyHeld (extract_sweep_apply.go:805) and replayDrops (:579) now call carriesRealMarker, the same rule as the ping scan. The apply-side skip raises sweep_apply_already_marked. The trace from round 1 now ends in an applied drop: offer (quoted hash not in Store) → verdict held → cold apply uses the same rule → drop applied and replayed byte for byte on the warm request. Tests cover all three: the quoting drop applies cold and replays warm; an output whose quoted hash became real after the ping is skipped and counted; the replay uses the same rule.
  3. Non-blocking items. The struct comment on SweepPingWait, the cap comment, the read-rules paragraph in advanced-offload.md, and the data-dependence row are all updated. The zero-read single-gate change and the ⟪cg⟫ quote are stated in the PR body as intended. The keeper turnRead test gap is left as is; I accept that — the wiring has a test and the gap is one assignment.

Non-blocking

  • docs/components/advanced-offload.md:542 — the request-side gate list does not name sweep_apply_already_marked. Round 1 added the new ping gate to this list; the new apply gate should get the same line.
  • PR body — two stale claims remain under "How it was tested" and "Technical notes": "a typed-prompt tail write of 300 passes" and "(15 table rows)" describe rows that this commit deleted (13 remain), and the notes still list "breakpoint on the ask" as a shape, which the code now never builds. The round-1 section corrects the record, so this is text only.

What I checked

  • Last review: round 1, 86e92f336a072a50c2d234dac1c7fc459a03dd3c, 2026-10-26T00:43:00Z.
  • New commits read: 1 — b9aeecb3 "fix(cheapmodel): keep the breakpoint off the ask, one rule for the marker check".
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files), plus the current PR body.
  • New items since my last review: reviewer 2's round-1 review (checked its finding myself against the new code), the author's round-1-fixes comment (each claim verified in the diff), and the fix commit (reviewed below).
  • The full diff 86e92f33..b9aeecb3 and the code around every change: insertAskMessage, askBridgeFor, takeLastBreakpoint, marshalAppended, AskBridge; applyHeld, replayDrops; carriesRealMarker's new doc; the gate file's new cap comment.
  • Traced all five last-message shapes through the new insertAskMessage (system with and without breakpoint, user with and without, assistant, empty array) against the position rule, the write coverage, and the measured reads from #721.
  • Confirmed the removed lastBridge helper has no remaining callers, and every helper used by the new tests exists (applyConv, refOutput, coldCtx, warmCtx, resetSweepLedgerForTest).
  • Checked the apply-side bookkeeping around the new skip: a skipped output writes no drop record, and the held answer is spent on a cold request either way.
  • No tests were run. Live tests are not approved and Go is not on this machine.

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

Verdict: approve

Earlier findings

  • Mine, round 1 (apply side skipped quoted-marker outputs) — fixed. applyHeld
    (extract_sweep_apply.go:800-803) now calls carriesRealMarker, the same function the ping scan
    calls, and counts the real-marker skip as sweep_apply_already_marked. replayDrops (line 579)
    uses the same rule. I verified the tests do what they claim:
    TestAColdApplyDropsAnOutputThatOnlyQuotesAMarker drops a quoting output on a cold request and
    replays it byte for byte on a warm one; TestAColdApplySkipsAndCountsAnOutputThatNowCarriesARealMarker
    covers the marker-turned-real skip and its counter.
  • Reviewer 1, round 1 (the cap refused every no-bridge question, because the write held the whole
    ask) — fixed, and I checked it myself.
    insertAskMessage now never puts the breakpoint on the
    ask: marshalAppended("user", ask, gjson.Result{}) at cheapmodel/anthropic.go:481. A trailing
    user message with a breakpoint gets the "Understood." bridge and the breakpoint moves onto it
    (askBridgeFor). I traced every shape: system-last (bridge always), user-last with a breakpoint
    (bridge), user-last without (no bridge, plain ask), assistant-last (untouched, plain ask). The
    breakpoint can never be dropped on the floor: moved is non-empty only for system or user last
    messages, and both then get a bridge. The invented "300-token tail write" test rows are gone,
    replaced by TestThePingGateWriteExcludesTheRealAsk, built from the real ask's token count.
  • My round-1 non-blocking items — all fixed. The SweepPingWait struct comment, the cap
    comment in prefixask_gate.go, the read-rules paragraph in advanced-offload.md, and the
    data-dependence row (presence-only Store read stated).
  • Reviewer 1's round-1 non-blocking items — dispositioned. The data-dependence row is updated.
    The zero-read gate change is stated in the PR body (I read the body; it says one failure, one
    gate — intended). The keeper turnRead assignment test and the ⟪cg⟫ quote were left as they
    are, with reasons in the body. I accept both reasons: the first is a coverage nit on a one-field
    copy, the second fails safe (the sentinel carries no key to check).

Findings

None in the new commit.

Non-blocking

  • docs/components/advanced-offload.md:542-543 — the apply gate list does not name
    sweep_apply_already_marked, which this PR adds. The list names the other apply gates. Add it.
  • cheapmodel/anthropic.go:464-466 — the assistant-last shape rests on an unmeasured assumption.
    The comment cites replays for the system and user shapes only. Under the PR's own text-turn
    theory, a thread whose last message is an assistant TEXT message with a breakpoint would read low
    and be refused by the cap. That outcome is counted and fail-safe, and it is no worse than main
    (the pre-PR code also left that breakpoint alone). But the PR's headline is "questions now hit the
    cache", so replay one assistant-last body before calling that settled.
  • components/offload/extract_sweep_apply.go:579 — at replay time, a quoted hash that became a
    real Store key after the drop was applied makes carriesRealMarker true, so the replay is
    skipped. That flips the prefix back to the original bytes, and unlike the apply side the skip is
    not counted. The trigger needs a stashed marker whose id equals text quoted inside that output —
    a content-hash collision, so vanishingly rare. Count it if you touch this line again.

What I checked

  • Last review: round 1, 86e92f3, 2026-10-26T00:41:03Z.
  • New commits read: 1 — b9aeecb "fix(cheapmodel): keep the breakpoint off the ask, one rule for
    the marker check".
  • Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files), plus the PR body.
  • New items since my last review: reviewer 1's round-1 review (00:43), the author's comment
    (01:06), and commit b9aeecb (03:06). I checked each fix the comment claims, in the code.
  • The full diff 86e92f33..b9aeecb3, and the final state of every changed file around the changes:
    insertAskMessage, askBridgeFor, AskBridge, takeLastBreakpoint, marshalAppended;
    applyHeld, replayDrops, gateApplyAlreadyMarked; the carriesRealMarker doc; the gate
    comment; both docs files; and every changed test.
  • Compile-level checks: lastBridge is fully removed with no stale references; the expand import
    removal from extract_sweep_apply.go leaves no other use; all new test helpers exist
    (applyConv, refOutput, coldCtx, warmCtx, assistantMsg, userMsg,
    resetSweepLedgerForTest, labelAsker.ask, Report.Replays, eventAppliedCold); test-file
    imports cover the new uses.
  • Behavior traces: the four last-message shapes (breakpoint moved and consumed by the bridge, never
    lost, never on the ask); a user-last tool_result message followed by the bridge (legal role
    sequence, tool_result position rule intact); breakpoint count preserved; ttl copied verbatim;
    strip failure fails open to the pre-#721 shape.
  • The gate tests against the new construction: a bridge-sized write passes the cap, an ask-sized
    write is refused; the removed "300-token tail" rows matched a shape the new construction no
    longer produces.
  • Did not run builds or tests (not approved). Findings rest on code reading only.

The owner chose the read rule only (2026-10-26). The cap code and its
constants stay behind prefixAskWriteCapEnabled, now false. One constant
turns it on.

Refs #721

Assisted-By: Claude Opus 5.5
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.310 offload-review skill, @amiddavid's session resumed 2 of 2 3 of 3 ac89546ded5c approve

Verdict: approve

The new commit

ac89546d ships the write cap OFF. prefixAskWriteCapEnabled is now false. The gate refuses a
read of 0 and a read below the last turn's read, and nothing else. This resolves the PR's open
owner decision (read rule only, 2026-10-26). I checked that every place agrees:

  • The code: prefixask_gate.go — the switch, the comment, and the unchanged read rules.
  • The tests: TestPrefixAskCacheOKShipsWithTheCapOff asserts the constant is false, a large write
    with a good read is accepted, and the read rule still refuses a model switch.
    TestThePingGateJudgesTheReadAgainstTheLastTurn now expects the large-write row to be held.
    TestThePingGateWriteExcludesTheRealAsk forces the cap on through prefixAskJudge to keep the
    cap arithmetic covered while it is off. The cap rows in TestPrefixAskCacheOK still pass capOn
    explicitly, so nothing there depended on the shipped value.
  • The docs: advanced-offload.md says a write alone is not refused, and names the cap as present
    but off.
  • The PR body: "Off as shipped" with the owner decision, and the mutation list updated
    (11a2, 12a).

The keeper's own stop guard (CacheWrite > CacheRead, keepalive/substitute.go:385) still
backstops the extreme case, and the cap-off switch also removes the one shape the cap could have
mis-refused. I found no defect in the commit.

Earlier findings

  • Mine, round 1 (apply side skipped quoted-marker outputs) — fixed in b9aeecb3, verified in
    round 2. The new commit does not touch it.
  • Reviewer 1, round 1 (the cap refused every no-bridge question) — fixed in b9aeecb3,
    verified in round 2. The new commit makes the concern moot by shipping the cap off, and keeps
    the ask off the breakpoint either way.
  • All round-1 and round-2 non-blocking items from both reviewers — the four fixed ones (struct
    comment, cap comment, read-rules docs, data-dependence row) stay fixed. The open ones are listed
    below; none were addressed by this commit, and none block.

Findings

None in the new commit.

Non-blocking

Still open from round 2, in priority order:

  • docs/components/advanced-offload.md:542-543 — the apply gate list still omits
    sweep_apply_already_marked. Both reviewers flagged it in round 2. One word.
  • PR body, "How it was tested" — line 40 still says "15 table rows" and "a typed-prompt tail
    write of 300 passes". Those rows were deleted in b9aeecb3 (13 remain). Reviewer 1 flagged this
    in round 2; it is text only, but the body now also contradicts itself (that line vs. the correct
    "Off as shipped" line 26).
  • cheapmodel/anthropic.go:464-466 — the assistant-last shape is still unmeasured. With the cap
    off, a bad read there is now caught by the below-turn rule only when the keeper knows the turn's
    read; the outcome stays counted and fail-safe. Still worth one replay.
  • components/offload/extract_sweep_apply.go:579 — the replay-side marker skip is still
    uncounted. Hash-collision trigger; note stands for whoever touches the line next.

What I checked

  • Last review: round 2, b9aeecb, 2026-10-26T01:13:34Z.
  • New commits read: 1 — ac89546 "fix(offload): ship the prefix-ask write cap off".
  • Read in full: 4 reviews, 1 comment, 0 inline comments (from the three files), plus the PR body
    re-fetched after the new commit.
  • New items since my last review: reviewer 1's round-2 review (01:12:14, approve — read in full;
    its verification of both round-1 fixes matches my own from round 2), the PR body edits (cap-off
    decision and mutation-list updates), and commit ac89546 (07:28). The issue comments and inline
    comments are unchanged since round 2.
  • The full diff b9aeecb3..ac89546d and the final state of all four changed files: the gate
    switch and its comment, all three touched test files, and the docs paragraph.
  • Traced the gate with the switch off: only read_zero and read_below_last_turn can fire;
    sweep_prefix_cache_write is unreachable in production, and the docs say so.
  • Checked no test still depends on the shipped cap value: every cap assertion either passes
    capOn explicitly or forces the switch through prefixAskJudge, and the one shipped-value test
    asserts OFF.
  • Did not run builds or tests (not approved). Findings rest on code reading only.

@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.310 offload-review skill, @amiddavid's session resumed 1 of 2 3 of 3 ac89546ded5c approve

Verdict: approve

Findings

None. The new commit turns the write cap off, and I found no defect in it.

The new commit

ac89546d ships prefixAskWriteCapEnabled = false. The owner chose the read rule only (2026-10-26, #721). I checked the change is consistent everywhere:

  • Code: prefixAskCacheOK now judges the read rules only. The cap, its constants, and the prefixAskWriteOverCap arm stay behind the switch, so one constant turns it back on.
  • Tests: the end-to-end row now asserts a 12,142 write with a good read is accepted and no write gate fires. TestThePingGateWriteExcludesTheRealAsk forces the cap on through prefixAskJudge(..., true), so the cap logic and the ask-size premise stay covered. TestPrefixAskCacheOKShipsWithTheCapOff pins the constant false and that the read rule still refuses a model switch.
  • Docs: advanced-offload.md now says a write alone is not refused, and names the constant that turns the cap on. The PR body and the gate file comment say the same.

The cap off is safe. Since round 2 the breakpoint sits on the bridge, so a question's write is the turn's own tail plus a few tokens — client bytes, not a defect signal. A true rebuild reads low or zero, and the read rules refuse it. The original production incident (asks that re-created the prefix) is still caught: those asks read a partial prefix, below the last turn's read.

Earlier findings

  1. Mine, round 1 (cap refused every no-bridge question) — fixed in round 2, unchanged by this commit. The cap question is now closed by the owner's decision, and the fix that made the cap safe (bridge carrier, ask as fresh input) stays in the code.
  2. Reviewer 2, round 1 (apply side skipped quoted-marker outputs) — fixed in round 2, unchanged by this commit.
  3. Round-2 non-blocking items. Reviewer 2's assistant-last note (live replay not done) and replay-skip note (not counted) were left with no reply; both are fail-safe and rare, and I accept them. My two doc items below are still open.

Non-blocking

  • docs/components/advanced-offload.md:542 — the apply gate list still does not name sweep_apply_already_marked. Both reviewers raised this in round 2; the new commit does not address it and no comment explains why. One line.
  • PR body, "How it was tested" — the stale claims from round 2 remain: "(15 table rows)" and "a typed-prompt tail write of 300 passes" describe rows deleted in round 2 (13 remain). Text only.

What I checked

  • Last review: round 2, b9aeecb3ad321d4c2c977c33736cc613e44b9c54, 2026-10-26T01:12:14Z.
  • New commits read: 1 — ac89546d "fix(offload): ship the prefix-ask write cap off".
  • Read in full: 4 reviews, 1 comment, 0 inline comments (from the three saved files), plus the current PR body.
  • New items since my last review: reviewer 2's round-2 review (01:13, read in full; its fixes-verified claims checked against the code in round 2 and re-confirmed at this head), the new commit (reviewed above), and the PR body's cap-decision edits (verified against the code).
  • The full diff b9aeecb3..ac89546d and the final state of prefixask_gate.go, both gate test files, and the docs paragraph.
  • Confirmed prefixAskWriteCapEnabled has no reader outside the gate file and its tests, and that the docs gate list and read-rules paragraph match the shipped behavior.
  • No tests were run. Live tests are not approved and Go is not on this machine.

@amiddavid
amiddavid merged commit 56f59a7 into main Oct 26, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 26, 2026
amiddavid added a commit that referenced this pull request Oct 26, 2026
…ds the cache (#491)

- Rewrite model. The provider reads back only up to a cache entry an
  earlier request wrote before the change. A drop farther back than
  warmLookbackBlocks (20 content blocks) from the last breakpoint
  reaches only the fixed system prompt and tools, so the rewrite is the
  whole conversation. A drop inside the look-back rewrites only the
  tail from the drop. In 6,968 recorded Opus calls every large cache
  drop read back exactly the fixed size.
- Mass gate: ask only when the removable mass is at least
  warm_min_mass_frac (0.20) of the conversation. The trigger's expected
  turns are the warm turns run so far, capped. Every refusal at the
  trigger is counted by reason.
- The warm question is judged by prefixAskCacheOK against the turn's
  own read (#725), with no write check of its own.
- Each applied warm sweep records the tokens removed, the conversation
  before and after, the gate's numbers and the expected net, in /stats
  and as events on the dashboard row.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Oct 26, 2026
…ds the cache (#491)

- Rewrite model. The provider reads back only up to a cache entry an
  earlier request wrote before the change. A drop farther back than
  warmLookbackBlocks (20 content blocks) from the last breakpoint
  reaches only the fixed system prompt and tools, so the rewrite is the
  whole conversation. A drop inside the look-back rewrites only the
  tail from the drop. In 6,968 recorded Opus calls every large cache
  drop read back exactly the fixed size.
- Mass gate: ask only when the removable mass is at least
  warm_min_mass_frac (0.20) of the conversation. The trigger's expected
  turns are the warm turns run so far, capped. Every refusal at the
  trigger is counted by reason.
- The warm question is judged by prefixAskCacheOK against the turn's
  own read (#725), with no write check of its own.
- Each applied warm sweep records the tokens removed, the conversation
  before and after, the gate's numbers and the expected net, in /stats
  and as events on the dashboard row.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Oct 26, 2026
…ds the cache (#491)

- Rewrite model. The provider reads back only up to a cache entry an
  earlier request wrote before the change. A drop farther back than
  warmLookbackBlocks (20 content blocks) from the last breakpoint
  reaches only the fixed system prompt and tools, so the rewrite is the
  whole conversation. A drop inside the look-back rewrites only the
  tail from the drop. In 6,968 recorded Opus calls every large cache
  drop read back exactly the fixed size.
- Mass gate: ask only when the removable mass is at least
  warm_min_mass_frac (0.20) of the conversation. The trigger's expected
  turns are the warm turns run so far, capped. Every refusal at the
  trigger is counted by reason.
- The warm question is judged by prefixAskCacheOK against the turn's
  own read (#725), with no write check of its own.
- Each applied warm sweep records the tokens removed, the conversation
  before and after, the gate's numbers and the expected net, in /stats
  and as events on the dashboard row.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Oct 27, 2026
…ds the cache (#491)

- Rewrite model. The provider reads back only up to a cache entry an
  earlier request wrote before the change. A drop farther back than
  warmLookbackBlocks (20 content blocks) from the last breakpoint
  reaches only the fixed system prompt and tools, so the rewrite is the
  whole conversation. A drop inside the look-back rewrites only the
  tail from the drop. In 6,968 recorded Opus calls every large cache
  drop read back exactly the fixed size.
- Mass gate: ask only when the removable mass is at least
  warm_min_mass_frac (0.20) of the conversation. The trigger's expected
  turns are the warm turns run so far, capped. Every refusal at the
  trigger is counted by reason.
- The warm question is judged by prefixAskCacheOK against the turn's
  own read (#725), with no write check of its own.
- Each applied warm sweep records the tokens removed, the conversation
  before and after, the gate's numbers and the expected net, in /stats
  and as events on the dashboard row.

Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
amiddavid added a commit that referenced this pull request Oct 30, 2026
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 added a commit that referenced this pull request Oct 30, 2026
… (#777)

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

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]>
docs(offload): the prefix question keeps the turn's breakpoint (#776)

Refs #776

Assisted-By: Claude
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
docs(cheapmodel): say the breakpoint is copied, not moved (#776)

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]>
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.

Prefix questions (sweep, summary substitute) miss the cache: the breakpoint stays on Claude Code's trailing system message

1 participant