fix: backfill model on gateway sessions after agent runs#996
Closed
heyalchang wants to merge 1 commit intoNousResearch:mainfrom
Closed
fix: backfill model on gateway sessions after agent runs#996heyalchang wants to merge 1 commit intoNousResearch:mainfrom
heyalchang wants to merge 1 commit intoNousResearch:mainfrom
Conversation
Gateway sessions had NULL model because the session is created before the AIAgent is constructed. Now update_session() accepts a model param and backfills it via COALESCE (only fills NULL, never overwrites). Upstream: NousResearch#987 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
Redone as #997 — squashed to a single commit and cleaned up whitespace noise in the diff. |
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 session is created beforeAIAgentis constructed. After the agent responds,update_session()writes token counts but never backfills the model.This adds the model to
_run_agent()'s return dict and threads it throughupdate_session()→update_token_counts(). The SQL usesCOALESCE(model, ?)so it only fills NULL — never overwrites a model that was set at creation time (e.g. CLI sessions).If the agent falls back to a different provider/model,
agent.modelis updated in-place by_try_activate_fallback(), so the recorded model reflects whichever model actually produced the response.Tested on a live gateway — new sessions now show the correct model in the DB. Older sessions with NULL are unaffected (COALESCE only fires on the next
update_session()call, not retroactively).