Skip to content

Use Copilot to resolve merge conflicts instead of rebuilding milestones #5

@markgar

Description

@markgar

Problem

When multiple agents (builders, tester, issue fixer) push to main while feature branches are active, merge_milestone_to_main() fails on merge conflicts that are almost always trivially resolvable — both sides added different code to the same file region (e.g., new DI registrations in Program.cs, new test methods in the same test class).

The current recovery is: abort merge → try rebase once → retry same merge 5 times → give up → unclaim story → re-plan from scratch → rebuild entire milestone. This wastes multiple Copilot premium requests per failure.

Observed in the stretto test run (20260226-143251):

  • Builder-2 failed on GlobalExceptionHandlerMiddleware.cs + AuthService.cs (issue fixer modified on main)
  • Builder-1 failed twice — first on Program.cs (issue fixer), then on AuthControllerTests.cs (tester pushed new tests to main)

Proposed Solution

After git merge --no-ff fails with conflicts, instead of aborting immediately, invoke Copilot CLI to resolve the conflict markers in-place:

  1. Leave the conflicted working tree as-is (conflict markers in files)
  2. Identify conflicted files via git diff --name-only --diff-filter=U
  3. Invoke a short Copilot session with a prompt like: "These files have git merge conflict markers. Resolve each by keeping BOTH sides — both branches are adding code. Remove the markers, git add each file."
  4. If Copilot succeeds and all conflicts are resolved, complete the merge commit
  5. If Copilot fails or conflicts remain, fall back to the existing abort-and-retry behavior

Why This Works

  • The conflicts are overwhelmingly additive — both branches added different things to the same region
  • LLMs handle "combine these two additions" trivially — much easier than writing the code originally
  • The conflict markers provide perfect context about both sides' intent
  • Cost: 1 premium request per resolution vs. N requests to rebuild an entire milestone from scratch

Implementation Location

merge_milestone_to_main() in src/buildteam/git_helpers.py (lines ~215-245) — after the merge conflict is detected, before git merge --abort.

Considerations

  • Should attempt resolution only on the first conflict (before the rebase attempt), or after rebase also fails
  • Need to verify no conflict markers remain after Copilot runs (grep -r "<<<<<<" .)
  • Should log the resolution as a distinct step for diagnostics
  • The Copilot session needs access to run_copilot_session or equivalent from utils.py

Migrated from markgar/multi-agent-dev#7

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions