Repository navigation
refactor(workspace-client,web): standardize reconnecting WS clients on partysocket - #5637
Conversation
…n partysocket (SUPER-1469) Adds createRelaySocket — a thin wrapper over partysocket's generic reconnecting WebSocket that re-signs the URL with a fresh token and runs the _whoowns preflight before every attempt, treats a preflight 403 as a definitive denial (permanent close, or slow-poll via accessDeniedRetryMs), and keeps send semantics unbuffered. Migrates the two simplest hand-rolled reconnect loops onto it with zero consumer changes: - workspace-client eventBus (desktop host events) - apps/web WebTerminal TerminalConnection (kept attempt budget, visibility resume, and replay-suppression semantics; web now also gets the fly-affinity preflight) The desktop terminal transport is deferred by design — see plans/done/20260712-partysocket-ws-consolidation.md. Spike result: a rejecting async url provider surfaces as an error event and re-enters partysocket's backoff (verified in source and empirically), so the preflight can safely live inside the url provider.
|
Ready to review this PR? Stage has broken it down into 7 individual chapters for you: Chapters generated by Stage for commit 7005f11 on Jul 12, 2026 9:41pm UTC. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe change adds a shared ChangesRelay transport consolidation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant EventBus
participant TerminalConnection
participant RelaySocket
participant Relay
participant WorkspaceServer
EventBus->>RelaySocket: create shared connection
TerminalConnection->>RelaySocket: create terminal connection
RelaySocket->>Relay: probe affinity and connect with token
Relay-->>RelaySocket: deliver messages
RelaySocket-->>EventBus: dispatch server events
RelaySocket-->>TerminalConnection: deliver binary and control messages
EventBus->>RelaySocket: replay active fs:watch commands
RelaySocket->>WorkspaceServer: send watch commands
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Greptile SummaryThis PR standardizes two reconnecting WebSocket clients on a shared relay socket wrapper. The main changes are:
Confidence Score: 5/5This looks safe to merge after checking the terminal replay behavior.
apps/web/src/app/workspaces/[workspaceId]/components/WebTerminal/TerminalConnection.ts
|
| Filename | Overview |
|---|---|
| packages/workspace-client/src/lib/relaySocket/relaySocket.ts | Adds the shared relay socket wrapper with per-attempt signing, preflight probing, access-denied handling, and partysocket reconnect options. |
| packages/workspace-client/src/lib/eventBus.ts | Replaces the event bus hand-rolled reconnect loop with the shared relay socket and keeps fs:watch replay on open. |
| apps/web/src/app/workspaces/[workspaceId]/components/WebTerminal/TerminalConnection.ts | Moves the web terminal connection lifecycle onto the shared relay socket and keeps terminal state, resume, fatal-close, and replay controls. |
| packages/workspace-client/package.json | Adds the relay-socket subpath export and partysocket dependency. |
| apps/web/package.json | Adds the workspace-client dependency for the web terminal import. |
Sequence Diagram
%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Client as EventBus / WebTerminal
participant RelaySocket as createRelaySocket
participant Token as getToken()
participant Preflight as _whoowns preflight
participant Socket as partysocket
Client->>RelaySocket: create socket with buildUrl()
RelaySocket->>Token: request fresh token
Token-->>RelaySocket: token
RelaySocket->>Preflight: probe signed URL
alt access denied
RelaySocket->>Client: onAccessDenied()
RelaySocket-->>Socket: close or delayed retry
else allowed
RelaySocket-->>Socket: signed WebSocket URL
Socket-->>Client: open / message / close events
end
Socket->>RelaySocket: reconnect attempt
RelaySocket->>Token: request fresh token again
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Client as EventBus / WebTerminal
participant RelaySocket as createRelaySocket
participant Token as getToken()
participant Preflight as _whoowns preflight
participant Socket as partysocket
Client->>RelaySocket: create socket with buildUrl()
RelaySocket->>Token: request fresh token
Token-->>RelaySocket: token
RelaySocket->>Preflight: probe signed URL
alt access denied
RelaySocket->>Client: onAccessDenied()
RelaySocket-->>Socket: close or delayed retry
else allowed
RelaySocket-->>Socket: signed WebSocket URL
Socket-->>Client: open / message / close events
end
Socket->>RelaySocket: reconnect attempt
RelaySocket->>Token: request fresh token again
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
apps/web/src/app/workspaces/[workspaceId]/components/WebTerminal/TerminalConnection.ts:163
**Replay Skips Missed Output**
When the socket receives any binary bytes before a later disconnect, the next URL adds `replay=0`. If the disconnect happens before xterm has all output from the daemon ring buffer, the reconnect suppresses the server replay that was supposed to fill the gap, so terminal output produced while offline can be lost.
Reviews (1): Last reviewed commit: "refactor(workspace-client,web): standard..." | Re-trigger Greptile
| // Once xterm holds scrollback, skip the daemon ring-buffer re-dump on | ||
| // reattach; the in-memory buffer still replays output missed offline. | ||
| if (this.hasReceivedBytes) url.searchParams.set("replay", "0"); | ||
| return url.toString(); |
There was a problem hiding this comment.
When the socket receives any binary bytes before a later disconnect, the next URL adds replay=0. If the disconnect happens before xterm has all output from the daemon ring buffer, the reconnect suppresses the server replay that was supposed to fill the gap, so terminal output produced while offline can be lost.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/web/src/app/workspaces/[workspaceId]/components/WebTerminal/TerminalConnection.ts
Line: 163
Comment:
**Replay Skips Missed Output**
When the socket receives any binary bytes before a later disconnect, the next URL adds `replay=0`. If the disconnect happens before xterm has all output from the daemon ring buffer, the reconnect suppresses the server replay that was supposed to fill the gap, so terminal output produced while offline can be lost.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Pre-existing semantics carried over verbatim from the old implementation (and mirrored in the desktop transport): replay=0 after first bytes is deliberate — the host-side in-memory buffer replays output missed while disconnected; replay only controls the daemon ring-buffer re-dump of scrollback xterm already holds. Not a regression in this PR; if the offline-gap concern is real it predates this change and belongs in a host-service issue.
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/workspace-client/src/lib/relaySocket/relaySocket.ts`:
- Around line 48-63: The 403 retry path in provider still passes through
PartySocket’s backoff after sleeping, causing compounded delays. Update the
access-denied handling in provider to use a terminal connection shutdown path
when accessDeniedRetryMs is configured, bypassing PartySocket’s retry/reconnect
state while preserving the callback, configured delay behavior, and immediate
close behavior for unset accessDeniedRetryMs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7a7ec1b1-9b38-4e51-a75a-892e23b21280
⛔ Files ignored due to path filters (1)
bun.lockis excluded by!**/*.lock
📒 Files selected for processing (9)
apps/web/package.jsonapps/web/src/app/workspaces/[workspaceId]/components/WebTerminal/TerminalConnection.tspackages/workspace-client/package.jsonpackages/workspace-client/src/index.tspackages/workspace-client/src/lib/eventBus.tspackages/workspace-client/src/lib/relaySocket/index.tspackages/workspace-client/src/lib/relaySocket/relaySocket.test.tspackages/workspace-client/src/lib/relaySocket/relaySocket.tsplans/done/20260712-partysocket-ws-consolidation.md
There was a problem hiding this comment.
2 issues found across 10 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/web/src/app/workspaces/[workspaceId]/components/WebTerminal/TerminalConnection.ts">
<violation number="1" location="apps/web/src/app/workspaces/[workspaceId]/components/WebTerminal/TerminalConnection.ts:126">
P2: Terminal retries never reach the 12-attempt error state when `buildUrl`, `getAuthToken`, or the relay URL-provider preflight rejects: those failures emit `error`, but this handler assumes a later `close`. Account for provider-error retries (without double-counting socket errors that do close) so the existing retry budget still bounds this path.</violation>
</file>
<file name="packages/workspace-client/src/lib/relaySocket/relaySocket.ts">
<violation number="1" location="packages/workspace-client/src/lib/relaySocket/relaySocket.ts:56">
P2: When `accessDeniedRetryMs` is configured, the effective retry interval compounds: the provider sleeps for `accessDeniedRetryMs` and then throws, but partysocket treats the rejection as a failed attempt—incrementing its internal retry counter and adding its own exponentially-growing backoff delay before the next `_connect()`. The actual cadence becomes `accessDeniedRetryMs + partysocket_backoff` rather than a fixed `accessDeniedRetryMs` interval.
The test "keeps re-probing at accessDeniedRetryMs" passes only because it uses very short delays (50ms retry + 10–20ms partysocket backoff). With the production value of 5 minutes, the growing library delay would be noticeable after several 403 cycles.
Consider either resetting partysocket's retry state before throwing (via `socket._retryCount = 0` or similar), or restructuring the 403 path to bypass partysocket's backoff entirely (e.g., close + schedule a manual reconnect after `accessDeniedRetryMs`).</violation>
</file>
Architecture diagram
sequenceDiagram
participant WebTerm as Web Terminal
participant Desktop as Desktop (eventBus)
participant RelaySock as createRelaySocket
participant PartySock as partysocket
participant Relay as Relay (edge)
participant Host as Host Service
participant Auth as auth-token
Note over RelaySock,PartySock: NEW: Unified reconnecting WS wrapper
WebTerm->>RelaySock: createRelaySocket(opts)
Desktop->>RelaySock: createRelaySocket(opts)
rect rgb(240, 245, 250)
Note over RelaySock,Auth: On every connection attempt
PartySock->>RelaySock: async url provider
RelaySock->>RelaySock: buildUrl() + getToken() → signed URL
alt URL contains /hosts/ (relay-fronted)
RelaySock->>Relay: GET /_whoowns (preflight)
alt 403 (definitive denial)
Relay-->>RelaySock: 403 Forbidden
RelaySock->>RelaySock: onAccessDenied()
alt accessDeniedRetryMs set
RelaySock->>RelaySock: sleep(accessDeniedRetryMs)
RelaySock-->>PartySock: reject (retry loop)
else no retry configured
RelaySock->>PartySock: close(1000, "denied")
RelaySock-->>PartySock: reject (no-op after close)
end
else 200 allowed
Relay-->>RelaySock: OK
RelaySock-->>PartySock: return signed URL
PartySock->>Relay: WebSocket upgrade
Relay->>Host: forward
Host-->>Relay: upgrade
Relay-->>WebTerm: open
end
else local URL (no /hosts/)
RelaySock-->>PartySock: return signed URL (no preflight)
PartySock->>Host: WebSocket upgrade directly
Host-->>WebTerm: open
end
end
Note over PartySock: partysocket owns backoff<br/>and reconnection
alt Web Terminal: on open
PartySock-->>WebTerm: open event
WebTerm->>WebTerm: reset failedAttempts
WebTerm->>WebTerm: mark everAttached
else Web Terminal: on close (unexpected)
PartySock-->>WebTerm: close event
WebTerm->>WebTerm: failedAttempts++
alt failedAttempts >= 12
WebTerm->>WebTerm: emitState("error")
WebTerm->>PartySock: close()
else document.hidden
Note over WebTerm: frozen tab – don't count
else
WebTerm->>WebTerm: emitState(reconnecting|connecting)
PartySock->>PartySock: auto-reconnect
end
else Web Terminal: handleResume (visibility/online)
WebTerm->>WebTerm: failedAttempts = 0
alt socket not OPEN or CONNECTING
WebTerm->>PartySock: reconnect()
end
end
alt eventBus: on open
PartySock-->>Desktop: open event
Desktop->>Desktop: replay fs:watch commands
else eventBus: on close (no more subscribers)
Desktop->>PartySock: close(1000, "No more subscribers")
end
Note over WebTerm,Desktop: Both consumers use same wrapper –<br/>WebTerm adds attempt budget,<br/>eventBus adds fs:watch replay
Params->>RelaySock: maxEnqueuedMessages: 0 (no buffering)
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| this.emitState(this.everAttached ? "reconnecting" : "connecting"); | ||
| }); | ||
|
|
||
| socket.addEventListener("error", () => { |
There was a problem hiding this comment.
P2: Terminal retries never reach the 12-attempt error state when buildUrl, getAuthToken, or the relay URL-provider preflight rejects: those failures emit error, but this handler assumes a later close. Account for provider-error retries (without double-counting socket errors that do close) so the existing retry budget still bounds this path.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/web/src/app/workspaces/[workspaceId]/components/WebTerminal/TerminalConnection.ts, line 126:
<comment>Terminal retries never reach the 12-attempt error state when `buildUrl`, `getAuthToken`, or the relay URL-provider preflight rejects: those failures emit `error`, but this handler assumes a later `close`. Account for provider-error retries (without double-counting socket errors that do close) so the existing retry budget still bounds this path.</comment>
<file context>
@@ -67,12 +70,66 @@ export class TerminalConnection {
+ this.emitState(this.everAttached ? "reconnecting" : "connecting");
+ });
+
+ socket.addEventListener("error", () => {
+ // close fires after error; partysocket owns the retry loop.
+ });
</file context>
There was a problem hiding this comment.
Valid gap: provider-side failures (token fetch rejection, preflight throw) surface as error events without a close, so the close-counted budget doesn't see them — worst case is indefinite silent retry with the UI stuck on "connecting" if the token fetch rejects forever. Two mitigating facts: partysocket's own backoff still bounds the retry rate, and this surface (web terminal) is currently unused. Fixing it properly means the wrapper exposing an attempt/error callback rather than consumers guessing event semantics — that's queued as part of the SUPER-1469 phase 4 wrapper API work (desktop terminal migration), where the same accounting is needed for real. Not addressed in this PR.
There was a problem hiding this comment.
The parent comment is too broad for this PR: the web terminal surface is currently unused, and the durable attempt/error accounting belongs in the phase 4 wrapper API work. The retry-rate behavior is still bounded by partysocket, but this PR doesn’t need to fix the provider-error accounting path.
| if (opts.accessDeniedRetryMs == null) { | ||
| socket?.close(1000, "relay access denied"); | ||
| } else { | ||
| await sleep(opts.accessDeniedRetryMs); |
There was a problem hiding this comment.
P2: When accessDeniedRetryMs is configured, the effective retry interval compounds: the provider sleeps for accessDeniedRetryMs and then throws, but partysocket treats the rejection as a failed attempt—incrementing its internal retry counter and adding its own exponentially-growing backoff delay before the next _connect(). The actual cadence becomes accessDeniedRetryMs + partysocket_backoff rather than a fixed accessDeniedRetryMs interval.
The test "keeps re-probing at accessDeniedRetryMs" passes only because it uses very short delays (50ms retry + 10–20ms partysocket backoff). With the production value of 5 minutes, the growing library delay would be noticeable after several 403 cycles.
Consider either resetting partysocket's retry state before throwing (via socket._retryCount = 0 or similar), or restructuring the 403 path to bypass partysocket's backoff entirely (e.g., close + schedule a manual reconnect after accessDeniedRetryMs).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/workspace-client/src/lib/relaySocket/relaySocket.ts, line 56:
<comment>When `accessDeniedRetryMs` is configured, the effective retry interval compounds: the provider sleeps for `accessDeniedRetryMs` and then throws, but partysocket treats the rejection as a failed attempt—incrementing its internal retry counter and adding its own exponentially-growing backoff delay before the next `_connect()`. The actual cadence becomes `accessDeniedRetryMs + partysocket_backoff` rather than a fixed `accessDeniedRetryMs` interval.
The test "keeps re-probing at accessDeniedRetryMs" passes only because it uses very short delays (50ms retry + 10–20ms partysocket backoff). With the production value of 5 minutes, the growing library delay would be noticeable after several 403 cycles.
Consider either resetting partysocket's retry state before throwing (via `socket._retryCount = 0` or similar), or restructuring the 403 path to bypass partysocket's backoff entirely (e.g., close + schedule a manual reconnect after `accessDeniedRetryMs`).</comment>
<file context>
@@ -0,0 +1,73 @@
+ if (opts.accessDeniedRetryMs == null) {
+ socket?.close(1000, "relay access denied");
+ } else {
+ await sleep(opts.accessDeniedRetryMs);
+ }
+ // Rejecting aborts this attempt; partysocket surfaces it as an error
</file context>
There was a problem hiding this comment.
Same assessment as the CodeRabbit thread above: bounded at +maxReconnectionDelay (30s on a 5-minute floor), and the option is a minimum interval by contract. Resetting _retryCount would reach into private internals; a parallel manual-reconnect timer re-introduces exactly the hand-rolled state machine this PR deletes. Accepting ≤10% drift on denied-host polling.
There was a problem hiding this comment.
The parent comment was too broad here: accessDeniedRetryMs is a minimum slow-poll interval, and the extra partysocket delay is capped at maxReconnectionDelay, so the denied-host cadence stays bounded. I agree with keeping the wrapper as-is rather than reaching into _retryCount or adding a parallel reconnect timer.
…ocket, drop no-op error listeners
…lConnection eventBus gets its first tests (listener routing, per-host connection sharing, fs:watch refcounting, watch replay after reconnect, last-listener cleanup). TerminalConnection takes its env wiring (getToken/relayUrl) via constructor deps — WebTerminal injects the real ones — so the class is importable in bun tests without web's env/posthog modules; tests cover dial shape, binary + control delivery, fresh-token + replay=0 redial, and permanent stop on exit. The fresh-token redial test fails if the original #5628 stale-URL bug is reintroduced (mutation-verified). Web tsconfig gains bun test types.
|
Perf check — partysocket clones + re-dispatches every message event, and web terminal binary PTY frames now flow through that path, so I benchmarked it (bun, local WS server, 50k × 512B binary frames, median of 3, interleaved):
Overhead ≈ 0.56µs/frame. Real terminal traffic is network- and xterm-render-bound at a few thousand frames/sec, so this is ~0.3% CPU at worst-case output rates — negligible. The desktop terminal transport (the genuinely hot path, unmigrated) is unaffected. Other perf-relevant deltas, reasoned rather than benched: web terminals gain one preflight RTT before the first dial (deliberate — fly edge affinity + denial visibility, same as desktop already did); reconnect network load strictly decreases (403s now poll at 5min instead of 1–30s exponential); token fetches per attempt are TTL-cached/deduped on both platforms; and partysocket's 4s |
|
Live E2E (CDP + real browser) on this branch — full rig: local relay running this repo's relay code, dev desktop with relay exposure (host-service tunneled), web dev server, Chrome driven via CDP. Verified end-to-end through the migrated code:
The relay-restart recovery is the scenario that used to strand clients; it now self-heals in ~15s with zero user action. |
|
Stress test: this branch vs revert (old eventBus from main) — identical harness against both implementations: 150 concurrent connections to one WS server, 15,000-event broadcast flood, 3× server flap (mass disconnect), dispose sweep.
Reading: throughput, delivery, herd behavior, and cleanup are at parity. Two intentional differences: (1) under rapid flapping (server bouncing faster than every 5s), partysocket escalates backoff per attempt and only resets after 5s of stable uptime — recovery grows 1.0→1.4→1.7s instead of staying constant. That's protective (a flapping relay gets progressively less hammering) and fully resets with ≥5s uptime, verified above. (2) ~5KB extra heap per connection for the partysocket instance — trivial at realistic host counts. No regression that would motivate a revert; the rapid-flap backoff escalation is arguably the better behavior for relay protection. |
Links
plans/done/20260712-partysocket-ws-consolidation.md(moved to done in this PR)Summary
createRelaySocketin@superset/workspace-client: a ~75-line wrapper over partysocket's generic reconnecting WebSocket. It re-signs the URL with a fresh token and runs the_whoownspreflight before every attempt, treats a preflight 403 as a definitive denial (permanent close +onAccessDenied, or slow-poll viaaccessDeniedRetryMs), and disables buffering so send semantics stay "only while open".WebTerminal/TerminalConnection.Why / Context
The stale-token reconnect-loop bug (#5628, ~25 users/day) existed because three transports each hand-roll backoff + token freshness and drift independently. partysocket's async URL provider — evaluated before every dial — makes that bug class structurally impossible for anything built on the wrapper. Research/selection rationale in the design doc; partysocket is the maintained reconnecting-websocket fork (Cloudflare/PartyKit, 1.3.0 June 2026).
How It Works
urlprovider. Spike result (was the design doc's blocking question): a rejecting provider surfaces as anerrorevent and re-enters partysocket's backoff loop — verified in partysocket's source (_connect's catch →_handleError→_connect) and empirically against a live server.connect/scheduleReconnect/disposedmachinery deleted; partysocket owns reconnection. fs:watch replay still happens on eachopen. 403 → 5-min slow poll (unchanged semantics from fix(desktop): refresh relay JWT on WS reconnect and stop retrying definitive 403s #5628).reconnect()(also the recovery path after budget exhaustion),replay=0suppression, and fatal exit/error handling. New behavior: web terminals now also get the fly-affinity preflight and fatal-403 handling.@superset/workspace-client/relay-socketsubpath export so the React/tRPC barrel stays out of web's graph.Manual QA / Verification done
_whoowns): fresh token per attempt, fatal 403 (no dial, single denial callback, CLOSED), 403 slow-poll then recovery when access granted, local URLs skip preflight. Fatal-close test mutation-verified./eventssocket opens through the wrapper (Network.webSocketCreated handshake confirmed), and unreachable relay hosts retry with backoff without console errors (the two React setState warnings present trace toDockBadgeController— pre-existing, unrelated).Testing
bun test packages/workspace-client apps/web(17 pass): wrapper behavior (fresh token per attempt, fatal 403, 403 slow-poll recovery, http→ws conversion), eventBus's first-ever regression suite (listener routing, per-host connection sharing, fs:watch refcounting, watch replay after reconnect, last-listener cleanup), and TerminalConnection (dial shape, binary/control delivery, fresh-token + replay=0 redial, permanent stop on exit). The fresh-token redial test fails if fix(desktop): refresh relay JWT on WS reconnect and stop retrying definitive 403s #5628's stale-URL bug is reintroduced (mutation-verified).getToken/relayUrlas constructor deps (WebTerminal injects the real ones) so it's unit-testable without web's env/posthog module graph.bun run lint,bunx turbo typecheck --filter=@superset/desktop --filter=@superset/web --filter=@superset/workspace-clientKnown Limitations
connectionTimeout(4s default) now applies to both migrated transports — previously unbounded browser default; strictly tighter.Summary by cubic
Standardized reconnecting WebSocket clients on
partysocketviacreateRelaySocketthat refreshes tokens, preflights on every attempt, converts http→ws, and handles 403s. Migrated the event bus and web terminal; added regression tests, addressing SUPER-1469.Refactors
createRelaySocketin@superset/workspace-client: fresh token per dial,_whoownspreflight on each attempt, 403 → permanent close or slow‑poll viaaccessDeniedRetryMs, http(s)→ws(s) conversion, and unbuffered sends by default (maxEnqueuedMessages=0).WebTerminal/TerminalConnectionto the wrapper: event bus replaysfs:watchon open and closes when the last listener unsubscribes; terminal injectsgetToken/relayUrl, keeps the 12‑attempt budget and resumes viareconnect(), setsreplay=0after first bytes, and stops onexit/error.plans/done/20260712-partysocket-ws-consolidation.md.Dependencies
[email protected]; new export@superset/workspace-client/relay-socket;apps/webadds@superset/workspace-clientand dev@types/bun(tsconfig includesbun).Written for commit 7005f11. Summary will update on new commits.
Summary by CodeRabbit
./relay-socketentry).