fix(gateway): add chat_id to session:start, session:end, and session:reset hook contexts#24982
Open
AhmetArif0 wants to merge 1 commit into
Open
Conversation
…reset hook contexts _handle_message_with_agent() emits session:start and _handle_reset_command() emits session:end and session:reset, but none of them included chat_id in the hook context. Hook authors who subscribe to session lifecycle events cannot identify which conversation the session belongs to, making routing (e.g. sending a welcome message on session:start or cleanup on session:end) impossible. Fix: mirror the "chat_id": source.chat_id or "" field added to agent:start by NousResearch#24710 into the three sibling session hooks. source is in scope at all three emit sites and chat_id is a required str field on SessionSource.
This was referenced May 19, 2026
Open
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.
What does this PR do?
Root cause:
_handle_message_with_agent()emitssession:startand_handle_reset_command()emitssession:endandsession:reset, but none of them includedchat_idin the hook context. Hook authors who subscribe to session lifecycle events cannot identify which conversation the session belongs to, making routing (e.g. sending a welcome message onsession:startor cleanup onsession:end) impossible without it.Fix: mirror the
"chat_id": source.chat_id or ""field added toagent:startby #24710 into the three sibling session hooks.sourceis in scope at all three emit sites andchat_idis a requiredstrfield onSessionSource, so no guard is needed beyond the existingor ""fallback.Type of Change
Changes Made
gateway/run.py: add"chat_id"tosession:start(+1 line),session:end(+1 line),session:reset(+1 line) hook contextstests/gateway/test_session_boundary_hooks.py: two new tests assertingchat_idis present insession:endandsession:resetcontextsHow to Test
Checklist