Skip to content

Fix/session streamed to another chat#318

Merged
viper151 merged 4 commits intomainfrom
fix/session-streamed-to-another-chat
Jan 25, 2026
Merged

Fix/session streamed to another chat#318
viper151 merged 4 commits intomainfrom
fix/session-streamed-to-another-chat

Conversation

@blackmammoth
Copy link
Collaborator

@blackmammoth blackmammoth commented Jan 20, 2026

This fixes an issue with streaming response to another session when clicking another session while the current session is still not finished.

Summary by CodeRabbit

  • New Features

    • Outgoing messages now carry session context so session-aware tooling and usage reporting remain linked to the correct chat.
    • UI adds a pending-view guard and reset behavior to keep new chat views isolated during initial streaming.
  • Bug Fixes

    • Prevented background streaming and error messages from leaking into the active chat view.
    • Improved session-switch handling and token-budget reporting for accurate per-session state.

✏️ Tip: You can customize this high-level summary in your review settings.

@blackmammoth blackmammoth requested a review from viper151 January 20, 2026 10:23
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 20, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

This change consistently attaches sessionId to WebSocket messages across server modules and updates the ChatInterface to scope streaming and session-switch behavior using a pending-session ref and streaming reset logic.

Changes

Cohort / File(s) Summary
Server: WebSocket message sessionId propagation
server/claude-sdk.js, server/openai-codex.js
Attach sessionId (capturedSessionId
Server: Cursor CLI session propagation & errors
server/cursor-cli.js
Propagate sessionId on nearly all outbound WS messages (cursor-system, cursor-user, cursor-response, cursor-output, cursor-error, claude-response deltas/stops), capture session_id from init messages, and include sessionId on fallback/non-JSON and error paths.
Client: Chat view/session-scoped streaming & state
src/components/ChatInterface.jsx
Add pendingViewSessionRef and resetStreamingState; reset view state on session switches (non-system), gate incoming WS messages with isSystemInitForView / pending-session checks to prevent cross-view streaming, and clear pending markers when the real session is ready.

Sequence Diagram

sequenceDiagram
    actor User
    participant ChatInterface as ChatInterface (Client)
    participant WebSocket as WebSocket
    participant Server as Server (claude-sdk / cursor-cli / openai-codex)

    User->>ChatInterface: Start new chat / switch session
    ChatInterface->>ChatInterface: set pendingViewSessionRef
    ChatInterface->>WebSocket: emit session init / subscribe

    WebSocket->>Server: init received
    Server->>Server: capture sessionId
    Server->>WebSocket: send claude-response / token-budget / error (+ sessionId)

    WebSocket->>ChatInterface: deliver message (+ sessionId)
    ChatInterface->>ChatInterface: isSystemInitForView? / match pendingViewSessionRef
    alt Message matches current view
        ChatInterface->>ChatInterface: apply updates, clear pendingViewSessionRef
        ChatInterface->>User: render content
    else Message for background session
        ChatInterface->>ChatInterface: route to background handler (no view streaming)
    end

    User->>ChatInterface: switch away
    ChatInterface->>ChatInterface: resetStreamingState(), reset UI state
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

Possibly related PRs

Poem

🐰 Hopping through websockets, I carry a key,

sessionId tucked in each message for thee,
Pending views guarded, streams kept in place,
No cross-talk now — each chat finds its space,
A rabbit's small nod to tidy session grace. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix/session streamed to another chat' accurately describes the main issue being addressed: preventing streaming responses from being delivered to incorrect sessions when users switch between chats.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@viper151 viper151 merged commit 0d1a3df into main Jan 25, 2026
1 check was pending
@viper151 viper151 deleted the fix/session-streamed-to-another-chat branch February 3, 2026 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants