fix(tui): sync ctx.sid on session.info after compression fork (#36777)#36811
Open
luyao618 wants to merge 1 commit into
Open
fix(tui): sync ctx.sid on session.info after compression fork (#36777)#36811luyao618 wants to merge 1 commit into
luyao618 wants to merge 1 commit into
Conversation
When /compress forks the session (ends parent, creates continuation), the gateway emits session.info with the new session_id, but the TUI event handler dropped sid updates on the floor — leaving ctx.sid pointing at the closed parent session and breaking subsequent RPCs. Two interlocking bugs: 1. The top-level guard in createGatewayEventHandler dropped any event whose ev.session_id differed from state.sid (except gateway.*). That meant the post-compression session.info — which by definition carries a *different* sid — was silently discarded before reaching any case handler. 2. The session.info case patched info/status/usage but never touched state.sid, so even if the event arrived, the UI would not re-anchor onto the new continuation session. Fix: - Allow 'session.info' through the sid guard so the compression-fork event still reaches the handler. - In the session.info handler, read ev.session_id (set by the gateway _emit envelope) and update state.sid when it differs. Vitest covers both update-on-mismatch and no-op-on-match. Fixes NousResearch#36777
13 tasks
mxnstrexgl
approved these changes
Jun 1, 2026
mxnstrexgl
left a comment
There was a problem hiding this comment.
🤖 Automated PR Review
Security Scan
- ✓ No hardcoded secrets, injection sinks, unsafe deserialization, or dependency red flags found by this automated scan.
Code Quality
- ✓ No blocking code-quality issues found by this automated scan.
Summary
Status: APPROVE — security findings: 0, quality suggestions: 0.
Automated review; raw diff content intentionally omitted.
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
Fixes #36777. After
/compressforks the TUI session (ends parent, creates continuation), the gateway emitssession.infowith the newsession_id— but the TUI handler was dropping the update on the floor, leavingctx.sidpointing at the closed parent session. All subsequent RPCs (message submission,/image,/model, etc.) then targeted the dead session.Root cause
Two interlocking bugs in
ui-tui/src/app/createGatewayEventHandler.ts:ev.session_iddiffered fromstate.sid(exceptgateway.*). The post-compressionsession.info— which by definition carries a different sid — was silently discarded before any case ran.session.infocase only patchedinfo/status/usage— neversid.The gateway side (
tui_gateway/server.py::_sync_session_key_after_compress,_emit("session.info", new_sid, ...)) is correct; the bug was purely on the TS receiver.Fix
session.infopast the sid mismatch guard so the compression-fork event reaches the handler.session.infocase, readev.session_id(set by the gateway_emitenvelope) and updatestate.sidwhen it differs.Testing
ui-tui/src/__tests__/createGatewayEventHandler.test.ts:sidwhenev.session_iddiffers (compression fork)sidunchanged when it matches or is absentnpx vitest run src/__tests__/createGatewayEventHandler.test.ts→ 52/52 passnpx tsc --noEmit→ no new errors in touched filesNotes
info.session_idfrom the payload, but the gateway putssession_idon the event envelope (_emitlineparams = {"type": event, "session_id": sid}), not in the payload dict — so this PR usesev.session_id, which is the source of truth and is what the existing guard also reads.