fix(gateway): emit session:end from idle-expiry and auto-reset paths (#28746)#32514
Open
Jiahui-Gu wants to merge 1 commit into
Open
fix(gateway): emit session:end from idle-expiry and auto-reset paths (#28746)#32514Jiahui-Gu wants to merge 1 commit into
Jiahui-Gu wants to merge 1 commit into
Conversation
…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>
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
session:endhook, breaking external observers (orphanrunningrows downstream).session:endwithreason="idle_expiry"afterexpiry_finalizedis set.get_or_create_sessionplumbs the closed priorsession_idvia a transientauto_reset_prior_session_idfield on the newSessionEntry;_handle_message_with_agentconsumes it and emitssession:endwithreason="auto_reset"before the newsession:start./new/resetemit site gainsreason="manual_reset"and the closedsession_idfor symmetry; docstring ingateway/hooks.pyupdated.Fixes #28746.
Test plan
pytest tests/gateway/test_session_reset_notify.py(19 passed; 3 new tests for prior-session-id plumbing + non-persistence)session:start/session:endhook, observe end-event fires on idle expiry (path A) and on auto-reset on the next turn (path B).Generated with Claude Code.