Skip to content

fix(gateway): break stuck session resume loops on restart - #7747

Closed
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/gateway-stuck-session-resume-7536
Closed

fix(gateway): break stuck session resume loops on restart#7747
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/gateway-stuck-session-resume-7536

Conversation

@konsisumer

@konsisumer konsisumer commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #7536 — when a gateway session gets stuck (hung terminal command, runaway tool loop), restarting the gateway re-enters the stuck state because the agent reloads the session transcript and resumes the stuck task. This creates an unrecoverable loop.

Changes

  • suspended flag on SessionEntry — a new persisted boolean that, when set, causes get_or_create_session() to auto-reset the session (new session_id, clean transcript) on the next incoming message.
  • /stop marks session as suspended — both the early intercept (for truly hung agents) and the normal command handler now suspend the session, so the user's next message starts fresh instead of replaying stuck context.
  • Gateway startup suspends all active sessions — any session that was in-flight when the gateway last exited is marked suspended, preventing blind resume on restart.

How it works

  1. User's agent gets stuck → user sends /stop → session is suspended
  2. User's next message → get_or_create_session() sees suspended=True → auto-resets to a new session → fresh conversation
  3. If the gateway crashes (no /stop possible) → on restart, suspend_all_active() marks every existing session as suspended → same auto-reset behavior

What's NOT in this PR (future work)

Test plan

  • All 60 existing tests/gateway/test_session.py tests pass
  • All 17 test_session_reset_notify + test_session_reset_fix tests pass
  • Python syntax verified for both modified files

…ch#7536)

When a gateway session gets stuck (hung tool, runaway loop) and the user
restarts the gateway, the agent would reload the stuck session transcript
and re-enter the same stuck state — creating an unrecoverable loop.

Three changes break this cycle:

1. Add `suspended` flag to SessionEntry — when set, the session
   auto-resets (new session_id, clean transcript) on the next incoming
   message instead of resuming from where it left off.

2. `/stop` now marks the session as suspended — after force-stopping a
   stuck agent, the next message starts a fresh conversation instead of
   replaying the stuck context.

3. Gateway startup suspends all active sessions — any session that was
   in-flight when the gateway last exited is marked suspended, so it
   cannot be blindly resumed on restart.

Closes NousResearch#7536
@konsisumer
konsisumer marked this pull request as ready for review April 11, 2026 14:04
teknium1 pushed a commit that referenced this pull request Apr 11, 2026
Cherry-picked from PR #7747 with follow-up fixes:
- Narrowed suspend_all_active() to suspend_recently_active() — only
  suspends sessions updated within the last 2 minutes (likely in-flight),
  not all sessions which would unnecessarily reset idle users
- /stop with no running agent no longer suspends the session; only
  actual force-stops mark the session for reset
teknium1 pushed a commit that referenced this pull request Apr 11, 2026
Cherry-picked from PR #7747 with follow-up fixes:
- Narrowed suspend_all_active() to suspend_recently_active() — only
  suspends sessions updated within the last 2 minutes (likely in-flight),
  not all sessions which would unnecessarily reset idle users
- /stop with no running agent no longer suspends the session; only
  actual force-stops mark the session for reset
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #7910. Your commit was cherry-picked onto current main with authorship preserved, plus two follow-up fixes: suspend_all_active() narrowed to only recently-active sessions, and /stop with no running agent no longer suspends. Thanks for the stuck-resume-loop fix!

@teknium1 teknium1 closed this Apr 11, 2026
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
…ch#7536)

Cherry-picked from PR NousResearch#7747 with follow-up fixes:
- Narrowed suspend_all_active() to suspend_recently_active() — only
  suspends sessions updated within the last 2 minutes (likely in-flight),
  not all sessions which would unnecessarily reset idle users
- /stop with no running agent no longer suspends the session; only
  actual force-stops mark the session for reset
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 28, 2026
…ch#7536)

Cherry-picked from PR NousResearch#7747 with follow-up fixes:
- Narrowed suspend_all_active() to suspend_recently_active() — only
  suspends sessions updated within the last 2 minutes (likely in-flight),
  not all sessions which would unnecessarily reset idle users
- /stop with no running agent no longer suspends the session; only
  actual force-stops mark the session for reset
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
…ch#7536)

Cherry-picked from PR NousResearch#7747 with follow-up fixes:
- Narrowed suspend_all_active() to suspend_recently_active() — only
  suspends sessions updated within the last 2 minutes (likely in-flight),
  not all sessions which would unnecessarily reset idle users
- /stop with no running agent no longer suspends the session; only
  actual force-stops mark the session for reset
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…ch#7536)

Cherry-picked from PR NousResearch#7747 with follow-up fixes:
- Narrowed suspend_all_active() to suspend_recently_active() — only
  suspends sessions updated within the last 2 minutes (likely in-flight),
  not all sessions which would unnecessarily reset idle users
- /stop with no running agent no longer suspends the session; only
  actual force-stops mark the session for reset
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…ch#7536)

Cherry-picked from PR NousResearch#7747 with follow-up fixes:
- Narrowed suspend_all_active() to suspend_recently_active() — only
  suspends sessions updated within the last 2 minutes (likely in-flight),
  not all sessions which would unnecessarily reset idle users
- /stop with no running agent no longer suspends the session; only
  actual force-stops mark the session for reset
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
…ch#7536)

Cherry-picked from PR NousResearch#7747 with follow-up fixes:
- Narrowed suspend_all_active() to suspend_recently_active() — only
  suspends sessions updated within the last 2 minutes (likely in-flight),
  not all sessions which would unnecessarily reset idle users
- /stop with no running agent no longer suspends the session; only
  actual force-stops mark the session for reset
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] Stuck session resumes on restart — creates unrecoverable loop

2 participants