You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(remote): stop redialing servers removed from the saved list - #41902
When a server is removed with orca environment rm, the running Orca app (desktop or headless orca serve) kept a background connection to it and kept dialing it every five minutes, forever, until Orca restarted. Orca now hangs up on a server as soon as it leaves the saved list, and a server that stays unreachable for about an hour with nothing using it stops being dialed until someone uses it again.
What Changed
Before:
The CLI rewrites orca-environments.json in its own process. The running app's cached transports for the removed id (status owner, request connection, shared-control connection) stayed in runtime-environment-request-connections.ts. Only the in-app Remove button tore them down.
Headless serve never calls registerCoreHandlers, so it has no registry watch at all. On one Mac running orca serve, 168 of the 172 environments with failing reconnects had already been removed from the store. They produced about 242 remote-runtime.control-socket-close spans per 10 minutes (cause: socket_error, state: awaiting_ready, errorCode: remote_runtime_unavailable), and one had reached reconnectAttempt: 62. That timer work kept the idle server's main thread 60 to 67% busy, 45% of it in JavaScript timer callbacks.
An idle shared-control connection (no subscriptions) climbed the backoff ladder to 300s and then redialed every 300s with no attempt limit.
After:
runtime-environment-removed-connections.ts (new) watches the registry file with the existing watchRuntimeEnvironmentRegistry helper, so it sees atomic replaces and writes from other processes, with the 30s rebind sweep as a backstop. On each change it reads the raw records and closes the cached transports of every id the file listed before and no longer lists. It advances the transport generation first, so retained streams close the same way they do on a re-pair. The read uses the raw records, so ids of unreadable or overlay-hidden records count as still saved. A failed read closes nothing.
initializeMainProcessRuntime installs that watch, so desktop and headless serve both get it. It is disposed on will-quit.
SharedControlReconnectScheduler stops scheduling an idle connection after MAX_IDLE_RECONNECT_ATTEMPTS = 20 consecutive redials. Any open the backoff timer did not schedule resets the count and starts the ladder from 250ms again: a request, a subscription, reconnectNow from the status owner or the Connect button, or a re-pair, which builds a new connection.
Values: the idle ladder is unchanged (250ms doubling to 30s, then 60s, 120s, 300s). Twenty attempts cover about 54 minutes of backoff, up to about 65 with the existing +20% jitter. A server that drops for a restart, a network change or a VM reboot keeps reconnecting for that whole hour without anyone touching it. After that it is dialed again on first use. Connections with live subscriptions keep the existing unbounded backoff, capped at 30s: a subscriber owns that recovery, and the removal watch covers the removed-server case for them.
Why
Earlier PRs for this issue, #21048 and #25974, check removal from the socket heartbeat and the reconnect path, and install the check from registerRuntimeEnvironmentHandlers. Headless serve never runs that function, and that is where these 168 connections lived. Both PRs now conflict with the runtime-environments/ and remote-runtime/control/ directory moves. This PR takes a smaller route: the registry watch the desktop already uses for the Active Server preference, installed where both modes start the runtime. It adopts #25974's rule that only an id this registry once listed can be judged removed, so a connection resolved from another registry is never closed. If maintainers prefer to land this through #25974, the idle cap carries over on its own.
A cap with no removal watch was rejected: a removed server would still be dialed for an hour after every restart of the remote side. A removal watch with no cap was rejected too: any path that misses the watch (a store unreadable when the removal lands, an orcad host, or a server that is saved but gone for good) would redial forever again.
N/A: no UI change. The difference is whether a removed server keeps getting dialed, which shows up in sockets and trace spans, not on screen.
Testing
Node modules were not installed in this checkout, so I did not run the tests, typecheck or lint locally. CI runs them.
runtime-environment-removed-connections.test.ts: a reconnecting socket whose environment is removed is closed, its reconnect timer is cleared, and no dial happens across 10 minutes of fake time. The file watch closes the connection after a removal written to the file directly, the way the CLI writes it. Saved servers, servers from another registry, and every server while the file is unreadable keep their connections. A server paired again after removal connects.
remote-runtime-shared-control-idle-cap.test.ts: a connection to a dead endpoint redials exactly 20 times, leaves no timer armed, then dials again on the next request and goes back to reconnecting at attempt 1.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Risk
The riskiest part is the sweep closing a connection that is still wanted. It closes only ids that the watched file listed earlier and no longer lists, counting unreadable records as listed. A user sees a removed server go to disconnected, which is what Remove already does in Settings. The second risk is the idle cap. A saved server that is offline for over an hour with no subscriptions shows disconnected until it is used, Connect is pressed, or it is re-paired; it does not reconnect by itself when it returns. A plain revert backs out both parts. Nothing on disk changes.
Level: Low
AI Disclosure
Written with Claude Code (Claude Opus 5.5). The diff got one finder pass from OpenAI Codex (gpt-6.1-sol).
Review
One Codex finder pass over the diff found four issues:
Fixed: the first sweep read the merged catalog, which hides records it cannot parse and servers whose sidecar entry is unreadable, so those would have counted as removed. It now reads the raw records, unreadable ids included.
Fixed: the idle-cap test advanced 10 minutes at a time, and real socket errors arriving between fake timers could fire several redials per step. It now fires one timer per observed close.
Left as is: a server added, connected and removed within one watch coalescing window (200ms to 1.6s) is never seen in the file, so the sweep cannot judge it removed. If it has no subscriptions, it parks after the cap.
Out of scope: an unverified status owner retries its one-shot status.get every 60s with no limit. That path existed before this PR, and none of the measured removed servers were on it, since their status owners had verified earlier.
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
The watch is one more fs.watch on a single file and one stat every 30s, the same cost as the existing preference watch. Nothing changes for paired phones, SSH-managed servers, or the wire protocol.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
The runtime-environment registry sweep detects removed environment IDs and closes their cached request connections. Main-process startup registers the watcher through a will-quit handler. Shared-control reconnection now parks after 20 idle attempts and resumes parked work when the connection opens. Tests cover removal, retained connections, and idle reconnect behavior.
Severity of issue fixed: Medium
Merge Risk: Low · up to 7b4a3
Removed servers are no longer redialed, and idle reconnects are capped. One small gap remains: an explicit retry made after several failed redials does not get a full retry budget before parking. The next request restarts reconnection, so this is bounded and can be addressed as a follow-up.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: the app stops redialing servers after they are removed from the saved list. It is specific and follows the conventional-commit style. The title covers the removal-watc…
Description check
The description follows the repository template. It has the ELI5, What Changed, Why, Linked Issue (Fixes #20995), Visual Proof (N/A with reason), Testing, Risk (Level: Low), AI Disclosure, Review, Age…
Linked Issues check
Issue #20995 requires that removing an environment closes its transport and drops it from the in-memory reconnect set, so saved and live connections agree. The new `createRemovedRuntimeEnvironmentSwee…
Out of Scope Changes check
All changes connect to the issue goal of stopping reconnects to removed environments. The registry watch and sweep (runtime-environment-removed-connections.ts, listCachedRuntimeEnvironmentIds, the…
Full details: Title check
Explanation
The title names the main change: the app stops redialing servers after they are removed from the saved list. It is specific and follows the conventional-commit style. The title covers the removal-watch fix; it does not mention the idle reconnect cap, which is a secondary part of the change.
Full details: Description check
Explanation
The description follows the repository template. It has the ELI5, What Changed, Why, Linked Issue (Fixes #20995), Visual Proof (N/A with reason), Testing, Risk (Level: Low), AI Disclosure, Review, Agent skill boundary, Notes, and Checklist sections. The description explains the before and after behavior, the mechanism, the alternatives considered, and the rollback path. Some gaps remain: the Testing section says the tests were not run locally, and the manual-test box is unchecked. The final checklist item for lint, typecheck, test and build is also unchecked, and CI is expected to cover it. The template's Risk section asks to say how to back out; the author did this with a plain revert.
Full details: Linked Issues check
Explanation
Issue #20995 requires that removing an environment closes its transport and drops it from the in-memory reconnect set, so saved and live connections agree. The new createRemovedRuntimeEnvironmentSweep in runtime-environment-removed-connections.ts compares the previously listed registry ids with the current ids. For each cached id that was listed and is no longer listed, it calls advanceRuntimeEnvironmentTransportGeneration and closeRemoteRuntimeRequestConnection. At the reviewed head, closeRemoteRuntimeRequestConnection deletes and disposes the status owner, closes and deletes the request connection, and calls closeRemoteRuntimeSharedControlConnection, which deletes and closes the shared-control connection. The sweep runs on each registry-file change through watchRuntimeEnvironmentRegistry, and initializeMainProcessRuntime installs it, so the CLI write path in the issue is covered. Sweep keys are environment ids, so a surviving environment that shares a runtimeId with a removed one keeps its connection. The idle cap in SharedControlReconnectScheduler (MAX_IDLE_RECONNECT_ATTEMPTS = 20) is a backstop for the case where the watch misses a removal. Automated tests are described in the PR; I did not run them. Coding requirements are met by the code at the reviewed head.
Full details: Out of Scope Changes check
Explanation
All changes connect to the issue goal of stopping reconnects to removed environments. The registry watch and sweep (runtime-environment-removed-connections.ts, listCachedRuntimeEnvironmentIds, the will-quit wiring in main-process-runtime-service.ts) implement the issue directly. The idle cap in remote-runtime-shared-control-reconnect.ts and the resumeParked() call in remote-runtime-shared-control-connection.ts are a backstop for missed removals. The cap also applies to saved servers, not only removed ones. It stops idle auto-reconnect after about 54 minutes for those servers. The PR states this trade-off, so reviewers can judge it, but it is a behavior change beyond the literal issue text. It is related to the issue and is not an unrelated change. The new tests cover the sweep and the cap. Minor note: parked is not cleared by retryNow(). This affects only the flag that resumeParked() reads and does not change dial behavior.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Reset the idle retry budget on explicit use before parking.
If an explicit request or reconnectNow() reaches open() after 19 failed redials, resumeParked() does nothing because parked is still false. clear() also preserves the counter. If the new dial fails, only one scheduled redial remains before parking.
This does not satisfy the stated reset-on-use behavior. Reset the idle retry budget at explicit activity entry points. Preserve the counter during automatic opens.
`orca environment rm` and other out-of-app edits only rewrite the saved-server
registry. The in-app Remove button retires the server's transports, but a
removal written by another process never reached the running app (desktop or
headless `orca serve`), so the removed server's sockets kept redialing until
restart.
Each registry read now also finds the servers that left the saved list (those
the last read listed or that still hold a transport) and retires them through
the same transport invalidation the Remove button uses. Desktop reuses its
existing registry watch; headless serve, which registers no Settings handlers,
gets its own watch. An unreadable registry retires nothing.
Fixes#20995. Rebuilt from #41902 by yasyf (Yasyf Mohamedali).
Co-authored-by: Yasyf Mohamedali <[email protected]>
Retirement of a server removed outside Settings is now one reconciliation loop
per desktop registration and per headless watch. Each pass reads the saved list
and retires every server listed by the last read, still holding a socket,
status owner, stream or browser route, or still owed an earlier failed
retirement, and not saved now. It retries on a bounded backoff (1 s doubling to
60 s) until the list and the held transports agree, so an unreadable read or a
failed cleanup no longer goes quiet. A transport, status owner or browser route
created after a removal scan for a server the last read did not list wakes the
loop, so a caller that resolved the server before its removal is still retired.
Each retirement starts every step synchronously in the read's continuation,
browser client-host retirement included, so a same-id re-add, which resolves
through a later registry read, queues behind it; one failed step skips no
other. Settings' Remove uses the same steps. Retirement stays eventual: a dial
already in flight may open once more.
Rebuilt from #41902 by yasyf (Yasyf Mohamedali).
Co-authored-by: Yasyf Mohamedali <[email protected]>
`orca environment rm` and other out-of-app edits only rewrite the saved-server
registry. The in-app Remove button retires the server's transports, but a
removal written by another process never reached the running app (desktop or
headless `orca serve`), so the removed server's sockets kept redialing until
restart.
Each registry read now also finds the servers that left the saved list (those
the last read listed or that still hold a transport) and retires them through
the same transport invalidation the Remove button uses. Desktop reuses its
existing registry watch; headless serve, which registers no Settings handlers,
gets its own watch. An unreadable registry retires nothing.
Fixes#20995. Rebuilt from #41902 by yasyf (Yasyf Mohamedali).
Co-authored-by: Yasyf Mohamedali <[email protected]>
Retirement of a server removed outside Settings is now one reconciliation loop
per desktop registration and per headless watch. Each pass reads the saved list
and retires every server listed by the last read, still holding a socket,
status owner, stream or browser route, or still owed an earlier failed
retirement, and not saved now. It retries on a bounded backoff (1 s doubling to
60 s) until the list and the held transports agree, so an unreadable read or a
failed cleanup no longer goes quiet. A transport, status owner or browser route
created after a removal scan for a server the last read did not list wakes the
loop, so a caller that resolved the server before its removal is still retired.
Each retirement starts every step synchronously in the read's continuation,
browser client-host retirement included, so a same-id re-add, which resolves
through a later registry read, queues behind it; one failed step skips no
other. Settings' Remove uses the same steps. Retirement stays eventual: a dial
already in flight may open once more.
Rebuilt from #41902 by yasyf (Yasyf Mohamedali).
Co-authored-by: Yasyf Mohamedali <[email protected]>
…ce stale starts
- A reconcile pass starts its retirements without waiting for them; each settles
on its own, and a failure or a server still held afterwards is owed to a later
read on the bounded backoff, so one slow browser close no longer holds back
another server's removal.
- A close or dispose that throws is kept by identity and retried on every pass,
even after the server id is re-added; generation, relay and pending-subscription
siblings each run past a throwing one.
- A browser client host's route is published only if no retirement happened since
its start began (a per-server retirement epoch that never resets), so an old
start never becomes authoritative over a removal or a same-id replacement.
- Settings' Remove settles both the release and the status reactivation on every
path, handles a failed release at once, and rejects with it so the partition
clear knows; callers that drop the promise now handle the rejection.
- Desktop startup and the registry watch act only while their registration is
current, the preference repair cannot write after its watch stops, and one read
per pass decides transports, sessions and port forwards.
Rebuilt from #41902 by yasyf (Yasyf Mohamedali).
Co-authored-by: Yasyf Mohamedali <[email protected]>
…ce stale starts
- A reconcile pass starts its retirements without waiting for them; each settles
on its own, and a failure or a server still held afterwards is owed to a later
read on the bounded backoff, so one slow browser close no longer holds back
another server's removal.
- A close or dispose that throws is kept by identity and retried on every pass,
even after the server id is re-added; generation, relay and pending-subscription
siblings each run past a throwing one.
- A browser client host's route is published only if no retirement happened since
its start began (a per-server retirement epoch that never resets), so an old
start never becomes authoritative over a removal or a same-id replacement.
- Settings' Remove settles both the release and the status reactivation on every
path, handles a failed release at once, and rejects with it so the partition
clear knows; callers that drop the promise now handle the rejection.
- Desktop startup and the registry watch act only while their registration is
current, the preference repair cannot write after its watch stops, and one read
per pass decides transports, sessions and port forwards.
Rebuilt from #41902 by yasyf (Yasyf Mohamedali).
Co-authored-by: Yasyf Mohamedali <[email protected]>
…ackoff once per cycle
- Every close retained anywhere (a stream, an old socket while a browser release
is held) wakes the recovery timer at once, and each pass re-checks for retained
closes after its own retirements, so recovery never waits for a held browser
teardown or a later registry write. The old object stays in custody by
identity across a same-id replacement.
- One recovery timer, armed at most once at a time: retirements that fail
together advance the backoff once, and it resets only when the last read
succeeded, nothing is owed, no retirement is in flight and no close is retained.
Rebuilt from #41902 by yasyf (Yasyf Mohamedali).
Co-authored-by: Yasyf Mohamedali <[email protected]>
`orca environment rm` and other out-of-app edits only rewrite the saved-server
registry. The in-app Remove button retires the server's transports, but a
removal written by another process never reached the running app (desktop or
headless `orca serve`), so the removed server's sockets kept redialing until
restart.
Each registry read now also finds the servers that left the saved list (those
the last read listed or that still hold a transport) and retires them through
the same transport invalidation the Remove button uses. Desktop reuses its
existing registry watch; headless serve, which registers no Settings handlers,
gets its own watch. An unreadable registry retires nothing.
Fixes#20995. Rebuilt from #41902 by yasyf (Yasyf Mohamedali).
Co-authored-by: Yasyf Mohamedali <[email protected]>
Retirement of a server removed outside Settings is now one reconciliation loop
per desktop registration and per headless watch. Each pass reads the saved list
and retires every server listed by the last read, still holding a socket,
status owner, stream or browser route, or still owed an earlier failed
retirement, and not saved now. It retries on a bounded backoff (1 s doubling to
60 s) until the list and the held transports agree, so an unreadable read or a
failed cleanup no longer goes quiet. A transport, status owner or browser route
created after a removal scan for a server the last read did not list wakes the
loop, so a caller that resolved the server before its removal is still retired.
Each retirement starts every step synchronously in the read's continuation,
browser client-host retirement included, so a same-id re-add, which resolves
through a later registry read, queues behind it; one failed step skips no
other. Settings' Remove uses the same steps. Retirement stays eventual: a dial
already in flight may open once more.
Rebuilt from #41902 by yasyf (Yasyf Mohamedali).
Co-authored-by: Yasyf Mohamedali <[email protected]>
…ce stale starts
- A reconcile pass starts its retirements without waiting for them; each settles
on its own, and a failure or a server still held afterwards is owed to a later
read on the bounded backoff, so one slow browser close no longer holds back
another server's removal.
- A close or dispose that throws is kept by identity and retried on every pass,
even after the server id is re-added; generation, relay and pending-subscription
siblings each run past a throwing one.
- A browser client host's route is published only if no retirement happened since
its start began (a per-server retirement epoch that never resets), so an old
start never becomes authoritative over a removal or a same-id replacement.
- Settings' Remove settles both the release and the status reactivation on every
path, handles a failed release at once, and rejects with it so the partition
clear knows; callers that drop the promise now handle the rejection.
- Desktop startup and the registry watch act only while their registration is
current, the preference repair cannot write after its watch stops, and one read
per pass decides transports, sessions and port forwards.
Rebuilt from #41902 by yasyf (Yasyf Mohamedali).
Co-authored-by: Yasyf Mohamedali <[email protected]>
…ackoff once per cycle
- Every close retained anywhere (a stream, an old socket while a browser release
is held) wakes the recovery timer at once, and each pass re-checks for retained
closes after its own retirements, so recovery never waits for a held browser
teardown or a later registry write. The old object stays in custody by
identity across a same-id replacement.
- One recovery timer, armed at most once at a time: retirements that fail
together advance the backoff once, and it resets only when the last read
succeeded, nothing is owed, no retirement is in flight and no close is retained.
Rebuilt from #41902 by yasyf (Yasyf Mohamedali).
Co-authored-by: Yasyf Mohamedali <[email protected]>
Thank you @yasyf for finding this bug, diagnosing it so clearly, and proposing the fix. We rebuilt it on current main in #53623, which grew to also cover a few related cases (a failed registry read, connections opened just after a removal, and same-id re-adds). You're credited there in the description and as co-author on the commits. We're closing this PR in favor of #53623. Thanks again for the contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When a server is removed with
orca environment rm, the running Orca app (desktop or headlessorca serve) kept a background connection to it and kept dialing it every five minutes, forever, until Orca restarted. Orca now hangs up on a server as soon as it leaves the saved list, and a server that stays unreachable for about an hour with nothing using it stops being dialed until someone uses it again.What Changed
Before:
orca-environments.jsonin its own process. The running app's cached transports for the removed id (status owner, request connection, shared-control connection) stayed inruntime-environment-request-connections.ts. Only the in-app Remove button tore them down.registerCoreHandlers, so it has no registry watch at all. On one Mac runningorca serve, 168 of the 172 environments with failing reconnects had already been removed from the store. They produced about 242remote-runtime.control-socket-closespans per 10 minutes (cause: socket_error,state: awaiting_ready,errorCode: remote_runtime_unavailable), and one had reachedreconnectAttempt: 62. That timer work kept the idle server's main thread 60 to 67% busy, 45% of it in JavaScript timer callbacks.After:
runtime-environment-removed-connections.ts(new) watches the registry file with the existingwatchRuntimeEnvironmentRegistryhelper, so it sees atomic replaces and writes from other processes, with the 30s rebind sweep as a backstop. On each change it reads the raw records and closes the cached transports of every id the file listed before and no longer lists. It advances the transport generation first, so retained streams close the same way they do on a re-pair. The read uses the raw records, so ids of unreadable or overlay-hidden records count as still saved. A failed read closes nothing.initializeMainProcessRuntimeinstalls that watch, so desktop and headless serve both get it. It is disposed onwill-quit.SharedControlReconnectSchedulerstops scheduling an idle connection afterMAX_IDLE_RECONNECT_ATTEMPTS = 20consecutive redials. Any open the backoff timer did not schedule resets the count and starts the ladder from 250ms again: a request, a subscription,reconnectNowfrom the status owner or the Connect button, or a re-pair, which builds a new connection.Values: the idle ladder is unchanged (250ms doubling to 30s, then 60s, 120s, 300s). Twenty attempts cover about 54 minutes of backoff, up to about 65 with the existing +20% jitter. A server that drops for a restart, a network change or a VM reboot keeps reconnecting for that whole hour without anyone touching it. After that it is dialed again on first use. Connections with live subscriptions keep the existing unbounded backoff, capped at 30s: a subscriber owns that recovery, and the removal watch covers the removed-server case for them.
Why
Earlier PRs for this issue, #21048 and #25974, check removal from the socket heartbeat and the reconnect path, and install the check from
registerRuntimeEnvironmentHandlers. Headless serve never runs that function, and that is where these 168 connections lived. Both PRs now conflict with theruntime-environments/andremote-runtime/control/directory moves. This PR takes a smaller route: the registry watch the desktop already uses for the Active Server preference, installed where both modes start the runtime. It adopts #25974's rule that only an id this registry once listed can be judged removed, so a connection resolved from another registry is never closed. If maintainers prefer to land this through #25974, the idle cap carries over on its own.A cap with no removal watch was rejected: a removed server would still be dialed for an hour after every restart of the remote side. A removal watch with no cap was rejected too: any path that misses the watch (a store unreadable when the removal lands, an orcad host, or a server that is saved but gone for good) would redial forever again.
Linked Issue
Fixes #20995
Visual Proof
N/A: no UI change. The difference is whether a removed server keeps getting dialed, which shows up in sockets and trace spans, not on screen.
Testing
Node modules were not installed in this checkout, so I did not run the tests, typecheck or lint locally. CI runs them.
runtime-environment-removed-connections.test.ts: a reconnecting socket whose environment is removed is closed, its reconnect timer is cleared, and no dial happens across 10 minutes of fake time. The file watch closes the connection after a removal written to the file directly, the way the CLI writes it. Saved servers, servers from another registry, and every server while the file is unreadable keep their connections. A server paired again after removal connects.remote-runtime-shared-control-idle-cap.test.ts: a connection to a dead endpoint redials exactly 20 times, leaves no timer armed, then dials again on the next request and goes back toreconnectingat attempt 1.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Risk
The riskiest part is the sweep closing a connection that is still wanted. It closes only ids that the watched file listed earlier and no longer lists, counting unreadable records as listed. A user sees a removed server go to disconnected, which is what Remove already does in Settings. The second risk is the idle cap. A saved server that is offline for over an hour with no subscriptions shows disconnected until it is used, Connect is pressed, or it is re-paired; it does not reconnect by itself when it returns. A plain revert backs out both parts. Nothing on disk changes.
Level: Low
AI Disclosure
Written with Claude Code (Claude Opus 5.5). The diff got one finder pass from OpenAI Codex (gpt-6.1-sol).
Review
One Codex finder pass over the diff found four issues:
status.getevery 60s with no limit. That path existed before this PR, and none of the measured removed servers were on it, since their status owners had verified earlier.Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
The watch is one more
fs.watchon a single file and one stat every 30s, the same cost as the existing preference watch. Nothing changes for paired phones, SSH-managed servers, or the wire protocol.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)