Skip to content

Ignore stale WebSocket lifecycle events after reconnect#2372

Merged
juliusmarminge merged 1 commit into
mainfrom
feature/ignore-stale-ws-lifecycle
Apr 27, 2026
Merged

Ignore stale WebSocket lifecycle events after reconnect#2372
juliusmarminge merged 1 commit into
mainfrom
feature/ignore-stale-ws-lifecycle

Conversation

@juliusmarminge
Copy link
Copy Markdown
Member

@juliusmarminge juliusmarminge commented Apr 27, 2026

  • Gate protocol lifecycle callbacks on the active session
  • Prevent old sockets from mutating connection state after reconnect
  • Add regression coverage for stale close handling

What Changed

Why

UI Changes

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk
Touches core WebSocket transport/protocol lifecycle handling and reconnect behavior; a mistake could suppress legitimate connection state updates or mask errors.

Overview
Prevents old WebSocket sessions from updating connection/error state after a WsTransport.reconnect() by introducing an isActive guard on protocol lifecycle callbacks.

WsTransport now assigns a per-session id and passes an isActive predicate into createWsRpcProtocolLayer, while tests add regression coverage ensuring a stale socket close does not trigger onClose or overwrite the current connection status.

Reviewed by Cursor Bugbot for commit 3f6bcd8. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Ignore stale WebSocket lifecycle events after reconnect in WsTransport

  • Introduces per-session tracking (nextSessionId/activeSessionId) in WsTransport so each connection attempt gets a unique session ID.
  • Adds an isActive(): boolean hook to the WsProtocolLifecycleHandlers interface in protocol.ts; onAttempt, onOpen, onError, and onClose are skipped when isActive() returns false.
  • When a reconnect starts, the previous session's isActive returns false, so any late-arriving lifecycle events (e.g. a close from the old socket) are silently ignored instead of mutating connection state.
  • Behavioral Change: lifecycle callbacks from stale sessions no longer fire, which prevents spurious onClose calls from updating connection status after a reconnect.

Macroscope summarized 3f6bcd8.

- Gate protocol lifecycle callbacks on the active session
- Prevent old sockets from mutating connection state after reconnect
- Add regression coverage for stale close handling
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7929dcb2-4117-45c8-aa76-83afad42db2e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/ignore-stale-ws-lifecycle

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

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Apr 27, 2026
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Apr 27, 2026

Approvability

Verdict: Approved

Straightforward bug fix that adds session ID tracking to prevent stale WebSocket lifecycle events from being processed after reconnection. The change is self-contained, includes comprehensive tests, and has no side effects outside the WebSocket transport layer.

You can customize Macroscope's approvability policy. Learn more.

@juliusmarminge juliusmarminge merged commit dbebc38 into main Apr 27, 2026
12 checks passed
@juliusmarminge juliusmarminge deleted the feature/ignore-stale-ws-lifecycle branch April 27, 2026 16:50
Morphexe pushed a commit to Morphexe/t3code that referenced this pull request May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant