Skip to content

feat(orcad): per-feature readiness latches and requires: on RPC methods - #35571

Merged
nwparker merged 1 commit into
mainfrom
nwparker/orcad-feature-readiness
Oct 29, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/orcad-feature-readiness

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​267 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​267
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​173 $\color{#cf222e}{\Huge{\mathbf{−}}}$​9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​164

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.
@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[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]
Loading

Reviews (1) · Last reviewed commit: "feat(orcad): per-feature readiness latch..." · Reviewed by Greptile

@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

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: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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 Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main change: per-feature readiness latches and RPC method requirements.
Description check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d63bbd46-bd65-4cb7-a247-66d370f35291
Commits

Reviewing files that changed from the base of the PR and between f5c84ea and 3655500.

Files selected for processing: 13
  • src/main/orcad/orcad-entry.ts
  • src/main/orcad/orcad-restored-terminal-authority.test.ts
  • src/main/orcad/orcad-restored-terminal-authority.ts
  • src/main/runtime/rpc/core.ts
  • src/main/runtime/rpc/dispatcher-feature-readiness.test.ts
  • src/main/runtime/rpc/dispatcher.ts
  • src/main/runtime/rpc/methods/accounts.ts
  • src/main/runtime/rpc/methods/ai-vault.ts
  • src/main/runtime/rpc/methods/orchestration.ts
  • src/main/runtime/rpc/methods/terminal-orphan.ts
  • src/main/runtime/rpc/orcad-feature-readiness-manifest.test.ts
  • src/main/runtime/rpc/orcad-feature-readiness.test.ts
  • src/main/runtime/rpc/orcad-feature-readiness.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Comment on lines +87 to 93
const featureWait = rpcMethodFeatureWait(admission.method.requires)
if (featureWait) {
await featureWait
}
return successResponse(request.id, meta, await this.invokeUnary(admission, options))
} catch (error) {
if (probeEmulator) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Supported by static analysis

Script executed:

sed -n '60,105p' src/main/runtime/rpc/dispatcher.ts
rg -n -F '.dispatch(' src/main/runtime/runtime-rpc src/main/ipc/runtime.ts src/main/runtime/rpc/unix-socket-transport.ts | head -65
sed -n '95,125p' src/main/ipc/runtime.ts

Repository: stablyai/orca

Length of output: 3566


Script executed:

set -o pipefail
sed -n '1,140p' src/main/runtime/runtime-rpc/runtime-rpc-request-admission.ts
printf '\n--- runtime RPC transport callers and signal setup ---\n'
rg -n -F --glob '*.ts' -e 'runtime-rpc-request-admission' -e 'dispatch(request' -e 'signal:' src/main/runtime src/cli src/main | head -160
printf '\n--- unix socket transport ---\n'
sed -n '1,260p' src/main/runtime/rpc/unix-socket-transport.ts
printf '\n--- gated method declarations and signal usage ---\n'
rg -n -F --glob '*.ts' -e 'requires:' -e 'context.signal' -e 'ctx.signal' -e 'RpcContext' src/main/runtime/rpc/methods src/main/runtime/rpc | head -240

Repository: stablyai/orca

Length of output: 41849


Script executed:

set -o pipefail
printf '%s\n' '--- readiness-gated method declarations ---'
rg -n -B 6 -A 28 -F --glob '*.ts' 'requires:' src/main/runtime/rpc/methods src/main/runtime/rpc
printf '%s\n' '--- long-poll classification ---'
sed -n '1,240p' src/main/runtime/runtime-rpc/runtime-rpc-long-poll.ts
printf '%s\n' '--- dispatcher context and invocation ---'
rg -n -B 12 -A 35 -F -e 'invokeUnary' -e 'signal:' src/main/runtime/rpc/dispatcher.ts src/main/runtime/rpc/dispatcher-stream-options.ts
printf '%s\n' '--- terminal orphan method ---'
sed -n '1,180p' src/main/runtime/rpc/methods/terminal-orphan.ts
printf '%s\n' '--- orchestration gated methods ---'
rg -n -B 8 -A 35 -F --glob '*.ts' -e 'requires: ['"'"'orchestration'"'"']' -e 'requires: ['"'"'accounts'"'"']' -e 'requires: ['"'"'sessionSearch'"'"']' src/main/runtime/rpc/methods

Repository: stablyai/orca

Length of output: 42269


Script executed:

set -o pipefail
printf '%s\n' '--- RuntimeRpcRequestAdmission bindings ---'
rg -n -B 12 -A 28 -F --glob '*.ts' -e 'new RuntimeRpcRequestAdmission' -e 'extends RuntimeRpcRequestAdmission' -e 'RuntimeRpcRequestAdmission' src/main src/cli
printf '%s\n' '--- binary routing and transport signal lifecycle ---'
sed -n '1,120p' src/main/runtime/runtime-rpc/runtime-rpc-binary-routing.ts
rg -n -B 18 -A 35 -F --glob '*.ts' -e 'new AbortController' -e 'inflight' -e 'cleanup' -e 'handleMessage' src/main/runtime/rpc/unix-socket-transport.ts
printf '%s\n' '--- exact long-poll classification ---'
sed -n '1,180p' src/main/runtime/runtime-rpc/runtime-rpc-long-poll.ts

Repository: stablyai/orca

Length of output: 20213


Script executed:

set -o pipefail
printf '%s\n' '--- RuntimeRpcState and message-handler binding ---'
rg -n -B 18 -A 35 -F --glob '*.ts' -e 'messageHandler' -e 'handleMessage.bind' -e 'setMessageHandler' -e 'start.*Unix' -e 'UnixSocketTransport' src/main/runtime/runtime-rpc src/main/runtime/rpc src/main
printf '%s\n' '--- RpcMessageContext declaration ---'
rg -n -B 10 -A 22 -F --glob '*.ts' 'RpcMessageContext' src/main/runtime/rpc src/main/runtime/runtime-rpc
printf '%s\n' '--- readiness wait implementation ---'
sed -n '1,125p' src/main/runtime/rpc/orcad-feature-readiness.ts

Repository: stablyai/orca

Length of output: 42072


Script executed:

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.

Comment on lines +121 to +129
const featureWait = rpcMethodFeatureWait(method.requires)
if (featureWait) {
try {
await featureWait
} catch (error) {
reply(JSON.stringify(mapDispatcherError(request, meta, error)))
return
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Repository: stablyai/orca

Length of output: 8165


Script executed:

set -o pipefail
printf '%s\n' '--- dispatcher declarations and dispatch paths ---'
rg -n -F --glob '*.ts' -e 'class RpcDispatcher' -e 'dispatch(' -e 'dispatchStreaming' -e 'rpcMethodFeatureWait' -e 'signal.aborted' -e 'throwIfAborted' src/main/runtime/rpc src/main/runtime/runtime-rpc
printf '%s\n' '--- dispatcher source ---'
sed -n '1,260p' src/main/runtime/rpc/dispatcher.ts
printf '%s\n' '--- websocket abort registration and dispatch entry ---'
rg -n -F --glob '*.ts' -e 'registerWebSocketDispatchAbort' -e 'new AbortController' -e 'dispatchStreaming(request' src/main/runtime/runtime-rpc
printf '%s\n' '--- unix socket transport complete relevant class ---'
sed -n '1,280p' src/main/runtime/rpc/unix-socket-transport.ts
printf '%s\n' '--- terminal orphan callers and runtime implementation ---'
rg -n -F --glob '*.ts' -e 'adoptTerminalOrphans' -e 'TERMINAL_ORPHAN_METHODS' -e 'terminal.adoptOrphans' src
printf '%s\n' '--- focused tests for cancellation/readiness/terminal orphan ---'
rg -n -F --glob '*.{ts,tsx}' -e 'terminal.adoptOrphans' -e 'aborted' -e 'readiness' -e 'requires' src/main/runtime/rpc src/main/runtime/runtime-rpc | head -240

Repository: stablyai/orca

Length of output: 42089


Script executed:

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)) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant