-
Notifications
You must be signed in to change notification settings - Fork 0
Fix merge race condition — add retry loop on push failure in mergeWorktree #168
Copy link
Copy link
Closed
Description
Problem
mergeWorktree() in src/worktree.ts has a TOCTOU race condition. Two agents finish within seconds of each other, both call mergeWorktree() on the same workspace:
- Agent A pulls main, merges its branch
- Agent B pulls main at the same moment, merges its branch
- Agent A pushes successfully
- Agent B's push fails because main moved forward
- Silent data loss — Agent B's code never reaches main
The function returns success: false but the task was already marked completed by Claude. The work is lost.
What to do
In src/worktree.ts, mergeWorktree() function:
- After push fails, add a retry loop (max 3 attempts):
git reset --hard HEAD~1(undo the merge)git pull --ff-only origin main(get latest)git merge <branch> --no-edit(re-merge)git push origin HEAD(try again)
- If all 3 retries fail, return
success: falsewith a clear error - Log each retry attempt
Acceptance
- Push failure triggers retry with fresh pull
- Max 3 retry attempts before giving up
- No silent data loss — either code reaches main or error is clearly reported
- Build passes:
npm run build
Reactions are currently unavailable