Skip to content

Core: Remove client-side WebSocket timeout detection - #36244

Merged
JReinhold merged 1 commit into
nextfrom
jeppe-cursor/drop-client-ws-timeout-235e
Sep 9, 2026
Merged

JReinhold merged 1 commit into
nextfrom
jeppe-cursor/drop-client-ws-timeout-235e

Conversation

@JReinhold

Copy link
Copy Markdown
Contributor

Closes #

Related: #36229 (perf fixes stay there; this is the timeout-detection follow-up from review).

What I did

Removed the client-side WebSocket receive watchdog that closed /storybook-server-channel with code 3008 and showed Server timed out.

That 20s setTimeout ran on the manager main thread. A busy UI (large Component Testing run, webpack compile, CLI docgen) made the timer fire late, so a healthy server looked dead. The original user report this code was added for (#28258, shipped in #30288) was a false disconnect during webpack, not a hung TCP connection.

A crashed or killed server already closes the socket. The manager still shows Connection lost on CHANNEL_WS_DISCONNECT. Server JSON ping every 15s and client pong stay in place so idle proxies and NATs do not drop a quiet tab.

Also removed:

  • enableHeartbeat, pauseHeartbeat, and resumeHeartbeat (the CLI already had to disable the watchdog because the same event loop blocked past 20s)
  • The Server timed out toast branch and the ServerTimedOut story
  • Unused HEARTBEAT_MAX_LATENCY export

The leftover gap is a process that is frozen (SIGSTOP, deadlock) with TCP still open. That case was never the filed bug, and this detector could not tell it apart from a busy manager.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

  1. From the repo root: yarn then yarn nx compile core.
  2. Start the internal UI: cd code && yarn storybook:ui.
  3. Open http://localhost:6006/?path=/story/manager-main--connection-lost. Confirm the toast headline is Connection lost, and that there is no Server Timed Out story under Manager / Main.
  4. In DevTools → Network, select the storybook-server-channel WebSocket. Confirm {type:"ping"} still arrives from the server about every 15s and the client replies {type:"pong"}.
  5. Click Run tests in the Testing widget and let a full run finish. Confirm there is no Server timed out / Connection lost notification while the server is healthy.
  6. Stop the Storybook process without reloading the manager. Confirm the toast is Connection lost (not Server timed out), and that the socket closes because the server went away, not after a 20s client timer.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Declare whether manual QA will be needed for this PR during the next release, through qa:needed or qa:skip

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.
Open in Web Open in Cursor 

A 20s receive watchdog on the manager main thread measured browser
busyness, not a dead server, and closed healthy connections with 3008.
Server crashes already close the socket. Keep ping/pong for proxy keepalive.

Co-authored-by: Jeppe Reinhold <JReinhold@users.noreply.github.com>
@JReinhold JReinhold added addon: vitest bug ci:normal Run our default set of CI jobs (choose this for most PRs). core qa:skip Pull Requests that do not need any QA. (e.g. documentation) labels Sep 9, 2026 — with Cursor
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 900d5daa-9c7a-4dd5-bfb4-2006e6b679cb

📥 Commits

Reviewing files that changed from the base of the PR and between 2623153 and e7f59fc.

📒 Files selected for processing (8)
  • code/core/src/channels/index.ts
  • code/core/src/channels/websocket/index.test.ts
  • code/core/src/channels/websocket/index.ts
  • code/core/src/cli/tools/sdk/node-channel.test.ts
  • code/core/src/cli/tools/sdk/node-channel.ts
  • code/core/src/manager/globals/exports.ts
  • code/core/src/manager/index.stories.tsx
  • code/core/src/manager/runtime.tsx
💤 Files with no reviewable changes (2)
  • code/core/src/manager/globals/exports.ts
  • code/core/src/cli/tools/sdk/node-channel.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The WebSocket transport no longer implements heartbeat timers or timeout closures. Related exports, tests, Node transport configuration, and manager disconnect handling now use generic connection-loss behavior.

Changes

WebSocket heartbeat removal

Layer / File(s) Summary
Remove heartbeat handling
code/core/src/channels/websocket/index.ts, code/core/src/channels/index.ts, code/core/src/channels/websocket/index.test.ts
The transport removes heartbeat configuration, timers, timeout cleanup, and the HEARTBEAT_MAX_LATENCY export. Tests verify persistent connections and pong handling.
Update Node transport behavior
code/core/src/cli/tools/sdk/node-channel.ts, code/core/src/cli/tools/sdk/node-channel.test.ts
The Node channel removes its heartbeat override. The disconnect test uses WebSocket close code 1000 with an empty reason.
Simplify disconnect reporting
code/core/src/manager/runtime.tsx, code/core/src/manager/index.stories.tsx, code/core/src/manager/globals/exports.ts
Manager disconnect handling always reports “Connection lost” and no longer checks timeout code 3008. The global heartbeat export is removed.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to e7f59

The manager no longer closes healthy WebSocket connections based on delayed browser timer execution, while retaining generic connection-loss reporting and ping/pong keepalive behavior. No concrete current-head merge risk remains.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@kasperpeulen kasperpeulen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. This is the right fix: the 20s watchdog measured how busy the client was, not whether the server was alive. Keeping the server ping and client pong for proxies is fine.

@JReinhold
JReinhold merged commit c084968 into next Sep 9, 2026
177 of 187 checks passed
@JReinhold
JReinhold deleted the jeppe-cursor/drop-client-ws-timeout-235e branch September 9, 2026 12:14
@github-actions github-actions Bot mentioned this pull request Sep 9, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal Run our default set of CI jobs (choose this for most PRs). core qa:skip Pull Requests that do not need any QA. (e.g. documentation)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants