Skip to content

fix(agent.launch): the creation operation owns a new workspace's first surface - #29095

Closed
brennanb2025 wants to merge 12 commits into
mainfrom
brennanb2025/unify-row1-first-surface
Closed

brennanb2025 wants to merge 12 commits into
mainfrom
brennanb2025/unify-row1-first-surface

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 21 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​299 $\color{#cf222e}{\Huge{\mathbf{−}}}$​114 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​185
Prod 32 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​561 $\color{#cf222e}{\Huge{\mathbf{−}}}$​169 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​392

ELI5

Creating a workspace with an agent could leave an extra plain “Terminal 1” beside Setup and the agent, or start the agent twice after a failed first attempt. Workspace setup and the agent launch both acted as if they owned the first tab. The running creation operation now owns that first surface until it succeeds or fails.

What Changed

Phone, CLI and worker agent creates keep Setup and the requested agent without an incidental shell. If a terminal agent fails before it starts, its launch retries once; the desktop does not also start another copy. When Orca cannot confirm whether an agent started, it leaves the workspace available to inspect instead of adding a shell beside a potentially running agent. A definite failure can still produce a recovery terminal.

The creation operation registers ownership when the workspace is created, and host provisioning reads that live registration for worktrees and folder workspaces. This replaces the chat-only promisedAgentChat plumbing. The existing optional activation hint remains temporarily so delayed desktop navigation cannot seed another primary terminal; the planned creation-path convergence removes that adapter. No new saved field or wire operation is introduced.

The integration preserves main’s #29810 behavior: background creates that merely attribute a workspace to an agent leave the first surface to their caller, while activated creates retain their normal startup path. It also adopts #29819: Setup always opens in its own tab, including a retry after failure, and no longer requires a terminal split anchor. The removed setting and obsolete failure notice stay removed. Desktop New Workspace, explicit New Terminal and older paired servers retain their existing launch paths.

Why

A single running operation should create the first surface and own its failure handling. That follows the common pattern and prevents independent provisioning and activation paths from launching competing surfaces. Recovery requires evidence that no surface was created; an uncertain outcome cannot safely authorize another one.

Intended differences from the common pattern: Orca also provisions terminal agents, Setup and configured tabs across folders, execution hosts and multiple viewers. Temporary difference: the existing optional activation hint carries ownership through delayed desktop navigation until the planned creation-path convergence removes it.

Linked Issue

Maintainer follow-up to #28451; row 1 of the workspace-creation convergence plan.

Visual Proof

M4Air desktop comparisons passed on main merge parent 41fdd7e6d8301ff1faa956e8ecc6a8ef86cff10f and final head f329417f808474f5098cc73ae11a1228aa874c93, using the same committed fixture with Setup and one configured Project Checks tab. Native phone QA remains queued, so the full review is incomplete. Desktop behavior is intentionally unchanged.

Flow Main This PR
Desktop Claude Chat Main: Desktop Claude Chat This PR: Desktop Claude Chat
Setup completes in its own tab Main: Setup completes in its own tab This PR: Setup completes in its own tab
Terminal agent Main: Terminal agent This PR: Terminal agent
Create without an agent Main: Create without an agent This PR: Create without an agent

New Terminal added exactly one functioning shell on both commits after its shell prompt was visible and the terminal element was focused. One earlier automated target attempt sent partial input without proving that readiness/focus; its cause remains unproven, and the bounded same-input recheck passed on both commits.

Testing

The final integration is independently source-reviewed at f329417. Seven named suites passed 156 focused tests, and the normal pre-commit checks passed with serial scheduling. The full PR workflow passed on this final head, including static analysis/typecheck, all five node shards, relay tests, cross-version wire compatibility, packaging, rendered checks and its aggregate gate. Mobile Checks, node-server tests and the WSL workflow also passed. Earlier exact-head checks passed before this final main merge, and existing regression coverage checks failed first starts, uncertain outcomes, folder creation, provisioning and renderer activation. Final-head desktop rendered QA passed all three create flows and the bounded New Terminal recheck. Native phone QA is queued separately; the earlier M4Air phone run does not certify this head.

  • I manually tested these changes locally
  • Automated tests added/updated

AI Disclosure

Review

Independent source review agrees with the final main integration, including background attribution-only creates and Setup in its own tab. Exact-head CI and desktop rendered QA passed. Fresh native phone QA must finish before the status comment is marked complete.

Agent skill upstream boundary

  • This change copies no upstream skill-installer material.

Notes

Author: @BrennanKB5

Checklist

  • This PR is focused on creation’s first surface
  • Explained the problem, user-facing change, mechanism and alternatives
  • Before/after screenshots attached
  • Self-reviewed for correctness, security and performance
  • Cross-platform, SSH, folder and mixed-version behavior considered
  • Full PR workflow and Mobile Checks pass on the current head

…t surface

A workspace that agent.launch creates gets its first surface (chat, agent
terminal or folder agent) from the running launch. That fact now lives in
one place, the launch's live registration, which dies with the launch.

- Host provisioning reads the live launch instead of a threaded
  promisedAgentChat flag, for terminal agents and folders as well as chats.
- A failed first agent start stays with the launch, which builds the agent
  next; the window is no longer also handed the start (two agents).
- The activation event's providesInitialSurface field is gone; the window
  asks the host's tab inventory when a host-retried Setup arrives.
- A recovery shell is added only when the surface is definitely missing,
  never after the host reported an unknown chat outcome.
Main now always runs Setup in its own tab (#29819) and lets background
agent creates leave the first surface to the caller (#29810). Keep both:
the creation owner still suppresses the starter shell, and background
attribution-only creates follow main's narrower rule. With no split Setup
mode left, owned navigation queues Setup directly and the "Setup could
not run" fallback is gone.
@brennanb2025
brennanb2025 marked this pull request as ready for review October 16, 2026 23:09
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b38f763b-c572-4f46-a45e-8a680bbe80ee
📥 Commits

Reviewing files that changed from the base of the PR and between d7cfbc7 and f329417.

📒 Files selected for processing: 22
  • mobile/src/session/mobile-existing-agent-launch.ts
  • src/main/agent-hooks/server/server-status-application.ts
  • src/main/agent-hooks/server/server-status-update.ts
  • src/main/agent-launch/agent-launch-execution.ts
  • src/main/agent-launch/agent-launch-executor.test.ts
  • src/main/agent-launch/agent-launch-executor.ts
  • src/main/daemon/pty-subprocess-spawn-file-foreground.test.ts
  • src/main/daemon/terminal-host-process-inspection.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-attach-orchestration.ts
  • src/main/providers/local-pty-child-process-verdict.test.ts
  • src/main/providers/local-pty-provider-foreground-process.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session-create.ts
  • src/main/runtime/rpc/methods/structured-agent-session-wire-contracts.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session.test.ts
  • src/main/runtime/runtime-local-worktree-create.ts
  • src/main/runtime/runtime-managed-worktree-create-types.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/terminal/launch/terminal-create.ts
  • src/main/runtime/workspaces/workspace-creation.ts
  • src/main/runtime/worktree-agent-first-surface.test.ts
  • src/renderer/src/hooks/ipc-events/worktree-event-runtime.ts
  • src/renderer/src/lib/worktree-activation.ts

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

📝 Walkthrough

The changes add surface-acquisition tracking for structured sessions and terminals, and use proof of surface absence to control launch recovery. Worktree creation and terminal startup now share first-surface ownership state with provisioning and renderer activation. Renderer activation blocks automatic reseeding when live PTY ownership is uncertain. Mobile retry handling returns an agent-specific message for unknown launch outcomes. Several other test edits only reformat existing fixtures or assertions.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to f3294

Some failed workspace launches may open a competing recovery terminal. Resolve those failure paths before merging, or explicitly accept the 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 21.05% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 38 functions across 56 files. 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 and concisely describes the main change: the creation operation owns the workspace's first surface.
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.
Description check Passed The pull request description is detailed and covers the required ELI5, changes, rationale, linked issue reference, visual proof, testing, review, scope boundary, notes, and checklist sections. It incl…
Full details: Description check

Explanation

The pull request description is detailed and covers the required ELI5, changes, rationale, linked issue reference, visual proof, testing, review, scope boundary, notes, and checklist sections. It includes before-and-after screenshots and extensive test results. Minor inconsistencies remain: the checklist says screenshots are not attached even though they are included, the linked issue is referenced as “#28451” rather than using the template’s “Fixes #” form, and the AI Disclosure section is blank.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • 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: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a6cb30fa-e033-4fb3-85c5-310c94056814
📥 Commits

Reviewing files that changed from the base of the PR and between 39cf870 and e8e8171.

📒 Files selected for processing: 53
  • mobile/src/session/mobile-existing-agent-launch.ts
  • mobile/src/tasks/agent-launch-mobile-replay.test.ts
  • mobile/src/tasks/mobile-agent-launch-architecture.test.ts
  • mobile/src/tasks/worktree-create-launch-operation.test.ts
  • mobile/src/tasks/worktree-create-retry.ts
  • src/main/agent-launch/agent-launch-created-workspace.ts
  • src/main/agent-launch/agent-launch-execution.ts
  • src/main/agent-launch/agent-launch-executor.test.ts
  • src/main/agent-launch/agent-launch-executor.ts
  • src/main/agent-launch/agent-launch-not-started.ts
  • src/main/agent-launch/agent-launch-surface-factories.ts
  • src/main/agent-launch/agent-launch-token.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-attach-orchestration.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-failed-create-sink-release.test.ts
  • src/main/runtime/orca-runtime-tests/repository-project-operations-part-02.spec.ts
  • src/main/runtime/rpc/methods/agent-launch-floating-workspace.test.ts
  • src/main/runtime/rpc/methods/agent-launch-instant-tab.test.ts
  • src/main/runtime/rpc/methods/agent-launch-pane-reservation.test.ts
  • src/main/runtime/rpc/methods/agent-launch-surfaces.ts
  • src/main/runtime/rpc/methods/agent-launch-worktree-creation.ts
  • src/main/runtime/rpc/methods/agent-launch.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-start-agent-placement.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-start-launch-executor-parity.test.ts
  • src/main/runtime/rpc/methods/orchestration/worker/worker-worktree-creation.ts
  • src/main/runtime/rpc/methods/structured-agent-session-create.ts
  • src/main/runtime/rpc/methods/structured-agent-session-wire-contracts.test.ts
  • src/main/runtime/rpc/methods/structured-agent-session.test.ts
  • src/main/runtime/runtime-folder-worktree-create.test.ts
  • src/main/runtime/runtime-folder-worktree-create.ts
  • src/main/runtime/runtime-local-worktree-create.ts
  • src/main/runtime/runtime-local-worktree-terminal-startup.test.ts
  • src/main/runtime/runtime-local-worktree-terminal-startup.ts
  • src/main/runtime/runtime-managed-worktree-create-types.ts
  • src/main/runtime/runtime-terminal-contracts.ts
  • src/main/runtime/runtime-worktree-terminal-provisioning.test.ts
  • src/main/runtime/runtime-worktree-terminal-provisioning.ts
  • src/main/runtime/runtime-worktree-terminal-startup-attempt.ts
  • src/main/runtime/terminal/launch/terminal-create.ts
  • src/main/runtime/workspaces/workspace-activation.ts
  • src/main/runtime/workspaces/workspace-creation.ts
  • src/main/runtime/workspaces/workspace-host-notifications.ts
  • src/main/runtime/worktree-agent-first-surface.test.ts
  • src/renderer/src/hooks/ipc-events/worktree-event-runtime-activation.test.ts
  • src/renderer/src/hooks/ipc-events/worktree-event-runtime.ts
  • src/renderer/src/lib/worktree-activation-gated-empty-reseed.ts
  • src/renderer/src/lib/worktree-activation-structured-chat-surface.test.ts
  • src/renderer/src/lib/worktree-activation-surface-selection.ts
  • src/renderer/src/lib/worktree-activation.ts
  • src/renderer/src/lib/worktree-agent-activation-gate.test.ts
  • src/renderer/src/lib/worktree-agent-activation-gate.ts
  • src/renderer/src/lib/worktree-agent-activation-seam.test.ts
  • src/renderer/src/lib/worktree-owned-navigation.ts
  • src/shared/worktree-first-surface.ts
💤 Files with no reviewable changes: 2
  • src/main/runtime/rpc/methods/orchestration/worker/worker-worktree-creation.ts
  • src/main/runtime/runtime-folder-worktree-create.test.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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Mark pane acquisition as unverifiable before the abort check. · terminal-create.ts:67-74

src/main/runtime/terminal/launch/terminal-create.ts:67-74
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Mark pane acquisition as unverifiable before the abort check.

When an unhinted startup has an aborted signal, terminal-create.ts throws client_disconnected before it calls onPaneAcquisition('unverifiable'). The startup remains absence-eligible and runtime-worktree-terminal-startup-attempt invokes recovery creation. Because adoptStablePane has not run, recovery has not proved that no stable pane exists. It can therefore create a competing initial surface.

Suggested fix
       try {
         // A pane moved from another host reopens where it last was, until a spawn commits.
         cwd = (await restoreHint.peekCwd(launchOpts.cwd)) ?? cwd
+        launchOpts.onPaneAcquisition?.('unverifiable')
         if (launchOpts.signal?.aborted) {
           throw new Error('client_disconnected')
         }
-        launchOpts.onPaneAcquisition?.('unverifiable')
         const adoptedBeforeLaunch = await this.ptyController.adoptStablePane?.({

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4af6f155-e52c-4ad5-8ca0-9cbe3d5f5bdf
📥 Commits

Reviewing files that changed from the base of the PR and between e8e8171 and d7cfbc7.

📒 Files selected for processing: 2
  • src/main/runtime/rpc/methods/structured-agent-session-wire-contracts.test.ts
  • src/main/runtime/runtime-terminal-contracts.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.

@brennanb2025

brennanb2025 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Not ready: native phone comparison finished, but both the phone and later desktop navigation open Project Checks instead of the requested agent chat. GitHub also reports merge conflicts.

Creating a workspace with an agent could leave an extra plain “Terminal 1” beside Setup and the agent. A failed terminal-agent start could also trigger a retry from both the host and desktop. Host provisioning and agent launch were independently deciding who should create the first tab.

The running creation operation now owns the first agent surface and its bounded retry/recovery. Phone, CLI and worker creates keep Setup, configured tabs and the requested agent without an incidental shell; ordinary desktop creation and explicit New Terminal keep their existing paths. Recovery requires evidence that no agent surface was created. An uncertain result leaves the workspace available to inspect instead of creating another shell.

The final integration preserves main’s #29810 background attribution-only behavior and #29819 separate Setup tab. Independent source review agrees on f329417, including all three final-main conflict resolutions. No new source-proven defect introduced by the PR remains; the requested landing acceptance below fails on both tested heads. The source fixes cover duplicate retries, uncertain acquisition, Setup retry without a split anchor, folder creation, and delayed desktop activation. Deferred historical concerns about inventory event ordering and folder publication timing remain unconfirmed; this pass found no new evidence to reopen them.

Verification: seven named suites passed 156 tests and the normal pre-commit checks passed. Exact-head full PR workflow 39243124036 passed, including static analysis/typecheck, five node shards, relay tests, wire compatibility, packaging, rendered checks and its aggregate gate; Mobile Checks, node-server and WSL workflows also passed. Desktop comparisons on M4Air passed for Claude Chat creation, terminal-agent creation, no-agent creation and a controlled explicit New Terminal check, using the same committed Setup/default-tab fixture on main and this head. Native phone comparison completed on the pinned main baseline 41fdd7e and this head f329417. Each used normal native pairing from an unpaired state, an exact-source mobile-web bundle, and a real Claude reply through the team's load balancer under an isolated QA home. Both created Project Checks, Setup and Claude Chat, with no extra plain “Terminal 1”; Setup completed with exit status 0 and the desktop stayed on its previous workspace. Both failed the requested Chat landing: the phone initially selected Project Checks, and later ordinary desktop workspace navigation also selected Project Checks before any tab click. Selecting Chat manually allowed a real reply, but does not satisfy automatic landing. The baseline's first agent start was stopped by a QA launcher environment guard; the corrected isolated launcher then produced the baseline reply and was used from the outset on the target. This was a rig correction, with no product source changes. All owned apps, agents, drivers, Metro servers and simulator helpers were stopped; the owned simulator and temporary homes were removed and ticket 635 was released. The original immediate New Terminal input attempt had different timing on main and target; one bounded ready-prompt/terminal-click recheck passed both, and no source regression was established. Live app, agent and driver environment checks were recorded for the phone run. Other observations were retained without attributing them to this PR: the baseline startup-error banner remained after its successful retry; both Setup-source badges read ORCA.YAML despite Local only settings, and configured default-tab readiness output was absent; the target desktop showed a phone-size Restore notice. The run did not diagnose those causes. Source review checked SSH/execution-host routing, folders, old paired-server fallbacks and platform-aware Setup commands. Live Windows/WSL/SSH failures and runtime performance were not exercised in this pass; no minimum server version, new saved field or new wire operation is introduced.

For Brennan’s review

Flow Main This PR
Desktop Claude Chat Main: Desktop Claude Chat This PR: Desktop Claude Chat
Setup completes in its own tab Main: Setup completes in its own tab This PR: Setup completes in its own tab
Terminal agent Main: Terminal agent This PR: Terminal agent
Create without an agent Main: Create without an agent This PR: Create without an agent

Native phone screenshots below distinguish the initial landing from the manually selected chat reply. The same landing failure exists on the tested main baseline; this run does not establish that the PR introduced it. The requested landing acceptance failed, so the review does not certify this head. GitHub reports mergeStateStatus DIRTY / CONFLICTING on the unchanged head; no merge or source change was attempted.

Native phone comparison Main This PR
Phone initial landing (fails Chat landing) Main: Phone initial landing (fails Chat landing) This PR: Phone initial landing (fails Chat landing)
Setup finishes Main: Setup finishes This PR: Setup finishes
Real reply after manually selecting Chat Main: Real reply after manually selecting Chat This PR: Real reply after manually selecting Chat
Later desktop initial landing (fails Chat landing) Main: Later desktop initial landing (fails Chat landing) This PR: Later desktop initial landing (fails Chat landing)

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Closing: main already stops the extra terminal when a workspace is created with an agent (#28451, then #29810 and #29819); phone QA showed main and this branch behave the same. What remained here only changed failure-path handling. The follow-up that opens a new workspace on its agent's chat (#29204) is being rebuilt directly on main as a new PR.

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