Understand what happens after plan approval: how the Orchestrator invokes executors, what waves are, which quality gates are mandatory, and how the completion gate and optional final review work.
- Phase — a plan unit with a fixed
executor_agent. - Wave — a group of phases executed in parallel.
- Quality gate — a mandatory readiness condition for a phase (tests_pass, lint_clean, schema_valid, safety_clear, human_approved_if_required).
- Phase task card — compact executor handoff with allowed files, forbidden areas, validation commands, acceptance checks, budgets, and escalation rule.
- Resource profile — optional execution profile such as
small_local, read fromgovernance/runtime-policy.json. - Completion gate — the final task summary.
- Final review gate — optional final CodeReviewer pass for LARGE tasks.
flowchart TD
Approved[Plan approved] --> Wave1[Wave 1\nparallel: W1 phases]
Wave1 -->|all phases done| Wave2[Wave 2]
Wave2 -->|all done| WaveN[Wave N]
WaveN --> CompletionGate[Completion Gate]
CompletionGate -->|LARGE or requested| FinalReview[Optional Final Review]
CompletionGate -->|TRIVIAL/SMALL/MEDIUM| Done[Done]
FinalReview --> Done
Wave1 --> CR1[CodeReviewer\nafter each phase]
Wave2 --> CR2[CodeReviewer\nafter each phase]
WaveN --> CRN[CodeReviewer\nafter each phase]
For each phase the Orchestrator runs:
sequenceDiagram
participant O as Orchestrator
participant E as Executor
participant CR as CodeReviewer
participant U as User
O->>O: Pre-Phase Gate\n(verify previous phase todo is marked completed)
O->>O: PreFlect (4 risk classes)
O->>O: Resolve phase.executor_agent
O->>O: Build phase_task_card\n(if small_local or card path exists)
O->>E: delegate phase
E-->>O: execution report
O->>O: Verification Build Gate\n(build.state=PASS or independent run)
O->>CR: dispatch CodeReviewer
CR-->>O: verdict
alt validated_blocking_issues empty
O->>O: Mark todo as completed
O->>U: phase approval gate
U-->>O: approved
else has blocking issues
O->>E: revise (failure classification routing)
end
When resource_profile: small_local is active, Orchestrator applies resource_profiles.small_local before dispatch: lower parallelism, require compact context artifacts for SMALL+, and send a phase_task_card to implementation, documentation, platform, or browser-testing executors. If the card's file or read budget is exceeded, the executor returns NEEDS_INPUT or needs_replan instead of widening scope silently.
Rules:
- Phases are grouped by
wave(ascending). - Within a wave, phases may execute in parallel (up to
max_parallel_agents, default 10, or the active resource profile cap). - Wave N+1 waits for all phases of wave N to complete.
- If a wave phase fails — failure classification routing decides: retry / replan / escalate.
Example:
| Phase | Wave | Dependencies |
|---|---|---|
| 1: research backend | 1 | — |
| 2: research frontend | 1 | — |
| 3: design API | 2 | 1 |
| 4: implement endpoint | 3 | 3 |
| 5: implement UI | 3 | 2, 3 |
| 6: e2e tests | 4 | 4, 5 |
Wave 1 — phases 1, 2 in parallel. Wave 3 — phases 4, 5 in parallel. Total: 4 waves for 6 phases.
Each phase contains executor_agent from an enum (8 values):
- CodeMapper-subagent
- Researcher-subagent
- CoreImplementer-subagent
- UIImplementer-subagent
- PlatformEngineer-subagent
- TechnicalWriter-subagent
- BrowserTester-subagent
- CodeReviewer-subagent
Hard rule: The Orchestrator must not infer executor_agent heuristically. If the field is missing from a legacy plan → REPLAN via Planner.
Each phase declares quality_gates from an enum:
| Gate | Meaning |
|---|---|
tests_pass |
All tests in the target scope pass. |
lint_clean |
Lint is clean (read/problems is empty). |
schema_valid |
All produced schemas are valid. |
safety_clear |
PreFlect revealed no unresolved risk. |
human_approved_if_required |
If approval is required — it has been obtained. |
Verification Build Gate (mandatory): after every phase, the Orchestrator either uses build.state: PASS from the execution report or independently runs the build. Accepting a completion claim without verification is a contract violation.
Before marking a phase as complete, the Orchestrator must verify:
- ✅ Tests passed — evidence from the subagent report or an independent run.
- ✅ Build passed —
build.state: PASS. - ✅ Lint/problems are clean.
- ✅ Review status is
APPROVEDfrom CodeReviewer. - ✅ Phase todo item is marked completed via
#todos.
If any check fails → Failure Classification Handling → do not mark complete.
CodeReviewer is mandatory on all tiers (including TRIVIAL).
Key idea: The Orchestrator blocks continuation only on validated_blocking_issues, not on raw CRITICAL/MAJOR findings. This is because not every CRITICAL finding is confirmed as applicable in the specific context of the phase.
If validated_blocking_issues is empty — the phase proceeds even with unresolved INFO/WARNING items.
If a subagent returns a failure (see Chapter 13):
| Classification | Action | Limit |
|---|---|---|
| transient | Retry the same task | 3 |
| fixable | Retry with a hint | 1 |
| needs_replan | Targeted phase replan via Planner | 1 |
| escalate | STOP → user | 0 |
Reliability policy:
- Cumulative budget per phase = 5 retries.
- 3 identical failures in a row → escalate (regardless of class).
- ≥2 transient failures in one wave → 50% parallelism for subsequent waves.
- Empty response, timeout, HTTP 429 — silent failure, not counted as success.
To avoid approval fatigue: one approval message per wave, not per phase.
Template:
"Wave 2: 3 phases, agents: [CoreImplementer, UIImplementer, TechnicalWriter]. Approve all? (y/n/details)"
Exception: if the wave contains destructive/production operations — per-phase approval for that wave.
After all phases:
- Cross-phase consistency review.
- Verify all phase todo items are marked completed.
- If Final Review Gate is active → run it.
- Append session-outcome entry to
plans/session-outcomes.md(usingplans/templates/session-outcome-template.md). - Produce completion summary for the user.
Order matters: the session-outcome is written before the completion summary, so the user sees the summary after telemetry is flushed.
Activates per rules in governance/runtime-policy.json → final_review_gate:
enabled_by_default: true, orcomplexity_tieris inauto_trigger_tiers, or- user explicitly requested.
Workflow:
- Normalize
changed_files[]— collect from all phase reports (mapped by agent type). - Build
plan_phases_snapshot[]—[{phase_id, files[]}]. - Dispatch CodeReviewer with
review_scope: "final". - If
validated_blocking_issues(CRITICAL/MAJOR) are found:- Resolve fix executor: the phase with the highest
phase_idwhosefiles[]contains the affected file. - Dispatch that executor with targeted fix scope.
- Re-run CodeReviewer (final mode) — max
max_fix_cycles= 1. - If still blocked → escalate to user.
- CodeReviewer NEVER owns the fix cycle.
- Resolve fix executor: the phase with the highest
- If clean → advisory log to
plans/artifacts/<task>/final_review.md, continue.
- Prefix from enum:
fix,feat,chore,test,refactor. - Do not mention plan names or phase numbers in commit messages.
- Accepting a completion claim without verification. Forbidden — always check the build.
- Skipping CodeReviewer on TRIVIAL. Mandatory on all tiers.
- Inferring
executor_agent. Forbidden — REPLAN via Planner. - Marking a phase complete before updating the todo. The Pre-Phase Gate will break on the next phase.
- Running phases from different waves in parallel. Forbidden: wave N+1 waits for wave N.
- Giving CodeReviewer the fix. Forbidden — fix cycles always belong to executors.
- (beginner) A plan with 5 phases: phases 1, 2 in wave 1; phase 3 in wave 2; phases 4, 5 in wave 3. How many approval prompts does the Orchestrator show in batch mode?
- (beginner) Open
schemas/planner.plan.schema.jsonand find thequality_gatesenum. List all values. - (intermediate) What should the Orchestrator do if the phase report does not contain
build.state? - (intermediate) A MEDIUM-tier plan has completed. Will the final review gate activate? What must you check to answer?
- (advanced) Final review found a CRITICAL issue in
src/api/users.ts. The file was created in phase 3 and modified in phase 5. Who does the Orchestrator delegate the fix to?
- What does "wave 2 waits for wave 1" mean?
- Why must the Orchestrator not infer
executor_agent? - What are
validated_blocking_issuesand why do they matter? - What 5 items are in the Phase Verification Checklist?
- When does CodeReviewer own a fix cycle? (hint: never)