GeezerVison is showing github.com — fix(app): move sessions to new worktrees through one state machine and recover orphan worktrees by Hona · Pull Request #61948 · anomalyco/opencode
Conversation
Hona
commented
Nov 5, 2026
•
edited by opencodejr
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Moving a session from the location menu to New worktree ran as a detached try/finally inside a menu that unmounts on click. This PR turns it into one state machine (details/workspace-move-machine.ts) with a plugin-scoped driver, and adds a recovery dialog for a worktree that was created but did not receive the session.
Bugs
- Orphan worktree.
worktree.create succeeds, then location.syncInfo or session.move fails or hangs → toast, created.directory forgotten, worktree left on disk with no retry or cleanup.
- Session moved mid-run. Session idle at the click → it starts running during
worktree.create (git + the project's start command) → session.move still runs and pulls the checkout away mid-run (reproduced on dev: the move request goes out while the composer shows Stop).
- Stale worktree list wins. Menu open starts list feat: compact and other improvements #1,
worktree.updated starts list Roadmap & Existing Issues #2, Roadmap & Existing Issues #2 answers first, feat: compact and other improvements #1 answers last and overwrites the newer inventory.
- Duplicate moves. Picking an item unmounts the menu and its
store.selected; reopening during the move shows enabled items and starts a second create/move. No request had a timeout.
State
type WorkspaceMoveState =
| (Base & { status: "idle" })
| (Base & { status: "creating"; attempt })
| (Base & { status: "moving"; attempt; destination; created?: CreatedWorktree; dialog?: RecoveryDialog })
| (Base & { status: "recovering"; dialog: number; created; reason: WorkspaceMoveFailure })
| (Base & { status: "removing"; attempt; created; dialog: RecoveryDialog })
| { status: "disposed" }
// Base: mounts, issued (attempt counter), projectID, directories, listing?: { attempt, refresh }
type RecoveryDialog = { status: "open"; attempt; reason } | { status: "dismissed" }
type WorkspaceMoveFailure = { type: "failed"; error } | { type: "timed-out" } | { type: "running" }
stateDiagram-v2
idle --> creating: New worktree
idle --> moving: existing worktree
creating --> moving: worktree.created (idle session)
creating --> recovering: worktree.created (session running)
creating --> idle: create.failed / timed-out (toast)
moving --> idle: move.succeeded
moving --> recovering: failed / blocked / timed-out (created worktree)
moving --> idle: failed / blocked / timed-out (existing worktree, toast)
recovering --> moving: Retry (session idle)
recovering --> removing: Delete worktree
recovering --> idle: Keep worktree / Escape / session arrived / worktree gone
removing --> idle: remove.succeeded
removing --> recovering: remove.failed / timed-out
idle --> disposed: last menu unmounts
Loading
- Every create, move, remove and list carries an attempt; a result for an attempt the state no longer holds is ignored.
run-move re-checks session.status after syncInfo and reports move.blocked instead of sending session.move.
worktree.updated aborts the list in flight and keeps its pending worktree.refresh.
WorkspaceMoveControllers in renderer.tsx (same pattern as McpControllers, fix(app): model the Extensions flyout, MCP toggles and config actions as state machines #61886) keeps the controller alive while anything runs or the dialog shows; the dialog opens on the shared stack (fix(ui): drive the dialog stack through one state machine #61903) with ctx.dialogs.open and closes by its own handle.
- The driver queues events, advances in a
finally, and isolates each effect with Promise.try.
Deleted
store.selected, store.directories, the start-only blocked() check, and the detached createWorktree + session.move saga in workspace-menu.tsx.
Product calls
- Recovery dialog (new UI): "Session not moved" with Keep worktree, Delete worktree and Retry. Copy is in
details/i18n/en.ts only; other locales fall back to English.
- Retry reuses the created worktree, never creates another. It stays disabled while the session runs; focus starts on Retry, or on Keep worktree while the session runs, never on Delete.
- Delete worktree sends
force: true, as the start command can leave untracked files.
- Closing the dialog keeps the worktree, which then shows under Worktree. A retry or delete in flight keeps running after the dialog closes; a late failure shows a toast.
- A move into an existing worktree that finds the session running shows a toast ("The session is running. Try again once it finishes.").
- Timeouts: list 15 s (keeps the shown worktrees), create 5 min (start commands often install dependencies), move 30 s, remove 2 min.
- Toasts go through
ctx.toast, so they close with the plugin.
- Until a list answers, the menu shows the project's sandboxes and worktrees found on disk.
Deviations from the design
- No
project.synced or workspace.removed events: menu.opened carries the project, and a removal elsewhere arrives as worktree.updated → list.
- A list closes the dialog for a missing worktree only if it was issued after the dialog opened; an older list can predate the worktree.
- One
toast effect with kind and reason instead of three; a RecoveryDialog union instead of number | "dismissed" plus a nullable reason.
- The dialog reports dismissal on unmount and keeps its last content through the exit animation, instead of watching
useDialog().closing.
- The controller follows
worktree.updated and the session's directory in its own root, so the dialog still closes on its own after the menu is gone.
Open questions
Worktree.create registers the worktree before running the start command. If that command fails, the client gets an error without a directory, so this machine cannot offer cleanup. That needs a server change.
- Creating a worktree with a long start command still shows no progress. This PR keeps the
dev behavior.
Off the hot path, so no benchmark.
Visual
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72" fill="none" stroke="currentColor">
<style>
.card{animation:pop 4s ease-in-out infinite;transform-origin:150px 36px}
.dot{animation:go 4s ease-in-out infinite}
@keyframes go{0%{transform:translateX(0);opacity:1}30%{transform:translateX(56px);opacity:1}35%,100%{opacity:0;transform:translateX(56px)}}
@keyframes pop{0%,32%{opacity:.25;transform:scale(.96)}40%,92%{opacity:1;transform:scale(1)}100%{opacity:.25;transform:scale(.96)}}
@media (prefers-reduced-motion:reduce){.card,.dot{animation:none}.dot{opacity:0}}
</style>
<rect x="8" y="16" width="64" height="40" rx="4" opacity=".5"/>
<rect x="14" y="22" width="52" height="8" rx="2" fill="currentColor" opacity=".35" stroke="none"/>
<rect x="14" y="36" width="40" height="6" rx="2" fill="currentColor" opacity=".2" stroke="none"/>
<circle class="dot" cx="76" cy="26" r="3" fill="currentColor" stroke="none"/>
<g class="card">
<rect x="92" y="8" width="140" height="56" rx="6" opacity=".8"/>
<rect x="100" y="16" width="70" height="6" rx="2" fill="currentColor" opacity=".6" stroke="none"/>
<rect x="100" y="27" width="110" height="4" rx="2" fill="currentColor" opacity=".25" stroke="none"/>
<rect x="128" y="44" width="30" height="12" rx="3" opacity=".4"/>
<rect x="162" y="44" width="30" height="12" rx="3" opacity=".4"/>
<rect x="196" y="44" width="28" height="12" rx="3" fill="currentColor" opacity=".7" stroke="none"/>
</g>
</svg>
|
Before |
After |
session.move fails after the worktree exists |
 |
 |
Session starts running during worktree.create |
(moved anyway) |
 |
Added by the opencode bot (AI-generated).
Related: #58693
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…and recover its worktree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sound to me. I ran session-summary.spec.ts against both checkouts. On dev, the two new tests fail: a failed session.move after worktree.create leaves the worktree with no recovery, and a session that starts running during create still gets moved. With this PR both pass, and the rest of the file passes too, except the summary-catalogs test that also fails on dev. The details/ unit tests (57) and tsc -b for gui-plugins pass.
The machine is pure, results are tied to attempt numbers so stale results are ignored, and plugin shutdown cancels work in flight and closes the dialog. The directory watcher also covers a session.move that times out but succeeded on the server. I have no blocking concerns.
Public API is unchanged: only the details plugin's internals and new English strings.
Related: #58693


Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|