Skip to content

Bail cleanly on concurrent push to PR branch#2564

Merged
hiroshinishio merged 2 commits intomainfrom
wes
Apr 20, 2026
Merged

Bail cleanly on concurrent push to PR branch#2564
hiroshinishio merged 2 commits intomainfrom
wes

Conversation

@hiroshinishio
Copy link
Copy Markdown
Collaborator

@hiroshinishio hiroshinishio commented Apr 20, 2026

Summary

Adds concurrent-push detection to GitAuto's agent loop so that when another commit lands on a PR branch while GitAuto is working, GitAuto stops cleanly instead of continuing on stale state.

  • git_commit_and_push returns a new GitCommitResult dataclass; on non-fast-forward push it sets concurrent_push_detected=True
  • Tool wrappers (write_and_commit_file, apply_diff_to_file, search_and_replace, move_file, delete_file) surface the flag via FileWriteResult/FileMoveResult/FileDeleteResult
  • chat_with_agent reads the flag on any tool result, sets it on AgentResult, and short-circuits remaining tool calls in the current turn
  • check_suite_handler, review_run_handler, new_pr_handler break their agent loop on the flag, skip the forced verify_task_is_complete and the final empty commit (racer's push already triggers CI), then run normal cleanup (usage record, slack, PR comment)
  • New helper get_branch_head_author fetches the racer's author for log lines

Final PR comment reflects the race: "Another commit landed on `` while I was working. Their push triggers CI on its own, so I'm stopping here — your push stands."

Social Media Post (GitAuto)

Agent now detects a concurrent push to a PR branch and stops cleanly

  • git_commit_and_push returns a typed result with concurrent_push_detected on non-fast-forward push
  • Tool wrappers propagate the flag up through AgentResult; agent loop breaks the turn instead of retrying on stale state
  • Handler skips the final empty commit when the racer's push already triggers CI, posting a truthful status on the PR

Social Media Post (Wes)

When two webhooks hit the same PR branch close together, the second agent would happily keep editing on state the first push had already moved past. Added a typed race signal: the commit function flags it, every file-edit tool propagates it, the agent loop breaks the turn, the handler runs its normal finalize. Fewer confused PR statuses, no wasted tokens racing a push that already landed.

On non-fast-forward push (racer advanced the branch), git_commit_and_push now returns GitCommitResult(concurrent_push_detected=True) instead of SystemExit. Tool wrappers propagate via FileWriteResult/FileMoveResult/FileDeleteResult, chat_with_agent surfaces via AgentResult and short-circuits remaining tool calls, handlers break the agent loop and skip the final empty commit so the racer's push owns CI. Handlers still run normal cleanup (update_usage, slack, accurate PR comment).
Follow-up to the previous commit: three test files still had stale
assertions that didn't match the new dataclass return or the actual
slack/workflows-block messages. Partial-assertion hook also required
stricter exact-match checks in test_search_and_replace.py.
@hiroshinishio hiroshinishio self-assigned this Apr 20, 2026
@hiroshinishio hiroshinishio merged commit 6579510 into main Apr 20, 2026
1 check passed
@hiroshinishio hiroshinishio deleted the wes branch April 20, 2026 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant