Repository navigation
feat(sweep): apply the held answer on the next cold request, and book what it earns (#404 PR C) - #695
Conversation
0d05be1 to
f2de57e
Compare
f2de57e to
efb3542
Compare
…dependence approval presets.md: xhigh and housellm now describe the sweep as it is: it asks at the keep-alive ping and removes content only on a cold request. The old max_calls and "adjudicates at depth on an expired cache" text is gone. data-dependence.md: Decided by records David Amid's approval of 2026-10-25 (#695). Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 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 | efb35429d60e |
approve |
Verdict: approve
I read the full diff (5179 lines, base a56d814f to head efb35429) and the code around every change. The cold apply is sound. I found no defect that breaks a repo invariant. I list four non-blocking defects and three notes below.
Findings
None. No defect I can prove breaks reversibility, fail-open, cache stability, or the money rules.
Non-blocking
-
A panic in the commit loop leaves drop records for restored messages.
applyHeldwritesputDrop, thecg:swx:marker ref, and the index only after every drop is in the request (extract_sweep_apply.go:678-688). But the writes happen one drop at a time. A store that panics mid-loop (the PR's ownputPanicStoreshape) leaves records for drops the deferred recover then restores (extract_sweep_apply.go:605-624). The failed request goes upstream in full form. The next request replays the dropped form (replayDrops,getDrophit). The two requests differ, so the provider rewrites the suffix once. Cost is bounded, and only a panicking store reaches it. Consider deleting the written records in the recover path, or writing them all after a single store round-trip. -
Two threads that drop identical content share one
cg:swx:mapping.
The marker id ishashKey(content), with no thread in it (extract_sweep_apply.go:100,marker.go:66). Thecg:swx:record holds one(Thread, CK)pair (extract_sweep_apply.go:682-683). When a second thread drops the same bytes, its write overwrites the first. A later expand of that marker creditsExpandedto the wrong thread's record (NoteSweepExpand,extract_sweep_apply.go:300). The thread that expanded keeps a false drop it earned, so its false-drop rate undercounts. The stash itself is content-addressed, so expansion still restores the right bytes. The defect is in the metric the PR ships to watch, not in behavior. Consider keyingcg:swx:by marker plus thread, or recording all owners per marker. -
scanReferencesandNoteSweepExpandrace on one drop record.
Both do read-modify-write on the same record with no lock (extract_sweep_apply.go:322,extract_sweep_apply.go:532). Two requests of one thread can lose aReferencedorExpandedflag. The false-drop count undercounts again. Fail-open direction is right: a lost flag never changes a request. -
The change point can come from a stale answer.
applyHeldreadshand computescpfrom its prints (extract_sweep_apply.go:567-585). ThenclaimHeldSpendmay hand back a newer answer (extract_sweep_apply.go:593-597). Thenow/latersplit atextract_sweep_apply.go:631-641uses the stalecpagainst the newer answer's outputs. A drop before the true change point can be applied early. The recheck still validates each output, and this path only runs when the prefix already changed, so the suffix is rewritten anyway. Narrow window, bounded cost.
Notes (no action needed):
extract_sweep.go:1111namesselectAffordableDrops, which this PR deletes. Stale comment.coldApplyCacheindash/sweepattr.goruns one query per cold row, and its "next warm" test (cache_read > 0) can match a later cold-apply row. Measurement imprecision on the dashboard only.- Shadow mode returns before
replayDrops(extract_sweep.go). A deployment that turns shadow on with existing drop records stops replaying them. New deployments, the stated use, are unaffected.
What I checked
- The whole diff, file by file, including every test file, doc, and the deleted code (sweep econ pricing,
BuildFallbackAsk/ClipSample,SweepReasonNeedsShadow). - H1 (warm and unchanged never changes):
applyHeldreturns before the claim whensweepColdRequestis false andchangePointfinds no difference (extract_sweep_apply.go:578-585). - Byte-stable replay:
replayDropsmatches onextract.ContentKeyand replays throughcommitRefresh, which never refuses (extract_sweep_drop.go,marker.go:155-175). The C1 and replay tests assert byte identity. - Print coordinates: the ping records
cand.rawfromc.RawInput;applyHeldandrecheckHeldreadc.RawInputtoo.apply.Bodyalways setsRawInput(apply/apply.go, normalized pre-pipeline copy). The two sides count the same messages. - Fail open: a store that cannot stash refuses the drop (
commitMark,marker.go:124-127); a panic in apply restores every touched message, writes no record, is counted, and hands the answer back once (maxApplyAttempts = 2, matches the test). - Claim-first concurrency:
claimHeldSpendunderheldMuwith a tombstone;putHeldLockedrefuses strictly-older writes, so the panic give-back (sameAskedAtMs) and the trimmed re-hold both land. Tests cover theslowStorerace. - Change point:
msgPrintfingerprints role, tool ids, argument length, text length, and first/last 48 chars. Growth after the judged point is not change (test covers it). A missed change fails safe: the answer stays held. - Reversibility and metadata: drop records hold ids, hashes, counts, and flags only. The stash is the only customer data, same as every other Offload.
docs/data-dependence.mdhas the row and the approval. - Store namespaces:
cg:swd:andcg:swx:are pinned (store/store.go:258);\x01and\x02separators keep index and record keys apart. - Money: answer cost is booked once on the ping row in
sweep_answer_usdand is part ofCostUSD, never subtracted again (ApplySweepLedgerToRowsubtracts onlyExpandChargeUSD); credit at write rate on the cold request, request rate later; expand charge at write rate. The M1/M2 tests cover the arithmetic. - Preset and gates: xhigh adds
extract_llm_sweepwithmin_tokens: 1000, no shadow; the sweep'sgateExemptentry is gone andcommitgate_test.gonow drives a real ping-to-cold-apply through the gate;decisionPrefixescovers the new markers. - Keeper C5: the substitute ping carries the forwarded dropped body, so the ask sees the conversation the model sent.
- Host wiring:
proxy.gocallsNoteSweepExpandon the response path and on expand-error repair;SweepMarkerIDis the samehashKeythe apply wrote.
amiddavid
left a comment
There was a problem hiding this comment.
| 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 | efb35429d60e | approve |
Review of PR #695 — cold apply for extract_llm_sweep
Verdict: approve.
Findings
None blocking. I traced every changed file and the code around each change. I checked the fail-open paths, the store keys, the concurrency, and the ledger arithmetic. The defects I suspected and then disproved are listed under "What I checked".
Non-blocking
-
The commit-window panic claim does not hold in one window.
applyHeldsays a panic "restores every message it touched, writes no record" (extract_sweep_apply.go:599, and the C4 test asserts it). A panic between the start of the commit loop (line 678) andpending = nil(line 721) breaks that claim. In that window theputDroprecords, thecg:swx:marker refs, the drop index, and the trimputHeldare already written, but the deferred recover still restores the messages. Consequences are observability only: the ledgerAppliedcounts and thesweep_applied_coldevents describe drops the request did not carry. The records themselves stay consistent — stash, marker ref, and drop record all exist — so the next request replays them correctly and the request itself is forwarded unchanged. No shipped store can panic inPut(store.Memory,store.Nop). TestC4 arms its panic store atafter = 3, inside the apply loop, so the window is untested. Fix: tombstone the just-written records in the panic path (aputDropwithV != dropVersionreads as absent), or arm the panic inside the commit loop and narrow the comment. -
Field-name typo in dash/sweepattr.go.
AppliedChangedPrefx(lines 49, 128, 138). The JSON tag is correct, so the API is fine. Rename the field. -
N+1 queries in
coldApplyCache(dash/sweepattr.go:264). One extra query per cold-apply request, to find the next warm request of the thread. Bounded by the filter. Fine at current scale. -
Stale hint at extract_sweep.go:1111. The
min_tokenshint namesselectAffordableDrops. This PR deletes that function (prefix_econ.go). Update the hint. -
maxDropsPerThread= 512 index trim. Drops past the cap stop replaying. This is deliberate and commented. Note it as a limit to watch when reading long threads.
What I checked
- The full diff
a56d814f..HEAD, file by file, plus the code around each change:extract_sweep_apply.go(all 736 lines),extract_sweep.go,extract_sweep_hold.go,extract_sweep_ping.go,extract_sweep_recheck.go,extract_sweep_drop.go,extract_sweep_testing.go, the new tests,prefix_econ.goand its guard tests,internal/coref,internal/extract/adjudicate.go,keepalive/keeper.goandsubstitute.go,store/store.go,config,dash/sweepattr.goand its test, the dash wiring (api.go,event.go,query.go,schema.go,store.go,ui/app.js), the proxy call sites (dashcapture.go,proxy.go,modes.go),components/pipeline.go,apply/apply.go,cmd/context-guru-proxy/main.go, the docs, andinsights.py. - Fail open and reversibility. A panic in the apply restores every pending message; the pipeline's per-component recover backs that.
applySweepDropgoes throughcommitMark, which refuses a drop the store cannot back. Degraded marker modes setrep.Irreversible, so the pipeline's "dropped content without stashing" revert cannot fire (marker.go:132). - Cold and changed-prefix gating.
sweepColdRequestuses the same cache-phase signal as the summary reserve. A warm unchanged request returns before the claim (H1).changePointcomparesmsgPrintfingerprints of the held answer's prints againstc.RawInputwhen set, andbuildHeldstashes the same raw form, so the two sides match. - Concurrency.
putHeldis serialized byheldMuwith a staleness refusal.claimHeldSpendtombstones the answer, so two cold requests of one thread cannot both apply. The apply retry is bounded bymaxApplyAttempts. - Disproved defect hypotheses, each with evidence:
- A bypassed request applying drops:
Pipeline.Runreturns before any component whenc.Bypass(pipeline.go:78). - Observe mode applying drops:
applyModenever runs the enforced pipeline inModeObserve(modes.go:41). - Migration loss from the removed
cg:res:replay: the base sweep wrote nocg:res:and applied nothing in-request, so nothing is lost. - First-request / Unknown-phase apply: same documented
ColdApplyPhasethe summary reserve already trusts, plus an extra narrowing. scanReferences/addToDropIndexraces: bounded to lostSeenupdates; the index rewrite needs two claim wins on one thread, which cannot happen.- Summarizer interaction: the summarizer also graduates only on cold, so a summary cannot sit above a changed-prefix split.
- Callers of the deleted
BuildFallbackAsk/ClipSample: none remain (grep overcomponents/andinternal/).
- A bypassed request applying drops:
- Ledger and pricing.
SweepAnswerUSD= output + fresh input + cache write, never the read, booked once on the ping row.FalseDrops = Referenced + Expanded − Overlap.ApplySweepLedgerToRowsubtracts the expand charge from saved and net columns. The xhigh preset placesextract_llm_sweepafterextract_llmwith no shadow phase, and the false-drop signals are wired so that is watchable. - Data dependence.
sweepDropRecis metadata only (ids, hashes, counts). The docs rows are updated and record the approval. The new store prefixes are pinned.
Live tests were not run: they were not approved for this review, and Go is not installed on this laptop. This review is a code read only.
efb3542 to
b72ffa2
Compare
…dependence approval presets.md: xhigh and housellm now describe the sweep as it is: it asks at the keep-alive ping and removes content only on a cold request. The old max_calls and "adjudicates at depth on an expired cache" text is gone. data-dependence.md: Decided by records David Amid's approval of 2026-10-25 (#695). Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
|
Round 1 points, all answered. Fixed in Reviewer 1
Reviewer 2
|
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 8df3280126ea |
approve |
Round 2 — review of everything new since round 1
Verdict: approve.
Findings
None. I read the one new PR commit in full and verified every fix it claims. I found no defect that breaks fail-open, reversibility, cache stability, or the money rules.
Earlier findings, checked one by one
Reviewer 1
- Panic in the commit loop leaves records — fixed. Every record and marker owner the attempt writes is tracked in
committed. The recover tombstones all of them and removes the marker owners, underdropMu.Appliedandsweep_applied_*are counted after the commit and the held trim. Tests arm the panic inside the commit loop and at the held trim. I traced both windows; the claim in the comment now holds. - Shared
cg:swx:marker between threads — fixed. A marker ref now lists every owner(thread, ck).NoteSweepExpandcredits only the thread that expanded, and only an owner. With no thread known, every owner is credited. The new test covers A, B, and a foreign thread C. scanReferences/NoteSweepExpandrace — fixed.dropMuserialises the read-modify-write. The scan writes its flags from a fresh read under the lock. The slow-store test drives the race.- Stale change point — fixed. The change point is computed from the answer
claimHeldSpendreturns. If that answer shows no change, it is given back unspent. The swap-store test drives a newer answer landing between the read and the claim.
- Note,
selectAffordableDropshint — fixed. The sentence is gone. - Note, shadow stops replaying — fixed. Shadow now replays existing drops and stops only new applies. The replay call mirrors
coldStepexactly: same guard, same thread key, same value. - Note,
coldApplyCacheN+1 — left, with reason. Dashboard-only, bounded by the filter. The imprecision is now documented at the query. I accept the reason.
Reviewer 2 (me)
- Commit-window panic claim — fixed by the same change as R1-1. Verified above.
AppliedChangedPrefxtypo — fixed. Renamed indash/sweepattr.goandkeepalive/keeper.go. The JSON tags are unchanged.- N+1 in
coldApplyCache— left, same reason as R1's note. Accepted. - Stale hint — fixed, same change as R1's note.
maxDropsPerThread= 512 — left. Deliberate and commented. Accepted.
Non-blocking
metrics.RecordExtractionSavingandRecordExtractionValuestill fire inside the apply loop (extract_sweep_apply.go:771-774), before the commit. The fix moved the events and the ledger to after the commit, but not these two metrics. A panic in the commit, the trim, or the counting leaves extraction-saving metrics counted for a request that was restored. Same window the fix just closed, metrics only. Pre-existing at round 1.- A panic at the held trim gives back the already-trimmed answer. The trim mutates
hin memory (Outputs = later) beforeputHeld(extract_sweep_apply.go:808-814). A panic at or after thatputHeldmakes the recover write the give-back from the trimmedh. The after-change-point outputs that were applied and then restored are no longer in the held answer, so they are never re-applied. Lost savings only, panic path only, and no shipped store can panic there. The trim-panic test does not assert the held answer's shape. - An expand with no thread known counts once per owner in the overall ledger.
NoteSweepExpandwiththreadKey == ""(the request-path repair) callsledgerNoteonce per owner, andledgerNotealso bumps the OVERALL entry (extract_sweep_apply.go:303). One expand of a marker shared by two threads adds 2 toOverall.ExpandEventsand doublesExpandTokens. Per-thread credit is the documented and correct choice; the overall aggregation is the imprecise part. Rare path, rare shape, /stats only.
What I checked
- Last review: round 1,
efb35429d60ebaace8b0a5485e685b47e8183b38, 2026-10-25T14:54:51Z. - New commits read: 6, from
git log --stat efb35429..HEAD:8df32801fix(sweep): round 1 review fixes — the only new PR commit. Full diff read (841 lines), plus the code around every change.b72ffa24,9d5828fb,479dd25a— the round-1 PR commits rebased. I diffedefb35429againstb72ffa24: only the new base's files differ (#698 plugin, #699 script). The PR's own content is unchanged by the rebase.0a22b9ca(#698),aa116d0a(#699) — main commits the rebase picked up. Plugin and review-script files only. No interaction with the sweep.
- 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, and what I did:
- Reviewer 1's round-1 review (14:46). Read now for the first time, as round 2 requires. Its four findings and three notes are checked above; none overlap a finding I missed.
- The author's comment (16:50). Every claim in it checked against the code: all "fixed" claims verified, both "left" items verified as deliberate.
- Commit
8df32801. Reviewed as a first review:- The tombstone path.
committedis appended before eachputDrop, the commit holdsdropMuwith a deferred unlock, and the recover re-takesdropMuto tombstone and remove marker owners. A panic on the first record tombstones a record that never landed — it reads as absent, so that is harmless.removeMarkerOwnerfilters only this attempt's(thread, ck), so another thread's owner survives. Lock order is safe:dropMuandheldMuare never held together. - The index.
addToDropIndexruns after the commit and is not undone on panic. Entries that point at tombstoned records are inert, becausegetDropreads a wrong-version record as absent. A retry re-adds the same keys, deduplicated. - The change-point re-order. The pre-claim check on the read answer is now only the H1 gate. The split uses the claimed answer. A newer answer that shows no change is given back unspent;
putHeldallows the write because the claim wrote the sameAskedAtMs. - Shadow replay. The shadow branch calls
replayDropswith the same arguments ascoldStep, thenshadowStep.changedfeeds the deferred Skipped guard, andkeyskeeps the pipeline's stash-key contract. - The marker-ref shape change (
{t, ck}→{o: [...]}). No old-format records can exist in production: the cold apply ships only with this PR. All writers and readers use the new shape; no test writes the old JSON directly. - Call sites and helpers.
NoteSweepExpandhas exactly two non-test callers, both updated (proxy.go:1589passes""before the thread is resolved,proxy.go:2031passesthread.Key(session, threadID);servehas both in scope). The dash test seeds the drop on the thread the proxy derives, viaapply.SessionIDFor. All new test helpers exist. - The renames.
AppliedChangedPrefixindash/sweepattr.goandkeepalive/keeper.go; JSON tags unchanged.
- The tombstone path.
- Live tests were not run: not approved, and Go is not on this laptop. This round is a code read only.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 8df3280126ea |
blocking |
Verdict: blocking
The author fixed all seven of my round-1 items, and the fixes are right. But the dropMu fix introduces one new defect: a store panic inside scanReferences' locked window leaves the mutex held forever. That is a broken fail-open path, so I block on it. The fix is one line.
Findings
components/offload/extract_sweep_apply.go:601-614— a panic in the locked window ofscanReferencesdeadlocks the process.- What fails:
scanReferenceslocksdropMuat line 601 and unlocks at line 614 in straight-line code, not deferred. The function's own recover at line 571 swallows any panic. A store whoseGetorPutpanics inside the window (lines 602-612) skips the unlock, the recover eats the panic, and the request completes normally — withdropMuheld forever. Every later caller blocks:scanReferenceson any request of a thread with a drop index,NoteSweepExpandon every expand response (proxy/proxy.go:2031), every apply commit, every tombstone. The proxy wedges; requests hang. - Proof: the lock/unlock pair is the only non-deferred one in production code (
grep dropMu.Lock|dropMu.Unlock: lines 374-375, 708-709, 787-788 all defer; 601/614 does not). The three deferred sites are also ordered correctly — the unlock runs before the swallowing recover. Line 571's recover is registered at function scope, before the lock, so a panic at 612 reaches it with the mutex held. A panicking store is in this PR's own threat model:getPanicStore,putPanicStoreandcommitPanicStoreexist in the tests, andapplyHeld's whole panic machinery exists for them. No test arms a panic insidescanReferences, so the tests pass while the defect stands. The fail-open rule in CLAUDE.md says a panic reverts that component only; here it reverts nothing and takes the process. - Fix: scope the locked window in a closure with
defer dropMu.Unlock(), as the commit closure at line 787 already does. Add a test that arms a panic store inside the scan and asserts a laterNoteSweepExpandstill completes.
- What fails:
Non-blocking
components/offload/extract_sweep_apply_test.go:491— the comment says "putCountStore panics on the Nth Put", but the type below it iscommitPanicStore. Stale name in a comment.
Earlier findings, round 1
Mine, all against head efb35429:
- Panic in the commit loop leaves records — fixed.
committedtracks every record and marker owner the attempt writes; the recover tombstones them all (extract_sweep_apply.go:697-716).Appliedandsweep_applied_*are counted last, after the commit and the held trim (extract_sweep_apply.go:816-832). Tests:TestAPanicInsideTheCommitLoopLeavesNoRecordAndNoCount(panic armed inside the loop, next request replays nothing),TestAPanicAfterTheCommitStillCountsNothing(panic at the held trim). Both drive the realOffloadpath. Verified. - Shared
cg:swx:marker mis-credits an expand — fixed.sweepMarkerRefnow lists every owner (extract_sweep_apply.go:171-181);NoteSweepExpandtakes the expanding thread and credits only that thread, or every owner when the host does not know the thread (extract_sweep_apply.go:369-410). I checked the proxy passes the same key the records use:servegetstr.Session/threadIDfromapplyMode, which returns the sameapplyresolution the pipelineCtxis built from (proxy/proxy.go:1427,apply/responses.go:567).TestAnExpandOfASharedMarkerCreditsOnlyTheThreadThatExpandedcovers both directions. Verified. scanReferences/NoteSweepExpandrace — fixed in effect (dropMu, fresh read under the lock,extract_sweep_apply.go:598-614), andTestAReferenceAndAnExpandOnOneDropBothLandkills the unlocked variant. But the fix introduces finding 1 above.- Stale change point — fixed.
cpnow comes from the answer the claim returns; no change point means the answer is given back unspent (extract_sweep_apply.go:676-689). I checked the give-back:claimHeldSpendreturns the pre-tombstone answer, soSpentis false, andputHeldrefuses the write only when a newer answer landed — the right outcomes on both paths.TestTheChangePointComesFromTheClaimedAnswerswaps in a newer answer between the read and the claim. Verified. - Notes: the
selectAffordableDropshint is removed; shadow mode now replays existing drops beforeshadowStep(extract_sweep.go:486-498), withTestShadowModeKeepsReplayingExistingDrops; thecoldApplyCacheimprecision is left and now documented in the code (dash/sweepattr.go:261-264). I agree with leaving it.
Reviewer 2's, same head:
- Commit-window claim — same fix as my item 1, and the panic is now armed inside the commit loop. Fixed.
AppliedChangedPrefx— renamed indash/sweepattr.goandkeepalive/keeper.go. The JSON tags are unchanged, so no consumer breaks. Fixed.- N+1 in
coldApplyCache— left, documented. Agree with reviewer 2 and the author. - Stale hint — fixed, as my note.
maxDropsPerThread= 512 — left; it is deliberate and commented. Agree.
The author's reply (2026-10-25T16:50:08Z) matches what the code does on every point.
What I checked
- Last review: round 1,
efb35429d60ebaace8b0a5485e685b47e8183b38, 2026-10-25T14:46:09Z - New commits read: 1 new PR commit —
8df32801"fix(sweep): round 1 review fixes for the false-drop signal and the commit window". The log also listsb72ffa24,9d5828fb,479dd25a: these are rebase copies of commits I reviewed in round 1 (the PR was rebased onto base0a22b9ca), and I verified the rebase changed no PR file (git diff efb35429 b72ffa24touches onlydocs/plugin/statusline.md, which comes from #698 in the new base).0a22b9ca(#698) andaa116d0a(#699) are the new main base, outside the PR diff. - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt; the inline list is empty). - New items since my last review: reviewer 2's round-1 review (14:54:51Z, read in full, its five items tracked above); the author's reply (16:50:08Z, every claim checked against the code); commit
8df32801(full 841-line diff plus the code around each change). - The fix commit, line by line: the owner list and its add/remove;
NoteSweepExpand's thread filter andnote.Firsthandling;dropMuat every site and the lock order againstheldMu(no path holds one and takes the other); the tombstone path (V = -1reads as absent throughgetDrop, dead index entries are pruned by the 512 cap); the counting move to last; the panic give-back (Spent = Attempts >= maxApplyAttempts, sameAskedAtMspassesputHeld); the shadow replay branch (replays feed the deferredSkippedguard, so a replay-only shadow request is not marked skipped). - Old-format
cg:swx:records (single owner,{"t":…,"ck":…}) read as zero owners under the new struct. The feature ships whole in this PR, so no production record has the old shape. Not a defect. - Live tests were not run: not approved, and Go is not installed on this laptop. Code read only.
|
Round 2 points, all answered. Fixed in Blocking (reviewer 1): Reviewer 2
|
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 3 of 3 | c0139bf1ace4 |
approve |
Verdict: approve
The new commit fixes my round-2 blocker correctly, and closes the three gaps reviewer 2 raised in round 2 plus my comment nit. I found no new defect. The PR is ready from my side.
Findings
None.
Non-blocking
None new.
Earlier findings
- My round-2 blocker (a panic in
scanReferences' locked window wedgesdropMu) — fixed. The locked part is now a closure withdefer dropMu.Unlock()and an earlyreturnon a missed record (extract_sweep_apply.go:637-656). A panic ingetDroporputDropruns the deferred unlock before the function-level recover swallows it.TestAPanicInTheScansLockedWindowDoesNotWedgeDropMuarms a panic on every sweep-dropPutinside the window, proves the panic fired, then runs a laterNoteSweepExpandand a later scan under a 3-second timeout — a regression fails the test instead of hanging the suite. This is the fix I proposed. - The author's lock audit — verified independently. I listed every
Lock/Unlockpair in the sweep package. Every remaining straight-line pair guards only operations that cannot panic:resetSweepLedgerForTest(extract_sweep_apply.go:363-366, test-only map assignments), the ping counters and registries (extract_sweep_ping.go:166-194, 325-337, 362-364, map copies, deletes and one map read), and the retired-key counter (extract_sweep.go:252-254, a map increment after aslog.Warn).SweepPingSubstituteunlocks before its recover-protected work starts. AlldropMu,heldMuand ledger sites defer. - Reviewer 2's round-2 notes — fixed in
c0139bf1, verified:- Metrics before the commit — the extraction-saving and value metrics now fire after the commit, the trim and the counting, from
p.rec.Tokens(extract_sweep_apply.go:871-877);TestAPanicAfterTheCommitStillCountsNothingasserts the saved-token metric did not move for a restored request. - Trim panic gave back the trimmed answer — the give-back now uses
whole, a copy ofhtaken before the recheck (extract_sweep_apply.go:739, 765). The trim only assigns new slices toh, sowholekeeps the full answer. The test asserts the given-back answer has all four outputs, judged 5, one attempt. Attempts still accumulate across retries: the second attempt readsAttempts=1from the store, so the give-back spends it. - Shared-marker expand counted once per owner in the overall total —
NoteSweepExpandnow books each owner's row withledgerNoteThreadand the overall once withledgerNoteOverall(extract_sweep_apply.go:392-437).TestASharedMarkerExpandCountsOnceInTheTotalchecks the total and both rows. The split is coherent:ExpandEventscounts calls,Expandedcounts drops, and the false-drop rate is drop-denominated. - The
putCountStorecomment — fixed to namecommitPanicStore.
- Metrics before the commit — the extraction-saving and value metrics now fire after the commit, the trim and the counting, from
- My round-1 items and notes, and reviewer 2's round-1 items, were all resolved in
8df32801and verified in round 2. The two items the author left (coldApplyCacheN+1 and imprecision,maxDropsPerThread= 512) are deliberate, documented, and I agreed with leaving them.
The author's reply (2026-10-25T17:35:22Z) matches what the code does on every point.
What I checked
- Last review: round 2,
8df3280126ea2226e89f61b8052ae43229c17200, 2026-10-25T16:56:09Z - New commits read: 1 —
c0139bf1"fix(sweep): release dropMu when the reference scan panics, and close the panic paths". Full 290-line diff read, plus the code around each change. - Read in full: 4 reviews, 2 comments, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt; the inline list is empty). - New items since my last review, and what I did:
- Reviewer 2's round-2 review (16:55:43Z, approve with three non-blocking notes). Read in full; each note checked against the fix commit above. I agree with its findings and its verdict on
8df32801; the notes are now fixed. - The author's round-2 reply (17:35:22Z). Every claim checked against the code, including the lock audit, which I re-ran myself.
- Commit
c0139bf1. Reviewed as a first review: the closure shape and its early return; the ledger split (ledgerNotekeeps booking both, soscanReferencesand the apply paths are unchanged); the lock order (dropMuheld while taking the ledger mutex only, never the reverse); thewholecopy and slice-assignment reasoning; the metrics move and its test; the wedge test's panic arming, disarm and timeout;SeedSweepDropForTest's closure; the existence ofextractGrossSaved(components/offload/commitgate_freshpath_test.go:133, same package).
- Reviewer 2's round-2 review (16:55:43Z, approve with three non-blocking notes). Read in full; each note checked against the fix commit above. I agree with its findings and its verdict on
- Live tests were not run: not approved, and Go is not installed on this laptop. Code read only.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 3 of 3 | c0139bf1ace4 |
approve |
Round 3 — review of everything new since round 2
Verdict: approve.
Findings
None. The one new commit fixes reviewer 1's round-2 blocking finding and my three round-2 notes. I traced each fix in the code. I found no defect that breaks fail-open, reversibility, cache stability, or the money rules.
Round-2 items, checked one by one
Reviewer 1, round 2, finding 1 — a panic in scanReferences' locked window wedges dropMu. Agree with the finding; I checked it myself. It was real, and I missed it in round 2: the round-2 code locked dropMu in straight-line code inside a function whose top-level recover swallows any panic, so a store panic between Lock and Unlock left the mutex held for the life of the process. Every later scan, expand note, and commit would block. Fixed. The locked window is now a closure with defer dropMu.Unlock() (extract_sweep_apply.go:637-656). I grepped every production dropMu site: all four (lines 392, 641, 751, 825) now defer the unlock. The new test arms a panicking store inside the window, then runs a later NoteSweepExpand and scan under a 3-second timeout, so a regression fails instead of hanging.
Reviewer 2 (me), round 2
- Extraction-saving metrics booked before the commit — fixed.
RecordExtractionSavingandRecordExtractionValuenow run after the commit, the held trim, and the ledger, fromp.rec.Tokens(extract_sweep_apply.go:871-877).agentRatesmoved with them; the apply loop no longer needs it. The trim-panic test now asserts the saved-token metric did not move. - Trim panic gave back the trimmed answer — fixed. The give-back uses
whole, a copy of the claimed answer taken before the trim (extract_sweep_apply.go:739, 765). I checked for slice aliasing: the trim rebindsh.Outputsandh.Printsto new slices and never writes into the shared backing arrays, andrecheckHeldtakeshby value and only reads it, sowholestays the full answer. The test asserts the shape: 4 outputs, judged 5, 1 attempt. - Shared-marker expand counted once per owner in the total — fixed.
NoteSweepExpandbooks each owner's thread row throughledgerNoteThread, and the overall entry once per expand call throughledgerNoteOverall(extract_sweep_apply.go:424-437).Expandedin the total still counts per owner, which keeps it comparable withApplied(also per drop and thread). The test pins both: 1 event and 700 tokens in the total, 2 owner rows.
Reviewer 1, round 2, non-blocking — the stale putCountStore comment — fixed (extract_sweep_apply_test.go:892).
The author's reply (17:35:22Z) matches what the code does on every point.
Non-blocking
- A scan-path panic can book
Referencedwithout the flag landing. In the scan's locked window,ledgerNoteandrep.Event(eventFalseRef)run beforeputDrop(extract_sweep_apply.go:650-655). If the store panics on thatputDrop, the recover swallows it and the ledger counts a reference the record on disk does not carry. Panic path only, one counter, /stats only. The same shape was deliberate everywhere else (count last); here the flag write is the last step for a reason the lock already covers.
What I checked
- Last review: round 2,
8df3280126ea2226e89f61b8052ae43229c17200, 2026-10-25T16:55:43Z. - New commits read: 1 —
c0139bf1"fix(sweep): release dropMu when the reference scan panics, and close the panic paths". Full diff read (290 lines), plus the code around every change. - Read in full: 3 reviews, 2 comments, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review, and what I did:
- Reviewer 1's round-2 review (16:56:09Z, blocking). Read in full. Its finding is checked above; I verified the defect existed in
8df32801and that the fix closes it. Its round-1 verification notes match what I found in round 2. - The author's comment (17:35:22Z). Every claim checked against the code: all fixed, including the note that the other locks in the PR were audited — I repeated that audit myself (
dropMufour sites, all deferred;heldMusites in extract_sweep_hold.go guard put/copy code whose panics are caught by inner recovers). - Commit
c0139bf1. Reviewed as a first review:- The scan closure. The locked window reads fresh, merges
Seenas a maximum, setsReferencedonce, and writes under the lock. The deferred unlock survives a panic from the store or the ledger; the function-level recover still swallows it, so the request completes. - The ledger split.
ledgerNotenow delegates toledgerThreadLockedunder the same mutex;ledgerNoteThreadandledgerNoteOverallare the per-row and total-only forms. All three take onlysweepLedger.mu. WheredropMuandsweepLedger.munest (NoteSweepExpand, the scan, the commit), the order is alwaysdropMuoutside, ledger inside — one order, no inversion. - The give-back.
wholeis captured after the claim and beforerecheckHeld; nothing between the capture and the trim mutates the answer's slices in place. A panic after the trim'sputHeldlanded is also healed: the give-back overwrites the trimmed answer with the whole one, andputHeldallows the write at the sameAskedAtMs. - The metrics move. The booking loop reads
p.rec.Tokens, the samesavedvalue the old in-loop code used, and sits after the ledger block and beforepending, committed = nil, nil. A panic anywhere earlier now books nothing. - Tests.
extractGrossSavedexists (commitgate_freshpath_test.go:133, same package).scanPanicStore,TestASharedMarkerExpandCountsOnceInTheTotal, and the extended trim-panic test all use helpers that exist.SeedSweepDropForTestalso gained the deferred-unlock form.
- The scan closure. The locked window reads fresh, merges
- Reviewer 1's round-2 review (16:56:09Z, blocking). Read in full. Its finding is checked above; I verified the defect existed in
- Live tests were not run: not approved, and Go is not on this laptop. This round is a code read only.
c0139bf to
2bf591a
Compare
…dependence approval presets.md: xhigh and housellm now describe the sweep as it is: it asks at the keep-alive ping and removes content only on a cold request. The old max_calls and "adjudicates at depth on an expired cache" text is gone. data-dependence.md: Decided by records David Amid's approval of 2026-10-25 (#695). Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
… what it earns The sweep asked at the keep-alive ping and held the answer, and nothing used it. This change applies it. The sweep now saves money. - Cold apply (point 3): on the next cold request of a thread, rechecks the held answer and replaces each valid output with a shape descriptor and a <<cg:HASH>> marker. The original is stashed, so expand returns it byte for byte. Each drop writes a record (cg:swd:), and every later request of the thread replays the same bytes. A warm request with an unchanged conversation never changes (H1). - Changed prefix (point 4): a rewind, an edited turn or a fork applies only the held drops after the first changed message. The ones before it stay held. Counted apart as sweep_applied_changed_prefix. - Fail open: a store that cannot hold an original refuses that drop. A panic in the apply restores every message it touched, writes no record, and forwards the request unchanged. - Dashboard (point 9): the answer cost is booked once, on the ping row the question replaced, in its own column (sweep_answer_usd). The expands of sweep markers come off the sweep's credit at the write rate. - Quality signals (point 7): an expand of a sweep marker is charged to the sweep, and a later turn that uses something a dropped output introduced counts as a false drop. False-drop rate per thread and overall, in the Components tab and in /stats (keepalive.sweep_drops). Ids, hashes and counts only. - The ping carries the forwarded body after a cold apply (point 15), by test. - The shadow-only ask gate is gone. shadow stays a setting and applies nothing. - xhigh runs the sweep again. The other presets are unchanged. - From the #508 notes: registerPing no longer keeps a conversation copy for a thread with no candidate and prunes on every registration (D); the sweep reads its own cg:swd: record, not cg:res: (F); BuildFallbackAsk and the sweep-only pricing in prefix_econ.go are removed (coref keeps what it uses). Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
…anicked apply once - putHeld takes heldMu and never overwrites a newer AskedAtMs, so a claim that read an old answer cannot overwrite a new one, and two asks of one thread cannot land out of order. - The cold apply claims the held answer first. A panic in the apply or the recheck restores every message, is counted (sweep_apply_panic), and hands the answer back once. A second panic leaves it spent. - The ask-level slot refusal counts as sweep_concurrency_full, not sweep_ask_failed. - The cold test now uses the summary reserve's ColdApplyPhase. - The sweep row carries the net saving and the cold-apply cache numbers for L1 and C2. - docs/data-dependence.md: the sweep row now says it stashes originals for expand. PENDING. Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
…dependence approval presets.md: xhigh and housellm now describe the sweep as it is: it asks at the keep-alive ping and removes content only on a cold request. The old max_calls and "adjudicates at depth on an expired cache" text is gone. data-dependence.md: Decided by records David Amid's approval of 2026-10-25 (#695). Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
…mmit window - A marker shared by two threads lists every owner. An expand credits the thread that made it, and only a thread that carries the marker. With no thread known (the request-path repair), every owner is credited. - The reference scan, the expand note and the commit take dropMu, so a flag is not lost. - The commit is atomic in effect. A panic after the first record tombstones every record and marker owner this attempt wrote. Applied and sweep_applied_* are counted last. - The change point is computed from the answer the claim returns. - Shadow mode keeps replaying drops that already exist. It only stops new applies. - Rename AppliedChangedPrefx; fix the stale selectAffordableDrops hint; document the next-warm imprecision. Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
…the panic paths - scanReferences held dropMu with a plain Unlock inside a function that recovers panics. A panic in the Store or the ledger left the lock held for good, and every later scan, expand note and commit blocked. The locked part is now a closure with a deferred unlock. - The extraction savings metrics are booked after the commit, with the events and ledger. - A panic at the held trim gives back the untrimmed answer, so the drops after the change point are not lost. - An expand of a marker with no thread known counts once in the total. Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
- A ping the sweep's question replaced uses no output-budget step (#712), so the next plain pings differ. - A failed question is not a transport failure of a ping: it does not set #710's retry flag, the ordinary ping goes out in its place, and a question that billed asks once per idle period. - A held answer and its drop records stay on their own thread key, so a thread that moves to another id (#711 prevents it for a resume) does not carry them. Tests only. Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
2bf591a to
7c3a05f
Compare
Summary
This is PR C of #404. The sweep now saves money.
<<cg:HASH>>marker.expandgives back the original, byte for byte.xhighruns the sweep again. Other presets are unchanged.Base:
main. Rebased onto main 344db7f (with #508, #688, #694, #697, #698, #705, #710, #711, #712, #714, #717). Commits: the cold apply, the review fixes, the docs, the round 1 fixes, and the round 2 fixes.What changed
extract_sweep_apply.go. The apply runsrecheckHeld, then replaces each valid output with a shape descriptor plus a marker, and stashes the original. Each drop writes a record (cg:swd:). Every later request of the thread replays the same bytes, so the prefix the cold request wrote stays byte-stable.sweep_applied_changed_prefix.sweep_answer_usd. It is the output plus the question's fresh input. It is not the cache read the ping pays anyway.sweep_expands,sweep_expand_tokens. The expand charge (write rate) comes off the sweep's credit and net. The totals still carry every expand, soSavedAdjustedis unchanged.sweep_false_ref./statsunderkeepalive.sweep_dropsand on the Components tab beside the sweep row. Threads show under a hash label, never a session id.shadowstays a setting. With it on, nothing is applied, even on a cold request.xhigh(point 6).extract_llm_sweepis back in the pipeline. Noshadowin the preset.registerPingkeeps no conversation copy for a thread with no output at the floor. It prunes old copies on every registration, not only at the cap.cg:swd:record. Onlyextract_llmwritescg:res:. The sweep no longer replays or hides candidates from it.BuildFallbackAsk,ClipSample,AdjudicationItem.Sample, and the sweep-only pricing inprefix_econ.go(prefixRewriteNet,rewritePricing, the ask/approval/premium terms). Coref keeps what it uses.How it was tested
Eval box 1,
-count=1.go vet ./...clean.gofmtclean.go testpasses on 40 packages (plugin package: preset tests pass).-racepasses on offload, keepalive, proxy, config, components/all. One flake, not mine: under-race,dash'sTestTheInsightsDocumentIsScopedToOneProjecthits the 10 s handler timeout in the full-package run. It passes alone, and on pristine main it passed once and failed once in the same full-package-racerun. It is not related to this PR.Acceptance tests (#404) for PR C
TestC1TheNextColdRequestAppliesTheValidDropsAndExpandGivesThemBack(each marker resolves to the original, byte for byte),TestAColdAppliedDropIsReplayedByteIdenticallyOnLaterRequestsTestC3AChangedPrefixRequestAppliesOnlyTheDropsAfterTheChangePoint,TestGrowthAloneIsNotAChangedPrefixTestC4AStoreErrorOrARecheckPanicForwardsTheRequestUnchanged(3 cases: store refuses, panic in the apply, panic in the recheck)TestC5AfterAColdApplyTheNextPingCarriesTheForwardedBody(keepalive)TestM1TheCreditIsTheWriteRateOnTheColdRequestAndTheRequestsRateAfter,TestM1TheAnswerCostIsBookedOnceOnThePingRowAndInItsOwnColumn(dash),TestTheAnswerCostIsBookedOnceOnThePingRowTheQuestionReplaced(keeper),TestTheAnswerCostIsNotSubtractedFromTheCreditAgain. Live: matches the provider's usage, release check.TestM2ReplayOfTheTwoLosingSweepsShowsNoLossAndNoFalseCredit(see below)TestH1AWarmRequestAfterAColdApplyIsIdenticalToTheOneBeforeItBesideTheNewMessages(new),TestAWarmRequestAppliesNothingAndKeepsTheAnswerHeld,TestAHeldAnswerChangesNoRequest,TestH1EveryRequestAfterAnAnswerIsByteIdenticalToTheSweepOff(from #508, still passes)TestAnExpandOfASweepMarkerIsChargedToTheSweep,TestAnExpandOfASweepMarkerIsChargedToTheSweepOnTheDashboardRow(real proxy, in-band loop),TestTheRepairPathChargesASweepMarkerOnceNotOnEveryTurn(real proxy, request-path repair),TestTheSweepsExpandsComeOffItsCreditAndOnlyTheSweepsTestALaterReferenceToADroppedOutputCounts,TestTheFalseDropRateCountsDropsNotExpandCalls,TestTheDropRecordHoldsNoCustomerContentextract_llm_sweepis back inTestNoStateIsRecordedBeforeTheCommitGate(it was ingateExempt).cg:swd:andcg:swx:are indecisionPrefixes.M2: the two losing sweeps
Built from the numbers in #404's Technical details. No stored customer data. First the test reproduces the issue's own credit with the real pricing path ($0.126 and $0.050). That fixes the price. Then:
Mutation checks
Each mutation was applied to a scratch copy and made a named test fail. Nothing below survived the final tests.
TestAWarmRequestAppliesNothing...,TestGrowthAlone...,TestAHeldAnswerChangesNoRequestTestC3...TestC3...TestC1...,TestC3...TestC4...TestC4...TestC4...TestC1...TestAColdAppliedDrop...,TestH1AWarm...TestShadowModeStillAppliesNothing...,TestAHeldAnswerChangesNoRequestTestTheSweepAsksAtThePingWithShadowOffTestAnExpandOfASweepMarker...TestAnExpandOfASweepMarker...TestALaterReferenceToADroppedOutputCountsTestALaterReferenceToADroppedOutputCountsTestTheAnswerCostIsBookedOnceOnThePingRow...TestTheSweepsExpandsComeOffItsCredit...TestTheAnswerCostIsNotSubtractedFromTheCreditAgainTestTheFalseDropRateCountsDropsNotExpandCallsregisterPingkeeps a copy with no candidateTestRegisterPingKeepsNoCopy...collectreadscg:res:TestAnAlreadyDroppedOutputIsNotOfferedAgain,TestAnExtractLLMRecordIsNotTheSweepsDropxhighloses the sweepTestXHighPresetIsHighPlusTheSweepTestAnExpandOfASweepMarker...OnTheDashboardRowTestTheRepairPathChargesASweepMarker...TestAnExpandOfASweepMarker...OnTheDashboardRowFour survived first, and each was a gap in a test, not in the code:
shadowStepspends the answer first, so the apply had nothing left. A stronger mutation (apply runs before the report) is killed.collectreadscg:res:. I had named a test that did not exist. Written.Tests moved, changed or deleted
TestHousellmSweepActuallyFires: no longer needs shadow. It asks with the shipped block.TestWithShadowOffThePingStaysPlain: replaced byTestTheSweepAsksAtThePingWithShadowOff(the opposite claim).TestShadowOffReportsNothing: removed. With shadow off the sweep now asks and applies, so the claim is false. Shadow-on is covered byTestShadowReportsTheAskThenTheRecheckAtTheColdRequestand the new cold-request test.TestAHeldAnswerChangesNoRequest: warm phases for both modes, plus the cold phase for shadow only. The cold phase for shadow off is now the apply (TestC1...).TestNoCandidatesMeansNoQuestion: a conversation with no output at the floor now registers nothing, so it readsno_candidate(item D). One whose big outputs are all markers still readsno_inventory. Both are tested.TestSweepRecordsNoReplayForADropItDeclined: rewritten for the new drop record.prefix_econ_premium_test.go(reward premium, ask term, approval, horizon credit) andprefix_econ_prunecredit_test.go; two ask-term tests inprefix_econ_guard_test.go. The coref-side tests (TestPrefixRewritePaysUnchangedWithoutAnAsk,TestTurnsRemainingAfterCollapsesToTheOriginal,TestCorefHorizonIsNotCredited) stay.Review fixes (from the #508 review)
putHeldtakesheldMuand never overwrites a newerAskedAtMs. Tests:TestAClaimNeverOverwritesANewerAnswer(slow store, both claims),TestAnOlderAnswerNeverReplacesANewerOne. Mutations: lock removed, staleness check removed. Both killed.claimHeldSpend), so two cold requests of one thread cannot both apply. A panic in the apply or the recheck restores every message, forwards the request unchanged, and is counted (sweep_apply_panic,SweepApplyPanics()).TestAColdApplyPanicIsCountedAndRetriedOnce, with mutations for no retry, unbounded retry, and no count.sweep_concurrency_full, notsweep_ask_failed. Test:TestAFullAskSlotCountsAsConcurrencyFull.sweepColdRequestusesColdApplyPhase(cold or unknown). One narrowing: unknown with a known cached prefix is not cold for the sweep, because a drop would rewrite a live prefix.The summary and the sweep on one cold request
I chose (a): a fixed, safe order, and tested it. In xhigh the summarizer runs first, so the sweep sees the request after the summary has replaced its span.
RawInput), so the shifted indexes do not move the answer.TestTheSummaryAndTheSweepOnOneColdRequest(4 outputs, the summary replaces 2: 2 dropped, 2 skipped, no record or count for the skipped ones, all markers expand, the summary message untouched).ClaimPing's in-flight look is still check-then-act, so a detached summary started by a real request can overlap the sweep's question on one thread. That overlap costs a wasted read at worst. It cannot change a request, because the sweep applies only from the held answer, and the apply claims it exactly once.Data dependence
cg:swd:(one record per applied drop and a per-thread index),cg:swx:(marker id to drop record), and the stashed original behind each marker (content, the same as every other offloader). The records hold ids, a content key, the marker id, token counts, time, the kind, and 4-byte hashes of up to 48 identifiers. No output text. The quality ledger is counters in process memory.cg:swh:), the drop records, and the stash forexpand. It no longer readscg:res:.docs/data-dependence.mdrow forextract_llm_sweepis updated (Store column, "metadata only" column, the work column). Approved by David Amid on 2026-10-25. "Decided by" in the row records it.Docs
docs/reference/presets.md: thexhighandhousellmrows describe the sweep as it is now (asks at the keep-alive ping, removes content only on a cold request). The oldmax_callsand "adjudicates at depth on an expired cache" text is gone.Round 1 review fixes
cg:swx:lists every owner, and an expand credits only the thread that made it.dropMuserialises the reference scan, the expand note and the commit, so a flag is not lost.sweep_applied_*are counted last.coldApplyCacheN+1 and the "next warm" imprecision (dashboard-only), andmaxDropsPerThread= 512.Round 2 review fixes
scanReferencesreleasesdropMuwith a deferred unlock, so a panic in the Store or the ledger cannot leave it held. Every other lock was checked.With the keep-alive fixes (#710, #711, #712)
TestAPingTheSweepQuestionReplacedUsesNoStep.TestAFailedSweepQuestionFallsToAPlainPingAndAsksOnceWhenItBilled.thread.Key(session, thread), so a held answer and its drops stay on their thread.TestAHeldAnswerAndItsDropsStayOnTheirThreadKey.For the release check (L1, C2)
The sweep row on the Components tab (
/api/components) carries:sweep_net_usd(credit - expand charge - answer cost, from stored provider usage),sweep_answer_usd,sweep_expands,sweep_expand_tokens,sweep_false_drop_rate, and for C2sweep_cold_apply_cache_read/_writeandsweep_next_warm_cache_readover the cold-apply requests and the first warm request after each./statshaskeepalive.sweep_drops. Test:TestTheLedgerCarriesTheNetSavingAndTheColdApplyCacheNumbers.Open questions
keepalive.sweep_dropsledger is process-wide, like the ping counters. A restart resets it. The per-row columns on the dashboard database are durable. The Components-tab rate reads those.Technical notes
sweepDescriptor(content)plus the marker, so a replay emits the same bytes as the request that made the drop. The record exists only for a drop the request carries (committed after every drop is inreq).Ctx.ColdCache, notCachePhase(0).ColdCacheis apply's own verdict with a clock margin.CachePhase(0)also calls the last minute before the margin cold. Shadow and the apply use the same test, so shadow reports what the apply would do.msgPrintis a fingerprint of role, tool ids, length and the two ends of the text. A same-length edit that keeps both ends is missed, and a missed change only means the apply waits for a cold request. It can never apply a drop on a warm request.-race,dash'sTestTheInsightsDocumentIsScopedToOneProjecthits the 10 s handler timeout in a full-package run (go test -race ./dash/). It passes alone, and on pristineorigin/mainit failed in 1 of 2 full-package-raceruns. If CI hits it, rerun.cg:swd:(drop record, per thread and content key, plus a per-thread index) andcg:swx:(marker id to drop record). Both pinned. The Store is in memory, so a restart loses them. That fails open: a lost record means the output is no longer replayed. The next cold request sends it in full. The ledger columns on the database are not affected.requestscolumns (sweep_expands,sweep_expand_tokens,sweep_false_expands,sweep_answer_usd). They are in theCREATE TABLEand inadditiveColumns, so old databases migrate without a version bump.recordSubstitutePinggains ananswerUSDargument (the summary passes 0), andfireSweepSubstitutecomputes it. I did not touch the ping choice.Part of #404.