Repository navigation
fix(extract_llm): grant no exploration call while the stash reserve refuses (#214) - #758
Conversation
…efuses (#214) While the reserve refused splices, the ratio tracker saw nothing, so every new session spent its 2 trial calls on output that would be refused. The tracker now records the last stash refusal and clears it on a splice. exploring() grants no slot for 60 s after a refusal with no splice since. The skip is counted as the explore_skipped_reserve_full gate. Fixes #214 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.311 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 1573283fd405 |
approve |
Verdict: approve
Findings
None. The change is correct and fail-open holds. Details of what I verified are below.
Non-blocking
-
components/offload/extract_llm.go:1545 — only the phase-3 splice clears the refusal.
noteSplicedruns after a fresh model-call splice. Two other splices also prove the reserve took a payload, but do not clear it:- the cross-session cache hit (extract_llm.go:1035), whose
commitMarkmay refuse — and a refusal there DOES set the marker, throughapply; - the same-session replay (extract_llm.go:949), whose
commitRefreshretained the payload.
So the refusal signal is fed from every path, but the clear signal is not. Effect: exploration stays off up to 60 s longer than the evidence warrants. The direction is conservative and self-heals. The PR description says "Exploration resumes when a splice lands", which is not true for these two paths.
- the cross-session cache hit (extract_llm.go:1035), whose
-
components/offload/extract_econ_reserve_test.go:131 — the test comment names the wrong path.
TestExtractLLMSpliceClearsTheReserveRefusalsays the splice is "a cross-session cache hit (no model call)". Eachrunbuilds a freshgatedStore, so the global lookup misses and the model IS called. The clear comes from the phase-3noteSpliced. The assertion still proves a real splice clears the refusal. But the cross-session path from point 1 is not covered by any test, and the comment says it is. -
components/offload/extract_econ.go:592 —
exploringhas no production caller now. Only tests call it. Consider testing throughexploringWhyand deleting the wrapper. -
docs/data-dependence.md:198 — the extract_llm row says "Memory: counts per session". The tracker now also holds the time of the last stash refusal. Same class (in-memory metadata), and the PR body states "Metadata only", so the classification does not change. The row's memory note could name it.
What I checked
- Read the full diff and the code around each change:
extract_econ.go(tracker),extract_llm.go(apply, phase 1-3, the gate block),marker.go(commitMark/commitRefresh/tryMark). - Refusal signal is exact.
commitMarkrefuses only inmarkerFullmode (marker.go:122-134). Soeff == markerFullat extract_llm.go:861 matches the refusal branch exactly. Replays usecommitRefresh, which never refuses, and cannot set the marker. - No new race.
noteRefused/noteSpliced/exploringWhyall holdmu.applyruns only on the serial phases (1 and 3); the phase-2 goroutines never call it. The tracker is never copied. - No new off-switch. A withheld slot is not consumed (
explored[session]is untouched). Under a persistently refusing reserve, the window expires after 60 s, one session probes, its refusal restarts the window. Spend is bounded at about 2 calls per 60 s, process-wide. This matches the intent of #214. - Store semantics.
PutStashrefuses per payload against the byte budget and slot cap (store/store.go:789). So a small payload can land after a large one was refused;noteSplicedon any landing splice is a defensible reading of "not full". A refusal followed by a success in one request clears the marker; the next refused probe re-sets it. Bounded, self-correcting. - End-to-end test is deterministic. I traced
TestExtractLLMMakesNoTrialCallUnderAFullReserve:- The log line matches no content class (checked every regex in contentclass.go), so the pooled ratio 0.12 governs.
- Session B:
seenBeforeis false (fresh store per run,markSeenContentis store-scoped), tail candidate, sosaving ≈ $0.003 < cost ≈ $0.010at default rates. The gate suppresses it,callsB == 0holds with about a 3x margin. - Session A: fresh tracker, no refusal recorded yet, p50 latency from the fake model is far under
slowCallMs. The exploration slot is granted. Precondition holds.
- The awkward assertion
if !r.exploring("sessB") || r.exploring("sessB")inTestExploringResumesWhenTheReserveFreesevaluates to false as intended (short-circuit: second call true, third call false at the budget cap). Correct, though hard to read. - Read issue #214 and the PR body. The fix matches the issue's chosen policy (a recent-refusal timestamp, its option 1). The PR states its data dependence ("Metadata only. No new global."). extract_llm already has a data-dependence row, and the storage class is unchanged.
- Did not run tests or builds. Live tests are not approved for this review, and Go is not installed on this machine. The PR reports the suite, the race run, and lint passing on the eval box; I could not verify that.
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.311 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 1573283fd405 |
blocking |
Verdict: blocking
One finding. It is low in severity, and the rest of the change is sound.
Findings
- components/offload/extract_llm.go:1035 — a cross-session splice does not clear the reserve refusal
- What fails: the stash reserve refuses one payload, so
refusedAtis set. Within 60 s, a cross-session cache hit lands:applysucceeds, which meanscommitMarkstashed a payload and the reserve accepted it.noteSplicedis not called on this path. So exploration stays withheld for the rest of the window, although the reserve just proved it is not full. This breaks the tracker's own invariant, extract_econ.go:486-488:refusedAtis "the zero time once a splice has landed since (#214)". - Proof:
noteSplicedhas exactly one call site, extract_llm.go:1545, in phase 3 (the fresh model-call path).applyhas three call sites: extract_llm.go:949 (same-session replay — correct not to clear,commitRefreshnever refuses), extract_llm.go:1035 (cross-session,commitMark, can refuse — not cleared), and extract_llm.go:1542 (fresh — cleared). The trigger is realistic because a refusal is size-dependent, not binary:store.PutStashrefuses onbyteRoom(len(payload))(store/store.go:828), so a large payload can be refused while a smaller cross-session payload is accepted right after. The new test also misses this: TestExtractLLMSpliceClearsTheReserveRefusal (extract_econ_reserve_test.go:128-129) says "The splice here is a cross-session cache hit (no model call)", but the test runs one request against a fresh store, so no global hit is possible — the splice it exercises is the fresh phase-3 path with ashrinkingModelcall. - Fix: call
e.ratios.noteSpliced()after the cross-sessionapplyreturns true (after extract_llm.go:1037), and add a test that drives a real cross-session hit after a refusal. If the omission is deliberate, change therefusedAtdoc on extract_econ.go:486-488 to say only a fresh splice clears it.
- What fails: the stash reserve refuses one payload, so
Non-blocking
- extract_econ_reserve_test.go:128-129: the comment describes a cross-session hit with no model call. The test makes a model call. A reader who trusts the comment learns the wrong thing about which path clears the refusal.
- extract_econ_reserve_test.go:62-64:
if !r.exploring("sessB") || r.exploring("sessB")reads as a tautology. It only works because each call has a side effect (the first grants the last slot, the second must refuse). Two explicit calls with named results would say what it asserts. - extract_llm.go:1545:
noteSplicedfires for every successful phase-3apply, including a splice in a degraded marker mode (summary/off), where no reserve write happened. Harmless today:noteRefusedis only set in full mode, and the mode and store are constant per process. But the comment's justification ("a payload fit") does not hold on that arm. - The 60 s window leaks under persistent saturation: when it expires with no splice, the next exploring session gets a slot, its call is refused, and the window re-arms. That is about one wasted trial call per minute for as long as the episode lasts (the extract_llm.go:1583 comment says such an episode can run for hours). Small, and far better than the old 2-calls-per-session spend, but the new comment at extract_llm.go:1595-1598 ("only to the first calls of a refusal burst") states slightly more closure than the mechanism delivers.
What I checked
- The full diff (one commit, three files) and the code around each change:
ratioTrackerin extract_econ.go, theapplyclosure, phase 1 (gate, cross-session reuse), and phase 3 (splice, observe) in extract_llm.go. - The refusal source:
commitMarkrefuses only inmarkerFullmode (marker.go:122-134), so theeff == markerFullguard at extract_llm.go:861 is correct.commitRefreshnever refuses, so the replay path must not clear the refusal — and it does not. - Concurrency:
noteRefused,noteSpliced,exploringWhyall holdr.mu;applyruns only on the serial phases. No new race. - Withheld-slot semantics: a withheld slot does not increment
explored, andtooSlowToExploreshort-circuits beforeexploringWhy, so no slot is burned when calls are slow. Both match the doc comments. - The end-to-end tests, traced by hand against the helpers (
refusingStore,gatedStore,shrinkingModel,newTimeoutTestComponent),TailOnlywithMaxCachedIdx0,savedTokenValueAton a tail candidate, and the economic gate. I found no flaw in what they assert; the defect above is in what they do not cover. - Data dependence: the change adds an in-memory timestamp only. The
extract_llmrow in docs/data-dependence.md ("Memory: counts per session") still covers it; no direction change, so no doc update is required. - Fail-open: a withheld exploration slot only suppresses a speculative call. The request still goes out unchanged. No new fail-closed path.
- I did not run builds or tests (not approved). I did not read the PR body, other reviews, or PR comments, to keep this round independent.
…#214) A cross-session splice goes through commitMark, so a success proves the reserve took a payload. It did not clear the refusal, so exploration stayed off for up to 60 s. - Call noteSpliced after the cross-session apply succeeds. - Leave the same-session replay out: commitRefresh never refuses. - Remove the unused exploring wrapper. Tests use exploringOK. - Fix the comments that named the wrong path or overstated closure. - Add the stash refusal time to the extract_llm row in data-dependence.md. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Round 1 replies (head after this push: see the last line)Blocking: a cross-session splice did not clear the refusal. Fixed.
Non-blocking, all fixed:
Eval box 1 results:
|
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.311 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 43f53dc8c75e |
approve |
Verdict: approve
Findings
None. My round-1 blocking finding is fixed correctly, and the new commit introduces no defect.
Round-1 findings
- Cross-session splice did not clear the refusal (extract_llm.go:1035) — fixed.
e.ratios.noteSpliced()now runs after the cross-sessionapplysucceeds (extract_llm.go:1041), with a comment that names the rule. The call sits in phase 1, which is serial, andnoteSplicedholdsr.mu. No new race.- The new test is genuine. I traced it:
getResultis session-scoped (state.go:63,resultKey(c.Session, id)), so session B cannot take the same-session replay path. It must hit the global result or make a model call — and a model call fails the test's own assertion. The global key also matches on both sides:DefaultCfgleavesCacheContextfalse, session A has one candidate so phase 2 keeps it false, and session B reads in phase 1 before phase 2 runs. The finalrefusingassertion fails if thenoteSplicedcall is removed, which matches the author's mutation check.
- Non-blocking items — all fixed. The wrong test comment now names the fresh phase-3 path. The tautology-looking assertion is now two named calls,
secondandthird. The unusedexploringwrapper is deleted; tests useexploringOK. ThenoteSplicedcomment now states it is a no-op in degraded marker modes. The "observe nothing" comment now says "about one trial call per window while saturation lasts", which matches what the mechanism delivers. Theextract_llmrow in docs/data-dependence.md now names the refusal time.
Author's one rejection, checked
- The same-session replay still does not clear the refusal. The reason given:
commitRefreshnever refuses, so a replay says nothing about room. I checked it and accept it. A replay of an entry still in the store takes no reserve decision at all (store/store.go:792-819 retains an existing entry whatever the reserve says). A replay whose payload the TTL took can re-create the entry through the new-payload path, butapplyignorescommitRefresh's return value by design, so that signal is not available at the call site without a contract change. Wiring it would add complexity for a case the 60 s window already covers.
Other reviewer's round-1 items
- Reviewer 1 raised the same cross-session gap as their non-blocking #1, plus the test comment, the unused wrapper, and the data-dependence row. I checked each myself against the new head: all four are addressed. Nothing new to add.
Non-blocking
- In
TestExtractLLMCrossSessionSpliceClearsTheReserveRefusal, theextractCacheHitsdelta alone does not distinguish the cross-session branch from a same-session replay — both record a lookup hit. The test still pins the branch through the session-scoped miss, the no-model-call check, and the finalrefusingassertion. Harmless as written.
What I checked
- Last review: round 1, 1573283, 2026-10-27T17:31:49Z
- New commits read: 1 —
43f53dc8"fix(extract_llm): clear the reserve refusal on a cross-session splice (#214)" - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files in my folder)
- New items since my last review: the fix commit and the author's round-1 reply comment. I read both in full and checked every claim in the reply against the code.
- The full diff
1573283f..HEADand the code around each change: the cross-session branch in extract_llm.go, the tracker docs in extract_econ.go, both test files, and the data-dependence row. - That no stale reference to the deleted
exploringwrapper remains (grep overcomponents/, none). - Fail-open and concurrency are unchanged from round 1: the new
noteSplicedcall is on a serial phase behind the same mutex. - The author's reply reports
go test,go test -race, andmake lintpassing on the eval box. I could not verify that; live tests are not approved and Go is not on this machine.
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.311 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 43f53dc8c75e |
approve |
Verdict: approve
Findings
None. Every earlier finding is fixed, and the new commit introduces no defect.
Earlier findings
- Mine 1 (cross-session splice did not clear the refusal) — fixed.
noteSplicednow runs after the cross-sessionapplysucceeds (extract_llm.go:1041). - Mine 2 (test comment named the wrong path) — fixed. The comment now says the fresh phase-3 path with one model call.
- Mine 3 (
exploringhad no production caller) — fixed. Deleted. Tests useexploringOK, a helper overexploringWhy. No caller of the old wrapper remains (grepped the package). - Mine 4 (data-dependence row) — fixed. The extract_llm row now names "the time of the last stash refusal".
- Reviewer 2, finding 1 (blocking; same defect as my non-blocking 1) — fixed, and I verified it myself. See above. The author also left the same-session replay out on purpose. I checked the reason and accept it: a replay refreshes the payload key this session already stashed (the key is the content hash), and
PutStash's refresh path never refuses and does not consult the byte budget (store/store.go:792-819). So a replay's success is no evidence about room. Correct to exclude. - Reviewer 2, non-blocking (4 items) — all fixed. The
second/thirdrewrite, the degraded-mode comment onnoteSpliced, the "one trial call per window" comment, and the test comment. All verified in the diff.
Non-blocking
- extract_llm.go:1038 — the new comment overstates what a cross-session success proves. "commitMark took the payload, so the reserve is not full" holds only when the payload key is NEW. A cross-session hit is by definition on content another session compacted, and that session stashed the same payload key
hashKey(original). While that entry is live (stash TTL 1800 s), session B'scommitMarktakes the refresh path, which never refuses and does not test the byte budget. So the clear can fire while the reserve still refuses new payloads. Worst case: exploration resumes, one trial call is made, its splice is refused, the window re-arms. Bounded at one call per event — the same scale as the documented window leak. A wording change ("took the payload or refreshed one already held") would make the comment exact. - extract_econ_reserve_test.go:15 — the file-top comment still says "exploring() must grant no slot". The function is now
exploringWhy. Trivial.
What I checked
- Last review: round 1, 1573283, 2026-10-27T17:31:30Z.
- New commits read: 1 —
43f53dc8"fix(extract_llm): clear the reserve refusal on a cross-session splice (#214)". Read the full diff and the code around each change. - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files).
- New items since my last review, and what I did:
- Reviewer 2's round-1 review (posted 19 s after mine). Its blocking finding matches my non-blocking 1. Checked it myself; the fix is correct.
- The author's reply comment. Every claim in it matches the diff.
- The new commit. Reviewed as a first review:
- The new
noteSplicedcall sits on the serial phase-1 path, afterapplyreturns true. No new race; all tracker methods holdmu. - The new test isolates the fix. I traced
TestExtractLLMCrossSessionSpliceClearsTheReserveRefusal: one sharedgatedStore; session A gets no same-session or global hit on a fresh store, so it makes the model call and publishescg:xres:; session B misses the same-session result (session-scoped key), skips the tail gate (CacheAwarefalse), and hits the global result — the branchcontinues, so phase 3 never runs for session B and the only possible clear is the new call. The result-cache-hit metric and the unchangedmodel.callsprove the branch was taken. The result key matches across the two runs (CacheContextis false on both sides: sessA has one candidate, sessB reads before phase 2 sets it). - The reworded closing comment is accurate. "About one trial call per window while saturation lasts" is what the mechanism delivers: the first slot after expiry is refused and re-arms the window; the session's second slot is withheld, not consumed.
- The
exploring→exploringOKrename is mechanical inextract_econ_test.go; the assertions are unchanged. - The
noteSpliceddoc comment on the degraded marker modes matches what I verified in round 1:noteRefusedis never set in those modes, so the call is a no-op there.
- The new
- Did not run tests or builds. Live tests are not approved, and Go is not installed on this machine. The author reports the suite, the race run, and lint passing on eval box 1; I could not verify that.
Summary
What changed
ratioTrackerrecords the time of the last stash refusal. A splice clears it.exploring()grants no slot while a refusal is less than 60 s old with no splice since.explore_skipped_reserve_full.commitMarkrefusal. No new global. Metadata only.extract_llm.gono longer points to store: a saturated rewind reserve is released only by the TTL, so one busy period can zero out savings process-wide for ~2.8h #190. It describes this fix.How it was tested
go test -count=1 ./...,go test -race ./components/offload/, andmake lintpass on eval box 1.exploring()commitMarkrefusal not fed to the trackerOpen questions
Technical notes
reserveRefuseWindow = 60 * time.Second. It stays short because the stash TTL (fix(store): give rewind payloads their own shorter horizon, and count the reclamations a replay absorbs #204) also frees the reserve.eff == markerFull) is fed in. Replays never refuse.Fixes #214