Description
The root cause of worktree disappearance, failed git operations, and terminal crashes appears to be git corruption from concurrent access patterns in local-only multi-agent workflows.
Root Cause Analysis
Concurrent Access Patterns
- Multiple agents committing simultaneously - Race conditions in object database
- Rebase while other worktrees active - Ref updates conflict with checked out branches
- Shared git objects - All worktrees share .git/objects leading to write conflicts
- Index operations - Concurrent index updates can corrupt state
- Garbage collection - GC running during active operations causes issues
Related Known Issues
Current Symptoms
- Worktree directories disappear entirely
- Git operations fail in seemingly valid worktrees
- Terminal crashes without warning
- Stale lock files persist
- Corrupted refs or index
Proposed Solutions
Detection
Prevention
Recovery
Technical Details
Files/Areas Affected
.git/objects/ - Shared object database
.git/refs/ - Branch references
.git/index - Worktree-specific but conflicts possible
.git/worktrees/ - Worktree metadata
.git/*.lock - Lock files for various operations
Concurrent Operations to Handle
- Commit + Commit
- Rebase + Commit
- Rebase + Rebase
- GC + Any operation
- Worktree add/remove + Other operations
Testing Needed
- Stress test with multiple concurrent agents
- Simulate race conditions
- Test rebase with active worktrees
- Validate lock file handling
- Test recovery mechanisms
Related Context
Description
The root cause of worktree disappearance, failed git operations, and terminal crashes appears to be git corruption from concurrent access patterns in local-only multi-agent workflows.
Root Cause Analysis
Concurrent Access Patterns
Related Known Issues
git rebase --update-refsdoesn't work with checked out worktrees (https://www.brandonpugh.com/til/git/update-refs-working-directory/)Current Symptoms
Proposed Solutions
Detection
Prevention
Recovery
Technical Details
Files/Areas Affected
.git/objects/- Shared object database.git/refs/- Branch references.git/index- Worktree-specific but conflicts possible.git/worktrees/- Worktree metadata.git/*.lock- Lock files for various operationsConcurrent Operations to Handle
Testing Needed
Related Context