Skip to content

fix: backfill model on gateway sessions after agent runs#997

Open
heyalchang wants to merge 1 commit intoNousResearch:mainfrom
heyalchang:fix/backfill-session-model
Open

fix: backfill model on gateway sessions after agent runs#997
heyalchang wants to merge 1 commit intoNousResearch:mainfrom
heyalchang:fix/backfill-session-model

Conversation

@heyalchang
Copy link

Fixes #987

Gateway sessions have model = NULL because the row is created before AIAgent is constructed. After the agent responds, update_session() writes token counts but never fills in the model.

This threads agent.model through _run_agent()'s return dict into update_session()update_token_counts(). The SQL uses COALESCE(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.model is 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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gateway sessions have NULL model in DB

1 participant