refactor(worker/queue): split queue waker and picker, auto-wake on enqueue
Slice 3 of the worker state and queue consolidation refactor. - Add IQueueWaker / QueueWaker (singleton holding the wake semaphore). - Add IQueuePicker / QueuePicker; raw SQL UPDATE...RETURNING moves out of TaskRepository.GetNextQueuedAgentTaskAsync (deleted) and now also filters on blocked_by_task_id IS NULL and writes started_at on claim. - TaskStateService takes IQueueWaker directly; the Func<QueueService> indirection is gone. State transitions to Queued auto-wake the dispatcher. - QueueService waits via the shared waker and dispatches via the picker. - Drop explicit _queue.WakeQueue() calls in WorkerHub.QueuePlanningSubtasksAsync and ExternalMcpService.AddTask. The hub WakeQueue endpoint stays for diagnostics, delegating to _waker.Wake(). - Migrate tests; pre-existing flaky AppSettings/ExternalMcp tests untouched. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -302,28 +302,4 @@ public sealed class TaskRepositoryPlanningTests : IDisposable
|
||||
Assert.NotNull(stillThere);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetNextQueuedAgentTask_SkipsDraftPlanningPlanned()
|
||||
{
|
||||
var listId = await CreateListAsync();
|
||||
var agentTagId = await _tags.GetOrCreateAsync("agent");
|
||||
|
||||
async Task<TaskEntity> T(TaskStatus s, bool withTag, string? parent = null)
|
||||
{
|
||||
var t = MakeTask(listId, s, parentId: parent);
|
||||
await _tasks.AddAsync(t);
|
||||
if (withTag) await _tasks.AddTagAsync(t.Id, agentTagId);
|
||||
return t;
|
||||
}
|
||||
|
||||
var planning = await T(TaskStatus.Planning, withTag: true);
|
||||
var planned = await T(TaskStatus.Planned, withTag: true);
|
||||
var draft = await T(TaskStatus.Draft, withTag: true, parent: planning.Id);
|
||||
var queued = await T(TaskStatus.Queued, withTag: true);
|
||||
|
||||
var picked = await _tasks.GetNextQueuedAgentTaskAsync(DateTime.UtcNow);
|
||||
|
||||
Assert.NotNull(picked);
|
||||
Assert.Equal(queued.Id, picked!.Id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user