Skip to content

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

Merged
teknium1 merged 3 commits intomainfrom
hermes/hermes-2ba57c8a
Mar 14, 2026
Merged

fix: backfill model on gateway sessions after agent runs#1306
teknium1 merged 3 commits intomainfrom
hermes/hermes-2ba57c8a

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

Summary

  • salvage PR fix: backfill model on gateway sessions after agent runs #997 onto current main by backfilling gateway session models after agent runs so sessions created before agent construction no longer remain NULL in SQLite
  • preserve the contributor’s COALESCE(model, ?) behavior so existing session models are never overwritten
  • add regression coverage for model backfill/preservation plus a small compatibility fix so _run_agent() tolerates fake agents and test doubles that do not define a model attribute

Contributor credit

Test plan

  • python -m pytest tests/test_hermes_state.py tests/gateway/test_session.py tests/gateway/test_reasoning_command.py tests/gateway/test_run_progress_topics.py -n0 -q
  • python -m pytest tests/ -n0 -q

Closes #987

heyalchang and others added 3 commits March 14, 2026 06:42
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 #987
Add regression coverage for backfilling NULL gateway session models in SQLite, preserving existing models, and forwarding the resolved agent model through SessionStore updates.
Use getattr() when returning model metadata from GatewayRunner._run_agent so fake agents and minimal stubs without a model attribute do not break unrelated gateway flows while preserving the session-model backfill behavior.
@teknium1 teknium1 merged commit 917adcb into main Mar 14, 2026
1 check passed
@teknium1 teknium1 deleted the hermes/hermes-2ba57c8a branch March 14, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants