Skip to content

fix(gateway): emit session:end from idle-expiry and auto-reset paths (#28746)#32514

Open
Jiahui-Gu wants to merge 1 commit into
NousResearch:mainfrom
Jiahui-Gu:fix/session-end-event-28746
Open

fix(gateway): emit session:end from idle-expiry and auto-reset paths (#28746)#32514
Jiahui-Gu wants to merge 1 commit into
NousResearch:mainfrom
Jiahui-Gu:fix/session-end-event-28746

Conversation

@Jiahui-Gu

Copy link
Copy Markdown
Contributor

Summary

  • Idle-expiry watcher and auto-reset previously closed sessions without emitting the gateway-level session:end hook, breaking external observers (orphan running rows downstream).
  • Expiry watcher now emits session:end with reason="idle_expiry" after expiry_finalized is set.
  • get_or_create_session plumbs the closed prior session_id via a transient auto_reset_prior_session_id field on the new SessionEntry; _handle_message_with_agent consumes it and emits session:end with reason="auto_reset" before the new session:start.
  • Existing /new /reset emit site gains reason="manual_reset" and the closed session_id for symmetry; docstring in gateway/hooks.py updated.

Fixes #28746.

Test plan

  • pytest tests/gateway/test_session_reset_notify.py (19 passed; 3 new tests for prior-session-id plumbing + non-persistence)
  • Manual: install a session:start / session:end hook, observe end-event fires on idle expiry (path A) and on auto-reset on the next turn (path B).

Generated with Claude Code.

…ousResearch#28746)

Previously session:end fired only on explicit /new and /reset. Idle-expiry
watcher and auto-reset (get_or_create_session stale-replace) closed sessions
silently, leaving external hook subscribers with orphan running rows.

- Expiry watcher: emit session:end with reason="idle_expiry" after
  expiry_finalized is set.
- get_or_create_session: plumb the closed session_id onto the new
  SessionEntry via a transient auto_reset_prior_session_id field.
- _handle_message_with_agent: when starting a new session that replaced a
  prior one via auto-reset, emit session:end (reason="auto_reset") for the
  prior session_id before session:start.
- Add reason="manual_reset" to the existing /new /reset emit site and
  session_id to its payload for symmetry.
- Update gateway/hooks.py docstring to describe the new contract.
- Tests cover the SessionEntry plumbing + non-persistence of the transient
  field.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #28750 which already fixes session:end emission from idle-expiry watcher and auto-reset paths (#28746).

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists labels May 26, 2026
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 duplicate This issue or pull request already exists 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.

[Bug]: gateway session:end event not emitted from idle-expiry watcher or auto-reset path

3 participants