Skip to content

Use git worktrees for parallel task isolation #28

@chanakyav

Description

@chanakyav

All autopilot tasks currently share a single git working directory. Branch locking prevents two tasks on the same branch, but true parallel execution on different branches would cause git state corruption (git checkout in one task blows away another's working tree).

Use Case

Run multiple autopilot tasks simultaneously on different branches — e.g., implement feature A while fixing CI on feature B.

Proposed Design

Use git worktrees to give each task its own isolated checkout:

~/repo/                              # main checkout (user's terminal)
~/.autopilot-loop/worktrees/abc123/  # worktree for task abc123
~/.autopilot-loop/worktrees/def456/  # worktree for task def456

Changes Needed

  1. On task creation, run git worktree add <path> -b <branch> (or git worktree add <path> <existing-branch>)
  2. Pass cwd=<worktree_path> to subprocess.Popen in run_agent()
  3. On task completion/cleanup, run git worktree remove <path>
  4. Update prompts — agent no longer needs to git checkout -b, it's already on the right branch
  5. Store worktree path in the task DB record

Benefits

  • True parallel task execution with zero git conflicts
  • Each agent sees a clean, isolated working tree
  • Prerequisite for task chaining (#TBD) and research mode (#TBD)

Risks

  • Worktree paths need cleanup on crash/failure
  • Some tools may not work correctly in worktrees (rare)
  • Disk usage increases (each worktree is a full checkout)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions