Skip to content
Source
Sign inSign up
pingdotgg/t3code

Preserve live stream subscriptions across explicit reconnects #1972

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/1972/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Summary

  • Preserve active WebSocket stream subscriptions when the transport is explicitly reconnected.
  • Avoid resubscribing against a stale session after reconnect by checking the session that initiated the stream.
  • Add coverage for reconnecting an active subscription and verifying the listener resumes on the new socket.

Testing

  • Added apps/web/src/rpc/wsTransport.test.ts coverage for explicit reconnect behavior.
  • Not run: bun fmt
  • Not run: bun lint
  • Not run: bun typecheck
  • Not run: bun run test

Note

Medium Risk Touches WsTransport.subscribe retry logic during reconnects, which could affect real-time stream reliability if session tracking is wrong. Scope is small and guarded by a new reconnect resubscription test.

Overview Active WsTransport.subscribe streams now survive an explicit reconnect() by continuing the subscription loop on the new session and skipping retry/resubscribe handling for errors from the old session.

Adds a Vitest case asserting that a live stream listener is re-subscribed on the new socket after reconnect(), with onResubscribe firing and events continuing to deliver.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit c1c0ae4e7cf08c6f7f54a3ad38584b06a278508b. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Preserve live stream subscriptions across explicit reconnects in WsTransport

  • When transport.reconnect() is called, the subscription loop now captures a session snapshot at the start of each iteration and checks in the catch block whether the session has changed; if so, the error is ignored and the loop continues immediately.
  • This allows listeners to re-subscribe on the new session without prematurely terminating or logging a spurious disconnect for the stale session.
  • A new test in wsTransport.test.ts verifies that after reconnect, a new subscribe request is sent, onResubscribe fires once, and subsequent events are delivered to the original listener.
Macroscope summarized c1c0ae4.
    1. 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: 0dc8d624-848d-4331-8027-382cd9bb183a

      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 `t3code/resume-stream-subscriptions`

      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. Approvability

      Verdict: Approved

      Small bug fix that captures WebSocket session state earlier in a subscription loop and adds a staleness check to prevent processing errors from old sessions after an explicit reconnect. The change is minimal (4 lines), well-tested, and the author is a frequent contributor to this file.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. juliusmarminge merged this94d13a2

    5. juliusmarminge closed this

Sign in to join this conversation.