Skip to content

fix(extract_llm): grant no exploration call while the stash reserve refuses (#214) - #758

Merged
amiddavid merged 2 commits into
mainfrom
fix/extract-llm-explore-reserve
Oct 27, 2026
Merged

amiddavid merged 2 commits into
mainfrom
fix/extract-llm-explore-reserve

Conversation

@amiddavid

@amiddavid amiddavid commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • extract_llm no longer spends trial calls while the stash reserve refuses payloads.
  • Exploration resumes when a splice lands or after 60 s.

What changed

  • ratioTracker records 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.
  • A withheld slot is not used up. The session keeps its full budget.
  • The skip shows as the gate explore_skipped_reserve_full.
  • The refusal signal is the existing commitMark refusal. No new global. Metadata only.
  • The ratio math and the "observe nothing while refusing" rule are unchanged.
  • The code comment at extract_llm.go no 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

  • New unit tests: no slot under a full reserve across 2 sessions; resume after a splice; resume after the window; normal path unchanged.
  • New component tests: session B makes 0 model calls under a refusing store and the gate is counted; a real splice clears the refusal.
  • Full suite go test -count=1 ./..., go test -race ./components/offload/, and make lint pass on eval box 1.
  • Mutation checks, each caught by a test:
    • ignore the refusal in exploring()
    • a splice does not clear the refusal
    • the window never ends
    • commitMark refusal not fed to the tracker
    • splice not fed to the tracker (needed a new test)
    • skip not counted
    • the per-session budget removed
  • No live runs.

Open questions

  • None.

Technical notes

Fixes #214

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

  1. components/offload/extract_llm.go:1545 — only the phase-3 splice clears the refusal. noteSpliced runs 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 commitMark may refuse — and a refusal there DOES set the marker, through apply;
    • the same-session replay (extract_llm.go:949), whose commitRefresh retained 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.
  2. components/offload/extract_econ_reserve_test.go:131 — the test comment names the wrong path. TestExtractLLMSpliceClearsTheReserveRefusal says the splice is "a cross-session cache hit (no model call)". Each run builds a fresh gatedStore, so the global lookup misses and the model IS called. The clear comes from the phase-3 noteSpliced. 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.

  3. components/offload/extract_econ.go:592 — exploring has no production caller now. Only tests call it. Consider testing through exploringWhy and deleting the wrapper.

  4. 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. commitMark refuses only in markerFull mode (marker.go:122-134). So eff == markerFull at extract_llm.go:861 matches the refusal branch exactly. Replays use commitRefresh, which never refuses, and cannot set the marker.
  • No new race. noteRefused/noteSpliced/exploringWhy all hold mu. apply runs 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. PutStash refuses 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; noteSpliced on 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: seenBefore is false (fresh store per run, markSeenContent is store-scoped), tail candidate, so saving ≈ $0.003 < cost ≈ $0.010 at default rates. The gate suppresses it, callsB == 0 holds 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") in TestExploringResumesWhenTheReserveFrees evaluates 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 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.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

  1. 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 refusedAt is set. Within 60 s, a cross-session cache hit lands: apply succeeds, which means commitMark stashed a payload and the reserve accepted it. noteSpliced is 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: refusedAt is "the zero time once a splice has landed since (#214)".
    • Proof: noteSpliced has exactly one call site, extract_llm.go:1545, in phase 3 (the fresh model-call path). apply has three call sites: extract_llm.go:949 (same-session replay — correct not to clear, commitRefresh never 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.PutStash refuses on byteRoom(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 a shrinkingModel call.
    • Fix: call e.ratios.noteSpliced() after the cross-session apply returns 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 the refusedAt doc on extract_econ.go:486-488 to say only a fresh splice clears it.

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: noteSpliced fires for every successful phase-3 apply, including a splice in a degraded marker mode (summary/off), where no reserve write happened. Harmless today: noteRefused is 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: ratioTracker in extract_econ.go, the apply closure, phase 1 (gate, cross-session reuse), and phase 3 (splice, observe) in extract_llm.go.
  • The refusal source: commitMark refuses only in markerFull mode (marker.go:122-134), so the eff == markerFull guard at extract_llm.go:861 is correct. commitRefresh never refuses, so the replay path must not clear the refusal — and it does not.
  • Concurrency: noteRefused, noteSpliced, exploringWhy all hold r.mu; apply runs only on the serial phases. No new race.
  • Withheld-slot semantics: a withheld slot does not increment explored, and tooSlowToExplore short-circuits before exploringWhy, 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), TailOnly with MaxCachedIdx 0, savedTokenValueAt on 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_llm row 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]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round 1 replies (head after this push: see the last line)

Blocking: a cross-session splice did not clear the refusal. Fixed.

  • noteSpliced now runs after the cross-session apply succeeds.
  • The same-session replay stays out on purpose. commitRefresh never refuses, so a replay says nothing about room. A comment says so.
  • New test TestExtractLLMCrossSessionSpliceClearsTheReserveRefusal. Two sessions share one store. Session B hits session A's global result with no model call.
  • Mutation check: remove the new noteSpliced call. The new test fails.

Non-blocking, all fixed:

  • Test comment named the wrong path: now says the splice is the fresh phase-3 path.
  • Tautology-looking line: now two named calls, second and third.
  • exploring had no production caller: deleted. Tests use exploringOK, a helper over exploringWhy.
  • noteSpliced in a degraded marker mode: the comment now says it is a no-op there, because noteRefused is never set in those modes.
  • Comment at the end of the "observe nothing" note: now says "about one trial call per window while saturation lasts".
  • docs/data-dependence.md: the extract_llm row now names the time of the last stash refusal.

Eval box 1 results:

  • go test -count=1 ./...: pass.
  • go test -race -count=1 ./components/offload/: pass.
  • make lint: pass.
  • Head: 43f53dc

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

  1. Cross-session splice did not clear the refusal (extract_llm.go:1035) — fixed.
    • e.ratios.noteSpliced() now runs after the cross-session apply succeeds (extract_llm.go:1041), with a comment that names the rule. The call sits in phase 1, which is serial, and noteSpliced holds r.mu. No new race.
    • The new test is genuine. I traced it: getResult is 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: DefaultCfg leaves CacheContext false, session A has one candidate so phase 2 keeps it false, and session B reads in phase 1 before phase 2 runs. The final refusing assertion fails if the noteSpliced call is removed, which matches the author's mutation check.
  2. 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, second and third. The unused exploring wrapper is deleted; tests use exploringOK. The noteSpliced comment 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. The extract_llm row 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: commitRefresh never 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, but apply ignores commitRefresh'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, the extractCacheHits delta 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 final refusing assertion. 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..HEAD and 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 exploring wrapper remains (grep over components/, none).
  • Fail-open and concurrency are unchanged from round 1: the new noteSpliced call is on a serial phase behind the same mutex.
  • The author's reply reports go test, go test -race, and make lint passing on the eval box. I could not verify that; 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 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. noteSpliced now runs after the cross-session apply succeeds (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 (exploring had no production caller) — fixed. Deleted. Tests use exploringOK, a helper over exploringWhy. 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/third rewrite, the degraded-mode comment on noteSpliced, 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's commitMark takes 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 noteSpliced call sits on the serial phase-1 path, after apply returns true. No new race; all tracker methods hold mu.
      • The new test isolates the fix. I traced TestExtractLLMCrossSessionSpliceClearsTheReserveRefusal: one shared gatedStore; session A gets no same-session or global hit on a fresh store, so it makes the model call and publishes cg:xres:; session B misses the same-session result (session-scoped key), skips the tail gate (CacheAware false), and hits the global result — the branch continues, so phase 3 never runs for session B and the only possible clear is the new call. The result-cache-hit metric and the unchanged model.calls prove the branch was taken. The result key matches across the two runs (CacheContext is 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 → exploringOK rename is mechanical in extract_econ_test.go; the assertions are unchanged.
      • The noteSpliced doc comment on the degraded marker modes matches what I verified in round 1: noteRefused is never set in those modes, so the call is a no-op there.
  • 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.

@amiddavid
amiddavid merged commit f136c37 into main Oct 27, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 27, 2026
@amiddavid
amiddavid deleted the fix/extract-llm-explore-reserve branch October 27, 2026 18:28
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.

extract_llm: a saturated reserve stops the ratio tracker learning, so exploration never self-terminates and re-pays its trial calls on every session

1 participant