feat(planning): consolidate finalize+chain via TaskStateService, fix queue pickup

Slice 4 of the worker state consolidation refactor. Eliminates the
"queue never picks up planning tasks" bug structurally by routing both
the manager and MCP finalize paths through TaskStateService and
PlanningChainCoordinator.SetupChainAsync, where the auto-wake on enqueue
guarantees the queue picker claims the first child immediately.

- Delete TaskRepository.FinalizePlanningAsync; PlanningSessionManager
  now orchestrates via _state.FinalizePlanningAsync + _chain.SetupChainAsync.
- Rename QueueSubtasksSequentiallyAsync to SetupChainAsync (internal);
  layout is now Status=Queued + BlockedByTaskId, with auto-attached agent tag.
- OnChildFinishedAsync looks up the successor by BlockedByTaskId, drops
  the legacy Waiting status lookup.
- PlanningMcpService.Finalize routes through state+chain; EditableStatuses
  drops Waiting and adds Idle; gate uses PlanningPhase==Active.
- TaskStateService.FinalizePlanningAsync clears the planning session token.
- UI: TaskRowViewModel adds BlockedByTaskId; IsQueued/IsWaiting reflect
  the new layout; TasksIslandViewModel.RemoveFromQueueAsync clears
  BlockedByTaskId on dequeue.
- New regression test PlanningEndToEndTests.FinalizeAsync_FirstChildIs
  ClaimedByPicker_WithinDeadline asserts the picker claims the first
  child within 200ms with no manual WakeQueue.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Mika Kuns
2026-04-27 14:16:12 +02:00
parent 064a903076
commit 4ab906ff0b
17 changed files with 315 additions and 206 deletions

View File

@@ -20,6 +20,7 @@ public sealed class PlanningSessionManagerTests : IDisposable
private readonly WorkerConfig _cfg;
private readonly AppSettingsRepository _settingsRepo;
private readonly PlanningSessionManager _sut;
private readonly TaskStateServiceBuilder.Built _built;
public PlanningSessionManagerTests()
{
@@ -31,7 +32,9 @@ public sealed class PlanningSessionManagerTests : IDisposable
_cfg = new WorkerConfig { CentralWorktreeRoot = Path.Combine(_rootDir, "central") };
_settingsRepo = new AppSettingsRepository(_ctx);
_settingsRepo.UpdateAsync(new AppSettingsEntity { WorktreeStrategy = "sibling" }).GetAwaiter().GetResult();
_sut = new PlanningSessionManager(_tasks, _lists, _settingsRepo, _git, _cfg, _rootDir);
_built = TaskStateServiceBuilder.Build(_db.CreateFactory());
_sut = new PlanningSessionManager(
_tasks, _lists, _settingsRepo, _git, _cfg, _rootDir, _built.State, _built.Chain);
}
public void Dispose()
@@ -173,7 +176,7 @@ public sealed class PlanningSessionManagerTests : IDisposable
}
[Fact]
public async Task FinalizeAsync_PromotesDraftsAndMarksPlanned()
public async Task FinalizeAsync_PromotesDraftsAndMarksPlanningFinalized()
{
var (listId, _) = await SeedListAsync();
var parent = await SeedManualTaskAsync(listId);
@@ -185,7 +188,9 @@ public sealed class PlanningSessionManagerTests : IDisposable
Assert.Equal(2, count);
var loaded = await _tasks.GetByIdAsync(parent.Id);
Assert.Equal(TaskStatus.Planned, loaded!.Status);
Assert.Equal(PlanningPhase.Finalized, loaded!.PlanningPhase);
Assert.NotNull(loaded.PlanningFinalizedAt);
Assert.Null(loaded.PlanningSessionToken);
}
[Fact]