Repository navigation
fix(worktree): stop terminal removal fence error flashing on delete - #10240
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds shared constants and a predicate for identifying worktree-removal fence errors. Removal-gate errors now use those constants. PTY connection skips fresh spawns for deleting worktrees, suppresses expected fence errors, and continues reporting other spawn errors. Tests cover predicate matching, gate-generated errors, deletion-state behavior, and PTY error handling. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 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: Pro Plus
Run ID: 08c19243-428d-4cb4-bb62-3ab5a3e6a515
📒 Files selected for processing (6)
src/main/ipc/watcher-removal-gate.test.tssrc/main/ipc/watcher-removal-gate.tssrc/renderer/src/components/terminal-pane/pty-connection.test.tssrc/renderer/src/components/terminal-pane/pty-connection.tssrc/shared/worktree-removal-fence-error.test.tssrc/shared/worktree-removal-fence-error.ts
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.
…tablyai#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 stablyai#10240.
Problem
Deleting a worktree sometimes flashes a scary error on a terminal tab that lived in it:
It clears once the worktree fully deletes (~1s later), but it's bad UI.
Root cause
When a worktree is deleted, main takes the removal fence (
acquireWatcherRemovalGate) and kills the worktree's PTYs for the filesystem teardown, then runsgit worktree remove(~1s). During that window the doomed pane races a fresh respawn, which main correctly fences withTerminalRemovalInProgressError(a shell must not spawn into a directory being deleted). The bug is purely renderer-side:reportErrorsurfaced that internal fence verbatim as a pane error banner (TerminalPane→setTerminalError), which only disappeared when the worktree unmounted.Fix (renderer-side, no IPC changes)
startFreshSpawnskips when the pane's own worktree hasdeleteStateByWorktreeId[worktreeId].isDeleting(a signal the renderer already sets at removal start). No shell should spawn into a directory being removed, and the pane is about to unmount.reportError(the single choke point for every pane-error path: connect/reattach/attach/SSH) drops the removal fence instead of surfacing it. This also covers the parent-removal-fences-child case that the own-worktree skip can't see.src/shared/worktree-removal-fence-error.ts); main's error classes throw them and the renderer'sisWorktreeRemovalFenceErrorpredicate matches them (robust to Electron's IPC error prefix), so the thrown text and the predicate can't drift.Verification
Unit (deterministic): new tests prove — the real gate throws a message the predicate recognizes (main↔renderer contract),
reportErrorswallows the fence (raw + IPC-wrapped) while non-fence errors still surface, andstartFreshSpawnskips duringisDeletingwhile normal spawns are unaffected. All affected suites green.Live app (Electron via CDP): created a worktree with a live PTY and deleted it under a DOM+console watcher for the fence text — clean, then 5 rapid create→activate→delete stress cycles.
isDeletingwas observed active during every deletion (the guard is genuinely in the removal window), all deletions completed, and zero fence hits (DOM, console, or error events) across all runs.tsc(node + web) andoxlintclean on all changed files.Notes / scope
reportErrorsink andisDeletingis set identically for remote removals.