You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WorktreeProvider.findExisting() (packages/isolation/src/providers/worktree.ts) checks the filesystem for an existing worktree at the computed path. Since two local clones of the same remote resolve to the same worktree base directory (~/.archon/workspaces/owner/repo/worktrees/), a worktree created from clone A is visible on disk when clone B checks. The DB-level guard added in #1186 prevents reuse via findActiveByWorkflow, but the git-level adoption in findExisting() runs independently during provider.create() and has no equivalent check.
2. Parallel workflows with the same identifier share a worktree without coordination
Two concurrent workflows with the same branch name (e.g., both using --branch fix/issue-123) compute identical worktree paths. The second workflow adopts the first's worktree via findExisting(). Both AI agents then operate in the same filesystem directory concurrently with no locking or coordination mechanism. This can cause:
File write conflicts
Partial/interleaved commits
Unpredictable workflow outcomes
Steps to Reproduce
Cross-checkout adoption:
Clone the same repo to ~/project-a and ~/project-b
From ~/project-a: archon workflow run my-workflow --branch fix/shared "task"
From ~/project-b: archon workflow run my-workflow --branch fix/shared "task"
From the same directory, run two workflows simultaneously with the same --branch
Both resolve to the same worktree path; the second adopts the first's worktree
Both AI agents write to the same directory concurrently
Suggested Fix
For cross-checkout adoption:findExisting() should incorporate the source repo root into its path computation or existence check, similar to how #1186 guards the DB-level reuse path. One approach: include a hash of the source repo root in the worktree directory name.
For parallel collision: Consider advisory locking (e.g., a lockfile in the worktree directory) or refusing to adopt an environment that is currently in use by another active workflow run.
Summary
Two related gaps exist in the worktree isolation layer that can cause workflows to operate in the wrong or shared directory:
1. Git-level adoption bypasses cross-checkout guard
WorktreeProvider.findExisting()(packages/isolation/src/providers/worktree.ts) checks the filesystem for an existing worktree at the computed path. Since two local clones of the same remote resolve to the same worktree base directory (~/.archon/workspaces/owner/repo/worktrees/), a worktree created from clone A is visible on disk when clone B checks. The DB-level guard added in #1186 prevents reuse viafindActiveByWorkflow, but the git-level adoption infindExisting()runs independently duringprovider.create()and has no equivalent check.2. Parallel workflows with the same identifier share a worktree without coordination
Two concurrent workflows with the same branch name (e.g., both using
--branch fix/issue-123) compute identical worktree paths. The second workflow adopts the first's worktree viafindExisting(). Both AI agents then operate in the same filesystem directory concurrently with no locking or coordination mechanism. This can cause:Steps to Reproduce
Cross-checkout adoption:
~/project-aand~/project-b~/project-a:archon workflow run my-workflow --branch fix/shared "task"~/project-b:archon workflow run my-workflow --branch fix/shared "task"provider.create()→findExisting()detects the worktree on disk and adopts it before the DB lookup path is reachedParallel collision:
--branchSuggested Fix
For cross-checkout adoption:
findExisting()should incorporate the source repo root into its path computation or existence check, similar to how #1186 guards the DB-level reuse path. One approach: include a hash of the source repo root in the worktree directory name.For parallel collision: Consider advisory locking (e.g., a lockfile in the worktree directory) or refusing to adopt an environment that is currently in use by another active workflow run.
Related
🤖 Generated with Claude Code