---
name: "Stale merge job lock prevents new merges after agent dies"
---

# Bug 498: Stale merge job lock prevents new merges after agent dies

## Description

When the mergemaster agent is killed or stops while a merge is in progress, the in-memory `merge_jobs` map retains a `Running` status entry for that story. Subsequent attempts to call `merge_agent_work` get "Merge already in progress" and fail. The lock is never cleaned up.

This causes the mergemaster to loop: spawn, try merge, get "already in progress", waste turns, exit, respawn. The merge never completes.

The fix: clear the merge job entry when the mergemaster agent exits (whether cleanly or via kill/stop).

## How to Reproduce

1. Start mergemaster on a story in merge
2. Kill/stop the mergemaster agent before merge completes
3. Try to merge_agent_work again for the same story
4. Get "Merge already in progress" error

## Actual Result

Stale Running entry in merge_jobs map blocks all future merge attempts until server restart.

## Expected Result

Merge job lock is cleaned up when the agent exits, allowing retry.

## Acceptance Criteria

- [ ] Bug is fixed and verified
