# Tasks — Domain 3: Multi-Agent Orchestration ## Phase 1 (4 tasks) ### 1. Task state machine Add formal states to Step: - Read ./apps/coder/src/services/flow-runner.ts and ./apps/coder/src/services/flow-runner-decisions.ts - Extend Step.type to add TIMED_OUT state - Add retriable flag: retry_count, max_retries to Step - Wire into flow-runner's advance/delegate path - On failure with retriable=true: re-queue instead of failing **Verification**: tsc --noEmit passes ### 2. DO_WHILE loop step - Add 'do_while' to StepKind - Step definition: { kind: 'do_while', condition: (ctx) => boolean, steps: Step[] } - Flow runner executes steps, re-evaluates condition, loops or advances - Guard against infinite loops (max 100 iterations default) **Verification**: tsc --noEmit passes ### 3. SWITCH branch step - Add 'switch' to StepKind - Step definition: { kind: 'switch', cases: [{ when: (ctx) => boolean, steps: Step[] }] } - Flow runner evaluates cases in order, executes first matching case's steps - Default/else case support **Verification**: tsc --noEmit passes ### 4. FORK_JOIN step - Add 'fork_join' to StepKind - Step definition: { kind: 'fork_join', branches: Step[][], joinStrategy: 'all' | 'any' } - Flow runner dispatches all branches in parallel via existing task queue - On completion, gathers results and passes to join handler **Verification**: tsc --noEmit passes ## Phase 2 (1 task) ### 5. JSON DAG format - Define JSON schema for flow DAG: nodes, edges, conditions - Create DAG loader that produces Step[] from JSON - Add validation for cycles, unreachable nodes, missing deps - Parallel to existing TypeScript Step[] arrays — not a replacement **Verification**: tsc --noEmit passes. Load a sample JSON DAG and verify it produces correct Step[]. ## Phase 3 (2 tasks) ### 6. Parallel batch execution - Modify flow runner to dispatch independent steps concurrently - Use Promise.all for independent steps in the same wave - Respect dependency ordering **Verification**: tsc --noEmit passes. Two independent steps with different durations finish concurrently. ### 7. Phased lifecycle template - Create conductor/flows/lifecycle.ts with 6-phase template: ticket → research → plan → execute → commit → review - Each phase is a step with agent dispatch + output validation - Users can fork and customize **Verification**: tsc --noEmit passes. Flow definition renders correct Step[].