Skip to content

fix(workspace): recreate missing registered worktrees - #2776

Closed
harshitsinghbhandari wants to merge 1 commit into
mainfrom
ao/agent-orchestrator-65/issue-2775
Closed

fix(workspace): recreate missing registered worktrees#2776
harshitsinghbhandari wants to merge 1 commit into
mainfrom
ao/agent-orchestrator-65/issue-2775

Conversation

@harshitsinghbhandari

Copy link
Copy Markdown
Collaborator

Fixes #2775

Summary

  • detect Git worktree registrations whose directories no longer exist
  • prune the stale registration and materialize a fresh worktree before runtime launch
  • cover both valid reuse and stale-registration recovery

Tests

  • cd backend && go test ./internal/adapters/workspace/gitworktree
  • cd backend && go build ./... && go test -race ./...

@harshitsinghbhandari

Copy link
Copy Markdown
Collaborator Author

Closing in favour of a single consolidated PR.

The fix here is still correct and still needed. main has no equivalent, and the failure is real: observed on 2026-07-25, session agent-orchestrator-78 kept its branches (ao/agent-orchestrator-78/root, ao/agent-orchestrator-78/gh-pages-landing) and its session row, but the worktree directory was gone, so cd '<workspace>' || exit exited instantly and restore failed with no useful signal.

It is being folded, approach intact, into one PR alongside the tmux server cwd pin and a retried pane-cwd verification, since all of them are the same #2775 failure surface. Will cross-link that PR here.

@harshitsinghbhandari

Copy link
Copy Markdown
Collaborator Author

Consolidated PR is up: #3098

harshitsinghbhandari added a commit to harshitsinghbhandari/agent-orchestrator that referenced this pull request Jul 26, 2026
Consolidates the tmux poisoned-cwd spawn failure fix (issue Untrivial-ai#2775 family).

- execRunner.Run now pins cmd.Dir to os.TempDir(), so the tmux CLI's first
  invocation (which auto-starts the persistent tmux server) never inherits
  a daemon cwd that a later Squirrel/ShipIt auto-update can delete.
- verifyPaneWorkingDirectory now retries up to 5 times, 50ms apart, honoring
  ctx cancellation via select. Measured live: #{pane_current_path} sampled
  immediately after new-session was stale, and the same probe sampled 50ms
  later was already correct, because buildLaunchCommand's
  cd '<workspace>' || exit; guard only corrects the pane once its shell
  actually runs. The prior single-shot check lost that race every time and
  turned a spawn that was going to succeed into a hard failure. Reuses the
  existing sameDirectory helper rather than adding a parallel one.
- gitworktree: a registered worktree whose directory no longer exists on
  disk (registration and DB row survive, directory does not) is now
  detected via worktreeDirMissing, its stale git registration pruned, and
  a fresh worktree materialized before the runtime launches, in both the
  Create-reuse and Restore paths.
- session service toAPIError maps the new ports.ErrRuntimeWorkspaceCwdMismatch
  sentinel to a typed WORKSPACE_CWD_MISMATCH apierr naming both the observed
  and wanted paths, instead of falling through to an opaque 500.

Supersedes Untrivial-ai#2984 and Untrivial-ai#2776 (both authored by this contributor, being closed
in favor of this PR). Credits Untrivial-ai#3027, which independently reached the same
cmd.Dir pin plus a retry loop.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spawn Failed for some reason

1 participant