Repository navigation
fix(runtime): release terminal.subscribe exit-waiters on teardown - #7490
Conversation
Every terminal.subscribe / terminal.multiplex slot registers a runtime exit-waiter via waitForTerminal(condition:'exit'). With no AbortSignal that waiter sits in waitersByHandle until the PTY actually exits — but agent terminals routinely never exit for the life of a session. It is only ever cleared by real exit or a desktop renderer graph reload (markRendererReloading / markGraphUnavailable), neither of which a remote/mobile WebSocket reconnect triggers. So on long SSH/mobile sessions every reconnect and tab-switch re-subscribe leaked a waiter, and each captured its closed-connection handler context (including the dead ws), growing host-process memory monotonically. - multiplex: give each stream an AbortController and abort it in detachStream (the single teardown point, reached on slot unsubscribe, re-subscribe pre-detach, and connection close via closeMultiplex). Passing its signal to waitForTerminal removes the waiter at detach. The existing .catch no-ops because the stream is already deleted (streams.get(streamId) !== stream). - legacy json/binary subscribe: pass the per-connection dispatch signal so the waiter is removed on socket close/error. Regression test proves a signalled exit-waiter is released when its signal aborts (and 25 reconnect churns leave zero waiters), while an unsignalled one accumulates — the pre-fix behavior. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughThis change adds an Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant TerminalMultiplex
participant TerminalSubscribe
participant Runtime
Client->>TerminalMultiplex: attach stream
TerminalMultiplex->>TerminalMultiplex: create exitWaiterAbort
TerminalMultiplex->>Runtime: waitForTerminal(condition: exit, signal)
Client->>TerminalMultiplex: detachStream
TerminalMultiplex->>TerminalMultiplex: exitWaiterAbort.abort()
TerminalMultiplex-->>Runtime: waiter released
Client->>TerminalSubscribe: subscribe(signal)
TerminalSubscribe->>Runtime: waitForTerminal(condition: exit, signal)
Client--)TerminalSubscribe: connection close/error
TerminalSubscribe-->>Runtime: waiter released
Related issues: None referenced in the provided context. Related PRs: None referenced in the provided context. Suggested labels: bug, runtime, terminal Suggested reviewers: None determinable from the provided context. Poem 🚥 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 |
…ing registration
A terminal.subscribe teardown was keyed on `${terminal}:${clientId}`, which is
stable across reconnects. cleanupSubscription invokes whichever cleanup currently
owns that key, so after a mobile reconnect rebound the id, a late teardown from the
dead connection killed the replacement stream and the terminal froze (STA-4510).
Add registerOwnedSubscriptionCleanup, returning a registration handle whose
releaseIfCurrent no-ops once the id has been rebound, and route all 12 teardown
call sites in the three terminal.subscribe branches through it. Register-time
eviction now also targets the owner it captured rather than re-resolving the key.
terminal.unsubscribe gains the same ownership rule via connectionId, matching the
runtime.clientEvents.unsubscribe precedent: make-before-break migration sends the
unsubscribe over the old session after the new one has already rebound the id.
The teardown-by-key pattern predates the bug; #7490 made it reachable by binding
the exit-waiter to the per-socket abort signal, so every socket close now runs it.
Tests use a faithful subscription-registry double; the ad-hoc Map stubs they
replace never evicted the prior generation, which is why no test caught this.
…ing registration (#14992) * fix(runtime): tear down terminal subscriptions only through their owning registration A terminal.subscribe teardown was keyed on `${terminal}:${clientId}`, which is stable across reconnects. cleanupSubscription invokes whichever cleanup currently owns that key, so after a mobile reconnect rebound the id, a late teardown from the dead connection killed the replacement stream and the terminal froze (STA-4510). Add registerOwnedSubscriptionCleanup, returning a registration handle whose releaseIfCurrent no-ops once the id has been rebound, and route all 12 teardown call sites in the three terminal.subscribe branches through it. Register-time eviction now also targets the owner it captured rather than re-resolving the key. terminal.unsubscribe gains the same ownership rule via connectionId, matching the runtime.clientEvents.unsubscribe precedent: make-before-break migration sends the unsubscribe over the old session after the new one has already rebound the id. The teardown-by-key pattern predates the bug; #7490 made it reachable by binding the exit-waiter to the per-socket abort signal, so every socket close now runs it. Tests use a faithful subscription-registry double; the ad-hoc Map stubs they replace never evicted the prior generation, which is why no test caught this. * test(runtime): migrate the remaining subscription stubs to the faithful registry streaming.test.ts and terminal-provider-snapshot-sequence.test.ts still stubbed registerSubscriptionCleanup only, so terminal.subscribe's owned registration was undefined and teardown never fired. Assert the registration is retired rather than spying on cleanupSubscription, which the owned path now calls internally. * fix(runtime): guard the lease-only presence release and use the shared registry double Review findings on this PR: - The lease-only branch's compensating handleMobileUnsubscribe ran unconditionally after a rebind. Presence is keyed (ptyId, clientId) with no refcount and `closed` is exactly the post-rebind state, so a superseded handler deleted the replacement subscriber's presence. Gate it on the registration still being current. This also gives SubscriptionRegistration.isCurrent its production caller. - The STA-4510 regression test hand-rolled a second registry copy that diverged from the shared double (no try/catch around cleanup, no in-flight join). Import the shared double instead, so the test proving the bug uses the same fidelity as the rest of the suite. - cleanupSubscriptionIfOwnedByConnection treats an absent connectionId as authority. That is the connection-less local unix-socket path, not an oversight; say so. * fix(runtime): drop the lease-only presence guard; it disabled a real compensation Review pass 2 showed the guard added in the previous commit was wrong. registration.isCurrent() is always false whenever `closed` is true: either our own cleanup ran, in which case cleanupSubscriptionAndWait already deleted the map entry, or a rebind replaced it. So the guard did not distinguish the two cases — it made the compensating handleMobileUnsubscribe unreachable, which is precisely the resurrect-after-cleanup case that line exists to handle. The scenario the guard was meant to fix is also not reachable: the lease-only call passes no viewport, and both !viewport paths in handleMobileSubscribeInternal return with no await, so the subscribe resolves in microtasks and a socket close cannot win it. Revert the guard, and drop SubscriptionRegistration.isCurrent with it — it had no remaining production caller and shipping unused runtime API invites exactly this. Also from review: - cleanupSubscriptionIfOwnedByConnection reported false for an id with no registration, conflating 'refused, another connection owns it' with 'already gone'. Report true. - Note on the registry double that it mirrors production and can drift; the runtime tests pin real behavior, the doubles only pin routing. * fix(runtime): make the unsubscribe refusal observable and restore test-double parity Review pass 3: - The registry test double omitted production's 'unregistered id is already gone' early-out, so it returned refused where production returns gone. The legacy terminal.unsubscribe path reaches that branch with a never-registered bare id, so a routing test would have locked in the inverse of production. - terminal.unsubscribe ORed the bare-id and composite results. Registrations always use the composite, so the bare id reported 'already gone' and masked a real ownership refusal: a stale connection was correctly refused but told unsubscribed: true. The composite answer is authoritative when we try it. - Pin why the lease-only compensating handleMobileUnsubscribe is deliberately unguarded: it is safe only because that call passes no viewport and returns with no await. - Cover the no-registration branch, which had no test. * fix(runtime): report an unsubscribe refusal without masking a real teardown Review pass 4 disproved the previous commit's rationale. A clientless legacy-JSON stream registers under the bare terminal id, not the composite, so either call in terminal.unsubscribe can be the real teardown. Overwriting reported false after a destructive success; the earlier OR reported true after a refusal. AND over the calls that actually ran is the honest aggregate: false needs a genuine refusal. Tests: - cover the bare-id path, which the ownership tests never exercised - pin the microtask invariant the unguarded lease-only compensation depends on. The first version of that test was vacuous: it raced two setTimeout(0) timers, and the earlier-registered one always won, so it passed with an await injected. It now drains microtasks only and goes red under that mutation.
…ing registration (stablyai#14992) * fix(runtime): tear down terminal subscriptions only through their owning registration A terminal.subscribe teardown was keyed on `${terminal}:${clientId}`, which is stable across reconnects. cleanupSubscription invokes whichever cleanup currently owns that key, so after a mobile reconnect rebound the id, a late teardown from the dead connection killed the replacement stream and the terminal froze (STA-4510). Add registerOwnedSubscriptionCleanup, returning a registration handle whose releaseIfCurrent no-ops once the id has been rebound, and route all 12 teardown call sites in the three terminal.subscribe branches through it. Register-time eviction now also targets the owner it captured rather than re-resolving the key. terminal.unsubscribe gains the same ownership rule via connectionId, matching the runtime.clientEvents.unsubscribe precedent: make-before-break migration sends the unsubscribe over the old session after the new one has already rebound the id. The teardown-by-key pattern predates the bug; stablyai#7490 made it reachable by binding the exit-waiter to the per-socket abort signal, so every socket close now runs it. Tests use a faithful subscription-registry double; the ad-hoc Map stubs they replace never evicted the prior generation, which is why no test caught this. * test(runtime): migrate the remaining subscription stubs to the faithful registry streaming.test.ts and terminal-provider-snapshot-sequence.test.ts still stubbed registerSubscriptionCleanup only, so terminal.subscribe's owned registration was undefined and teardown never fired. Assert the registration is retired rather than spying on cleanupSubscription, which the owned path now calls internally. * fix(runtime): guard the lease-only presence release and use the shared registry double Review findings on this PR: - The lease-only branch's compensating handleMobileUnsubscribe ran unconditionally after a rebind. Presence is keyed (ptyId, clientId) with no refcount and `closed` is exactly the post-rebind state, so a superseded handler deleted the replacement subscriber's presence. Gate it on the registration still being current. This also gives SubscriptionRegistration.isCurrent its production caller. - The STA-4510 regression test hand-rolled a second registry copy that diverged from the shared double (no try/catch around cleanup, no in-flight join). Import the shared double instead, so the test proving the bug uses the same fidelity as the rest of the suite. - cleanupSubscriptionIfOwnedByConnection treats an absent connectionId as authority. That is the connection-less local unix-socket path, not an oversight; say so. * fix(runtime): drop the lease-only presence guard; it disabled a real compensation Review pass 2 showed the guard added in the previous commit was wrong. registration.isCurrent() is always false whenever `closed` is true: either our own cleanup ran, in which case cleanupSubscriptionAndWait already deleted the map entry, or a rebind replaced it. So the guard did not distinguish the two cases — it made the compensating handleMobileUnsubscribe unreachable, which is precisely the resurrect-after-cleanup case that line exists to handle. The scenario the guard was meant to fix is also not reachable: the lease-only call passes no viewport, and both !viewport paths in handleMobileSubscribeInternal return with no await, so the subscribe resolves in microtasks and a socket close cannot win it. Revert the guard, and drop SubscriptionRegistration.isCurrent with it — it had no remaining production caller and shipping unused runtime API invites exactly this. Also from review: - cleanupSubscriptionIfOwnedByConnection reported false for an id with no registration, conflating 'refused, another connection owns it' with 'already gone'. Report true. - Note on the registry double that it mirrors production and can drift; the runtime tests pin real behavior, the doubles only pin routing. * fix(runtime): make the unsubscribe refusal observable and restore test-double parity Review pass 3: - The registry test double omitted production's 'unregistered id is already gone' early-out, so it returned refused where production returns gone. The legacy terminal.unsubscribe path reaches that branch with a never-registered bare id, so a routing test would have locked in the inverse of production. - terminal.unsubscribe ORed the bare-id and composite results. Registrations always use the composite, so the bare id reported 'already gone' and masked a real ownership refusal: a stale connection was correctly refused but told unsubscribed: true. The composite answer is authoritative when we try it. - Pin why the lease-only compensating handleMobileUnsubscribe is deliberately unguarded: it is safe only because that call passes no viewport and returns with no await. - Cover the no-registration branch, which had no test. * fix(runtime): report an unsubscribe refusal without masking a real teardown Review pass 4 disproved the previous commit's rationale. A clientless legacy-JSON stream registers under the bare terminal id, not the composite, so either call in terminal.unsubscribe can be the real teardown. Overwriting reported false after a destructive success; the earlier OR reported true after a refusal. AND over the calls that actually ran is the honest aggregate: false needs a genuine refusal. Tests: - cover the bare-id path, which the ownership tests never exercised - pin the microtask invariant the unguarded lease-only compensation depends on. The first version of that test was vacuous: it raced two setTimeout(0) timers, and the earlier-registered one always won, so it passed with an await injected. It now drains microtasks only and goes red under that mutation.
…ablyai#7490) Every terminal.subscribe / terminal.multiplex slot registers a runtime exit-waiter via waitForTerminal(condition:'exit'). With no AbortSignal that waiter sits in waitersByHandle until the PTY actually exits — but agent terminals routinely never exit for the life of a session. It is only ever cleared by real exit or a desktop renderer graph reload (markRendererReloading / markGraphUnavailable), neither of which a remote/mobile WebSocket reconnect triggers. So on long SSH/mobile sessions every reconnect and tab-switch re-subscribe leaked a waiter, and each captured its closed-connection handler context (including the dead ws), growing host-process memory monotonically. - multiplex: give each stream an AbortController and abort it in detachStream (the single teardown point, reached on slot unsubscribe, re-subscribe pre-detach, and connection close via closeMultiplex). Passing its signal to waitForTerminal removes the waiter at detach. The existing .catch no-ops because the stream is already deleted (streams.get(streamId) !== stream). - legacy json/binary subscribe: pass the per-connection dispatch signal so the waiter is removed on socket close/error. Regression test proves a signalled exit-waiter is released when its signal aborts (and 25 reconnect churns leave zero waiters), while an unsignalled one accumulates — the pre-fix behavior. Co-authored-by: Orca <[email protected]>
…ing registration (stablyai#14992) * fix(runtime): tear down terminal subscriptions only through their owning registration A terminal.subscribe teardown was keyed on `${terminal}:${clientId}`, which is stable across reconnects. cleanupSubscription invokes whichever cleanup currently owns that key, so after a mobile reconnect rebound the id, a late teardown from the dead connection killed the replacement stream and the terminal froze (STA-4510). Add registerOwnedSubscriptionCleanup, returning a registration handle whose releaseIfCurrent no-ops once the id has been rebound, and route all 12 teardown call sites in the three terminal.subscribe branches through it. Register-time eviction now also targets the owner it captured rather than re-resolving the key. terminal.unsubscribe gains the same ownership rule via connectionId, matching the runtime.clientEvents.unsubscribe precedent: make-before-break migration sends the unsubscribe over the old session after the new one has already rebound the id. The teardown-by-key pattern predates the bug; stablyai#7490 made it reachable by binding the exit-waiter to the per-socket abort signal, so every socket close now runs it. Tests use a faithful subscription-registry double; the ad-hoc Map stubs they replace never evicted the prior generation, which is why no test caught this. * test(runtime): migrate the remaining subscription stubs to the faithful registry streaming.test.ts and terminal-provider-snapshot-sequence.test.ts still stubbed registerSubscriptionCleanup only, so terminal.subscribe's owned registration was undefined and teardown never fired. Assert the registration is retired rather than spying on cleanupSubscription, which the owned path now calls internally. * fix(runtime): guard the lease-only presence release and use the shared registry double Review findings on this PR: - The lease-only branch's compensating handleMobileUnsubscribe ran unconditionally after a rebind. Presence is keyed (ptyId, clientId) with no refcount and `closed` is exactly the post-rebind state, so a superseded handler deleted the replacement subscriber's presence. Gate it on the registration still being current. This also gives SubscriptionRegistration.isCurrent its production caller. - The STA-4510 regression test hand-rolled a second registry copy that diverged from the shared double (no try/catch around cleanup, no in-flight join). Import the shared double instead, so the test proving the bug uses the same fidelity as the rest of the suite. - cleanupSubscriptionIfOwnedByConnection treats an absent connectionId as authority. That is the connection-less local unix-socket path, not an oversight; say so. * fix(runtime): drop the lease-only presence guard; it disabled a real compensation Review pass 2 showed the guard added in the previous commit was wrong. registration.isCurrent() is always false whenever `closed` is true: either our own cleanup ran, in which case cleanupSubscriptionAndWait already deleted the map entry, or a rebind replaced it. So the guard did not distinguish the two cases — it made the compensating handleMobileUnsubscribe unreachable, which is precisely the resurrect-after-cleanup case that line exists to handle. The scenario the guard was meant to fix is also not reachable: the lease-only call passes no viewport, and both !viewport paths in handleMobileSubscribeInternal return with no await, so the subscribe resolves in microtasks and a socket close cannot win it. Revert the guard, and drop SubscriptionRegistration.isCurrent with it — it had no remaining production caller and shipping unused runtime API invites exactly this. Also from review: - cleanupSubscriptionIfOwnedByConnection reported false for an id with no registration, conflating 'refused, another connection owns it' with 'already gone'. Report true. - Note on the registry double that it mirrors production and can drift; the runtime tests pin real behavior, the doubles only pin routing. * fix(runtime): make the unsubscribe refusal observable and restore test-double parity Review pass 3: - The registry test double omitted production's 'unregistered id is already gone' early-out, so it returned refused where production returns gone. The legacy terminal.unsubscribe path reaches that branch with a never-registered bare id, so a routing test would have locked in the inverse of production. - terminal.unsubscribe ORed the bare-id and composite results. Registrations always use the composite, so the bare id reported 'already gone' and masked a real ownership refusal: a stale connection was correctly refused but told unsubscribed: true. The composite answer is authoritative when we try it. - Pin why the lease-only compensating handleMobileUnsubscribe is deliberately unguarded: it is safe only because that call passes no viewport and returns with no await. - Cover the no-registration branch, which had no test. * fix(runtime): report an unsubscribe refusal without masking a real teardown Review pass 4 disproved the previous commit's rationale. A clientless legacy-JSON stream registers under the bare terminal id, not the composite, so either call in terminal.unsubscribe can be the real teardown. Overwriting reported false after a destructive success; the earlier OR reported true after a refusal. AND over the calls that actually ran is the honest aggregate: false needs a genuine refusal. Tests: - cover the bare-id path, which the ownership tests never exercised - pin the microtask invariant the unguarded lease-only compensation depends on. The first version of that test was vacuous: it raced two setTimeout(0) timers, and the earlier-registered one always won, so it passed with an await injected. It now drains microtasks only and goes red under that mutation.
Problem
Every
terminal.subscribe/terminal.multiplexslot registers a runtime exit-waiter viawaitForTerminal(request.terminal, { condition: 'exit' })with no AbortSignal.That waiter is stored in
waitersByHandleand is only ever removed by:markRendererReloading/markGraphUnavailable).Agent terminals routinely never exit for the whole session, and a remote/mobile WebSocket reconnect does not trigger the renderer graph lifecycle. So on long SSH/mobile sessions:
Each leaked waiter's
.then/.catchclosures capture the (now dead) streaming handler context — including the closedws— so host-process memory climbs monotonically and never releases. Confirmed against the code by the audit (waitersByHandleadd atorca-runtime.ts:9142; removal only viaresolvePtyExitWaiters/rejectAllWaiters).Fix
Give every teardown path a signal so the waiter is removed when the slot goes away:
terminal.ts:1663): each stream gets anAbortController;detachStreamaborts it.detachStreamis the single teardown point — reached on slotUnsubscribe, re-subscribe pre-detach, and connection close (closeMultiplexloops every stream through it). Passingstream.exitWaiterAbort.signaltowaitForTerminalremoves the waiter at detach; the existing.catchno-ops because the stream is already deleted (streams.get(streamId) !== stream).terminal.ts:1801,1851): pass the per-connection dispatchsignal, so the waiter is removed on socket close/error.No behavior change on real exit: abort after resolve is a no-op, and once a slot is detached there is no client to notify, so dropping the waiter loses no signal.
Evidence
New
terminal-subscribe-exit-waiter-leak.test.ts:waitersByHandle1 → 0);298 subscribe/rpc/pty tests pass (
mobile-subscribe-integration,runtime-rpc,pty). Typecheck + lint clean.Made with Orca 🐋
Description
Every
terminal.subscribeandterminal.multiplexslot arms a runtime exit-waiter viawaitForTerminal(..., { condition: 'exit' }). That waiter was created with noAbortSignal, so it was only ever removed from the runtime'swaitersByHandleset on a real PTY exit (resolveExitWaiters) or a desktop renderer graph reload (rejectAllWaitersonmarkRendererReloading/markGraphUnavailable) — neither of which a remote/mobile WebSocket reconnect or tab-switch re-subscribe triggers. On a long-lived, never-exiting agent terminal, every reconnect/re-subscribe therefore leaked one waiter, each pinning its now-dead per-slot handler context — on the multiplex path the stranded waiter also retains the slot'sstreamandemit/sendBinaryclosures, which reference the closed connection's send path (the two legacy paths retain only a lightercleanupSubscriptioncontinuation). The fix threads anAbortSignalinto each exit-waiter: the multiplex path gets a per-streamAbortController(exitWaiterAbort) aborted indetachStream— the single teardown point hit on unsubscribe, re-subscribe, and connection close (viacloseMultiplex); the two legacyterminal.subscribepaths bind to the connection dispatchsignal, which aborts on socket close/error. Aborting removes the waiter from the runtime set immediately instead of retaining it until real exit.Undeniable evidence + measured improvement
Measured (benchmark: 200 subscribe/reconnect cycles on one never-exiting terminal):
Correctness (new
src/main/runtime/terminal-subscribe-exit-waiter-leak.test.ts, driving the realOrcaRuntimeService; verified passing 3/3):releases a signalled exit-waiter when the signal aborts— registers a live connected PTY sowaitForTerminal({condition:'exit'})parks a pending waiter, assertswaiterCount === 1, callscontroller.abort()(simulatingdetachStream/connection close), and asserts the wait rejects andwaiterCount === 0.leaks an unsignalled exit-waiter across reconnects (documents the bug the fix prevents)— pins the pre-fix behavior: 3 unsignalled subscribes leavewaiterCount === 3with nothing to free them short of real exit.does not leak when many signalled subscribes churn (reconnect simulation)— 25 signalled subscribe→abort reconnect cycles end atwaiterCount === 0.The assertions read the runtime's private
waitersByHandleset directly, so they measure the leaked object itself, not a proxy metric.ELI5
Imagine every time you open a video call with a friend, a receptionist writes a sticky note that says "wait for this call to end, then clean up the room." The only thing that removes the note is the call actually ending normally. But on a phone with a shaky signal, the call keeps dropping and reconnecting — and each reconnect adds a new sticky note, while the old ones (each still clutching a dead phone line) are never thrown away. After a few hundred reconnects the wall is buried in stale notes, and the app is holding a pile of dead connections in memory. This change gives each note a self-destruct tab that fires the instant that particular connection tears down (hang-up, reconnect, or tab switch), so the wall stays clean instead of one note per reconnect forever.
Trade-offs that could regress the end experience
Honest search of ways this could regress the experience:
terminal.subscribepaths'.catch(() => cleanupSubscription(id))now also fires when the dispatch signal aborts. This is the intended behavior, but it meanscleanupSubscriptionmust tolerate running on close as well as on real exit; on a normal WS close it is now invoked both by this.catchand by the connection-close sweep (cleanupSubscriptionsForConnection), so it will run twice. This leans on that method being idempotent — verified: it deletes fromsubscriptionCleanupsbefore invoking the cleanup, so the second call no-ops (and the pre-fix code already double-called it via.then/.catch). Low risk, but it is the one behavior change to watch.detachStream, afterstreams.delete) may win and reject the waiter. The.catchthen no-ops becausestreams.get(streamId) === streamis already false, so no spuriousendframe is sent — but a client that unsubscribed at that exact moment relies on its own teardown rather than the exit notification. Acceptable: an unsubscribing client no longer needs the exit signal. (On a real exit while the connection is still open, the waiter still resolves normally and the live client still gets itsendframe — the signal only aborts on teardown, so no exit notification is lost for a connected client.)exitWaiterAbortis released on unsubscribe, re-subscribe, and close; the legacyterminal.subscribewaiter is bound to the dispatch signal, which aborts only on socket close/error — NOT on a same-id re-subscribe that evicts the old subscription (registerSubscriptionCleanupresolves the old dispatch, and dispatchdispose()removes the abort controller without aborting it). So an evicted legacy subscription can still strand its waiter until real exit. This is unchanged from before and effectively inert for current clients (the desktop/mobile remote path usesterminal.multiplex, whichdetachStreamfully covers;terminal.subscriberemains only for back-compat)./electron: the leak only manifests over many real remote/mobile WS reconnects on a long-lived session, so verification rests on the benchmark numbers and the runtime-level regression test rather than a desktop repro.