Overview
When an agent completes a task:- The branch is pushed to the remote repository
- The branch is enqueued in the merge queue with a priority
- The merge queue processes branches serially
- On conflict, the branch is automatically rebased and retried
- After exhausting retries, a fix task is created
Merge Strategies
Longshot supports three merge strategies, configured viaMERGE_STRATEGY in .env:
Fast-Forward
.env
- Clean, linear history
- No merge commits cluttering the log
- Ideal for sequential work
- Fails if main has diverged
- Requires frequent rebasing
- Low-concurrency workflows (1-5 agents)
- Projects that value linear history
- When tasks are unlikely to conflict
Rebase (Recommended)
.env
- Linear history like fast-forward
- Automatically resolves divergent branches
- Works well with parallel agents
- Conflicts are detected early
- Rewrites commit history (force push required)
- Slightly slower than fast-forward
- Default choice for most Longshot deployments
- Medium to high concurrency (5-50 agents)
- Projects that want clean history with parallel development
Merge Commit
.env
- Never rewrites history
- Preserves exact branch topology
- Explicit record of when work was integrated
- Most permissive (rarely fails)
- Creates extra merge commits
- History can become cluttered at scale
- High-concurrency workflows (50+ agents)
- When history preservation is critical
- As a fallback when rebase fails
Automatic Fallback
If the configured strategy fails (non-conflict error), Longshot automatically falls back tomerge-commit:
Conflict Detection and Retry
Longshot includes a sophisticated conflict retry system:Retry Logic
When a merge conflict occurs:- Detection: The merge queue detects conflicting files
- Abort: The merge is aborted to restore clean state
- Rebase: The branch is rebased onto the latest main
- Re-queue: The branch is re-queued with high priority (priority 1)
- Retry: The merge is attempted again
Configuration
Configure retry behavior in code (not exposed in.env yet):
Why Retries Work
After rebase, the branch is based on the latest main, which includes:- All branches that merged since the conflict
- Any conflicting changes that were integrated
- The conflicting branch already merged
- The changes are now compatible after rebase
- The files no longer overlap
Retry Example
Priority-Based Queue
The merge queue uses priority ordering:Priority Levels
- Priority 1 (highest) - Conflict retries
- Priority 5 (default) - Normal task completions
- Priority 10 (lowest) - Low-importance merges
enqueuedAt timestamp).
Deduplication
The queue automatically deduplicates:- Branches already merged are skipped
- Branches already in the queue are not added again
Background Processing
The merge queue runs as a background loop:- Check if there are branches in the queue
- Dequeue the highest-priority branch
- Attempt the merge
- Fire callbacks for merge results
- Continue until queue is empty
Callbacks
The orchestrator registers callbacks to handle merge results:Merge Lifecycle
Full lifecycle of a branch merge:1. Task Completion
2. Queue Processing
3. Git Operations
4. Success
5. Conflict → Retry
6. Conflict → Fix Task
After exhausting retries:Merge Statistics
The merge queue tracks statistics:Merge Success Rate
Calculated as:Dashboard Integration
The dashboard displays merge queue activity in real-time:Merge Queue Panel
- Success Rate - Visual progress bar and percentage
- Merged - Count of successfully integrated branches
- Conflicts - Branches with merge conflicts
- Failed - Merges that failed for other reasons
Activity Feed
Merge events appear color-coded:- Green -
>> merged worker/task-001 - Yellow -
!! conflict worker/task-001 - Red -
xx merge fail worker/task-001
Troubleshooting
High Conflict Rate
If you see many conflicts:- Increase retry limit: Set
maxConflictRetries: 3or higher - Switch to merge-commit: Reduces conflicts at the cost of history cleanliness
- Review task boundaries: Ensure tasks don’t overlap in scope
- Stagger task assignment: Reduce parallelism slightly
Merge Queue Stuck
If the queue stops processing:- Check if background loop is running:
mergeQueue.isBackgroundRunning() - Review logs for git errors
- Manually process:
await mergeQueue.processQueue() - Verify git mutex is not deadlocked
Push Failures
If branches merge locally but fail to push:- Verify
GIT_TOKENhas push access - Check for branch protection rules
- Ensure main branch exists on remote
- Review network connectivity
Slow Merge Processing
If merges take longer than expected:- Reduce
intervalMsinstartBackground()(default: 5000ms) - Check if rebases are slow due to large repo size
- Monitor CPU/disk I/O on orchestrator machine
- Consider using a dedicated git worktree
Advanced Configuration
Git Mutex
Prevent concurrent git operations:Custom Priority Logic
Manual Merge Control
Disable background processing for manual control:Best Practices
Strategy Selection
- Default: Use
rebasefor clean history and automatic conflict handling - High concurrency: Use
merge-commitfor >50 parallel agents - Low concurrency: Use
fast-forwardfor simplest linear history
Conflict Management
- Let retries handle most conflicts automatically
- Monitor conflict rate in the dashboard
- Review fix tasks to identify systematic issues
- Adjust task granularity if conflicts are frequent
Queue Tuning
- Keep
intervalMsat 5000ms for balanced responsiveness - Use priority levels sparingly (most tasks should be priority 5)
- Monitor queue length - sustained growth indicates bottleneck
Testing Strategies
Test each merge strategy with your codebase:- Merge success rate
- Conflict frequency
- History cleanliness (
git log --graph) - Overall throughput
Next Steps
Debugging
Debug merge conflicts and failures
Running with Dashboard
Monitor merge queue in real-time