fix(desktop): require session_id for all session-scoped gateway events - #52025
fix(desktop): require session_id for all session-scoped gateway events#52025Sahil-SS9 wants to merge 1 commit into
Conversation
Previously only subagent.* events required an explicit session_id. All other events (message, tool, reasoning, session.info, etc.) fell through to activeSessionIdRef.current when unscoped, causing background session output to bleed into the focused chat. Expand gatewayEventRequiresSessionId to require session_id for all session-scoped events. Only truly global broadcasts (gateway.ready, skin.changed) are exempt. Fixes NousResearch#49106 (Web/WeChat session history leak) Fixes NousResearch#47709 (Desktop stream-bleed: newer session output in older session)
Duplicate of #49659 — verified by comparing diffs: both PRs make the identical change to Related competing approaches that take a different mechanism (pin/resolve unscoped events to their originating session instead of dropping): #48281 and #47743. Maintainer should pick one mechanism across this cluster. |
|
Thanks @alt-glitch for flagging. You're right — #49659 made the same fix, and mine is a duplicate. I'll close this PR. Appreciate the pointer to #48281 and #47743 as well — I'll review those approaches. |
|
Closing as duplicate of #49659 — same fix authored independently. No further action needed on this branch. |
Fixes #49106
Fixes #47709
Description
Previously only
subagent.*events required an explicit session_id.All other events (
message.delta,message.complete,tool.start,tool.complete,reasoning.delta,session.info,clarify.request,approval.request, etc.) fell through toactiveSessionIdRef.currentwhen unscoped, causing background session output to bleed into whichever
session the user was currently viewing.
This was the root cause of:
Fix
Expanded
gatewayEventRequiresSessionIdto requiresession_idfor allsession-scoped events. Only truly global broadcasts (
gateway.ready,skin.changed) are exempt. Unknown event types are also required tohave a session_id (defensive).
The tui_gateway already stamps every session-scoped event with the
correct
session_id, so this change is safe in normal operation.If the gateway ever fails to stamp one (race, background-process
delivery, subagent mirror, stale transport), dropping is safer than
silently attributing to the focused session.
Verification
gateway-events.test.ts)C1 (conventional commits), C2 (no em-dashes), F1 (focused diff) all pass