Skip to content

fix(workspaces): complete a worktree create when a post-create step throws - #20175

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/fix-strand-wt
Sep 12, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/fix-strand-wt

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​377 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​377
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​147 $\color{#cf222e}{\Huge{\mathbf{−}}}$​48 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​99

ELI5

You create a workspace, and it comes up with no terminal and no tabs. Switch to another workspace and back, and everything is suddenly there. The workspace was fine the whole time — the "creating…" panel never came down, and that panel hides the tab bar.

What Changed

executeWorktreeCreation's try/catch ends the moment createWorktree resolves. Everything after it — activation, terminal seeding, the after-wake seed, the structured-session launch — runs unguarded, and all three callers invoke it as a bare void with no .catch().

completeWorktreeCreation is the only thing that removes the pending creation entry. So a throw in that tail left both pendingWorktreeCreations[creationId] and activePendingCreationId set, which makes shouldShowWorktreeCreationSurface true, which forces workspaceChromeActive false. The finished workspace then rendered no tab chrome, while the terminal workbench stayed mounted behind the panel — so its panes mounted and its PTYs spawned invisibly. Nothing announced it: no toast, no error state, the panel just sat at "creating".

  • Each post-create step is now guarded individually, falling back to the exact values the existing skip paths used (activation = false, primaryTabId = null). Control flow always reaches completeWorktreeCreation.
  • The structured-launch cancelled / visibilityUnknown early returns keep their semantics; a throw there is treated as a failed launch, which is what that module already returns for its own 'failed' case (accepted: true, prior activation/tab).
  • A .catch() backstop on the three call sites turns anything that still escapes into a visible error state plus a toast, instead of a silently stuck panel. That also covers prepareRequestForCreate, whose VM-provisioning await has try/finally with no catch.

Deliberately not wrapped as one big try/catch: the structured block's return statements must keep their meaning.

Why

Three of those calls are synchronous with no internal guard at all. The hazard was already known — the catch inside launchStructuredWorktreeSession says "nothing awaits this creation's caller, so an escaped throw would strand the panel mid-create" — but only that one call was protected. Past the create, the worktree exists on disk; the remaining steps are follow-up work and must not be able to abort the completion that tears the creation surface down.

Reported symptom that led here: a workspace created with Blank Terminal showed no terminal and no tabs until the user switched away and back. Its create took 25.2s under load (19.3s in git worktree add, with concurrent worktree removals), which is what widens this window.

Linked Issue

No filed issue — reported directly. Diagnosed from daemon logs and the app trace for the real occurrence.

Visual Proof

Not captured, and I'd rather say so than post something misleading. The failure needs a throw inside a specific window during a slow create; on a quiet machine I ran Blank Terminal creates through the real composer (fast, setup-enabled, and a deliberately slow 6.6s create against an 80k-file repo) and all of them rendered correctly. What pins it instead:

  • daemon log for the real occurrence: both PTYs spawned 1 ms apart in one batch (blank first), where every healthy create spawns setup first with a ~3 s gap as the blank tab's pane mounts
  • the app trace shows the workspace was revealed, so the failure is downstream of reveal
  • the fix is ablated below

Happy to build a forced-throw harness and record before/after if a reviewer wants it on the PR.

Testing

src/renderer/src/lib/worktree-creation-flow-stranded-surface.test.ts drives the real executeWorktreeCreation with a resolved create and a throw injected in the tail.

Ablation (measured, both arms):

  • guards removed → 4 failed / 1 passed; the survivor is the no-throw control
  • guards restored → 5 passed

Other gates:

  • 6 pre-existing worktree-creation suites: 30/30 passed
  • union of 19 affected suites with both this and the sibling drain fix applied: 123/123 passed
  • pnpm tc:web: exit 0
  • pnpm run check:code-quality:changed: 0 findings across code quality, type-aware and React Doctor

Platform: macOS only. Renderer-only change with no platform-conditional code, so Linux/Windows/SSH were not separately exercised.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

…hrows

executeWorktreeCreation's try/catch ends once createWorktree resolves, and all
three callers fire it with a bare void and no .catch. completeWorktreeCreation
is the only thing that removes the pending creation, so a throw in that tail
left pendingWorktreeCreations and activePendingCreationId set: the creation
surface stayed up, workspaceChromeActive went false, and the finished workspace
rendered no tab chrome while its panes mounted invisibly behind the panel. It
only cleared when the user switched workspaces, because setActiveWorktree nulls
the pointer. Silently -- no toast, no error state.

activateAndRevealWorktree, ensureWorktreeHasInitialTerminal and
ensureWebRuntimeWorktreeTerminalAfterWake are all synchronous with no internal
guard; launchStructuredWorktreeSession guards only its awaited launch, and that
catch's comment already names this stranding hazard.

The worktree exists past that point, so each follow-up step is now guarded
individually and falls back to the values the skip paths already used; control
flow always reaches completion. The structured-launch cancelled/visibility
returns keep their semantics, and a throw there is treated as a failed launch,
matching what that module already returns for 'failed'. A .catch backstop on
the three call sites turns anything that still escapes -- including
prepareRequestForCreate, whose VM await has try/finally with no catch -- into a
visible error state plus toast.

Ablated: with the guards removed the new suite fails 4 of 5, the survivor being
the no-throw control.

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

ℹ️ No critical issues — one minor suggestion inline.

Reviewed changes

  • Per-step post-create guards — executeWorktreeCreation now contains each throw-prone step after createWorktree (activateAndRevealWorktree, initial terminal seeding, after-wake seeding, structured-session launch) so control always reaches completeWorktreeCreation.
  • Caller-side backstop — the three fire-and-forget call sites route through a new startWorktreeCreation, which turns an escaped rejection into a visible error entry plus a toast instead of a silently stuck panel.
  • Regression test — a new suite drives the real executeWorktreeCreation with throws injected in the tail plus a prepareRequestForCreate rejection; I confirmed it passes (5/5) and the related suites still pass (44/44).

The guard reordering preserves the original skip semantics for an agent create with no explicit terminal work (verified against launchStructuredWorktreeSession's 'failed' → accepted: true contract), and preflightAgentTrust/attachEphemeralVmRuntimeToWorkspace already swallow their own errors, so the remaining post-create tail is covered. The one nit is about the backstop's error announcement.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The worktree creation flow now contains failures during activation, terminal seeding, and structured-session launch. Background, continuation, and retry paths use shared handling for escaped failures. Tests cover logging, cleanup, concurrent creation, error states, and error toasts.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to a82d3

A failed structured-session launch can leave the new workspace without a usable session or terminal while creation appears complete. This should be corrected before merge.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description gives a clear ELI5 explanation, change summary, rationale, testing details, and platform scope. However, it does not provide the required linked issue, required visual proof or the exa… Add a valid issue reference under Linked Issue, provide before-and-after visual proof or write exactly N/A with a reason if applicable, and complete the Review, Agent skill upstream boundary, Notes, and remaining Checklist sections.
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing post-create failures from leaving worktree creation incomplete.
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.
Full details: Description check

Explanation

The description gives a clear ELI5 explanation, change summary, rationale, testing details, and platform scope. However, it does not provide the required linked issue, required visual proof or the exact N/A statement, and it omits several template sections and checklist items.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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: f363a803-0e7c-4fc7-9b43-8a6400b55cbb

📥 Commits

Reviewing files that changed from the base of the PR and between 6252f81 and 2144e81.

📒 Files selected for processing (3)
  • src/renderer/src/lib/worktree-creation-flow-execute.ts
  • src/renderer/src/lib/worktree-creation-flow-stranded-surface.test.ts
  • src/renderer/src/lib/worktree-creation-flow.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron validation (hidden CDP)

Ran the Electron skill end-to-end against this PR worktree (brennanb2025/fix-strand-wt) with ORCA_BACKGROUND_LAUNCH=1. No desktop computer-use or OS mouse/keyboard automation.

Launch / identity

  • CDP 127.0.0.1:9334 (9333 was already owned by another instance; this launch bound its own port)
  • Renderer 127.0.0.1:5183 (strictPort)
  • Isolated profile /tmp/orca-pr-20175-profile.GHZQKl
  • window.api.app.getIdentity(): name=Orca: brennanb2025/fix-strand-wt, isDev=true, devWorktreeName=fix-strand-wt, devRepoRoot=/Users/brennanbenson/orca/workspaces/orca/fix-strand-wt
  • Electron PID 54577, electron-vite PID 54328, wrapper PID 54271

Scenario

  1. Added a tiny local git repo via IPC (window.api.repos.add), then opened New workspace from the sidebar.
  2. Filled the real composer: project selected, name strand-create-1, agent Blank Terminal, submitted Create worktree.
  3. Captured the in-flight creation surface, then the completed workspace.
  4. Painted the catch-backstop error creation surface (pendingWorktreeCreations[].status='error') and dismissed it.

Visible evidence

  • Composer: Create worktree dialog over the full Orca chrome, Blank Terminal selected.
  • Creating: sidebar row strand-create-1 with “Fetching base branch…”; content area is the creation surface (no real tab chrome).
  • Completed: sidebar strand-create-1 active; Terminal 1 tab + +; live shell prompt in the new worktree; Explorer shows README.md. Creation panel is gone.
  • Error surface: faux tab strand-error-surface, body “Couldn’t create worktree” + Retry/Dismiss; sidebar error row. This is the panel that used to stay stuck and hide tab chrome.
  • After Dismiss: pending creation cleared; tab chrome returns.

Composer: Blank Terminal create

Creating: fetching base branch, no tab chrome

Completed: Terminal 1 tab visible

Error creation surface: Couldn’t create worktree

After dismiss: pending gone, tabs back

Backing state

  • After successful create: activePendingCreationId=null, pending map empty, activeWorktreeId points at …/strand-create-1, tabsByWorktree has 1 tab titled Terminal 1, Resource Manager shows 1 terminal session.
  • Error paint: status='error', loaderVisible=true, activePendingCreationId set (same write the caller .catch() backstop performs).
  • After Dismiss: pendingCount=0, activePendingCreationId=null, tab chrome restored.

Console

  • 0 errors.
  • Warnings only: React Grab outdated; Linear CredentialDecryptionError (isolated profile / host keychain, unrelated); xterm task-queue deadline.

Remaining gaps

  • Did not inject a throw inside the post-create tail (activateAndRevealWorktree / terminal seeding / structured launch) on this live run. That stranding path is covered by worktree-creation-flow-stranded-surface.test.ts, not by a forced-throw harness in the running app.
  • Duplicate-name create through the composer did not fail (Orca created strand-create-1strand-create-1 instead); the error screenshot is the catch-backstop panel via the same store write, not a live createWorktree rejection.
  • macOS only; Linux/Windows/SSH not exercised.

Local copies: /tmp/orca-pr-20175-validation/screenshots/.

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

✅ No new issues found.

Reviewed changes

  • Terminal recovery after a partial activation failure — the activateAndRevealWorktree catch in executeWorktreeCreation now runs a guarded recovery tail: it re-seeds via ensureWorktreeHasInitialTerminal only when activation left no tabs, and otherwise keeps primaryTabId null so a default tab is never adopted as the agent launch tab; it then runs the after-wake seeding when the backend did not spawn the terminal.
  • Backstop toast de-duplication — startWorktreeCreation now suppresses the error toast while the creation surface is visible, addressing the prior review's nit, and toasts only after the user navigates away.

I verified the recovery path against ensureWorktreeHasInitialTerminal's tombstone/caller-provides-surface semantics and ensureWebRuntimeWorktreeTerminalAfterWake's duplicate guards; the branch-specific activate defaults match their activating/non-activating callers. The new suite passes 8/8 and pnpm tc:web is clean. The prior reviewer thread was addressed and resolved.

Pullfrog  | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

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

ℹ️ No critical issues — one stale comment inline.

Reviewed changes

  • Recover a verified launch tab after a partial activation failure — the activateAndRevealWorktree catch now adopts result.startupTerminal?.tabId or an existing tab stamped with the launch agent as primaryTabId, instead of leaving it null whenever tabs already existed. This keeps ensureAgentStartupInTerminal from falling back to tabsByWorktree[0] (a default tab) when delivering the agent draft/follow-up.
  • Regression test updated — the default-tab case now seeds a stamped agent-tab and asserts it becomes the primary id, so the new lookup can actually fail.

I traced the two seeding paths that stamp a launch agent (ensureWorktreeHasInitialTerminal and applyDefaultTerminalTabs) and confirmed exactly one seeded tab carries the startup launchAgent, so the lookup is unambiguous. seedAgentTabStateAfterWorktreeCreate already resolves the stamped tab independently (resolveLaunchAgentTabId), so it is unaffected. New suite 8/8, related suite 22/22, pnpm tc:web and oxlint on the changed files all clean.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Comment on lines +189 to +191
// Activation can publish the worktree before a later step throws. Do not
// infer a primary tab from default-tab ordering; only a fresh seed may
// return one here.

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.

This lead-in still says "only a fresh seed may return one here," which this commit just made false — a startup-terminal id or a launch-agent-stamped tab can now set primaryTabId too. The comment two lines below already states the correct rule, so reword this one to keep the two from contradicting.

Suggested change
// Activation can publish the worktree before a later step throws. Do not
// infer a primary tab from default-tab ordering; only a fresh seed may
// return one here.
// Activation can publish the worktree before a later step throws. Recover
// only ids provably tied to this launch — the startup terminal or a tab
// stamped with its agent — never default-tab ordering.

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

ℹ️ No new issues — one test-clarity nit inline.

Reviewed changes

  • Test-only follow-ups — 9ec692/a82d3ea rename the stamped-agent-tab case and add draftPrompt/followupPrompt to its startupPlan. No production code changed; the primary-id recovery from b083941 is untouched, and the assertion (primaryTabId: 'agent-tab') still fails without that lookup.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

})
})

it('activating branch: routes draft and follow-up delivery to the stamped agent tab', async () => {

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.

ensureAgentStartupInTerminal is mocked in this suite, so the added draftPrompt/followupPrompt are inert and the assertion only checks the primaryTabId argument — not that delivery reaches the agent tab. A name closer to what's asserted (targeting, not delivery) keeps the coverage honest.

Suggested change
it('activating branch: routes draft and follow-up delivery to the stamped agent tab', async () => {
it('activating branch: targets the stamped agent tab for startup delivery', async () => {

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: PASS

Final PR head: a82d3ea5b8 (pushed to brennanb2025/fix-strand-wt).

The same-model adversarial review loop is clean. It found and fixed a real partial-activation edge case: recovery now uses only a backend startup tab ID or a tab stamped for the requested agent, never default-tab ordering. The existing fixes also contain post-create failures and avoid duplicate inline/toast error announcements. The scope remains the three intended renderer files.

Validation completed:

  • End readiness checklist: PASS; no proven P0/P1/P2 findings.
  • Web typecheck passed.
  • Changed-code quality, type-aware checks, and React Doctor: 0 findings.
  • Five focused suites: 49 tests passed.
  • git diff --check: clean.
  • PR checks: merge state CLEAN; latest test-vs-non-test LoC check passed. The functional-fix commit CI also passed typecheck and all eight Node 24 test shards.
  • Hidden Electron/CDP validation ran with ORCA_BACKGROUND_LAUNCH=1, exercising real Blank Terminal worktree creation, the creating surface, completion, and error dismissal. Screenshots and detailed evidence are in the Electron validation comment.

Remaining validation limits are cross-platform/SSH runtime coverage and an injected live post-create throw; the latter is covered by the focused regression suite.

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

⚠️ Outside diff range comments (1)
src/renderer/src/lib/worktree-creation-flow-execute.ts (1)

282-309: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve failure state when structured session launch fails.

launchStructuredWorktreeSession returns accepted: true for a rejected launch, an escaped launch error, or no settlement. The caller then removes the pending creation and skips fallback terminal seeding because structuredLaunchAccepted remains true. The worktree can complete without a structured session or usable terminal. Return accepted: false for these failure paths, and keep cancelled reserved for cancellation so completion performs the fallback path.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 3390f352-d0f1-4b96-aa4b-452c76621719

📥 Commits

Reviewing files that changed from the base of the PR and between b083941 and a82d3ea.

📒 Files selected for processing (1)
  • src/renderer/src/lib/worktree-creation-flow-stranded-surface.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

CI follow-up for final head a82d3ea5b8: all required checks are now passing, including static analysis, typecheck, package (macOS and Windows), all eight Node 24 test shards, verify, and repository guards. The PR is mergeable with no failing checks.

@brennanb2025
brennanb2025 merged commit 70a588c into main Sep 12, 2026
27 checks passed
brennanb2025 added a commit that referenced this pull request Sep 14, 2026
… planless agent create (#20190)

* fix(workspaces): recover a real terminal when activation throws for a planless agent create

#20175's activation-failure recovery re-seeds the workspace surface, but passed
callerProvidesSurface: true whenever an agent was selected. Activation is the
caller that would have provided that surface, and it just threw. With the flag
set and no startup plan, worktree-initial-terminal-seeding takes its zero-tab
pre-seed branch: it queues setup/issue commands and returns null instead of
creating a terminal. The recovery then recovers nothing and the freshly created
workspace opens with no tabs.

Dropping the flag from the recovery call is the whole fix. The create-time call
keeps it: there, the agent pane really is the surface the caller provides.

The enclosing object literal becomes a ternary because oxlint's
unicorn/no-useless-spread rejects a lone conditional spread.

* test(workspaces): reuse activation recovery coverage

* test(workspaces): keep recovery assertion focused

---------

Co-authored-by: Merge Sim <sim@local>
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