Skip to content

Improve Merge with AI button to match chat agent success rate #875

@linear

Description

@linear

Root Cause

When you click "Merge with AI", the system:

  1. Runs the merge command directly via run.py --merge
  2. Uses a simplified conflict resolution path that tries to auto-merge and falls back to standard git merge
  3. The AI resolver is invoked with limited context and may not have all the information it needs
  4. If conflicts are detected, it shows an error but doesn't give the AI a chance to iteratively resolve them When you send a message to the AI saying "fix conflicts and merge":
  5. The AI agent gets full context about the conflicts
  6. Can use multiple tools and strategies iteratively
  7. Has access to the file system to view conflict markers, understand the changes, and make intelligent decisions
  8. Can retry if initial resolution attempts fail
  9. Has a conversation history to understand what has already been tried

Key Differences

Looking at the code in workspace.py lines 245-303:

if smart_result.get("success"):
    stats = smart_result.get("stats", {})
    had_conflicts = stats.get("conflicts_resolved", 0) > 0
    ai_assisted = stats.get("ai_assisted", 0) > 0
    if had_conflicts or ai_assisted:
        # AI actually resolved conflicts
        return True
    else:
        # No conflicts needed AI - do standard git merge
        success_result = manager.merge_worktree(...)

The "Merge with AI" button:

  • Only invokes AI when conflicts are detected in advance
  • Uses a one-shot resolution attempt
  • Falls back to standard git merge if the first attempt doesn't perfectly resolve everything
  • Limited to the merge orchestrator's predefined conflict resolution strategies The AI agent in chat:
  • Gets invoked after a problem occurs
  • Can read the actual git conflict markers in files
  • Has interactive problem-solving capabilities
  • Can use multiple approaches and tools
  • Gets feedback from the user

Why This Happens

The "Merge with AI" button is designed for pre-emptive conflict resolution - it tries to predict and resolve conflicts before merging. This works well for straightforward cases but fails when:

  1. Unexpected conflicts arise that weren't detected in the preview
  2. Complex merge logic is needed that doesn't fit predefined patterns
  3. Iterative resolution is required (fix one conflict, reveal another)

Context-dependent decisions are needed (understanding the broader codebase intent) When you ask the AI directly, it gets full visibility into the actual state of the merge and can use its general problem-solving capabilities rather than being limited to the merge orchestrator's specific patterns.

Suggested Fix

The 'Merge with AI' button fails in cases where explicitly asking the AI to 'fix conflicts and merge' succeeds. The button uses a one-shot merge orchestrator approach with limited context, while the chat agent has full interactive capabilities. Task: 1) Investigate and document the specific scenarios where button merge fails but chat merge succeeds 2) Enhance the merge orchestrator to provide more context to AI resolver 3) Add iterative resolution capability to the merge process 4) Consider giving the merge orchestrator access to the same tools and context as the chat agent 5) Add fallback mechanism to invoke full AI agent when orchestrator fails

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions