feat: Connect dispatch queue to agent spawning via auto-dispatch

ExecutionOrchestrator now listens for phase:queued and agent:stopped
events to drive the dispatch cycle, closing the gap between queueing
phases (Execute button) and actually spawning agents. Coalesced
scheduling prevents reentrancy with synchronous EventEmitter.
This commit is contained in:
Lukas May
2026-03-04 12:55:20 +01:00
parent d03b204096
commit 1c7d6f20ee
3 changed files with 83 additions and 3 deletions

View File

@@ -96,3 +96,24 @@ AccountCredentialsRefreshedEvent { accountId, expiresAt, previousExpiresAt? }
| `completePhase(phaseId)` | Mark phase complete |
| `blockPhase(phaseId, reason)` | Block phase |
| `getPhaseQueueState()` | Return queued, ready, blocked phases |
## Auto-Dispatch (ExecutionOrchestrator)
`apps/server/execution/orchestrator.ts` — Connects the queue to agent spawning via event-driven auto-dispatch.
### Trigger Events
| Event | Action |
|-------|--------|
| `phase:queued` | Dispatch ready phases → dispatch their tasks to idle agents |
| `agent:stopped` | Re-dispatch queued tasks (freed agent slot) |
| `task:completed` | Merge task branch, then dispatch next queued task |
### Coalesced Scheduling
Multiple rapid events (e.g. several `phase:queued` from `queueAllPhases`) are coalesced into a single async dispatch cycle via `scheduleDispatch()`. The cycle loops `dispatchNextPhase()` + `dispatchNext()` until both queues are drained, then re-runs if new events arrived during execution.
### Execution Mode Behavior
- **YOLO**: phase completes → auto-merge → auto-dispatch next phase → auto-dispatch tasks
- **review_per_phase**: phase completes → set `pending_review` → STOP. User approves → `approveAndMergePhase()` → merge → dispatch next phase → dispatch tasks