Skip to content

fix(gateway): consume was_auto_reset so /model survives session auto-reset (#48031)#51025

Merged
kshitijk4poor merged 1 commit into
mainfrom
salvage/cron-autoreset-override
Jun 24, 2026
Merged

fix(gateway): consume was_auto_reset so /model survives session auto-reset (#48031)#51025
kshitijk4poor merged 1 commit into
mainfrom
salvage/cron-autoreset-override

Conversation

@kshitijk4poor

@kshitijk4poor kshitijk4poor commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Problem

When /model X is the first message after an idle/daily/suspended auto-reset, the slash-command path stores a session model override but leaves session_entry.was_auto_reset = True (it never passes through _handle_message_with_agent, where the flag was consumed). On the next regular message, the auto-reset cleanup block pops the freshly-stored model/reasoning override before the flag is consumed — so the switch is silently lost and resolution falls back to the config default, while the session DB still shows the switched model (a two-sources-of-truth divergence). (#48031)

Fix

Consume was_auto_reset at both sites:

  1. gateway/run.py — capture the flag into a local and set the attribute False immediately at the top of the cleanup block, so the cleanup can't re-fire on a later message and wipe an override stored between turns. Downstream reads use the captured local.
  2. gateway/slash_commands.py — the model path consumes the flag before storing the override, so a /model-first-after-auto-reset isn't wiped by the next message's cleanup.

Salvage / credit

Salvaged from #48062 by @x7peeps (authorship preserved).

Tests

tests/gateway/test_48031_model_switch_after_auto_reset.py — AST invariants pinning both consume sites (load-bearing: verified they FAIL when either consume is removed). Mirrors the AST-pin approach in test_35809_auto_reset_clean_context.py. Gateway session/reset suite: 16 passed.

Closes

Fixes #48031


Review status

The automated review batch timed out on the slow full tests/gateway/ run, so I verified manually with a scoped suite + targeted edge-case checks:

  • (a) All downstream was_auto_reset reads in _handle_message_with_agent use the captured _was_auto_reset local (lines 8941, 8977); the only post-consume attribute writes are the False-assignments. No read depends on the flag still being True.
  • (b) The pre-existing notice-block clear (~line 9036) is now redundant for the flag but still clears auto_reset_reason — harmless, not conflicting.
  • (c) session_store.get_or_create_session() returns the same cached entry object for a given key (confirmed in gateway/session.py), so the slash-command path's consume mutates the same object the message handler later reads — the wipe is genuinely prevented.
  • AST-invariant tests verified to FAIL when either consume is removed (load-bearing). Scoped gateway suite (session/reset/boundary/slash): 22 passed.

@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/cron-autoreset-override vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11187 on HEAD, 11187 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5911 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery labels Jun 22, 2026
@kshitijk4poor
kshitijk4poor force-pushed the salvage/cron-autoreset-override branch from dc51f20 to fe12d30 Compare June 24, 2026 13:42
…reset

When `/model X` is the FIRST message after an idle/daily/suspended auto-reset,
the slash-command path stores a session model override but leaves
`session_entry.was_auto_reset = True` (it never passes through
`_handle_message_with_agent`, which is where the flag was consumed). On the
NEXT regular message, the auto-reset cleanup block pops the freshly-stored
model/reasoning override BEFORE the flag is consumed — so the switch is
silently lost and resolution falls back to the config default, while the
session DB still shows the switched model (a two-sources-of-truth divergence).

Consume the flag at both sites:
  1. gateway/run.py — capture `was_auto_reset` into a local and set the
     attribute False immediately at the top of the cleanup block, so the
     cleanup can't re-fire on a later message and wipe an override stored
     between turns. Downstream reads use the captured local.
  2. gateway/slash_commands.py — the model path consumes the flag before
     storing the override, so a /model-first-after-auto-reset isn't wiped by
     the next message's cleanup.

Salvaged from #48062 by x7peeps (authorship preserved).

Tests: tests/gateway/test_48031_model_switch_after_auto_reset.py — AST
invariants pinning both consume sites (load-bearing; verified they fail when
either consume is removed). Mirrors the AST-pin approach in
test_35809_auto_reset_clean_context.py. Gateway session/reset suite: 16 passed.

Fixes #48031
@kshitijk4poor
kshitijk4poor force-pushed the salvage/cron-autoreset-override branch from fe12d30 to 6879d77 Compare June 24, 2026 13:42
@kshitijk4poor
kshitijk4poor enabled auto-merge June 24, 2026 13:45
@kshitijk4poor
kshitijk4poor merged commit ae20c3f into main Jun 24, 2026
27 checks passed
@kshitijk4poor
kshitijk4poor deleted the salvage/cron-autoreset-override branch June 24, 2026 13:50
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…autoreset-override

fix(gateway): consume was_auto_reset so /model survives session auto-reset (NousResearch#48031)
liuchanchen pushed a commit to liuchanchen/hermes-agent that referenced this pull request Jul 3, 2026
…autoreset-override

fix(gateway): consume was_auto_reset so /model survives session auto-reset (NousResearch#48031)
Methodician added a commit to Methodician/hermes-agent that referenced this pull request Jul 4, 2026
…autoreset-override

fix(gateway): consume was_auto_reset so /model survives session auto-reset (NousResearch#48031)
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…autoreset-override

fix(gateway): consume was_auto_reset so /model survives session auto-reset (NousResearch#48031)
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…autoreset-override

fix(gateway): consume was_auto_reset so /model survives session auto-reset (NousResearch#48031)
kulikman pushed a commit to kulikman/hermes-agent that referenced this pull request Jul 16, 2026
…autoreset-override

fix(gateway): consume was_auto_reset so /model survives session auto-reset (NousResearch#48031)
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…autoreset-override

fix(gateway): consume was_auto_reset so /model survives session auto-reset (NousResearch#48031)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/model switch silently lost when first message after session auto-reset (was_auto_reset flag never consumed)

3 participants