Sign in or sign up before continuing. Don't have an account yet? Register now to get started.
Register now
Conflict Resolver Foundational Agent
## Overview Implement a foundational chat agent that **autonomously resolves merge request conflicts** by editing files, committing, and pushing changes with user validation. ## Problem Statement Resolving merge conflicts is time-consuming and error-prone: - Developers must manually edit files with conflict markers - Easy to make mistakes when combining changes - Requires understanding both branches' intentions - Manual git operations (add, commit, push) add friction - Slows down development velocity ## Proposed Solution Create a **Conflict Resolver** foundational agent that: - **Analyzes** merge request conflicts automatically - **Determines** the correct resolution strategy - **Validates** the approach with the user if uncertain - **Executes** the resolution by editing files - **Commits** the resolved changes with appropriate message - **Pushes** to the source branch - Reports success and provides commit details The agent works **autonomously with human oversight**: it performs the actual work but asks for approval or clarification when needed. ## User Interaction Flow 1. User clicks **"Resolve with AI"** on MR conflict page 2. **Chat panel opens** with Conflict Resolver agent selected 3. Agent analyzes conflicts and determines resolution strategy 4. Agent presents plan: "I can resolve these 3 conflicts by combining both authentication methods. Approve?" 5. User approves (or asks questions/requests changes) 6. **Agent executes**: edits files, commits, pushes 7. Agent reports: "✅ Resolved! Committed as abc123 and pushed to feature/oauth" 8. MR is now mergeable ## Technical Architecture ### MCP Tool in Monolith **Tool Implementation:** - **Type:** MCP Tool (CustomService in monolith) - **Location:** `app/services/mcp/tools/get_merge_request_conflicts_service.rb` - **Registry:** Auto-discovered via `built_in_tool_definitions.rb` (ID 88) - **Python:** Automatically wrapped by `McpTool` - no Python code needed **Reuses Existing Infrastructure:** - Leverages `MergeRequests::Conflicts::ListService` (same service as web UI) - Same logic as `ConflictsController` - no duplication - Battle-tested code that powers conflict resolution UI **Why MCP Tool (not REST API):** - ✅ Reuses existing Ruby logic (controller + services) - ✅ Simpler implementation (~1 day vs ~1 week) - ✅ No logic duplication - ✅ Internal-only tool (appropriate for experimental feature) - ✅ Can add public REST API later if external users need it ### Key Components **1. MCP Tool - `get_merge_request_conflicts` (ID 88)** - **Implementation:** CustomService in monolith - **Calls:** `MergeRequests::Conflicts::ListService.new(merge_request).to_json` - **Returns:** Structured conflict data with markers - **Python Access:** Auto-wrapped via `McpTool` class **2. Foundational Agent - `conflict_resolver_agent`** - **Reference:** `conflict_resolver_agent` - **Version:** experimental - **Type:** Foundational chat agent **Capabilities:** - Autonomous file editing via `edit_file` tool (ID 10) - Git commit creation via `run_git_command` tool (ID 3) - Branch push operations - User approval workflow **Agent Privileges:** - READ_ONLY_GITLAB (2) - Read MR data - READ_WRITE_GITLAB (3) - Create notes - READ_WRITE_FILES (1) - Edit files - USE_GIT (5) - Commit and push - RUN_MCP_TOOLS (6) - Use all tools **3. UI Integration** **"Resolve with AI" button** opens chat where agent: - Analyzes conflicts using `get_merge_request_conflicts` tool - Presents resolution plan - Asks for approval - Executes autonomously - Reports results ## Agent Behavior Examples ### High Confidence (✅) ``` Agent: I can safely combine these changes. Both branches added non-conflicting methods to the authentication class. Approve to resolve? User: Yes Agent: Executing... ✅ Edited app/models/user.rb ✅ Created commit: abc1234 ✅ Pushed to feature/oauth Done! View commit: https://gitlab.com/.../commit/abc1234 ``` ### Medium Confidence (⚠️) ``` Agent: I found 2 possible approaches: Option A: Combine both authentication methods in sequence Option B: Use strategy pattern with separate classes Which approach fits your architecture better? User: Option A Agent: Executing Option A... ``` ### Low Confidence (❌) ``` Agent: This conflict involves complex business logic changes. I recommend manual review because: - Payment processing logic modified - Security implications I can help by: - Explaining what each branch changed - Suggesting partial resolutions - Creating a draft commit for review ``` ## Safety Mechanisms 1. ✅ **User approval required** before executing resolutions 2. ✅ **Show plan** before any changes 3. ✅ **No force push** - respects branch protection 4. ✅ **Audit trail** - all agent actions logged 5. ✅ **Graceful errors** - handles push failures, rollback guidance 6. ✅ **Risk assessment** - flags security/logic changes ## Implementation Details ### Monolith Components 1. **CustomService:** `get_merge_request_conflicts_service.rb` - Wraps existing `ListService` - No logic duplication - ~50 lines of code 2. **Tool Registration:** `built_in_tool_definitions.rb` entry (ID 88) 3. **Agent Definition:** `foundational_chat_agents_definitions.rb` entry (ID 5) 4. **UI Button:** `resolve_with_ai_button.vue` component ### AI Gateway Components - **None!** MCP tools are auto-wrapped via `McpTool` class ## Benefits - **10x faster conflict resolution** - Automated execution vs manual editing - **Fewer errors** - Agent understands both branches' intent - **Lower barrier** - New developers can resolve complex conflicts - **Consistent quality** - Same resolution logic applied uniformly - **Educational** - Users learn by seeing agent's approach - **Scalable** - Handles simple to complex conflicts ## Implementation Timeline **Total: 2-3 weeks** - **Week 1 (Days 1-2):** MCP Tool implementation (CustomService) - **Week 1 (Days 3-4):** Agent creation and configuration - **Week 1 (Day 5):** UI integration (button) - **Week 2 (Days 1-4):** Testing and refinement - **Week 2 (Day 5):** Documentation - **Week 3:** Gradual rollout and monitoring ## Success Metrics - **Autonomous resolution success rate:** >70% of attempts succeed - **Time savings:** 80% reduction vs manual resolution - **User confidence:** >75% trust agent resolutions - **Accuracy:** <5% of resolutions need correction - **Adoption:** 30-40% of conflict pages use AI resolution - **Error rate:** <5% tool failures ## Technical Challenges & Solutions 1. **File editing in working directory** - Solution: Use `edit_file` tool with conflict marker removal 2. **Git operations** - Solution: Use `run_git_command` tool for commit/push 3. **Conflict marker removal** - Solution: Agent generates clean resolved content 4. **Error handling** - Solution: Graceful failure with rollback guidance 5. **Branch protection** - Solution: Respect rules, provide clear error messages ## Related Documentation - [Foundational Chat Agents](https://docs.gitlab.com/development/ai_features/foundational_chat_agents/) - [Agent Interaction Patterns](https://docs.gitlab.com/development/duo_agent_platform/agent_interaction_patterns/) - [MCP Tools Architecture](https://docs.gitlab.com/development/duo_agent_platform/mcp_tools/) - [Conflict Resolution Service](https://docs.gitlab.com/development/merge_request_concepts.html#conflicts)
epic