feat(planning): prevent orphaned subtasks via guards + startup repair

Three coordinated guards close the orphan-creation paths:

- CreateChildAsync refuses when the parent is not in a planning phase.
- DiscardPlanningAsync now returns a structured DiscardPlanningOutcome
  and refuses when children are queued or running; callers can opt into
  auto-dequeuing queued kids via dequeueQueuedChildren=true. Terminal
  children (Done/Failed/Cancelled) are promoted to top-level instead of
  becoming orphans when the parent's PlanningPhase is reset.
- OrphanRecovery hosted service clears ParentTaskId on any rows whose
  parent is missing or no longer in a planning phase on worker startup,
  mirroring the StaleTaskRecovery pattern.

UI surfaces the block reason: a confirm dialog offers to dequeue queued
children and retry; a running-children block is shown as a hard error
asking the user to cancel first.

WorkerClient now negotiates the JsonStringEnumConverter so the
DiscardPlanningResult enum round-trips correctly over SignalR.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
mika kuns
2026-05-18 16:02:15 +02:00
parent e68bb737e3
commit d094a21e09
17 changed files with 481 additions and 32 deletions

View File

@@ -217,7 +217,7 @@ public sealed class PlanningSessionManagerTests : IDisposable
var startCtx = await _sut.StartAsync(parent.Id, CancellationToken.None);
Assert.True(Directory.Exists(startCtx.Files.SessionDirectory));
await _sut.DiscardAsync(parent.Id, CancellationToken.None);
await _sut.DiscardAsync(parent.Id, dequeueQueuedChildren: false, CancellationToken.None);
Assert.False(Directory.Exists(startCtx.Files.SessionDirectory));
var loaded = await _tasks.GetByIdAsync(parent.Id);
@@ -235,7 +235,7 @@ public sealed class PlanningSessionManagerTests : IDisposable
var ctx = await _sut.StartAsync(parent.Id, CancellationToken.None);
Assert.True(Directory.Exists(ctx.WorktreePath));
await _sut.DiscardAsync(parent.Id, CancellationToken.None);
await _sut.DiscardAsync(parent.Id, dequeueQueuedChildren: false, CancellationToken.None);
Assert.False(Directory.Exists(ctx.WorktreePath));
// branch deleted