Repository navigation
fix(remote): shared-control replay-window subscription leak, benign snapshot banner, viewport clear - #8091
fix(remote): shared-control replay-window subscription leak, benign snapshot banner, viewport clear#8091Jinwoo-H wants to merge 3 commits into
Conversation
… leaked subscription Co-authored-by: Orca <[email protected]>
…minal error Co-authored-by: Orca <[email protected]>
… resize Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughThe changes clear queued viewport data during batcher teardown, classify oversized remote terminal snapshots as informational, and preserve live output without surfacing an error. Shared control subscriptions now track replay resubscription state, defer close cleanup while a new server identifier is pending, and complete cleanup once that identifier arrives. Tests cover viewport clearing, snapshot handling, and established, replaying, and never-sent subscriptions. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/shared/remote-runtime-shared-control-subscriptions.test.ts (1)
34-104: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a test for the error-during-replay-window case.
The three tests cover the happy paths well, but there's no test verifying what happens when the resubscribe response is an error during the replay window with
closeAfterReady=true. This is the exact scenario where theawaitingResubscribeclearing issue (flagged inremote-runtime-shared-control-state.ts) would cause a stuck subscription. Adding this test would both document the expected error behavior and guard against regression.🧪 Suggested test for error response during replay window
it('finishes locally without an unsubscribe for a never-sent subscription', () => { const { subscriptions, subscription } = makeSubscriptions() // Brand new: never sent, no server subscription exists. const request = vi.fn() closeSharedControlLogicalSubscription({ subscriptions, subscription, request }) expect(request).not.toHaveBeenCalled() expect(subscriptions.size).toBe(0) }) + + it('finishes a deferred close locally when the resubscribe response errors', () => { + const { subscriptions, subscription } = makeSubscriptions() + subscription.sent = true + subscription.remoteSubscriptionId = 'server-sub-1' + + const sent: SharedControlLogicalSubscription<unknown>[] = [] + replaySharedControlSubscriptions({ + subscriptions, + send: (s) => { sent.push(s) }, + tagReplayedResponses: true + }) + + const request = vi.fn() + closeSharedControlLogicalSubscription({ subscriptions, subscription, request }) + expect(subscriptions.size).toBe(1) + expect(request).not.toHaveBeenCalled() + + // Resubscribe fails — no server subscription was created. + handleSharedControlLogicalResponse({ + subscriptions, + subscription, + response: { ok: false, id: 'req-1', error: { code: -1, message: 'fail' } } as unknown as RuntimeRpcResponse<unknown>, + request + }) + + // No server subscription to unsubscribe from; deferred close finishes locally. + expect(request).not.toHaveBeenCalled() + expect(subscriptions.size).toBe(0) + }) })
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 253fdfa5-555e-430c-afbd-49008a98e737
📒 Files selected for processing (9)
src/renderer/src/components/terminal-pane/remote-runtime-pty-batching.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-batching.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.test.tssrc/renderer/src/components/terminal-pane/remote-runtime-pty-transport.tssrc/renderer/src/runtime/remote-runtime-terminal-multiplexer.tssrc/shared/remote-runtime-shared-control-state.tssrc/shared/remote-runtime-shared-control-subscriptions.test.tssrc/shared/remote-runtime-shared-control-subscriptions.tssrc/shared/remote-runtime-shared-control-types.ts
Summary
Three small, independently-committed remote-terminal / shared-control client fixes:
Shared-control subscription leak on close-during-replay (
fix(remote): defer close during shared-control replay window…). On reconnect,replaySharedControlSubscriptionsclearsremoteSubscriptionIdand flipssent=falseimmediately before re-sending each id-scoped subscription (accounts.subscribe,notifications.subscribe,runtime.clientEvents.subscribe,files.watch). Ifclose()raced that window,closeSharedControlLogicalSubscriptionfound no cleanup id and nosentflag, so it finished the record locally without sending an*.unsubscribe— leaking the server subscription the in-flight resubscribe was about to create. Fix: a new per-subscriptionawaitingResubscribeflag armscloseAfterReadyduring that window, so the deferred close fires the unsubscribe once the fresh server id arrives, then finishes.Benign snapshot overflow rendered a fatal red banner (
fix(remote): treat oversized snapshot skip as benign…). An initial replay snapshot over the 2 MiB limit is skipped while live output keeps flowing — informational, not fatal — but the multiplexer'sonError(REMOTE_TERMINAL_SNAPSHOT_TOO_LARGE)propagated through the transport to a red xterm banner. Fix: classify that exact message as benign inhandleRemoteTerminalError(same seam as the existingterminal_goneretire path) and swallow it. The constant is now exported so the transport can match on it.Viewport batcher
clear()leftpendingset (fix(remote): clear pending viewport in batcher clear()…). The text batcher'sclear()nulls its pending buffer; the viewport batcher'sclear()only cancelled the timer, leaving the queued viewport in place — a laterflush()or batcher reuse could emit a stale resize. Fix: nullpendinginclear(), matching the text batcher.Screenshots
No visual change.
Testing
pnpm typecheck(green)pnpm oxlinton all touched files (clean)--config config/vitest.config.tsso@/aliases resolve):remote-runtime-shared-control-subscriptions.test.ts— NEW: 3 cases (established close cleans up by id; close-during-replay defers then unsubscribes with the fresh id; never-sent close finishes locally with no unsubscribe). The replay-window case fails on pre-fix code (finishes locally, size 0, no unsubscribe).remote-runtime-pty-transport.test.ts— updated the oversized-snapshot case to assertonErroris not called and live output continues (44 passed).remote-runtime-pty-batching.test.ts— NEW viewportclear()cases; the flush-after-clear case fails on pre-fix code (9 passed after fix).remote-runtime-shared-control-connection.test.ts— passes (this real-websocket suite is pre-existing flaky under heavy parallel load withruntime_timeoutin the request path, unrelated to these changes; passes when run in isolation).AI Review Report
Reviewed for: correctness of the replay-window race (verified the leak window is
remoteSubscriptionId=null+ resubscribe in flight, and thatawaitingResubscribeis cleared on the successful resubscribe response so normal id-scoped close still works); no double-unsubscribe (established close path unchanged); benign-classification is an exact-string match so it can't mask unrelated errors; viewportclear()change matches the text batcher's existing semantics. Cross-platform: pure TypeScript client logic, no shell/path/shortcut/Electron-platform surface touched — behavior identical on macOS/Linux/Windows. SSH/remote: these are the remote-runtime client paths; the subscription-leak fix directly reduces stranded server subscriptions on flaky-reconnect (SSH/relay) links.Security Audit
No new input handling, command execution, path handling, auth, secrets, dependency, or IPC surface. The subscription fix sends one additional
*.unsubscribe(already an existing, authenticated cleanup message) in a previously-leaking path; the benign-classification fix only suppresses a UI banner and never widens what is treated as success. No follow-up needed.Notes
Each fix is a separate commit; all three are small and self-contained, so they ship as one PR per the task scope. Do not merge — flagging for review.
Made with Orca 🐋