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 - #53623
When a saved server was removed from outside the app (for example with orca environment rm), the running Orca app (desktop or headless orca serve) never heard about it. It kept its connections to that server and kept redialing it until Orca restarted. Now Orca notices the saved list changed and hangs up on the removed server, just as the Remove button in Settings already did.
Files
Added
Deleted
Net
Test
2
$\color{#1a7f37}{\Huge{\mathbf{+}}}$604
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$604
Prod
20
$\color{#1a7f37}{\Huge{\mathbf{+}}}$617
$\color{#cf222e}{\Huge{\mathbf{−}}}$66
$\color{#1a7f37}{\Huge{\mathbf{+}}}$551
What Changed
Before: only Settings' Remove closed a server's connections. orca environment rm and other edits rewrite the saved-server file from another process, so the app's cached sockets, status checks, streams and browser routes for that server stayed alive and kept reconnecting. Headless orca serve had no watch on the file at all.
After: one reconciler per process compares the saved list with everything the app still holds for a server, and retires whatever no longer belongs to a saved server. Desktop runs it from its existing registry watch; headless serve gets its own watch. It uses the same teardown as Settings' Remove.
It keeps going until the list and the held connections agree. An unreadable registry read, a failed cleanup step, or a close that throws is retried with a backoff (1 s doubling to 60 s), so a removal is never silently forgotten. A connection opened just after a removal, by a caller that looked the server up a moment earlier, also triggers a fresh check and is retired.
A server removed and re-added under the same id keeps its new connections and browser route. An old browser start that finishes after the removal can no longer publish its route.
Cleanup steps run independently, so one failing step no longer skips the rest.
Why
Fixes#20995. The idea and the original fix come from #41902 by @yasyf, who found and diagnosed the bug; this PR rebuilds it on current main and they are credited as co-author on these commits. Thank you!
Known limit
Retirement is eventual, not a fence, exactly like the Remove button today: a dial already in flight when the file is rewritten can connect once more before it is closed.
Testing
New desktop and headless suites drive the real entry points against a real registry file, the real file watch and a local server that drops every connection. They cover removal outside the app, a failed registry read with no further write, a connection opened after the removal scan, a same-id re-add (connections and browser route), a slow browser close not blocking other removals, a throwing cleanup step, a throwing close retried by identity, backoff progression, and a replaced registration not acting.
Each case was confirmed to fail with its fix reverted.
Ran on Linux: the new suites (12/12), src/main/ipc/runtime-environments, browser/client-hosts, ipc/ssh, ipc/wsl and ephemeral-vm suites (64/64), pnpm typecheck:node, pnpm lint (50/50) and pnpm check:changed (40/40).
Visual Proof
N/A: no UI change; the effect is that removed servers stop being redialed.
Performance
No hot-path work. Reconcile passes coalesce into one loop, each doing one async registry read and set work proportional to saved plus held servers. Retries share a single unref'd timer armed at most once, capped at one read per 60 s for a permanently failing close or unreadable registry. Desktop reuses its existing registry watch; headless adds one file watch (one sync stat at startup, recorded in the blocking-helper baseline) and lazy-loads its connection code only on the first change. A new connection triggers a read only when its server was not in the last read. A disposable local probe (not committed) retired 1,000 redialing removed servers about 243 ms after the registry write, with no redials afterwards; that is a test-environment number, not a production measurement.
Risk
Level: Medium. It touches how connections to paired servers are torn down. If the reconciler misjudged a server as removed, that server's connections would close and reopen on next use; it only acts on ids missing from a successful registry read. Size: about 1,290 changed lines, roughly 580 production and the rest tests. Back out with a plain revert.
`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]>
…te and drop real-time waits
The desktop suite registers handlers in beforeAll, before the shared setup
installs the app environment, so registration failed before any test ran. It
now installs the fake app environment (pointed at the suite's registry) in
beforeAll and again before each test.
Both suites now wait on observable conditions (held transports, settled
registry reads, an explicit later registry change) instead of fixed sleeps.
The failed read in the quiet-recovery cases is now the one that sees the
server gone, not merely the next one.
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]>
- Quiet recovery: the injected fault records that it fired on the read that saw
the removal while the server was still held, and the test asserts a later read
retired it, with no further write.
- Same-id re-add: the replacement socket is opened, a later pass runs, and the
socket is used again; it must be reused (one publication) and still held.
- Settings' Remove: waits for a new status owner object for that server instead
of any held id.
- The held-browser-release recovery case starts after a settled pass, so no retry
left armed by an earlier case can do the recovery for it.
Co-authored-by: Yasyf Mohamedali <[email protected]>
…al; type the read state
Opening the first shared-control socket also advances the transport generation,
so the one-shot throwing listener fired on the dial instead of the removal and
escaped from the test's own dial. It is now armed after the socket is held.
The headless suite's read state is typed instead of cast.
Co-authored-by: Yasyf Mohamedali <[email protected]>
The change adds transport publication tracking, retained-close retries, and reconciliation for transports belonging to removed runtime environments. Runtime-environment registration starts and stops the reconciler, and stale registration work is fenced. Paired browser-host route epochs prevent starts begun before retirement from publishing routes afterward. New regression tests cover failed reads and closes, retries, replacement environments, and browser-host retirement.
Severity of issue fixed: Medium
Merge Risk: Low · up to 1023a
Removing an environment outside the app now retires its connections as intended. A few narrow edge cases remain: status refreshes can time out instead of reporting a disconnect, same-ID pairing edits leave an idle connection cached, and sockets still in setup can outlive a removal until setup finishes. These are bounded and low-impact, so they are worth addressing but should not block merging.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: the app now stops redialing servers removed from the saved list. The changeset adds a reconciler that retires connections for servers no longer in the saved registry, …
Description check
The description follows the template closely. It covers ELI5, What Changed, Why with a linked issue (Fixes #20995), a Visual Proof N/A with reason, Testing with the suites and commands run, Performanc…
Linked Issues check
[#20995] The reported defect is that a removal written to orca-environments.json by another process (orca environment rm) never reaches the running app, which keeps its transport and redials. The PR…
Out of Scope Changes check
Most changes map directly to the #20995 objective. These include the reconciler, the headless watch, the desktop reconciler wiring in runtime-environments.ts, the transport-publication tracker, stat…
Full details: Title check
Explanation
The title names the main change: the app now stops redialing servers removed from the saved list. The changeset adds a reconciler that retires connections for servers no longer in the saved registry, which matches the title's fix. The title uses the conventional fix(remote) prefix and is concise.
Full details: Description check
Explanation
The description follows the template closely. It covers ELI5, What Changed, Why with a linked issue (Fixes #20995), a Visual Proof N/A with reason, Testing with the suites and commands run, Performance with a reason, and Risk with a level and backout plan. It also includes the AI Disclosure section. The Testing checklist boxes are unchecked, and the Review, Agent skill upstream boundary, and Notes sections are left as template text. The Risk section gives no explicit level in the template field format beyond 'Medium', which is acceptable. Overall the description is mostly complete.
Full details: Linked Issues check
Explanation
[#20995] The reported defect is that a removal written to orca-environments.json by another process (orca environment rm) never reaches the running app, which keeps its transport and redials. The PR adds a reconciler (runtime-environment-removed-transports.ts) that compares the saved registry IDs with the IDs the app still holds (request connections, shared-control connections, status owners, subscriptions, paired browser hosts). It retires every held ID that is absent from a successful registry read, using the teardown that the Settings Remove path already uses (retireRemoteRuntimeTransports, invalidateRuntimeEnvironmentTransport). Desktop runs it from its existing registry watch in runtime-environments.ts. Headless orca serve installs its own registry watch through watchRemovedRuntimeEnvironmentTransports, called from core-runtime-activation.ts. Failed reads and failed closes are retried with backoff from 1 s to 60 s, so a removal is not dropped. A connection opened after the scan triggers another check. The suggested outcome (close transport, drop from in-memory reconnect set) is covered. The PR description and the new suites (runtime-environments-removed-transports.test.ts, runtime-environment-removed-transports.test.ts) state that they drive the real registry file, real file watch, and a local server that drops connections, and that each case was confirmed to fail with the fix reverted. I did not run these tests. The assessment relies on the change summary and the PR's reported results. Retirement is eventual; an in-flight dial may connect once more before it closes. The PR states this limit, and the issue does not require a stronger fence.
Full details: Out of Scope Changes check
Explanation
Most changes map directly to the #20995 objective. These include the reconciler, the headless watch, the desktop reconciler wiring in runtime-environments.ts, the transport-publication tracker, status-owner and request-connection ID listing, retireRemoteRuntimeTransports, runEveryStep and closeOrRetain (retain failed closes by identity), and the removed-server test fixture and test suites. The browser-host route epoch and retirement changes (paired-runtime-browser-client-host-state.ts and the lifecycle runtime file) cover the paired browser route state that the removal must also tear down. The same-ID re-add and stale-start guards are part of that teardown. The small changes in ssh-host-user-disconnect.ts, wsl-host-handlers.ts, runtime-resume-pairing.ts, owned-runtime-cleanup.ts and runtime-environment-remove-handler.ts add rejection handling. They are needed because invalidateRuntimeEnvironmentTransport now rejects when a step fails. runtime-environment-mobile-relay-hosts.ts and runtime-environment-transport-generation.ts run every listener, so one failure does not skip the rest of the teardown. main-blocking-helper-baseline.txt records the one new synchronous statSync for the headless watch. runtime-environment-preference.ts adds stopped-flag guards so that a replaced registration does not act. These guards are the same class of stale-work protection the issue needs. No change was found that is unrelated to removing a runtime environment. The reviewed scope is based on the change summary, not a full diff read.
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; 6 remain after this review.
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 saved server was removed from outside the app (for example with
orca environment rm), the running Orca app (desktop or headlessorca serve) never heard about it. It kept its connections to that server and kept redialing it until Orca restarted. Now Orca notices the saved list changed and hangs up on the removed server, just as the Remove button in Settings already did.What Changed
orca environment rmand other edits rewrite the saved-server file from another process, so the app's cached sockets, status checks, streams and browser routes for that server stayed alive and kept reconnecting. Headlessorca servehad no watch on the file at all.Why
Fixes #20995. The idea and the original fix come from #41902 by @yasyf, who found and diagnosed the bug; this PR rebuilds it on current main and they are credited as co-author on these commits. Thank you!
Known limit
Retirement is eventual, not a fence, exactly like the Remove button today: a dial already in flight when the file is rewritten can connect once more before it is closed.
Testing
src/main/ipc/runtime-environments,browser/client-hosts,ipc/ssh,ipc/wslandephemeral-vmsuites (64/64),pnpm typecheck:node,pnpm lint(50/50) andpnpm check:changed(40/40).Visual Proof
N/A: no UI change; the effect is that removed servers stop being redialed.
Performance
No hot-path work. Reconcile passes coalesce into one loop, each doing one async registry read and set work proportional to saved plus held servers. Retries share a single unref'd timer armed at most once, capped at one read per 60 s for a permanently failing close or unreadable registry. Desktop reuses its existing registry watch; headless adds one file watch (one sync
statat startup, recorded in the blocking-helper baseline) and lazy-loads its connection code only on the first change. A new connection triggers a read only when its server was not in the last read. A disposable local probe (not committed) retired 1,000 redialing removed servers about 243 ms after the registry write, with no redials afterwards; that is a test-environment number, not a production measurement.Risk
Level: Medium. It touches how connections to paired servers are torn down. If the reconciler misjudged a server as removed, that server's connections would close and reopen on next use; it only acts on ids missing from a successful registry read. Size: about 1,290 changed lines, roughly 580 production and the rest tests. Back out with a plain revert.
AI Disclosure
Internal contributor.