Repository navigation
fix(agent-launch): report a launch that failed before spawning as failed, with its cause - #22913
Conversation
4255125 to
80eda09
Compare
Review status: ready to merge (head
|
| Scenario | Before (0a876b2f5a) |
After (80eda090d5) |
|---|---|---|
Claude disabled, agent.launchReplay into an existing workspace |
agent_session_operation_unknown, row unknown |
Agent claude is disabled. Choose an enabled agent., row failed with that code |
| Claude re-enabled, same operation id sent again | unknown again |
Answered from the record with the same refusal. No terminal was created (count 0 before and after). |
| Claude enabled, new operation id | Terminal created, Claude process live | Terminal created, Claude process live |
| Same operation id sent again | Same handle, no second terminal | Same handle, no second terminal |
Before, Claude disabled in Settings:

Before, no agent tab after the refused launch:

Before, a normal launch starts Claude:

After, Claude disabled in Settings:

After, no agent tab after the refused launch or its replay:

After, a normal launch still starts Claude:

Gaps
- Phone QA on Android was blocked. The shared emulator was already in another session, and it was not driven. The iPhone simulator check in the PR description still applies.
- The phone released today only sends
agent.launchReplaywhen it is creating a workspace, and that case stays unknown here on purpose. Phone users see this change once the "+" menu moves toagent.launchin fix(mobile): start + menu, quick command and diff-note agents through agent.launch #22954. - The refusal reaches the client as
error.code: runtime_error, with the real sentence inerror.message. The ledger stores that sentence as the operation's code, capped at 128 characters, as it already does.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe change adds a callback that reports when terminal creation dispatches a PTY spawn request. Agent launch handling tracks that dispatch state and uses it to classify certain failures for replay. Tests cover terminal dispatch timing, failures before and after dispatch, and retry outcomes. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to Concurrent launches into the same pane can record a failure when an agent may already have started, making a replay unsafe. Resolve this before merging unless the risk is explicitly accepted. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to A concurrent launch can receive another terminal creation’s failure and record its own request as definitively failed, even though a spawn for the shared pane may have occurred. Access remains gated, and the identified scenario is limited to concurrent work on the same pane. Retained concerns
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description is detailed and covers the change, rationale, testing, visual proof, compatibility, and known limitations. However, it states "No linked issue" even though the template requires a linked issue for outside contributors, and it omits the template's Review, Agent skill upstream boundary, and Checklist sections.
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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.
Important
One classification edge sits on the wrong side of this PR's own safety line: a launch that waits on a concurrent create's already-dispatched spawn for the same reserved pane is settled as failed even though an agent may be running in that pane. Details inline.
Reviewed changes
- Per-launch spawn-dispatch tracker — new
agent-launch-not-started.tsreturns a tracker whoserethrowrecords the exact error only while no spawn request has been dispatched, and whosefailedBeforeDispatchmatches that object by identity. The verdict is per launch, so a shared error object cannot clear another launch's record. - Runtime hook —
TerminalCreateOptions.onPtySpawnDispatchedfires immediately beforethis.ptyController.spawn(...)inorca-runtime-create-terminal.ts, and before the renderer-ownedcreateDesktopTerminal(deliberately conservative: the renderer path staysunknown). - Terminal surface wiring —
agent-launch-surfaces.tsforwards the hook and wrapscreateTerminalincreated.catch(terminalSpawn.rethrow). - Replay-safe classification —
executeReplaySafeAgentLaunchnow settles an existing-workspace launch that throws before dispatch asfailedwith the error's own code, and carries the decision once onAgentLaunchExecutionErrorso the handler no longer re-derives it from the error. - Tests —
agent-launch-prestart-failure.test.tsdrives the classifier through the real RPC dispatcher and ledger;terminal-spawn-dispatch.spec.tsexercises the realcreateTerminalhook.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| if (error instanceof AgentLaunchSessionAlreadyExistsError && targetKind === 'existing') { | ||
| return AGENT_LAUNCH_SESSION_ALREADY_EXISTS_CODE | ||
| } | ||
| if (terminalSpawn.failedBeforeDispatch(error) && targetKind === 'existing') { |
There was a problem hiding this comment.
For an existing-workspace launch, a pre-dispatch throw does not always prove nothing spawned. createTerminal runs adoptStablePane at orca-runtime-create-terminal.ts:64 before the new hook at :127, and that call can be blocked on a concurrent create's in-flight spawn for the same reserved pane. When that in-flight spawn fails after dispatch (e.g. a lost SSH/daemon reply), this launch's create rejects with the same error before its own hook, and this branch records it as failed even though an agent may be running in the pane it targeted — the reduction the PR exists to avoid.
Technical details
# A launch joined to another create's dispatched spawn is classified as failed
## Affected sites
- `src/main/runtime/rpc/methods/agent-launch.ts:234` — the new branch accepts the propagated error as "nothing spawned" for any `existing` target.
- `src/main/runtime/orca-runtime-create-terminal.ts:64,127` — `adoptStablePane` runs before `onPtySpawnDispatched`, so a rejection from it is observed as pre-dispatch.
- `src/main/ipc/pty/pane/adopt-stable.ts:24-29` — the waiter `await activePaneSpawn.promise` for the same `ownerKey`, which is the *other* create's spawn reservation.
- `src/main/ipc/pty/runtime/spawn.ts:78-81,105-121` — the reservation is created around dispatch and is rejected with the provider's own error, so the waiter receives a post-dispatch failure.
- `src/main/runtime/rpc/methods/agent-launch-prestart-failure.test.ts:135-151` — asserts the waiting launch becomes `failed`, but simulates it with a plain pre-throw, not the pane-wait path, so the lost-reply interleaving is untested.
## Required outcome
- A launch that failed only because a concurrent spawn for its target pane rejected should settle `unknown`, mirroring the spawner's own launch. Its create is joined to that spawn; treating the join's failure as a definitive "nothing spawned" is what re-opens the duplicate-agent path.
## Suggested approach (optional)
- Signal the tracker when `adoptStablePane`'s active-reservation branch is entered (e.g. pass `onPtySpawnDispatched` into the adopt call and fire it before awaiting), rather than firing the hook unconditionally earlier — a failure before adopt (shell/launch-command refusal) is still provably pre-spawn and should keep classifying as `failed`.
## Open questions for the human (optional)
- Is a second concurrent launch into one reserved pane reachable for `agent.launchReplay` (two distinct operation ids on the same `paneKey`), or is it precluded upstream? If unreachable, a comment saying so would make this classification defensible.…led, with its cause A launch into an existing workspace whose terminal create threw before the spawn request left this process (agent disabled, no launch command, runtime unavailable) created nothing, yet agent.launchReplay recorded and answered it as agent_session_operation_unknown. createTerminal now reports when it hands the spawn to the pty controller; a failure before that point settles the ledger row as failed and returns the original error. After the request leaves, the outcome stays unknown: an SSH or daemon spawn whose reply was lost may still have started.
… command A disabled agent is moving to a check made before either launch route runs, so the tests use a failure that stays inside the terminal build.
…e shared error A failed pane spawn rejects the same error object into the spawner (after its request left) and into a concurrent create waiting on that pane (before its own). Marking the error object globally let the waiting launch's verdict clear the spawner's, recording a launch that may have started an agent as failed. The launch now owns its dispatch tracker and carries the decision on its execution error instead of re-deriving it from the error. Also names the test's launch parameter type for the anti-slop audit.
…wn module Rebasing onto the caller-selection change took agent-launch.ts past its line limit; the failure-code helpers are a self-contained concern.
80eda09 to
823ac08
Compare
Review status update: still ready to merge (head
|
Host on main (bdaf9a3ed3) |
Host on this branch (823ac089a3) |
|
|---|---|---|
| Phone after tapping Claude | Couldn't confirm the agent started. Check the workspace before trying again. |
Could not build launch command for claude. |
| Ledger row | unknown |
failed, code Could not build launch command for claude. |
| Terminals created | 0 | 0 |
| Tapping again | New operation id, unknown again |
New operation id, same real cause |
| Tapping after restoring valid arguments | Claude starts in a new tab | Claude starts in a new tab |
| Before | After | After, with valid arguments |
|---|---|---|
![]() |
![]() |
![]() |
Not caused by this PR. While a phone is in a session, the desktop covers the terminal with "Your phone left this at phone size". This happens on both builds.




ELI5
When a client asks the computer to start an agent in an existing workspace and the computer can't even begin — the agent is turned off in settings, or its launch command can't be built — the computer used to answer "I'm not sure whether it started". Nothing had started, so it now says so, with the real reason. The shipped phone only uses this for launches that create a new workspace (which stay "not sure"), so phone users see the benefit once the mobile "+" agent menu change (#22954) moves that menu onto this call.
What Changed
Before:
agent.launchReplayrewrote every error raised while building the launch's terminal toagent_session_operation_unknownand recorded the operation as unknown. A launch refused because the agent is disabled, or because the runtime couldn't build a launch command, reached the phone as "couldn't confirm the agent started", and a retry of the same operation was answered "unknown" again.After: for a launch into an existing workspace, a failure raised before the terminal's spawn request leaves this process settles the operation as failed with its real cause. The caller gets the original error (for example "Could not build launch command for claude." or
runtime_unavailable), and a retry of the same operation id is answered from that record without launching again.Mechanism:
createTerminalgains anonPtySpawnDispatchedoption, called immediately before it hands the spawn to the PTY controller (and at the start of the renderer-owned path, which this process can't see into).launchFailureWithoutEffectsCodeasks that launch's tracker, and treats a "not started" error like the existing typed refusals: existing-workspace launches only, recorded with the error's own code. The decision is made once and carried on the launch's execution error, so the RPC handler reuses it instead of re-deriving it.Unchanged: any failure after the spawn request left stays unknown, and a launch that created its workspace first stays unknown (the workspace exists).
Why
A failure after the spawn request is sent proves nothing: an SSH or daemon spawn whose reply was lost may still have started an agent, and loss of contact is never evidence that nothing is running. So the line is drawn at the last point this process can see — the request leaving — rather than at "the spawn reported success". The spawn-committed signal was considered and rejected for this reason: it isn't fired when a remote spawn's reply is lost, so "never committed" can't distinguish "never started" from "started, reply lost". Refusals like a remote spawn being rejected therefore stay unknown; only the providers themselves could prove those, and that's out of scope.
Matching error messages ("agent is disabled", "could not build launch command") was rejected too: it would miss the next pre-spawn failure and could misclassify a post-spawn one with similar text.
Linked Issue
No linked issue.
Visual Proof
Android phone ("+" menu from #22954), tapping Claude while the host cannot build Claude's launch command because its CLI arguments have an unbalanced quote:
main)With valid arguments restored, the same tap still starts Claude (after):
Testing
agent-launch-prestart-failure.test.ts(through the real RPC dispatcher and operation ledger): a missing launch command before the spawn request → error carries the real message and the row isfailedwith that code;runtime_unavailablekeeps its code; a retry of the same operation id is answered from the record and creates nothing; a failure after the spawn request →agent_session_operation_unknown, rowunknown; one error object seen by one launch before its spawn request and by another after → the second staysunknown; a launch that created its workspace → unknown.terminal-spawn-dispatch.spec.ts(realcreateTerminal): the hook fires before the PTY controller'sspawn, still fires when that spawn throws, and does not fire when the create fails before any spawn request.createTerminal's options exactly now expect the new option.pnpm tc:node;src/main/runtime/rpc/methods/agent-launch*(including the caller-selection tests from fix(agent-launch): move only the requesting client's view to a launched tab #22914),src/main/agent-launchandcreated-mobile-session-tab-caller-selection.test.ts— 14 files / 194 tests pass; theorca-runtime.test.tsspawn-dispatch cases pass; oxlint on changed files;audit:anti-slopclean;check:code-quality:changed0 findings. (An earlier revision also passed the wholesrc/main/runtime/rpc/methodsdirectory andorca-runtime.test.ts: 216 files / 3,489 tests.)createTerminalnever reports the spawn requestagent.launchReplayrequest (existing workspace, prompt,launchSource) with Claude disabled:Agent claude is disabled. Choose an enabled agent.failedwith that code.trusted-local:runtimevs the phone's device id); the handler, classifier and ledger code are the same.orca emulator; isolated dev host from this branch with its own profile; phone from mobile PR fix(mobile): start + menu, quick command and diff-note agents through agent.launch #22954, which moves the "+" agent menu ontoagent.launch). I opened the "+" menu with Claude enabled, then disabled Claude on the host over a client pinned to that profile, then tapped Claude in the still-open menu:Agent claude is disabled. Choose an enabled agent.The host's tab and terminal lists were empty before and after, and no process started.mainas well, so this PR does not cover it; fix(agent-launch): refuse a disabled agent on the chat route too #23043 does (see Notes).Notes
agent_session_operation_unknown. The mobile client already reads any non-unknown refusal as "not started" with the host's message.agent-launch-surfaces.tschanges are limited to taking the launch's tracker, passing the new option and catching the create. The launch failure-code helpers moved unchanged fromagent-launch.tsintoagent-launch-failure-code.ts, because rebasing onto fix(agent-launch): move only the requesting client's view to a launched tab #22914 took that file past its line limit.