Overview
Each parallel task worker gets its own git worktree, eliminating filesystem conflicts during cf work batch run --strategy parallel.
Motivation
The current parallel strategy runs all workers on the same filesystem. This causes:
- Git index lock conflicts when multiple agents commit simultaneously
- Agents overwriting each other's uncommitted changes
- Non-deterministic outcomes in parallel batch runs
Deliverables
codeframe/core/sandbox/worktree.py
Worktree lifecycle management:
class WorktreeContext:
def create(task_id: str, base_path: Path) -> WorktreeContext
def cleanup(self) -> None # removes worktree, merges or discards
@property
def path(self) -> Path
Integration with conductor.py
- When
IsolationLevel.WORKTREE, each parallel worker calls WorktreeContext.create()
- Worker receives
context.workspace_path pointing to its worktree
- On completion, changes are merged back (or blocker raised on conflict)
cleanup() removes the worktree regardless of outcome
Atomic registration
- Prevent race conditions when multiple workers create worktrees simultaneously
- File-lock or DB-based registration in
.codeframe/worktrees.json
Auto-cleanup
- Orphaned worktrees (from crashed workers) cleaned up on next
cf work batch run
cf env doctor reports stale worktrees
Acceptance Criteria
Dependencies
Track
Phase 4.B — Execution Environment Layer
Overview
Each parallel task worker gets its own git worktree, eliminating filesystem conflicts during
cf work batch run --strategy parallel.Motivation
The current parallel strategy runs all workers on the same filesystem. This causes:
Deliverables
codeframe/core/sandbox/worktree.pyWorktree lifecycle management:
Integration with
conductor.pyIsolationLevel.WORKTREE, each parallel worker callsWorktreeContext.create()context.workspace_pathpointing to its worktreecleanup()removes the worktree regardless of outcomeAtomic registration
.codeframe/worktrees.jsonAuto-cleanup
cf work batch runcf env doctorreports stale worktreesAcceptance Criteria
WorktreeContextincore/sandbox/worktree.pyconductor.pyuses worktrees when--isolation worktreeworktree.pathcf env doctorDependencies
Track
Phase 4.B — Execution Environment Layer