Repository navigation
fix(runtime-environments): don't crash when a server removed via the CLI still responds - #22517
Conversation
…CLI still responds orca environment rm edits the environment store behind the running app, so the next ok response on a live socket called markEnvironmentUsed, which threw 'Unknown environment' out of an unguarded socket callback. Main-process callers now use markEnvironmentUsedIfPresent, which skips a missing environment and keeps every other store error; the status owner pauses shared control instead of re-establishing it for a removed server.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughIPC routes now record runtime usage through a helper that logs synchronous errors without rethrowing. Status verification establishes transport based on capability. The remote subscription frame router catches response and binary callback exceptions and reports them through its failure path. Priority: ⬇️ Low Merge Risk: 🟡 Moderate · up to A concurrent usage update can undo CLI environment removal, so that race should be resolved before merging. A temporary store failure can also leave usage metadata stale for an open subscription. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to A server removed from the saved list can still prompt the running app to reconnect its shared-control channel. The exposure appears limited to a previously paired server, but removal no longer blocks this connection attempt. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: a5fe37ce-131e-4124-8715-fee670acd58b
📒 Files selected for processing (7)
src/main/ipc/runtime-environment-removed-environment-routing.test.tssrc/main/ipc/runtime-environment-status-owner.tssrc/main/ipc/runtime-environment-support-routing.tssrc/main/ipc/runtime-environment-transport-routing.tssrc/main/ipc/runtime-environments-subscription-lifecycle.test.tssrc/shared/runtime-environment-store.test.tssrc/shared/runtime-environment-store.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Non-throwing store write:
markEnvironmentUsedIfPresentreturnsfalseand leaves the store untouched when the selector is absent, while ambiguous names and unreadable/corrupt stores still throw.markEnvironmentUsedkeeps its strict throwing behavior for the CLI. - Main-process call sites: transport routing, support routing, and the status owner now record usage through the non-throwing variant, so a successful response from a CLI-removed server can no longer escape a socket callback as an uncaught exception.
- Shared-control gate: the status owner only calls
transport.establish()when the server is still present (capable && present), pausing instead of reviving the channel for a removed server. - Tests: new removed-environment routing suite (status verification plus direct and support-routed subscriptions), new store cases, and an existing spy retargeted to the new function.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…s boundary Keep one strict store contract and move the leniency to the caller that cannot report a failure to anyone. - Revert markEnvironmentUsedIfPresent: drawing the line around one error string left corrupt, unreadable and oversized store files still fatal on the same unguarded socket callback. - Add recordRuntimeEnvironmentUsage, a named main-process boundary that says lastUsedAt is advisory and swallows every store failure. Route only the three sites with no observer through it (subscription onResponse in transport- and support-routing, and the status owner's verified hook, where a throw skips settleWaiters and hangs refresh callers). Awaited request paths stay strict. - Guard onResponse/onBinary in the subscription frame router the way the sibling request router already guards validateStatus, so no consumer throw can reach the ws 'message' emitter and become main_uncaught_exception. - Drop the status-owner `capable && present` gate: pauseStandingRetry no-ops while subscriptions exist, and removal teardown belongs to stablyai#21048's watcher. Co-authored-by: mmarabel <[email protected]>
…ow escapes The existing tests invoke the captured onResponse directly, which never touches the surface that actually kills the app. Drive a real WebSocket server through subscribeRemoteRuntimeRequest so the throw travels ws 'message' -> handleFrame -> consumer; without the frame-router guard vitest reports it as an unhandled error, which is main_uncaught_exception in production.
|
@mmarabel heads up — @nwparker took this over and pushed two commits directly to your branch rather than What changed:
Every test was verified to fail with its production change reverted. Thanks for the original find and the clear write-up — the crash trace in your description is what made the |
There was a problem hiding this comment.
ℹ️ No code issues — the only note is that the PR description no longer matches the implementation.
Reviewed changes
This run re-reviewed the two commits pushed after the prior pullfrog review (242d5bc2b6), which replaced the store-level markEnvironmentUsedIfPresent fix with a main-process boundary guard.
- Reverted the store-level fix:
markEnvironmentUsedIfPresentand its tests are gone;runtime-environment-store.tsis back to itsmainshape. - Added
recordRuntimeEnvironmentUsage: atry/catchwrapper aroundmarkEnvironmentUsedthat logs and swallows any store failure, now used by the status owner, the direct subscription, and the support-routed subscription. - Guarded the subscription frame router: a new
deliver(emit)helper converts a consumer-callback throw into a terminalfail()instead of letting it escape the websocketmessagehandler. - Reworked the tests:
runtime-environment-cli-removal-routing.test.tsreplaces the deleted removed-environment suite, and new frame-router plus end-to-end subscription tests prove a consumer throw fails the subscription rather than crashing.
Focused tests pass locally (5 files / 36 tests), and the new coverage is genuine: without the guard the frame-router and integration tests throw out of the handler.
ℹ️ PR description still describes the reverted markEnvironmentUsedIfPresent approach
The description's "What Changed", "After", and "Review" sections describe the store-level variant that these commits removed, so a reviewer reading it would expect code that is not in the diff. In particular it claims the status check "stops reconnecting the shared-control channel for a server that was removed", but the final code revives it.
Technical details
# PR description describes an implementation that is no longer in the diff
## Affected sites
- PR body (`What Changed` / `After` / `Review`) — still says usage is recorded via `markEnvironmentUsedIfPresent`, that a removed server returns `false` and leaves the store untouched, and that request paths now resolve instead of rejecting.
- `src/main/ipc/runtime-environment-status-owner.ts:64` — records through `recordRuntimeEnvironmentUsage`; the `capable && present` gate was dropped, so `transport.establish()` runs whenever `capable` and a removed environment's shared control is revived. The new test asserts `establish` is called once for a removed environment.
- `src/main/ipc/runtime-environment-transport-routing.ts:257` — `markEnvironmentUsedFromResponse` calls the strict `markEnvironmentUsed` again.
- `src/main/ipc/runtime-environment-support-routing.ts:106` — `executeSupportRoutedCall`'s `markUsed` calls the strict `markEnvironmentUsed` again.
## Required outcome
- The description matches the boundary-guard implementation actually in the diff: `recordRuntimeEnvironmentUsage` swallowing store failures on socket callbacks, plus the frame-router `deliver` guard. Either restore the presence gate and keep the removal-teardown claim, or drop that claim from the body.
## Open questions for the human
- Is dropping the presence gate intended? Relative to `main` the behavior is unchanged (the gate only existed in the intermediate commit), but the PR body presents removal teardown as part of the fix.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 4143a928-3891-487c-ae1d-b750aa934f67
📒 Files selected for processing (8)
src/main/ipc/runtime-environment-cli-removal-routing.test.tssrc/main/ipc/runtime-environment-status-owner.tssrc/main/ipc/runtime-environment-support-routing.tssrc/main/ipc/runtime-environment-transport-routing.tssrc/main/ipc/runtime-environment-usage-record.tssrc/shared/remote-runtime-subscription-frame-router.test.tssrc/shared/remote-runtime-subscription-frame-router.tssrc/shared/remote-runtime-subscription-request.test.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| onResponse: (response: RuntimeRpcResponse<unknown>) => { | ||
| if (response.ok && shouldMarkUsed()) { | ||
| markEnvironmentUsed(args.userDataPath, args.environment.id, { | ||
| recordRuntimeEnvironmentUsage(args.userDataPath, args.environment.id, { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
rg -n 'markedUsed|shouldMarkUsed|recordRuntimeEnvironmentUsage|markUsedOnce' src/main/ipc/runtime-environment-support-routing.ts src/main/ipc/runtime-environment-transport-routing.ts src/main/ipc/runtime-environment-cli-removal-routing.test.ts
sed -n '165,225p' src/main/ipc/runtime-environment-support-routing.ts
sed -n '80,120p' src/main/ipc/runtime-environment-cli-removal-routing.test.tsRepository: stablyai/orca
Length of output: 5361
🏁 Script executed:
#!/bin/bash
set -e
printf '%s\n' '--- support routing ---'
sed -n '105,145p' src/main/ipc/runtime-environment-support-routing.ts
sed -n '235,280p' src/main/ipc/runtime-environment-support-routing.ts
printf '%s\n' '--- transport routing ---'
sed -n '180,215p' src/main/ipc/runtime-environment-transport-routing.ts
printf '%s\n' '--- usage record ---'
cat -n src/main/ipc/runtime-environment-usage-record.ts
printf '%s\n' '--- related definitions/tests/docs ---'
rg -n -C 3 'shouldMarkUsed|markUsedOnce|recordRuntimeEnvironmentUsage|lastUsedAt|runtimeId|usage' src/main/ipc src -g '*.ts' -g '*.md' | head -n 300Repository: stablyai/orca
Length of output: 30451
🏁 Script executed:
set -e
sed -n '115,140p' src/main/ipc/runtime-environment-support-routing.ts
sed -n '250,275p' src/main/ipc/runtime-environment-support-routing.ts
sed -n '188,210p' src/main/ipc/runtime-environment-transport-routing.ts
cat -n src/main/ipc/runtime-environment-usage-record.ts
rg -n -C 3 'shouldMarkUsed|markUsedOnce|recordRuntimeEnvironmentUsage|lastUsedAt|runtimeId' src/main/ipc src -g '*.ts' -g '*.md' | head -n 250Repository: stablyai/orca
Length of output: 24593
🏁 Script executed:
printf '%s\n' 'support'; sed -n '115,140p' src/main/ipc/runtime-environment-support-routing.ts; printf '%s\n' 'support subscription'; sed -n '255,272p' src/main/ipc/runtime-environment-support-routing.ts; printf '%s\n' 'transport'; sed -n '190,204p' src/main/ipc/runtime-environment-transport-routing.ts; printf '%s\n' 'record'; cat src/main/ipc/runtime-environment-usage-record.ts; printf '%s\n' 'tests'; rg -n -C 4 'recordRuntimeEnvironmentUsage|shouldMarkUsed|markedUsed|lastUsedAt' src/main/ipc -g '*.test.ts' -g '*.ts' | head -n 220Repository: stablyai/orca
Length of output: 14983
🏁 Script executed:
set -e
rg -n -C 8 'export (async )?function markEnvironmentUsed|export const markEnvironmentUsed|function markEnvironmentUsed' src/shared
rg -n -C 5 'markEnvironmentUsed\(' src/shared src/main -g '*.test.ts' | head -n 180Repository: stablyai/orca
Length of output: 8060
🏁 Script executed:
sed -n '176,225p' src/shared/runtime-environment-store.tsRepository: stablyai/orca
Length of output: 1900
Retry usage recording after a failed store operation.
shouldMarkUsed() and markUsedOnce() consume markedUsed before recordRuntimeEnvironmentUsage() can fail. The recorder catches that failure and returns void. A later successful response can therefore skip usage recording while the subscription remains open.
Make recordRuntimeEnvironmentUsage() report whether markEnvironmentUsed() completed without a store error. Set both subscription flags only after that result succeeds. Preserve the existing freshness throttle.

ELI5
If you deleted a remote server with
orca environment rmwhile the Orca app was open, the app kept talkingto that server. The next message it sent back killed the app — all your windows closed at once.
The app was doing a small piece of housekeeping ("remember when this server was last used") in a place where
nothing was watching for mistakes. Looking up a server that had just been deleted failed, and because nobody
was catching that failure, it took the whole app down with it. Now housekeeping is allowed to quietly fail,
and one message from a server can no longer crash anything.
What Changed
Before: the app crashes (
main_uncaught_exception, every window gone) the first time a CLI-removedserver sends anything. It also crashes on the same code path if the settings file is merely unreadable — for
example half-written, or locked by file permissions.
After: the app keeps running. The response is still delivered to whatever asked for it. A line is logged
saying the usage timestamp was skipped.
The mechanism.
orca environment rmonly edits a file on disk; it never tells the running app, so theapp keeps live sockets to a server it can no longer look up. Every successful response triggers a
lastUsedAtwrite, and the lookup for that write now throws. Critically, that write is reached from aWebSocket
'message'callback — there is no promise to reject and no caller to notice, so the throw escapesinto Node's
uncaughtExceptionhandler, which re-throws it and ends the process.Two changes, at the two places responsible:
recordRuntimeEnvironmentUsage(new,src/main/ipc/runtime-environment-usage-record.ts) — one namedmain-process boundary that says "usage bookkeeping is advisory here" and swallows any store failure.
Only the three call sites that cannot report a failure to anyone use it: the two subscription
onResponsecallbacks, and the status owner'sverifiedhook. Awaited request paths keep callingmarkEnvironmentUseddirectly and still reject, because there the failure is observable and rejecting isthe right answer.
handleFrameruns straight off the socket emitter, so itnow catches a consumer throw and routes it to
fail()instead of letting it escape. This mirrors what thesibling request router already does, which is exactly why the CLI's identical
markEnvironmentUsedcallwas never a crash path. The subscription side was a plain omission.
Why
The first version of this PR added
markEnvironmentUsedIfPresentto the shared store: the same function,suppressing one error. Two problems with that seam.
It fixed one error message, not the crash. The PR's own tests enshrined the rest as intended behaviour
("still surfaces ambiguous selectors and unreadable stores"). A store file that is corrupt, oversized, or
ACL-hardened against the user still threw out of the same unguarded callback and still killed the app. Two
of the tests added here fail on that version.
It put main-process-only policy in a shared module. The store gained two exports with identical
signatures where the correct choice depends on which process you are in — the CLI must stay strict, since
it turns "Unknown environment" into a user-facing error. Nothing encoded that, so the next main-process
caller picks by coin flip. Drawing the line around the caller instead of the error keeps one store
contract and makes the leniency visible in the import path.
Alternative rejected: catching everything inside the shared frame routers. That would hide unrelated
bugs. The guard added here does not swallow — it routes a consumer throw into the existing failure path
(
onError+onClose), which is observable, already tested, and identical to the request router.Scope removed: the earlier version also gated
transport.establish()on the environment still existing.That is dropped. It was a no-op in the very scenario it targeted (
pauseStandingRetryreturns immediatelywhile subscriptions exist, and they always do here), it put removal policy in a status reader, and it
collided with #21048, which is doing that teardown properly. The PR body previously claimed this "stops
reconnecting the shared-control channel"; it did not, and that claim is gone.
Sequencing with #21048: the two compose rather than overlap. #21048 owns "a CLI-removed environment loses
its transport." This PR owns "a response that lands before that happens does not kill the app." Either can
merge first; neither needs the other.
Linked Issue
Fixes #22771
Split out of #14210 (side problem 2). The tailnet timeout that is the main subject of #14210 is untouched,
so this deliberately does not close it. Related: #20995 and #21048 cover the other half of this scenario —
tearing the connection down — which is out of scope here.
Visual Proof
N/A. This is main-process logic with no UI surface: nothing renders differently. The only user-visible
difference is the absence of a crash, which is covered by the tests below.
Testing
Reproducing the crash (this is what the tests automate):
orca environment rm <that server>.main, the app dies withmain_uncaught_exception.Automated, and each one verified to fail when the production change is reverted:
src/shared/remote-runtime-subscription-request.test.ts— drives a real WebSocket server throughsubscribeRemoteRuntimeRequest, so a consumer throw travels the genuine fatal route(
ws.on('message')→handleFrame→ consumer). Reverting the guard makes vitest report it as anunhandled error, which is
main_uncaught_exceptionin production. This is the surface the earlier testsnever touched.
src/main/ipc/runtime-environment-cli-removal-routing.test.ts— seeds a real temp store, subscribes, thenremoves the environment exactly as the CLI does, on both the direct and support-routed paths. Two further
cases overwrite the store with invalid JSON, covering the failure class the earlier fix left fatal.
src/shared/remote-runtime-subscription-frame-router.test.ts— the router routes a throwingonResponseor
onBinarytofail().Platforms: run on macOS (darwin arm64). No platform-specific code is involved — no paths, no shells, no
native modules; the store read/write paths are unchanged. Not exercised against a live Remote Orca Server,
which is why the end-to-end test above uses a real local WebSocket server instead of a mocked callback.
available here). Compensated for by the real-WebSocket test above, which exercises the actual fatal
route rather than a mocked callback.
Local gate:
pnpm tc:node,pnpm tc:cli,oxlint,pnpm run check:code-quality:changed(0 new findings),and
pnpm testacross the 71 runtime-environment / remote-runtime / CLI-runtime suites (500 passed,1 skipped).
AI Disclosure
Original change written with Claude Opus 5.5 in the pi coding agent by @mmarabel. Reworked by @nwparker with
Claude Opus 5.
Review
callRuntimeEnvironmentresolve instead of rejecting for a removed server. That is reverted: requestpaths reject exactly as they do on
main. Only callbacks with no observer are lenient.src/shared/runtime-environment-store.tsis byte-identical tomain, so theCLI's strict "Unknown environment" error is unchanged.
handleSharedControlSubscriptionResponse(
src/shared/remote-runtime-shared-control-state.ts) also calls a consumeronResponseunguarded. The bugin this PR is fixed there too, because that path's callbacks come from
runtime-environment-support-routing.tsand now go through the boundary. Adding the router-level guard tothe shared-control family as well would collide with fix(runtime-environments): retire transports for CLI-removed environments #21048, which is actively restructuring those files.
Worth a follow-up once fix(runtime-environments): retire transports for CLI-removed environments #21048 lands; flagging it rather than leaving it silent.
restart or an in-app action. That is [Bug]:
orca environment rmdoes not stop the connection — the running app keeps reconnecting to the removed environment until restart #20995, fixed by fix(runtime-environments): retire transports for CLI-removed environments #21048.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
secure-file rewrite behind
LAST_USED_PERSIST_INTERVAL_MS— is unchanged, and Windows is the platform mostlikely to hit the permission-denied variant this now survives.
store function and get the same protection. No wire change, so mixed client/host versions are unaffected.
mainon the success path.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)