Skip to content

fix(tui): drop cross-session events during null-sid switch window (#51058) - #53936

Open
yingliang-zhang wants to merge 2 commits into
NousResearch:mainfrom
yingliang-zhang:fix/tui-null-sid-event-filter
Open

fix(tui): drop cross-session events during null-sid switch window (#51058)#53936
yingliang-zhang wants to merge 2 commits into
NousResearch:mainfrom
yingliang-zhang:fix/tui-null-sid-event-filter

Conversation

@yingliang-zhang

Copy link
Copy Markdown
Contributor

Problem

During session switch/reset, getUiState().sid is momentarily null. The old event filter ev.session_id && sid && ev.session_id !== sid short-circuits to false when sid is null, so events from any live session bleed into the view — the cross-session bleed reported in #51058.

Fix

Change the condition so that when sid is null, all non-gateway session events are dropped:

- if (ev.session_id && sid && ev.session_id !== sid && !ev.type.startsWith('gateway.')) {
+ if (ev.session_id && (!sid || ev.session_id !== sid) && !ev.type.startsWith('gateway.')) {

(!sid || ev.session_id !== sid) means: drop the event if there is no active session or the event belongs to a different session. Gateway-meta events (gateway.*) are still always allowed through.

Scope

1 file, 1 condition change. Supersedes #53928 which was opened from a main branch and accidentally bundled 3 unrelated fixes.

Closes #51058

@alt-glitch alt-glitch added type/bug Something isn't working comp/tui Terminal UI (ui-tui/ + tui_gateway/) sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state P2 Medium — degraded but workaround exists labels Jun 28, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Clean one-line fix for cross-session event bleed during null-sid switch (#51058). The change from ev.session_id !== sid to !sid || ev.session_id !== sid ensures ALL non-gateway session events are dropped when sid is null (during session switch/reset). This prevents another live session's events from bleeding into the view.


Reviewed by Hermes Agent

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for isolating the TUI routing window; current main still has the null-sid short-circuit at ui-tui/src/app/createGatewayEventHandler.ts:407, and resetSession() does set sid: null at ui-tui/src/app/useSessionLifecycle.ts:159.

Problems

  • The proposed predicate starts with evSid && (ui-tui/src/app/createGatewayEventHandler.ts:418 in this diff), so session_id: '' bypasses it. That does not implement the PR's stated empty-string filtering.
  • The new negative tests do not exercise transcript routing. message.delta only records buffered state (ui-tui/src/app/createGatewayEventHandler.ts:939-942); assistant messages are appended on message.complete (:943-949). The new cases send only a delta before asserting no appended assistant message. The length >= 0 checks are tautological.

Suggested changes

  • Preserve the null-sid fix, and align the empty-ID behavior with a verified event contract.
  • Make the regression tests send a sequence that would append without filtering, including message.complete, then assert the transcript remains unchanged for rejected sessions.

Automated hermes-sweeper review.

Comment thread ui-tui/src/app/createGatewayEventHandler.ts Outdated
@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 15, 2026
@yingliang-zhang

Copy link
Copy Markdown
Contributor Author

Addressed the automated review in a4965755413ec9d9e2c4a9080c8725b1b99812cd.\n\n- Distinguished a truly absent session_id (unscoped) from an explicitly present empty ID (invalid scoped event).\n- Non-global explicit empty/foreign events are rejected unless they match the active session; global skin events remain accepted.\n- Replaced tautological checks with real message.delta + message.complete transcript sequences.\n- Full affected Ink file: 83 passed, 0 failed. Typecheck, scoped ESLint, Prettier, and git diff --check passed.

@teknium1 teknium1 added the area/sessions Session lifecycle, resume, persistence, history label Jul 19, 2026
@yingliang-zhang
yingliang-zhang force-pushed the fix/tui-null-sid-event-filter branch from a496575 to ee6b42b Compare July 20, 2026 17:33
…ross-session bleed (NousResearch#51058)

Rebased on current upstream/main. Combines two fixes:
1. null-sid guard: when sid is null during session switch/reset, drop ALL
   non-gateway events instead of letting them through (original NousResearch#51058 fix)
2. empty-string session_id: _emit() can set session_id='' when callers
   omit it. Use explicit equality (evSid !== sid) instead of truthiness,
   and broaden global-event bypass to gateway./pet./skin./billing.

Closes NousResearch#51058

(cherry picked from commit 638fc85ba945da7eb0a10b066a4237266d55515d)
(cherry picked from commit ee6b42b7c42fed7e376a79e4426c6aafc5577d35)
@yingliang-zhang
yingliang-zhang force-pushed the fix/tui-null-sid-event-filter branch from ee6b42b to 3cd3597 Compare August 16, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/tui Terminal UI (ui-tui/ + tui_gateway/) P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI/Desktop session mix-up after context compression / reconnect resumes the wrong chat

4 participants