fix(worker): stateless AbortPlanningMerge after worker restart mid-merge
PlanningMergeOrchestrator._states is in-memory. A worker restart during a conflict pause left the list repo mid-merge with no recovery path: both ContinuePlanningMerge and AbortPlanningMerge threw "no in-progress merge", and re-Approving failed on the IsMidMergeAsync guard. AbortAsync now falls through to a stateless path when no _states entry exists: it looks up the parent's list WorkingDir and, if the repo is mid-merge, runs git merge --abort there directly, then broadcasts PlanningMergeAborted. Parent remains WaitingForReview — the next Approve restarts the unit merge (already-Merged child worktrees are skipped as before). ContinueAsync error message now points to AbortPlanningMerge as the recovery action. StartAsync mid-merge guard also carries an actionable hint. Tests: AbortAsync stateless + mid-merge (restart recovery), AbortAsync stateless + clean repo (clear error). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -245,6 +245,59 @@ public sealed class PlanningMergeOrchestratorTests : IDisposable
|
||||
Assert.False(await git.IsMidMergeAsync(repo.RepoDir, CancellationToken.None));
|
||||
}
|
||||
|
||||
// ─── Stateless abort (post-restart recovery) ───────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Worker restarted while a conflict was paused: _states is empty but the list repo is
|
||||
/// still mid-merge. AbortAsync must abort the dangling merge, broadcast PlanningMergeAborted,
|
||||
/// and leave the parent in WaitingForReview so a fresh Approve can retry.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task AbortAsync_NoState_RepoMidMerge_AbortsAndBroadcasts()
|
||||
{
|
||||
var db = NewDb();
|
||||
var repo = NewRepo();
|
||||
GitRepoFixture.RunGit(repo.RepoDir, "branch", "-m", "main");
|
||||
|
||||
var (parentId, _, subB, _) = await SeedPlanningThreeChildrenMiddleConflictsAsync(db, repo);
|
||||
|
||||
// Drive orch1 into the conflict pause — repo is now mid-merge.
|
||||
var (orch1, _) = BuildOrchestrator(db);
|
||||
await orch1.StartAsync(parentId, "main", CancellationToken.None);
|
||||
|
||||
// Simulate restart: fresh orchestrator has no in-memory state.
|
||||
var (orch2, spy) = BuildOrchestrator(db);
|
||||
|
||||
await orch2.AbortAsync(parentId, CancellationToken.None);
|
||||
|
||||
var git = new GitService();
|
||||
Assert.False(await git.IsMidMergeAsync(repo.RepoDir, CancellationToken.None));
|
||||
|
||||
using var ctx = db.CreateContext();
|
||||
Assert.Equal(TaskStatus.WaitingForReview, ctx.Tasks.Single(t => t.Id == parentId).Status);
|
||||
|
||||
Assert.Contains(spy, c => c.Method == "PlanningMergeAborted" && (string)c.Args[0]! == parentId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// No in-memory state and repo is clean — nothing to abort. Must throw a clear error.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task AbortAsync_NoState_RepoNotMidMerge_ThrowsClear()
|
||||
{
|
||||
var db = NewDb();
|
||||
var repo = NewRepo();
|
||||
GitRepoFixture.RunGit(repo.RepoDir, "branch", "-m", "main");
|
||||
|
||||
var (parentId, _, _) = await SeedPlanningWithTwoNonConflictingChildrenAsync(db, repo);
|
||||
|
||||
var (orch, _) = BuildOrchestrator(db);
|
||||
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>(
|
||||
() => orch.AbortAsync(parentId, CancellationToken.None));
|
||||
Assert.Contains("no in-progress merge", ex.Message);
|
||||
}
|
||||
|
||||
private (PlanningMergeOrchestrator orch, List<(string Method, object?[] Args)> calls) BuildOrchestrator(DbFixture db)
|
||||
{
|
||||
var fakeHub = new OrchestratorFakeHubContext();
|
||||
|
||||
Reference in New Issue
Block a user