Skip to content

Start a plain new-tab agent the window's way when the host ran nothing - #27077

Closed
brennanb2025 wants to merge 6 commits into
mainfrom
brennanb2025/launch-record-store-fallback
Closed

brennanb2025 wants to merge 6 commits into
mainfrom
brennanb2025/launch-record-store-fallback

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

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.launchReplay since #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:

  • the launch record can't be opened or written (the reported case);
  • the host failed before its spawn request left: for example a deleted folder workspace's root, which the host refuses before spawning. Here the window's own launch now shows the spawn error main showed, instead of the host's "The agent couldn't start."

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.

  1. Host: a launch failure the host proves ran nothing keeps its existing error code and gains optional error data, { 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 on agent_session_operation_unknown, where an agent may be running. The fact travels on that launch's own answer (a wrapper that agent.launchReplay throws 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.)
  2. Window: launchFreshNewTabThroughHost(args, launchInWindow) is the one shared fallback. When the host says nothing ran, it closes the host's tab and runs launchInWindow, 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.
  3. Taking back a launch tab nothing ran in leaves the workspace as the click found it: the workspace stays selected, an empty split it was launched from stays, and the tab isn't added to the reopen-closed-tab history. Only that close changes; a user's own close of a workspace's last tab still goes to the landing page, as on main. Without this, a "+" from an empty workspace or the dashboard would have started the agent in a workspace the user was no longer looking at, and a "+" from an empty split would have lost the split. The fallback takes the host's tab back the same way the host does, so if the user split that tab while it waited, their pane stays. This applies to every launch tab the host takes back, including ones it showed for a CLI or paired-device launch.
  4. The host's request to show its tab early can arrive after its failure reply. The window now refuses to show a launch tab it already closed. Before, that late request brought the closed tab back, focused, until the host took it back again: the second flash above, and on this PR a brief second tab next to the replacement. This also covers a user who closes the tab before the host's request arrives.
  5. Telemetry: the host's spawn pipeline now records agent_error on 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:

  • The window fallback itself depends on the window's own pre-Start plain new-tab agent launches through the host's agent.launch #26489 launch, which launch unification will remove. Follow-up: the host starts the agent unrecorded when admission throws, behind an opt-in request field, so no window fallback is needed.
  • Close-and-reopen instead of reusing the tab exists because the window releases the pane's held spawn when the host shows the tab, before admission. Follow-up (phase 2): hold the spawn until the host has admitted the launch, so the fallback can run in the same tab.
  • Windows clients keep main's route until the host resolves the Windows runtime and shell from the same source as the window.
  • A deleted git-worktree folder: stacked follow-up that checks the folder before the spawn counts as sent.

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, keeps runtime_error and 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

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

…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.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

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.

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