fix: update model column on mid-session model switches#28677
Closed
annguyenNous wants to merge 1 commit into
Closed
fix: update model column on mid-session model switches#28677annguyenNous wants to merge 1 commit into
annguyenNous wants to merge 1 commit into
Conversation
The sessions table uses COALESCE(model, ?) which is first-writer-wins — once a model is recorded, it never updates on /model switches. This causes /usage and /insights to attribute all tokens to the initial model. Fix: change to model = ? so the column always reflects the latest model. The acp_adapter already uses the correct pattern (COALESCE(?, model)). Fixes NousResearch#28637
Contributor
|
Closed in favor of PR #35256 (merged), which uses a targeted update_session_model() rather than flipping COALESCE(model, ?) to an unconditional set in update_token_counts — that method runs on every API call and the unconditional set risked clobbering with stale/None from other callers. Same root cause you correctly identified (#34850). Thanks @annguyenNous! |
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.
Problem
The
sessionstable'smodelcolumn usesCOALESCE(model, ?)— first-writer-wins. Once a model is recorded for a session, it never updates on/modelswitches. Cumulative counters (input_tokens,output_tokens, etc.) keep summing across all models, but/usageand/insightsattribute everything to the single locked-in model.Fix
Change
model = COALESCE(model, ?)tomodel = ?in both UPDATE statements inhermes_state.py(lines 805 and 826). This makes the column always reflect the latest model used.Note: the
acp_adapter/session.pyalready uses the correct patternCOALESCE(?, model)(reverse argument order — prefer new value). Onlyhermes_state.pyhad the bug.Before vs After
model = gpt-4oforevermodel = claude-sonnetafter switch/usageattributionTests
Verified syntax with
py_compile.compile(). The change is 2 lines (removingCOALESCEwrapper) in a single file.