fix(tmux): run tmux CLI from stable cwd and verify pane starts in workspace#2984
Open
harshitsinghbhandari wants to merge 1 commit into
Open
fix(tmux): run tmux CLI from stable cwd and verify pane starts in workspace#2984harshitsinghbhandari wants to merge 1 commit into
harshitsinghbhandari wants to merge 1 commit into
Conversation
…kspace The first tmux CLI call after daemon boot auto-starts the persistent tmux server, which inherits and keeps the daemon's own cwd. After a Squirrel/ShipIt auto-update that cwd can be a deleted staging dir; tmux then silently falls back to the server cwd whenever new-session -c cannot resolve, stranding worker panes in a deleted directory and killing agents with a context-free Bun ENOENT (issue #2775, root-caused by inode matching). - execRunner.Run now sets cmd.Dir to os.TempDir() so the tmux server is never pinned to a path an app update can delete. - Create verifies the pane's #{pane_current_path} matches cfg.WorkspacePath (symlink-resolved, so macOS /var vs /private/var compares equal) and fails with an error naming both paths instead of leaving the silent fallback. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes the tmux poisoned-cwd bug that strands worker panes in deleted ShipIt directories (root-caused live by inode matching; related: #2775).
Root cause.
execRunner.Runcalledexec.CommandContextwithout settingcmd.Dir, so every tmux CLI invocation inherited the daemon's own cwd. The first tmux call after boot auto-starts the persistent tmux server, permanently pinning the server's cwd to whatever the daemon had. After a Squirrel/ShipIt auto-update that can be a staging dir that gets deleted (observed:/var/folders/.../ShipIt.zThlb2VO/...app/Contents/Resources; even the healthy case is the app bundle Resources dir, which ShipIt swaps every update). tmux has a silent fallback: whennew-session -c <dir>cannot be resolved at spawn time, the pane starts in the server's cwd instead of erroring. A session hit that fallback and its agent died with a context-freeENOENT: Bun could not find a fileplus shell-init getcwd errors.Reproduced on a scratch tmux socket:
tmux new-session -d -c <deleted-dir>exits 0 and the pane silently starts elsewhere;display-message -p '#{pane_current_path}'exposes the mismatch.Changes
execRunner.Runnow setscmd.Dir = os.TempDir(), so the auto-started tmux server is never pinned to a path an app update can delete. (tmux.Newis constructed config-free inruntimeselect, so the temp dir is the clean stable choice over plumbing the data dir through.)Createnow verifies the pane's#{pane_current_path}matchescfg.WorkspacePathafter the liveness check, resolving symlinks so macOS/varvs/private/varcompares equal. On mismatch it destroys the session and fails with an error naming both paths and pointing at the server-cwd fallback, replacing today's silent fallback plus downstream raw ENOENT.displayPaneCwdArgsbuilder incommands.go, following the existing arg-builder pattern.Tests
TestCreateFailsLoudlyWhenPaneCwdMismatches(fake runner reports a pane cwd that is not the workspace; asserts loud error naming both paths + kill-session cleanup),TestSamePathResolvesSymlinks,TestExecRunnerRunsFromStableDir.TestCommandBuildersand the existingCreatetests for the new sixth call.gofmt(clean),go vet,go build ./...,go test ./internal/adapters/runtime/tmux/(42 pass, including the real-tmux integration tests, which now exercise the verification through macOS/varaliasing end to end).go test ./...: 4 pre-existinginternal/clispawn-test failures reproduce identically on cleanupstream/mainon this machine (live AO daemon state interferes); unrelated to this change.Risks / follow-ups
Create.IsAliveandSendMessagedeliberately do not probe pane cwd in this PR (kept minimal per scope); a follow-up could add a cwd probe to the reaper path to catch a server whose panes were poisoned before this fix shipped.Createnow fails where it previously "succeeded" with a doomed pane. That is the intended behavior change: a loud, actionable error instead of a stranded agent.🤖 Generated with Claude Code