fix: clean up orphaned tmux windows on worktree list poll - #60
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Claude finished @centdix's task in 1m 9s —— View job Code Review: Clean up orphaned tmux windows
Clean, well-scoped PR. The approach of piggybacking on the existing poll cadence rather than adding a new timer is the right call. A few observations: Looks good
Minor concerns1. Synchronous blocking on every poll (
If this ever becomes a concern, switching to async 2. Hardcoded activeBranches.add("main");This protects 3. Potential code reuse with Both VerdictLGTM — this is a solid, minimal fix for a real problem. No blocking issues. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Claude finished @centdix's task in 1m 11s —— View job Code Review: Clean up orphaned tmux windows on worktree list poll
Clean, well-scoped PR. The approach of piggybacking on the existing poll cadence rather than adding a new timer is the right call. A few observations: Looks good
Minor concerns1. cleanupStaleWindows(activeBranches, `${PROJECT_DIR}__worktrees/`);The call is intentionally fire-and-forget, which is fine for cleanup. However, since it's an async function returning a Promise that's not awaited, any rejection would become an unhandled promise rejection (the internal try/catch should prevent this, but if something unexpected throws before the try block runs — e.g., argument validation — it could surface). Currently the function body is entirely wrapped in try/catch, so this is safe in practice. 2. Hardcoded activeBranches.add("main");This protects 3. Race between pane path check and worktree removal There's a narrow window where a worktree is being actively removed while 4. The VerdictLGTM — this is a solid, minimal fix for a real problem. The project-scoping via pane path is particularly well done — it avoids the cross-project footgun that a naive |
Summary
Orphaned tmux windows (e.g.
wm-favicon-ideas,wm-ai-logic-share) accumulate when worktrees are removed outside ofworkmux rm(manual git commands, crashes, Ctrl-C). This adds automatic cleanup that runs on every dashboard poll, killing anywm-*tmux window that has no matching active worktree.Changes
cleanupStaleWindows()inworkmux.ts— compares allwm-*tmux windows against a set of active branch names and kills orphansapiGetWorktrees()inserver.tsafter fetching worktree and pane data, so it piggybacks on the existing polling cadence with no new timersTest plan
workmux add, then remove it withgit worktree remove(bypassing workmux) — verify the tmux window gets cleaned up on next dashboard pollwm-cleanup-tmux-windows,wm-startup-envs, etc.) are never killed[cleanup] killing stale tmux window "wm-..."for each orphanGenerated with Claude Code