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:
@@ -188,65 +188,6 @@ public sealed class TaskRepositoryPlanningTests : IDisposable
|
||||
Assert.Null(found);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FinalizePlanningAsync_TransitionsDraftsAndParent()
|
||||
{
|
||||
var listId = await CreateListAsync();
|
||||
var parent = MakeTask(listId, TaskStatus.Manual);
|
||||
await _tasks.AddAsync(parent);
|
||||
await _tasks.SetPlanningStartedAsync(parent.Id, "tok");
|
||||
|
||||
var c1 = await _tasks.CreateChildAsync(parent.Id, "c1", null, tagNames: new[] { "agent" }, commitType: null);
|
||||
var c2 = await _tasks.CreateChildAsync(parent.Id, "c2", null, tagNames: null, commitType: null);
|
||||
|
||||
var count = await _tasks.FinalizePlanningAsync(parent.Id, queueAgentTasks: true);
|
||||
|
||||
Assert.Equal(2, count);
|
||||
|
||||
var c1Loaded = await _tasks.GetByIdAsync(c1.Id);
|
||||
var c2Loaded = await _tasks.GetByIdAsync(c2.Id);
|
||||
var parentLoaded = await _tasks.GetByIdAsync(parent.Id);
|
||||
|
||||
Assert.Equal(TaskStatus.Queued, c1Loaded!.Status);
|
||||
Assert.Equal(TaskStatus.Manual, c2Loaded!.Status);
|
||||
Assert.Equal(TaskStatus.Planned, parentLoaded!.Status);
|
||||
Assert.NotNull(parentLoaded.PlanningFinalizedAt);
|
||||
Assert.Null(parentLoaded.PlanningSessionToken);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FinalizePlanningAsync_QueueAgentTasksFalse_AllToManual()
|
||||
{
|
||||
var listId = await CreateListAsync();
|
||||
var parent = MakeTask(listId, TaskStatus.Manual);
|
||||
await _tasks.AddAsync(parent);
|
||||
await _tasks.SetPlanningStartedAsync(parent.Id, "tok");
|
||||
var c = await _tasks.CreateChildAsync(parent.Id, "c", null, tagNames: new[] { "agent" }, commitType: null);
|
||||
|
||||
await _tasks.FinalizePlanningAsync(parent.Id, queueAgentTasks: false);
|
||||
|
||||
var cLoaded = await _tasks.GetByIdAsync(c.Id);
|
||||
Assert.Equal(TaskStatus.Manual, cLoaded!.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FinalizePlanningAsync_ParentWithAgentListTag_ChildIsQueued()
|
||||
{
|
||||
var listId = await CreateListAsync();
|
||||
var agentTagId = await _tags.GetOrCreateAsync("agent");
|
||||
await _lists.AddTagAsync(listId, agentTagId);
|
||||
|
||||
var parent = MakeTask(listId, TaskStatus.Manual);
|
||||
await _tasks.AddAsync(parent);
|
||||
await _tasks.SetPlanningStartedAsync(parent.Id, "tok");
|
||||
var c = await _tasks.CreateChildAsync(parent.Id, "c", null, tagNames: null, commitType: null);
|
||||
|
||||
await _tasks.FinalizePlanningAsync(parent.Id, queueAgentTasks: true);
|
||||
|
||||
var cLoaded = await _tasks.GetByIdAsync(c.Id);
|
||||
Assert.Equal(TaskStatus.Queued, cLoaded!.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DiscardPlanningAsync_DeletesDraftsAndResetsParent()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user