Repository navigation
Start a plain new-tab agent the window's way when the host ran nothing - #27077
brennanb2025 wants to merge 6 commits into
Conversation
…the host ran nothing #26489 sent no-prompt "+" launches through the host's agent.launchReplay. When the host's launch record can't be opened, or the launch fails before its spawn leaves, the host takes its tab back and the window says nothing: the tab flashes and no agent starts, where main started one. The host now adds optional error data (agentLaunchNothingRan) beside the unchanged code when it proves nothing ran, and launchFreshNewTabThroughHost falls back to main's own window launch of the same pick. Taking back a launch tab nothing ran in keeps its workspace selected. The host's spawn pipeline also records agent_error as the window's does.
… open's own data A launch record that can't open is refused as an agent-session refusal, which already carries data on the wire, so the flag was dropped in exactly the case it exists for.
…h for now The host resolves a Windows runtime and shell from other sources than the window, so a plain new-tab launch from a Windows client keeps main's window route until they agree. Also tests that only a launch tab nothing ran in keeps its workspace selected.
…t on the shared error One spawn failure can reach two launches with different verdicts, so the fact is carried by a wrapper the launchReplay handler throws and the dispatcher unwraps, instead of a mark on the error object.
… found it The fallback takes the host's tab back the way the host does, so a split the user made while it waited stays, and the take-back keeps an empty split group it emptied, so the replacement starts in the split it was launched from. The 'nothing ran' fact is stated for a first send, as the replay refusal classifier already reads it.
The host's request to show its early tab can arrive after its failure reply. The window has then already closed its tab (and started the agent its own way), so the late request created the tab again, focused, until the host withdrew it: a second tab flashed. A pane this window closed is refused instead.
|
Closed without merging: superseded. This PR restored main's behaviour for the cases where a plain new-tab agent launch ("+", Quick Launch, the floating panel, the dashboard) fails after #26489 moved it onto the host's agent.launch. Examples: the launch-record store can't open; a spawn fails; a failure goes unrecorded. While fixing it, we found the root cause. #26489 starts these agents through a host terminal path built for terminals nobody is looking at, then puts them in a tab the window already owns. That mismatch causes the start size, the brief extra tab on the failure fallback, the focus jump, and the ordering problems this PR was patching one by one. So instead:
Useful pieces of this PR, such as the host's 'nothing ran' answer and the matching agent_error telemetry, are noted for that work. |
ELI5
Before #26489, clicking "+" to start an agent in a new tab always worked, even if Orca's internal launch log couldn't be written. #26489 started routing those clicks through Orca's background service, which writes that log first. When the log can't be written, the tab now appears for a moment, vanishes, and no agent starts, with no message. This PR makes that case do what it did before: the agent starts, in one tab.
What Changed
The problem. A plain new-tab agent launch with no prompt ("+", Quick Launch, the floating panel's agent button, the new-agent shortcut, the dashboard) goes through the host's
agent.launchReplaysince #26489. The host shows the tab early, then records the launch in its launch record before starting anything. If that record can't be opened (or its first write throws), the host takes the tab back and the launch fails. User sees: the tab flashes and disappears (sometimes twice), no agent. Depending on timing there is either no message at all or a "The agent couldn't start." toast; from an empty split, the split also disappears. On main before #26489 the agent started, because "+" never touched the launch record.User-facing change. When the host proves it ran nothing for one of these launches, the window starts the agent itself exactly as it did before #26489: one agent tab, in the same place, selected and focused the same way, and no error toast. Nothing changes when the host launch works.
This covers every failure where the host started nothing:
Not yet covered (follow-up): a git worktree whose folder was deleted but which the host still resolves. Its missing folder is only found after the spawn request leaves, so the host can't prove nothing ran; the pane still says "Couldn't confirm the agent started." where main showed its "Working directory ... does not exist" error. Checking the folder before the spawn counts as sent changes every background terminal create (and dozens of tests that use placeholder paths), so it gets its own stacked PR on the same signal.
Windows clients (temporary): a plain new-tab launch from a Windows client now keeps main's window route, as it did before #26489. The host resolves the Windows runtime and shell from different settings than the window does, and #26489 had no Windows QA. This goes once both resolve them from the same source.
Mechanism.
{ agentLaunchNothingRan: true }. It is set when admission throws (the record store or its claim), when resolving the launch fails, and on the host's own "failed before the spawn left" verdict, which it already records as failed. It is never set onagent_session_operation_unknown, where an agent may be running. The fact travels on that launch's own answer (a wrapper thatagent.launchReplaythrows and the dispatcher unwraps), never on the error object, because one spawn failure can reach two launches with different verdicts. (agent-launch.ts,agent-launch-nothing-ran.ts,agent-launch-execution-outcome.ts,dispatcher-error-response.ts.)launchFreshNewTabThroughHost(args, launchInWindow)is the one shared fallback. When the host says nothing ran, it closes the host's tab and runslaunchInWindow, which is main's own window launch of the same pick (same agent, arguments, split, and focus rules). It then selects and focuses the new tab, as the callers did for the tab they were handed. A tab the user closed while it started is never started again. Other host-route callers reuse the same function with their own window launch.agent_erroron a failed agent spawn, through the same helper as the window's spawn pipeline. Before, failed host launches went uncounted. This counts every host-started agent spawn that fails (CLI, phone, and workers too), not only "+".Prompted AI-button route (listed because the shared fix touches it): it does not fall back and still refuses as before. Its only change comes from point 3: when it takes back a tab nothing ran in, the workspace stays selected and the tab isn't added to the reopen history.
Why
Why the fallback replaces the tab rather than reusing it: the window snapshots a pane's startup command when the pane first mounts. The host also releases the pane's held spawn when it shows the tab, which happens before the record is opened, so by the time the host fails that spawn is already on its way with no command. Reusing the tab would mean reworking the hold and the pane's startup handling in both processes. Closing the host's tab and opening main's in the same place is small, uses main's own launch unchanged, and the QA below compares it frame by frame with main before #26489.
Starting the launch unrecorded on the host would give up the host's at-most-once guarantee for clients that retry with the same operation id, such as the phone, unless the window opted in with a new request field. The window never retries a click, so letting it run its own pre-#26489 launch restores parity without weakening that guarantee. Moving admission ahead of the early tab would not start the agent either: the launch would still fail, just before the tab instead of after it. The "nothing ran" fact rides as optional error data rather than a new error code. Older clients ignore it, and the phone's refusal handling, which reads specific codes, is unchanged.
Differences from the common pattern: none intended. Bookkeeping failing never blocks the user's action; the window's fallback is the same launch main ran.
Temporary pieces, each with its follow-up:
Linked Issue
Parity follow-up to #26489 (no separate issue).
Visual Proof
To be added from QA (hidden rig with an unopenable launch record: before = tab flashes and vanishes, after = agent starts in one tab).
Testing
agent-launch-nothing-ran.test.ts(host): with no launch record, the launch starts nothing, takes its tab back, keepsruntime_errorand adds the data. A failure before the spawn left is marked. A spawn that left is never marked.launch-agent-in-new-tab-fresh-host.test.ts(real store): exactly one window launch replaces the host tab, whether the host took the pane, already took the tab back, or never took it. The workspace stays selected, the replacement is selected and focused, the floating panel selects it in its group, and no toast is shown. No fallback for an unconfirmed launch, or for a tab the user closed. The AI-button route still refuses.launch-agent-fresh-new-tab-host-route.test.ts(including: a Windows client keeps the window route),spawn-telemetry.test.ts. A user's own close of a workspace's last tab still lands on the landing page.Typecheck (web, node) and the repo's static CI checks.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
SSH: unchanged; SSH workspaces never take the host route for these launches. Mobile/CLI: the only wire change is optional error data, which older peers ignore. Windows/WSL: Windows clients keep main's window route for these launches (temporary, above); no path handling changed.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)