Files
orca/src/shared/worktree-removal-fence-error.ts
T
Brennan Benson 00cda62ca9 fix(worktree): stop terminal removal fence error flashing on delete (#10240)
* fix(worktree): stop terminal removal fence error flashing on delete

Deleting a worktree kills its PTYs for the filesystem teardown, then runs
git worktree remove (~1s). During that window a doomed pane races a fresh
respawn that main correctly fences with TerminalRemovalInProgressError, but
the renderer surfaced that internal fence verbatim as a pane error banner
until the worktree unmounted.

- startFreshSpawn: skip the respawn when the pane's own worktree is being
  deleted (isDeleting) — no shell should spawn into a directory being removed
  and the pane is about to unmount.
- reportError: swallow the removal fence at the single pane-error sink so it
  never reaches the banner, covering the parent-removal-fences-child case the
  own-worktree skip cannot see.
- Share the fence messages between main (thrown) and renderer (recognized) via
  worktree-removal-fence-error.ts so the thrown text and predicate can't drift.

* test(worktree): assert onError callback captured before invoking

Optional invocation let the fence-suppression test false-pass if the
transport onError wiring broke; require the callback so a broken wire
fails loudly. Addresses CodeRabbit review on #10240.
2026-07-23 18:04:15 -07:00

19 lines
910 B
TypeScript

// Shared between main (which throws these at the PTY/watcher install fence while
// a worktree is being removed) and the renderer (which recognizes them so a
// doomed pane never surfaces the fence as a user-facing terminal error).
export const TERMINAL_REMOVAL_IN_PROGRESS_MESSAGE =
'Terminal cannot start while the worktree is being removed'
export const WATCHER_REMOVAL_IN_PROGRESS_MESSAGE =
'File watcher cannot start while the worktree is being removed'
// Why: both fence messages end with this tail. Matching the tail catches the
// terminal and watcher variants even after Electron IPC prefixes the rejected
// error with its own "Error invoking remote method ..." text.
const REMOVAL_IN_PROGRESS_FENCE_TAIL = 'cannot start while the worktree is being removed'
export function isWorktreeRemovalFenceError(message: string): boolean {
return message.includes(REMOVAL_IN_PROGRESS_FENCE_TAIL)
}