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
teknium1
reviewed
Jul 13, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for the focused lifecycle-hook fix. The omission is still present on current main: session:start lacks chat_id at gateway/run.py:10842-10847, and session:end / session:reset lack it at gateway/slash_commands.py:238-250.
Problems
- The PR's two reset edits target the pre-refactor location in
gateway/run.py;_handle_reset_commandmoved togateway/slash_commands.pyin619bd7827, so those hunks need to be applied there. tests/gateway/test_session_boundary_hooks.pyadds coverage forsession:endandsession:reset, but not the newsession:startfield.- The public event-context table at
website/docs/user-guide/features/hooks.md:78-80does not yet describechat_idfor these lifecycle events.
Suggested changes
- Move the reset payload additions to
gateway/slash_commands.py:239-250and add asession:startcontext assertion. - Document the additive
chat_idkey for all three lifecycle events.
Automated hermes-sweeper review.
| await self.hooks.emit("session:start", { | ||
| "platform": source.platform.value if source.platform else "", | ||
| "user_id": source.user_id, | ||
| "chat_id": source.chat_id or "", |
Contributor
There was a problem hiding this comment.
Please add a companion regression test for this session:start payload. The new tests cover session:end and session:reset, but not this third added field.
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