Skip to content

feat(orcad): gate agent launches on readiness and refuse callers that leave while waiting - #35710

Merged
nwparker merged 3 commits into
mainfrom
nwparker/orcad-agent-launch-gates
Oct 29, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/orcad-agent-launch-gates

Conversation

@nwparker

@nwparker nwparker commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​229 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​219
Prod 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​145 $\color{#cf222e}{\Huge{\mathbf{−}}}$​29 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​116

Flag-off: No behaviour change, flag on or off. Every readiness latch still opens before orcad starts RPC (from #35571), so no call waits today. The desktop never installs a readiness.
User-risk: Very low.

  • Methods with no requirement dispatch exactly as before, with no added await.
  • The new cancellation path only runs while a latch is closed, which never happens today.
  • The shared test setup file adds one reset after each unit test. It measured no slowdown.

ELI5

#35571 let an RPC method say "wait until this part of startup is done". This PR adds the same gate to everything that starts an agent: agents need their account setup. It also makes sure that if the caller goes away while waiting, the call is dropped rather than run for nobody. Today every gate opens before the first call, so nothing changes yet. These are prerequisites the reviewers asked for before any gate may open later.

What Changed

Requirements can now depend on a call's params. requires: is now OrcadFeatureRequirement<P>: either a fixed list or a function of the parsed params. The dispatcher resolves it from the admitted params. New file runtime/rpc/agent-launch-feature-requirement.ts.

What now waits on the accounts latch:

  • terminal.create and session.tabs.createTerminal, only when they start an agent: agent, launchAgent, launchConfig, resumeProviderSession or sourceChatFork is set, or command is recognised by the existing recognizeAgentLaunchCommand. Plain shells and commands like ls are never gated.
  • agent.launch and agent.launchReplay, unless they reuse a live terminal (reuseTerminal), which starts no process.
  • terminal.ensureAgentSession, only for kind: 'explicit'. An attach (kind: 'automatic') restores an existing pane, and its latency is what the user sees on restore. This matches the WSL account-env classifier.
  • terminal.createAgentSession, agentSession.create and git.generateCommitMessage, always.
  • The worker launches orchestration.workerStart and orchestration.federationAttachStart, in addition to orchestration.
  • Not gated: an agent started through a bare command the recogniser doesn't know. Only Claude and Codex use the account services, and both are recognised. A comment at the classifier says so.

A caller that leaves while waiting is never run.

  • The feature wait races the request's options.signal against a new dispatch-only connectionSignal. connectionSignal aborts when the connection closes and is never handed to handlers.
  • If either aborts, or had already aborted, the call is refused with the existing runtime_unavailable and the handler never runs.
  • Otherwise, a streaming handler such as accounts.subscribe would register close cleanup after the close already happened, and a unary mutation could run twice after the client retries.
  • WebSocket dispatch already sets options.signal from its socket-close registration. The Unix-socket transport now passes its per-message disconnect signal as connectionSignal (runtime-rpc-request-admission.ts), because short RPCs get no handler signal there.

Test isolation.

  • A new shared vitest setup file, config/scripts/vitest-orcad-feature-readiness-reset.ts, resets the module-level readiness after every unit test. A startOrcad test that fails partway can no longer leave latches closed and make later tests in the worker wait 10 s.
  • The readiness module has no runtime imports, so the setup file pulls in no orcad code. No test mocks it.

Why

  • Read the params rather than gating all of terminal.create. That method also opens plain shells, which must never wait for account setup.
  • Refuse rather than run when the caller has gone. Running a handler for a departed caller leaks stream cleanup and risks a double mutation. Refusing costs nothing: nobody reads the reply.
  • A dispatch-only signal rather than forwarding the disconnect signal to every handler. Forwarding would change cancellation for every short RPC on the Unix socket. This limits the change to the new wait.

Linked Issue

Internal WSL cold-start work, option (c) "staged readiness". This follows #35571 and covers e9-reviewer's two prerequisites (gate every agent launch; cancel while waiting) and fix-reviewer's test-reset nit.

Visual Proof

N/A: no UI or behaviour change.

Testing

  • dispatcher-feature-readiness.test.ts:

    • a plain-shell terminal.create runs at once while an agent one waits;
    • an attach-only ensureAgentSession runs at once with every latch closed, while an explicit one waits;
    • an aborted unary request is refused without running;
    • a streaming call whose connection closes is refused without running;
    • a caller that already left is refused at once.
    • The three cancellation cases fail with the signal race removed.
  • runtime-rpc-local-disconnect-forwarding.test.ts: a gated short RPC whose local Unix caller disconnects mid-wait is refused and never run. It fails without the connectionSignal wiring.

  • orcad-feature-readiness-manifest.test.ts: the exact gated set, plus the per-param cases (plain, ls, claude, codex, launchAgent, launchConfig, resume, reuseTerminal, ensure explicit/automatic).

  • orcad-feature-readiness.test.ts: latches closed in one test are open in the next, which proves the shared reset. It fails without the setup file.

  • Full src/main run with and without the setup file: 1054 s with and 1162 s without, with no new failures. The local-only failures appear in both runs or pass on re-run.

  • runtime/rpc and orcad suites after rebasing onto main: the only failures also fail on main locally, plus one flaky search test that passes alone.

  • Load rule: pnpm tc, typecheck:ci, check:code-quality:changed, the anti-slop lint 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: no new params, opcodes or published content. The only refusal code is the existing runtime_unavailable.
  • Hosts: SSH, WSL and serve hosts all run orcad. The desktop is unaffected.
  • Terminal restore is in scope (ensureAgentSession attach and plain shells stay ungated), so this needs two reviewers.

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)

… for departed callers

requires: may read the parsed params, so terminal.create and
session.tabs.createTerminal wait on accounts only when they start an
agent; plain shells stay ungated. createAgentSession, ensureAgentSession,
agentSession.create, agent.launch (unless it reuses a terminal),
git.generateCommitMessage and the worker-launching orchestration methods
also wait on accounts. The feature wait races the request signal and the
connection close and refuses without running the handler.
An attach to an existing session is restore latency and needs no fresh
account state; only kind 'explicit' may start an agent.
A startOrcad test that fails partway left latches closed, so later tests
in the same worker could wait 10 s on a gated method.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

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: d3bccdcc-2e6b-40a4-9f80-f5fe7d3f1044
Commits

Reviewing files that changed from the base of the PR and between bb20daf and e474348.

Files selected for processing: 20
  • config/scripts/ci-unit-files.mjs
  • config/scripts/vitest-orcad-feature-readiness-reset.ts
  • src/main/runtime/rpc/agent-launch-feature-requirement.ts
  • src/main/runtime/rpc/core.ts
  • src/main/runtime/rpc/dispatcher-feature-readiness.test.ts
  • src/main/runtime/rpc/dispatcher-stream-options.ts
  • src/main/runtime/rpc/dispatcher.ts
  • src/main/runtime/rpc/methods/agent-launch.ts
  • src/main/runtime/rpc/methods/agent-session.ts
  • src/main/runtime/rpc/methods/git-commit-message-generation-methods.ts
  • src/main/runtime/rpc/methods/orchestration/federation/federation.ts
  • src/main/runtime/rpc/methods/orchestration/worker/workers.ts
  • src/main/runtime/rpc/methods/session-tabs.ts
  • src/main/runtime/rpc/methods/structured-agent-session.ts
  • src/main/runtime/rpc/methods/terminal/terminal-lifecycle-methods.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
  • src/main/runtime/runtime-rpc-local-disconnect-forwarding.test.ts
  • src/main/runtime/runtime-rpc/runtime-rpc-request-admission.ts
  • 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.

@greptile-apps

greptile-apps Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The PR affects startup waits across agent-launch RPC workflows on orcad hosts.

The PR appears safe to merge, with non-blocking fixes recommended for Git-helper coverage and the reset test.

Findings

  1. P2 Git helpers miss the gate ▶
  2. P2 Reset test leaves a rejection ▶

Summary

Adds parameter-based startup requirements for agent launches and cancels readiness waits when callers disconnect.

  • Agent-starting calls wait for account setup only when they need it.
  • A waiting RPC call is refused when its caller leaves.
  • Unit tests start with open readiness latches.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Admit and parse request] --> B[Resolve required features]
  B --> C{Any feature closed?}
  C -- No --> H[Run handler]
  C -- Yes --> W[Wait for readiness or disconnect]
  W -- Ready --> H
  W -- Timeout or disconnect --> R[Refuse with runtime_unavailable]
Loading

Reviews (1) · Last reviewed commit: "test: reset orcad feature readiness afte..." · Reviewed by Greptile

export const GIT_COMMIT_MESSAGE_GENERATION_METHODS = [
defineMethod({
name: 'git.generateCommitMessage',
requires: ['accounts'],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Git helpers miss the gate

git.generatePullRequestFields and git.discoverCommitMessageModels also prepare Claude/Codex account environments and start agent processes, but neither declares requires: ['accounts']. Add both to the gated set and its manifest test.

RPC starts after accounts today, so this is non-blocking. It leaves these launches unprotected when startup is staged.

// The shared setup resets after every test; these two run in order in one worker.
it('may leave latches closed when a test stops partway', () => {
installOrcadFeatureReadiness()
expect(rpcMethodFeatureWait(['accounts'])).not.toBeNull()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Reset test leaves a rejection

This test starts a real 10-second wait and drops its promise. _resetOrcadFeatureReadinessForTests only replaces current; it does not settle that wait or clear its timer. If the worker remains alive, the abandoned promise rejects with runtime_unavailable after 10 seconds.

Keep the readiness handle, assert that the wait exists, then open accounts and await the promise. The readiness object can remain installed to test the shared reset.

@nwparker
nwparker merged commit 4049bc7 into main Oct 29, 2026
60 checks passed
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