fix(proxy): forward PriorServedModel on regular session-pin usage writeback#752
Open
rohith500 wants to merge 2 commits into
Open
fix(proxy): forward PriorServedModel on regular session-pin usage writeback#752rohith500 wants to merge 2 commits into
rohith500 wants to merge 2 commits into
Conversation
…iteback A regular (non-HMM) UpdateUsage must carry PriorServedModel so a new tier-role pin can latch has_ever_switched from sibling hmm_history evidence already surfaced on the turnLoopResult. Signed-off-by: N Rohith Reddy <rohithreddy2202@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
…teback Mirror the HMM history path so UpdateSessionPinUsage can latch has_ever_switched when the first write to a tier-role pin already has prior-served evidence from switchHistoryFromPins. Signed-off-by: N Rohith Reddy <rohithreddy2202@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
|
PR author is not in the allowed authors list. |
Contributor
|
Thanks for this, @rohith500 — clean, focused fix. 🙏 Forwarding
Approving from a conventions standpoint — thanks for the fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
recordTurnUsage(the regular per-turn session-pin writeback) never forwardedPriorServedModelintosessionpin.Usage, unlikerecordHMMTurnHistory(the HMM writeback), which has passed it correctly since #677. Because of that, a tier-role pin row whose first-ever write happens on the regular path can never latchhas_ever_switched = truefrom prior evidence — even when the session demonstrably switched models, as long as that knowledge only exists in the row's<role>_hmm_historysibling.This is invisible while the
_hmm_historysibling is alive (a read-time OR masks it). It surfaces once that sibling expires or is swept: a later same-model turn then forwards a stale-signed Anthropicthinkingblock from an earlier cross-model excursion straight to the upstream request body — reopening the exact failure class #383 fixed ("Invalid signature in thinking block").Full root-cause analysis, live repro with captured request bytes, and consequence trace: #751
Fix
One field, mirroring the existing
recordHMMTurnHistoryline:res.PriorServedModelis already computed every turn regardless of HMM classification (switchHistoryFromPins,turnloop.go:340) — this fix doesn't add new computation, it just stops dropping a value that was already available.Why this is safe (not a behavior change)
hmmHistoryis always a zero-valuesessionpin.Pin{}, soPriorServedModelresolves to the pin's own existingLastServedModel(or""on a first write) — identical to today's behavior. The fix is a no-op there.last_served_model <> '' AND last_served_model <> @last_served_modelclause, which reads the column fresh at UPDATE time — no new false-positive risk.PriorServedModelstays empty on a regular-pathUpdateUsagecall — none found. Nothing depends on the old (broken) shape.Tests
TestRecordTurnUsage_ForwardsPriorServedModel(internal/proxy/turnloop_internal_test.go), added next to the existingTestRecordTurnUsage_WritesToStore/TestRecordTurnUsage_HMMDecisionWritesHistoryOnlycoverage, using the samenewStubPinStore()test double already used there.main:PriorServedModelempty in the recordedUsage.store.lastUsage.PriorServedModel == "claude-fable-5", and separately confirms the write lands on the active tier role (store.usageRoles == [role]) and explicitly not onhmmHistoryRole(role)— so the test is provably exercising the regular path, not the HMM one.The hand-set
PriorServedModel: "claude-fable-5"fixture value matches whatswitchHistoryFromPinsactually produces for a fresh active pin (LastServedModel == "") with a switchedhmm_historysibling — verified by re-readingturnloop.go:1020-1026against the test setup, not assumed.Live verification (beyond the unit test)
Re-ran the full repro from #751 against this branch's actual committed code (
git diff HEADon the changed file confirmed empty throughout — not a locally re-applied patch), using a local mock Anthropic upstream and mock HMM sidecar:default_lowfromclaude-haiku-4-5→claude-fable-5.default_low_hmm_history.has_ever_switched = true.default_lowitself, served byclaude-haiku-4-5again.default_low_hmm_history(simulating TTL drift + sweep, per session-pin has_ever_switched latch never fires on the regular (non-HMM) writeback path #751's "why it's latent" analysis).default_low, client transcript carrying an assistantthinkingblock signed forclaude-fable-5. Captured outbound body to mock Anthropic: nothinkingblock present — correctly stripped, matching the "fixed" capture from session-pin has_ever_switched latch never fires on the regular (non-HMM) writeback path #751's original verification.Regression sweep
go test ./internal/proxy/ ./internal/router/sessionpin/make checkPriorServedModelstaying empty (regular path)sessionpin.Usage{}constructions/assertions affectedinternal/proxy; all already expectPriorServedModelset where relevantHygiene
gofmt -lclean on both changed filesSigned-off-by: N Rohith Reddy <rohithreddy2202@gmail.com>)maintip (f1e5e93), confirmed viagit ls-remoteimmediately before verification — main had not movedCommits
bc51dd9—test(proxy): require PriorServedModel on regular session-pin usage writebackdbb8864—fix(proxy): forward PriorServedModel on regular session-pin usage writebackFixes session-pin has_ever_switched latch never fires on the regular (non-HMM) writeback path #751