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
feat(orcad): per-feature readiness latches and requires: on RPC methods - #35571
Flag-off: no behaviour change, with the flag on or off. On orcad (serve, SSH and WSL hosts), every latch opens where its startup phase finishes today, which is before RPC starts. The desktop never installs a readiness, so every feature reads as open there. User-risk: Very low. Ungated methods dispatch exactly as before, with no added await. Gated methods add one isOpen check, which today is always true.
ELI5
An orcad host finishes some startup work (account services, the history search index, restored orchestration, placing unshown terminals) before it accepts any RPC call. A later PR will start accepting calls sooner. This PR adds the gates that will let that happen safely: a method can say which startup work it needs, and a call that arrives too early waits briefly or gets a "try again" answer. For now every gate opens before the first call can arrive, so nothing changes yet.
What Changed
New runtime/rpc/orcad-feature-readiness.ts: an OrcadFeatureReadiness with four named latches: accounts, sessionSearch, orchestration and unshownPlacement.
orcad installs one with every latch closed. A process that never installs one (the desktop) treats every feature as open.
requires: on defineMethod and defineStreamingMethod (core.ts). The dispatcher (dispatcher.ts, unary and streaming paths) waits up to 10 s for a method's features. After that it refuses with the existing retryable runtime_unavailable code, which is already a passthrough code that clients handle.
With nothing closed, the wait is null, so dispatch keeps its synchronous start. Existing subscribe tests depend on that.
Gated methods:
accounts: the Claude and Codex account methods (ACCOUNT_METHODS), except accounts.setHostLaunchEnv (the desktop's push, which needs only the runtime) and accounts.unsubscribe.
sessionSearch:aiVault.searchSessions, aiVault.searchStatus and aiVault.setSearchEnabled.
orchestration: every orchestration.* method, through requiringOrcadFeature.
unshownPlacement:terminal.adoptOrphans, so a client never adopts a PTY the host is about to place itself.
Kept on the critical path, with no latch: the reconcile-terminals phase, and everything a client calls when it connects (status.get, repo.list, session.tabs.*, terminal.list, worktree.teardownMissingTerminals). A test locks this list.
orcad startup (orcad-entry.ts):
accounts opens after the account services are attached and the host's launch environment is restored.
sessionSearch opens after the index is installed.
The orchestration, reconcile and placement steps moved unchanged into orcad-restored-terminal-authority.ts. That module opens orchestration after the authority refresh and unshownPlacement after placement. Placement only runs on layout-owner builds; elsewhere the latch opens right away.
The move keeps orcad-entry.ts under its line limit. The phases, their timed names and their order are unchanged.
Not changed: the readiness publish still waits for everything. Moving it earlier is a later PR.
Why
One latch per deferrable phase, from the gates memo (/tmp/fanout/coldstart-c-gates.md). A method declares what it needs where it is defined, so the next PR can move the readiness publish without reviewing every client caller again.
Wait, then refuse retryably, rather than refuse at once. Orchestration callers (the agents' orca CLI) retry poorly, and a short wait covers a cold start. The bounded wait then hands over to the client's existing runtime_unavailable handling.
No wire change. The wait happens host-side, and the refusal code already exists, so old clients and old hosts see nothing new.
Gating agent launches inside terminal.create is left for later. That method also serves plain shells, so it needs a parameter-level gate.
Linked Issue
Internal WSL cold-start work, option (c) "staged readiness", PR 3. The phase baseline and lane changes are owned separately (wsl-coldstart-perf).
Visual Proof
N/A: no UI or behaviour change.
Testing
orcad-feature-readiness.test.ts:
no await when nothing is closed;
waits for every named feature;
refuses with runtime_unavailable after the bound and leaves no timer behind.
dispatcher-feature-readiness.test.ts:
a gated method runs at once on a desktop;
under orcad it waits while an ungated method runs;
it refuses after the bound;
streaming methods are gated the same way.
Three of these fail with the dispatcher change reverted.
orcad-feature-readiness-manifest.test.ts:
exactly which registered methods require which feature;
connect-time methods stay ungated;
every latch opens before orcad's rpc.start().
orcad-restored-terminal-authority.test.ts: each latch opens only after its phase, and reconcile runs ungated in between.
Suites: the runtime and orcad suites pass (15,828 tests). The failures also occur on main locally: electron-serve-browser-process, orcad-forked-child-paths and runtime-failed-local-worktree-removal. One orchestration test failed under load and passes when run alone.
Load rule:pnpm tc, typecheck:ci, check:code-quality:changed, the anti-slop lint, oxlint and the ast-grep gates.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
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
Remote wire compatibility: there are no new params, opcodes or published content. The only refusal is the existing runtime_unavailable.
Hosts: SSH, WSL and serve hosts all run orcad; the desktop is unaffected.
Scope: one runtime per orcad process, so the readiness lives at module level, like other process-wide orcad state.
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)
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)
Adds OrcadFeatureReadiness (accounts, sessionSearch, orchestration,
unshownPlacement) and a requires: field on defineMethod. The dispatcher
waits a bounded 10 s for a method's features, then refuses with the
existing retryable runtime_unavailable. terminal.adoptOrphans waits for
unshown placement; reconcile-terminals stays on the critical path. Every
latch opens where its phase finishes today, before RPC starts, so
behaviour is unchanged.
[Low impact] The PR appears safe to merge; no actionable issue was found.
Summary
Adds four startup gates and lets RPC methods declare which gates they need.
Orcad RPC methods wait for the startup steps they need.
Account RPC calls wait until the host account services are ready.
Session-search RPC calls wait until the search index is ready.
Orchestration RPC calls wait until restored authority is ready.
Orphan-terminal adoption waits until host placement is finished.
Orcad startup opens each readiness latch when its phase finishes.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Admit RPC request] --> B{Required gates closed?}
B -- No --> C[Run handler]
B -- Yes --> D[Wait up to 10 seconds]
D -- Gates open --> C
D -- Timeout --> E[Return runtime_unavailable]
The change adds readiness tracking for four Orcad startup features. RPC methods can declare required features, and dispatch waits for those features before invoking unary or streaming handlers. Startup opens the account and session-search gates after setup. Terminal restoration refreshes orchestration, reconciles legacy terminals, conditionally places unshown terminals, and opens the related readiness gates.
Priority: Normal
Merge Risk: Low · up to 36555
A disconnected client’s terminal-adoption request can still change session state when startup readiness opens. Fix cancellation handling in both dispatch paths before merging, or explicitly accept this bounded risk.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly identifies the main change: per-feature readiness latches and RPC method requirements.
Description check
The description is detailed and covers the change, rationale, testing, compatibility, and checklist. It does not provide an actual issue reference in the required Linked Issue section, and several sta…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description is detailed and covers the change, rationale, testing, compatibility, and checklist. It does not provide an actual issue reference in the required Linked Issue section, and several standard checklist items remain unchecked.
Full details: Docstring Coverage
Explanation
Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 13 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches: 💡 2
📝 Generate docstrings: 💡
Commit to this branch
Create a new PR
🛠️ Fix failing CI checks: 💡
Commit to this branch
Create a new PR
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; 0 remain after this review.
rg -n -F --glob '*.ts' -e 'export class RuntimeRpcLifecycle' -e 'export class RuntimeRpcWebSocketDispatch' -e 'export class RuntimeRpcMobileDevices' -e 'export class RuntimeRpcRequestAdmission' -e 'export class RuntimeRpcState' src/main/runtime/runtime-rpc
Repository: stablyai/orca
Length of output: 779
Abort the gated unary wait before invoking the handler.
A Unix client can disconnect while terminal.adoptOrphans waits for unshownPlacement. The transport aborts the request, but the unary admission path drops that signal. When readiness opens, the dispatcher can still invoke runtime.adoptTerminalOrphans(params) for the disconnected client. Make the gated unary wait observe the transport abort before invoking the handler.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Data Integrity & Integration · Quick win
Supported by static analysis
Script executed:
sed -n '180,290p' src/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts
sed -n '205,250p' src/main/runtime/rpc/unix-socket-transport.ts
sed -n '1,115p' src/main/runtime/rpc/methods/terminal-orphan.ts
sed -n '45,95p' src/main/runtime/rpc/methods/accounts.ts
sed -n '265,290p' src/main/runtime/rpc/methods/accounts.ts
set -o pipefail
printf'%s\n''--- dispatcher exact readiness and invocation ---'
nl -ba src/main/runtime/rpc/dispatcher.ts | sed -n '1,230p'printf'%s\n''--- websocket abort registration exact definition ---'
rg -n -F -- 'registerWebSocketDispatchAbort' src/main/runtime/runtime-rpc
rg -n -F -- 'class' src/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts | head -20
nl -ba src/main/runtime/runtime-rpc/runtime-rpc-websocket-dispatch.ts | sed -n '1,190p'printf'%s\n''--- unix socket close and message dispatch exact source ---'
nl -ba src/main/runtime/rpc/unix-socket-transport.ts | sed -n '1,245p'printf'%s\n''--- adoptTerminalOrphans definition and direct callees ---'
rg -n -F -- 'adoptTerminalOrphans' src
nl -ba src/main/runtime/rpc/methods/terminal-orphan.ts
Repository: stablyai/orca
Length of output: 32107
Script executed:
set -o pipefail
printf'%s\n''--- websocket close-to-abort binding ---'
nl -ba src/main/runtime/runtime-rpc/runtime-rpc-binary-routing.ts | sed -n '1,90p'
rg -n -F -- 'registerWebSocketDispatchAbort' src/main/runtime
printf'%s\n''--- readiness wait implementation ---'
nl -ba src/main/runtime/rpc/orcad-feature-readiness.ts | sed -n '1,150p'printf'%s\n''--- runtime adoption owner and method ---'
nl -ba src/main/runtime/terminal/layout/terminal-resize-listeners.ts | sed -n '190,255p'
nl -ba src/main/runtime/terminal/adoption/adopt-terminal-orphans-from-inventory.ts | sed -n '1,180p'
nl -ba src/main/runtime/workspaces/persisted-surfaces/has-exact-persisted-terminal-surface-identity.ts | sed -n '140,190p'
Repository: stablyai/orca
Length of output: 21893
Script executed:
set -o pipefail
printf'%s\n''--- active method registry and transport entrypoints ---'
rg -n -F -- 'TERMINAL_ORPHAN_METHODS' src/main/runtime/rpc
rg -n -F -- 'ALL_RPC_METHODS' src/main/runtime/rpc/methods src/main/runtime
nl -ba src/main/runtime/rpc/transport.ts | sed -n '1,130p'
nl -ba src/main/runtime/runtime-rpc/runtime-rpc-request-admission.ts | sed -n '1,90p'printf'%s\n''--- cancellation contract and comparable pre-side-effect guards ---'
rg -n -F -- 'RpcMessageContext' src/main/runtime/rpc
rg -n -F -- 'signal?.aborted' src/main/runtime/rpc/methods | head -100
nl -ba src/main/runtime/rpc/methods/mobile-web-bundle.ts | sed -n '35,75p'
nl -ba src/main/runtime/rpc/methods/terminal/terminal-subscribe-method.ts | sed -n '1,55p'
Repository: stablyai/orca
Length of output: 20971
Reject an aborted request after the readiness wait.
terminal.adoptOrphans can remain in rpcMethodFeatureWait while its WebSocket closes. The close aborts the request signal, but the dispatcher does not re-check it before invoking runtime.adoptTerminalOrphans(params). The handler can therefore mutate terminal session state for a disconnected client.
Suggested fix
} catch (error) {
reply(JSON.stringify(mapDispatcherError(request, meta, error)))
return
}
}
+ if (options?.signal?.aborted) {+ return+ }
if (!isStreamingMethod(method)) {
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.
Flag-off: no behaviour change, with the flag on or off. On orcad (serve, SSH and WSL hosts), every latch opens where its startup phase finishes today, which is before RPC starts. The desktop never installs a readiness, so every feature reads as open there.
User-risk: Very low. Ungated methods dispatch exactly as before, with no added await. Gated methods add one
isOpencheck, which today is always true.ELI5
An orcad host finishes some startup work (account services, the history search index, restored orchestration, placing unshown terminals) before it accepts any RPC call. A later PR will start accepting calls sooner. This PR adds the gates that will let that happen safely: a method can say which startup work it needs, and a call that arrives too early waits briefly or gets a "try again" answer. For now every gate opens before the first call can arrive, so nothing changes yet.
What Changed
runtime/rpc/orcad-feature-readiness.ts: anOrcadFeatureReadinesswith four named latches:accounts,sessionSearch,orchestrationandunshownPlacement.requires:ondefineMethodanddefineStreamingMethod(core.ts). The dispatcher (dispatcher.ts, unary and streaming paths) waits up to 10 s for a method's features. After that it refuses with the existing retryableruntime_unavailablecode, which is already a passthrough code that clients handle.null, so dispatch keeps its synchronous start. Existing subscribe tests depend on that.accounts: the Claude and Codex account methods (ACCOUNT_METHODS), exceptaccounts.setHostLaunchEnv(the desktop's push, which needs only the runtime) andaccounts.unsubscribe.sessionSearch:aiVault.searchSessions,aiVault.searchStatusandaiVault.setSearchEnabled.orchestration: everyorchestration.*method, throughrequiringOrcadFeature.unshownPlacement:terminal.adoptOrphans, so a client never adopts a PTY the host is about to place itself.status.get,repo.list,session.tabs.*,terminal.list,worktree.teardownMissingTerminals). A test locks this list.orcad-entry.ts):accountsopens after the account services are attached and the host's launch environment is restored.sessionSearchopens after the index is installed.orcad-restored-terminal-authority.ts. That module opensorchestrationafter the authority refresh andunshownPlacementafter placement. Placement only runs on layout-owner builds; elsewhere the latch opens right away.orcad-entry.tsunder its line limit. The phases, theirtimednames and their order are unchanged.Why
orcaCLI) retry poorly, and a short wait covers a cold start. The bounded wait then hands over to the client's existingruntime_unavailablehandling.terminal.createis left for later. That method also serves plain shells, so it needs a parameter-level gate.Linked Issue
Internal WSL cold-start work, option (c) "staged readiness", PR 3. The phase baseline and lane changes are owned separately (wsl-coldstart-perf).
Visual Proof
N/A: no UI or behaviour change.
Testing
orcad-feature-readiness.test.ts:runtime_unavailableafter the bound and leaves no timer behind.dispatcher-feature-readiness.test.ts:orcad-feature-readiness-manifest.test.ts:rpc.start().orcad-restored-terminal-authority.test.ts: each latch opens only after its phase, and reconcile runs ungated in between.Suites: the runtime and orcad suites pass (15,828 tests). The failures also occur on main locally:
electron-serve-browser-process,orcad-forked-child-pathsandruntime-failed-local-worktree-removal. One orchestration test failed under load and passes when run alone.Load rule:
pnpm tc,typecheck:ci,check:code-quality:changed, the anti-slop lint, oxlint and the ast-grep gates.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
runtime_unavailable.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)