Repository navigation
fix(workspaces): complete a worktree create when a post-create step throws - #20175
Conversation
…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.
There was a problem hiding this comment.
ℹ️ No critical issues — one minor suggestion inline.
Reviewed changes
- Per-step post-create guards —
executeWorktreeCreationnow contains each throw-prone step aftercreateWorktree(activateAndRevealWorktree, initial terminal seeding, after-wake seeding, structured-session launch) so control always reachescompleteWorktreeCreation. - 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
executeWorktreeCreationwith throws injected in the tail plus aprepareRequestForCreaterejection; 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.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
📝 WalkthroughWalkthroughThe 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 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)
✅ Passed checks (3 passed)
Full details: Description checkExplanation 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.
✨ 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.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: f363a803-0e7c-4fc7-9b43-8a6400b55cbb
📒 Files selected for processing (3)
src/renderer/src/lib/worktree-creation-flow-execute.tssrc/renderer/src/lib/worktree-creation-flow-stranded-surface.test.tssrc/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.
Electron validation (hidden CDP)Ran the Electron skill end-to-end against this PR worktree ( Launch / identity
Scenario
Visible evidence
Backing state
Console
Remaining gaps
Local copies: |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Terminal recovery after a partial activation failure — the
activateAndRevealWorktreecatch inexecuteWorktreeCreationnow runs a guarded recovery tail: it re-seeds viaensureWorktreeHasInitialTerminalonly when activation left no tabs, and otherwise keepsprimaryTabIdnull 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 —
startWorktreeCreationnow 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.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
ℹ️ No critical issues — one stale comment inline.
Reviewed changes
- Recover a verified launch tab after a partial activation failure — the
activateAndRevealWorktreecatch now adoptsresult.startupTerminal?.tabIdor an existing tab stamped with the launch agent asprimaryTabId, instead of leaving itnullwhenever tabs already existed. This keepsensureAgentStartupInTerminalfrom falling back totabsByWorktree[0](a default tab) when delivering the agent draft/follow-up. - Regression test updated — the default-tab case now seeds a stamped
agent-taband 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.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| // 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. |
There was a problem hiding this comment.
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.
| // 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. |
There was a problem hiding this comment.
ℹ️ No new issues — one test-clarity nit inline.
Reviewed changes
- Test-only follow-ups —
9ec692/a82d3earename the stamped-agent-tab case and adddraftPrompt/followupPromptto itsstartupPlan. No production code changed; the primary-id recovery fromb083941is untouched, and the assertion (primaryTabId: 'agent-tab') still fails without that lookup.
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 () => { |
There was a problem hiding this comment.
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.
| 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 () => { |
Review status: PASSFinal PR head: 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:
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. |
There was a problem hiding this comment.
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 winPreserve failure state when structured session launch fails.
launchStructuredWorktreeSessionreturnsaccepted: truefor a rejected launch, an escaped launch error, or no settlement. The caller then removes the pending creation and skips fallback terminal seeding becausestructuredLaunchAcceptedremains true. The worktree can complete without a structured session or usable terminal. Returnaccepted: falsefor these failure paths, and keepcancelledreserved 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
📒 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.
|
CI follow-up for final head |
… 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>






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'stry/catchends the momentcreateWorktreeresolves. Everything after it — activation, terminal seeding, the after-wake seed, the structured-session launch — runs unguarded, and all three callers invoke it as a barevoidwith no.catch().completeWorktreeCreationis the only thing that removes the pending creation entry. So a throw in that tail left bothpendingWorktreeCreations[creationId]andactivePendingCreationIdset, which makesshouldShowWorktreeCreationSurfacetrue, which forcesworkspaceChromeActivefalse. 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".activation = false,primaryTabId = null). Control flow always reachescompleteWorktreeCreation.cancelled/visibilityUnknownearly 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)..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 coversprepareRequestForCreate, whose VM-provisioning await hastry/finallywith nocatch.Deliberately not wrapped as one big
try/catch: the structured block'sreturnstatements 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
launchStructuredWorktreeSessionsays "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:
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.tsdrives the realexecuteWorktreeCreationwith a resolved create and a throw injected in the tail.Ablation (measured, both arms):
Other gates:
pnpm tc:web: exit 0pnpm run check:code-quality:changed: 0 findings across code quality, type-aware and React DoctorPlatform: macOS only. Renderer-only change with no platform-conditional code, so Linux/Windows/SSH were not separately exercised.