fix: backfill model on gateway sessions after agent runs#997
Open
heyalchang wants to merge 1 commit intoNousResearch:mainfrom
Open
fix: backfill model on gateway sessions after agent runs#997heyalchang wants to merge 1 commit intoNousResearch:mainfrom
heyalchang wants to merge 1 commit intoNousResearch:mainfrom
Conversation
Gateway sessions end up with model=NULL because the session row is created before AIAgent is constructed. After the agent responds, update_session() writes token counts but never fills in the model. Thread agent.model through _run_agent()'s return dict into update_session() → update_token_counts(). The SQL uses COALESCE(model, ?) so it only fills NULL rows — never overwrites a model already set at creation time (e.g. CLI sessions). If the agent falls back to a different provider, agent.model is updated in-place by _try_activate_fallback(), so the recorded value reflects whichever model actually produced the response. Fixes NousResearch#987
1b249d4 to
073be3d
Compare
This was referenced Mar 12, 2026
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.
Fixes #987
Gateway sessions have
model = NULLbecause the row is created beforeAIAgentis constructed. After the agent responds,update_session()writes token counts but never fills in the model.This threads
agent.modelthrough_run_agent()'s return dict intoupdate_session()→update_token_counts(). The SQL usesCOALESCE(model, ?)so it only fills NULL — never overwrites a model set at creation time (e.g. CLI sessions).If the agent falls back to a different provider,
agent.modelis updated in-place by_try_activate_fallback(), so the recorded value reflects whichever model actually produced the response.Tested on a live gateway across CLI and Telegram sessions.