fix(worker): document and test Queued→Failed guard in FailAsync

OverrideSlotService dispatches RunAsync before calling StartRunningAsync,
so a preflight failure (list not found, worktree setup) can reach MarkFailed
while the task is still Queued. The guard is intentional, not dead code.

- Add comment in FailAsync explaining the OverrideSlotService preflight gap
- Add FailAsync_FromQueued_TransitionsToFailed test
- Update CLAUDE.md transition table with the precise rationale

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mika kuns
2026-06-09 23:41:12 +02:00
parent eee5c99e2f
commit fe73f45b74
3 changed files with 19 additions and 1 deletions

View File

@@ -232,6 +232,21 @@ public sealed class TaskStateServiceTests : IDisposable
Assert.Equal("boom", t.Result);
}
[Fact]
public async Task FailAsync_FromQueued_TransitionsToFailed()
{
// OverrideSlotService can call MarkFailed before StartRunningAsync when a
// preflight step (list lookup, worktree setup) fails — the task is still Queued.
var id = await SeedTaskAsync(TaskStatus.Queued);
var result = await _sut.FailAsync(id, DateTime.UtcNow, "list not found", default);
Assert.True(result.Ok);
var t = await GetTaskAsync(id);
Assert.Equal(TaskStatus.Failed, t.Status);
Assert.Equal("list not found", t.Result);
}
[Fact]
public async Task FailAsync_FromDone_Rejects()
{