Orchestration - Automated Multi-Agent Coordination
Scheduling
Goal
Automatically orchestrate multi-agent execution with task decomposition, native/fallback dispatch, memory coordination, progress monitoring, verification, QA cross-review, retry, and result collection.
Intent signature
- User asks to orchestrate, run in parallel, automate multi-agent execution, or coordinate full-stack work end to end.
- Task requires multiple specialist agents and a persistent review/remediation loop.
When to use
- Complex feature requires multiple specialized agents working in parallel
- User wants automated execution without manually spawning agents
- Full-stack implementation spanning backend, frontend, mobile, and QA
- User says "run it automatically", "run in parallel", or similar automation requests
When NOT to use
- Simple single-domain task -> use the specific agent directly
- User wants step-by-step manual control -> use oma-coordination
- Quick bug fixes or minor changes
Expected inputs
- Complex feature or workflow request
- Project config, model/vendor routing, agent types, task constraints, and workspace/session needs
- Acceptance criteria and verification expectations
Expected outputs
- Orchestrator session state, task board, progress files, result files, and final summary
- Specialist agent outputs after mechanical checks, automated verify, and QA cross-review
- Review history and retry/remediation status when loops fail
Dependencies
.agents/oma-config.yaml, .codex/agents/*.toml, .gemini/agents/*.md, or fallback oma agent spawn
- Memory provider config, subagent prompt template, scripts, task templates, verify script, and session metrics
Control-flow features
- Branches by vendor/native dispatch availability, priority tiers, agent completion/failure, verification status, QA verdict, retry limits, and clarification debt
- Spawns processes/agents and reads/writes memory/result files
- Preserves unresolved evidence when bounded recovery stops
Structural Flow
Entry
- Resolve agent vendor routing and runtime dispatch path.
- Decompose request into priority-tiered tasks.
- For each task, classify into one or more
domain_tags by matching against the Intent signature block of each installed .agents/skills/oma-*/SKILL.md. Tasks that match no domain confidently inherit the union of their parent feature's tags.
- Build a per-task
exposed_skill_set = skills whose name is in domain_tags. If |exposed_skill_set| < 2 after classification, fall back to the full installed set (flat exposure) and record exposure_fallback: true in the task board.
- Create session memory and task board with
exposed_skill_set and exposure_fallback per task.
Scenes
- PREPARE: Plan, setup session ID, and initialize memory files.
- ACT: Spawn agents by priority tier within parallelism limits.
- VERIFY: Run self-check,
oma verify, and QA cross-review loop.
- RECOVER: Retry failed agents with review history when limits allow.
- FINALIZE: Collect verified claims, compile summary, and preserve progress artifacts.
Transitions
- If native dispatch is available for current runtime/vendor, use it.
- If vendors differ or native path is unavailable, use fallback spawn.
- If verify or QA fails, feed feedback back to the implementation agent.
- If recovery limits are exceeded, preserve review history and return
partial or failed; never force completion.
- If a task's
exposed_skill_set excludes a skill that a recovered failure indicates was needed, re-classify the task and re-dispatch with the expanded set rather than retrying against the original narrow set.
Failure and recovery
- Retry failed agents up to configured limits.
- Re-spawn with review history when review loop is exhausted.
- Continue independent work after recording clarification debt; ask only for a material missing decision.
Exit
- Success: all tasks complete, verify/review pass, and results are summarized.
- Partial success: failed agents, exhausted review loops, or clarification debt are explicit.
Logical Operations
Actions
| Action |
SSL primitive |
Evidence |
| Read config and task context |
READ |
oma config, routing, request |
| Classify task into domain tags |
INFER |
task text vs each skill's Intent signature |
| Compute exposed skill set |
SELECT |
intersection of domain tags and installed skills |
| Select dispatch path |
SELECT |
Native vs fallback |
| Write session state |
WRITE |
task board and memory files |
| Spawn agents |
CALL_TOOL |
native CLI or oma agent spawn |
| Poll progress |
READ |
progress/result files |
| Run verification |
CALL_TOOL |
oma verify, tests, QA |
| Update retry state |
UPDATE_STATE |
loop counters and CD metrics |
| Report final result |
NOTIFY |
compiled summary |
Tools and instruments
- Native CLI subagent dispatch, fallback spawn scripts, memory tools, verify script, QA agent
- Session metrics, prompt templates, task templates
Canonical command path
oma agent spawn <agent-type> <prompt-file> <session-id> --task-id <task.id> -w <workspace>
oma verify <agent-type> --workspace <workspace> --json
When native runtime dispatch is available, prefer the runtime-specific native path listed in this skill before falling back to oma agent spawn.
Resource scope
| Scope |
Resource target |
LOCAL_FS |
Session, task-board, progress, result, config files |
PROCESS |
Agent CLI processes and verify scripts |
MEMORY |
Session state and clarification debt |
CODEBASE |
Workspaces owned by spawned agents |
Preconditions
- Task is decomposable into specialist agent work.
- Runtime/vendor dispatch path or fallback exists.
Effects and side effects
- Spawns agents and writes session/progress/result artifacts.
- May cause code changes through specialist agents.
- May trigger iterative review and retries.
Guardrails
- Orchestrate per-agent dispatch from the project configuration before spawning any agent.
- If
target_vendor === current_runtime_vendor and the runtime has a verified native path, use native dispatch.
- Otherwise fall back to
oma agent spawn.
- Never exceed configured parallelism or the aggregate recovery budget. Ordinary retries and exploration hypotheses both consume it.
- Keep session state, task-board state, progress files, claims, and receipts aligned. Use the plan task ID on every spawn and native begin/finish path.
- Domain gating must be soft: prefer a narrower
exposed_skill_set, but fall back to flat exposure when classification confidence is low rather than starving a task of a required specialist.
Current native executor paths:
- Claude Code: Agent tool with
.claude/agents/{agent}.md definitions (multiple Agent tool calls in one message run in parallel; results return synchronously — no polling)
- OpenCode: native
task tool with subagent_type: {agent-id}; do not use oma agent spawn for same-session OpenCode work because it will not appear as a native child task
- Codex CLI:
codex exec "@agent ..." using .codex/agents/*.toml
- Gemini CLI:
gemini -p "@agent ..." using .gemini/agents/*.md
Configuration
| Setting |
Default |
Description |
| MAX_PARALLEL |
3 |
Max concurrent subagents |
| MAX_RECOVERY_ATTEMPTS |
3 |
Total retries and exploration hypotheses per task, including the original attempt |
| POLL_INTERVAL |
30s |
Status check interval |
| Turn guidance |
role-specific |
Checkpoint/resume signal, not a hard stop or approval boundary |
These are workflow defaults. Resolve runtime/vendor settings from project configuration; do not depend on this skill's stale config/cli-config.yaml for runtime behavior.
Memory Configuration
Memory provider and tool names are configurable via .agents/mcp.json (not the repo-root .mcp.json, which is the Claude Code MCP server config):
{
"memoryConfig": {
"provider": "file",
"basePath": ".agents/state/memories",
"tools": {
"read": "Read",
"write": "Write",
"edit": "Edit"
}
}
}
Workflow Phases
PHASE 1 - Plan: Analyze request -> decompose tasks -> generate session ID
PHASE 1.5 - Domain gate: For each task, intersect Intent signature matches across installed skills to derive exposed_skill_set. Record exposure_fallback: true when the intersection is too small to be useful and the flat library is used instead.
PHASE 2 - Setup: Create orchestrator-session-{sessionId}.md and task-board-{sessionId}.md (include exposed_skill_set per task)
PHASE 3 - Execute: Spawn agents by priority tier (never exceed MAX_PARALLEL); inject only exposed_skill_set into each subagent's available specialist list
PHASE 4 - Monitor: Poll every POLL_INTERVAL; handle completed/failed/crashed agents
PHASE 4.5 - Verify: Run mechanical checks for every completed agent; run oma verify {agent-type} only for backend, frontend, mobile, qa, debug, and pm; then run QA cross-review for every completed implementation
PHASE 5 - Collect: Read claims and run-scoped reports for plan tasks whose checks passed; compile summary without deleting evidence.
Memory File Ownership
| File |
Owner |
Others |
orchestrator-session-{sessionId}.md |
orchestrator |
read-only |
task-board-{sessionId}.md |
orchestrator |
read-only |
progress-{agentId}-{taskId}-{runId}-{sessionId}.md |
that run |
orchestrator reads |
result-{agentId}-{taskId}-{runId}-{sessionId}.md |
that run |
orchestrator reads |
Agent-to-Agent Review Loop (PHASE 4.5)
After each agent completes, enter an iterative review loop, not a single-pass verification.
Loop Flow
Agent completes work
↓
[1] Mechanical Self-Check: lint, type-check, tests, diff scope
↓
[2] Verify: For supported types, run `oma verify {agent-type} --workspace {workspace}`
Unsupported (`db`, `refactor`, `architecture`, `tf-infra`, `docs`) → record SKIP and continue
↓ FAIL → Agent receives feedback, fixes, back to [1]
↓ PASS
[3] Cross-Review: QA agent reviews the changes
↓ FAIL → Agent receives review feedback, fixes, back to [1]
↓ PASS
Accept result
Step Details
[1] Mechanical Self-Check (formerly "Self-Review"):
Before requesting external review, the implementation agent must:
- Run lint, type-check, and tests in the workspace
- Verify only planned files were modified (diff scope check)
- Fix any mechanical failures (compile errors, test failures)
Quality judgment is NOT performed in this step.
Design quality, architecture alignment, and acceptance criteria satisfaction
are evaluated exclusively in [3] Cross-Review by the QA agent.
Reason: Self-evaluation bias causes agents to consistently overrate their own output
(ref: Anthropic harness design research).
[2] Automated Verify:
oma verify {agent-type} --workspace {workspace} --json
- Run only for
backend, frontend, mobile, qa, debug, and pm.
- For
db, refactor, architecture, tf-infra, and docs, record that automated verify is unsupported and continue to QA cross-review after the mechanical checks.
- PASS (exit 0): Proceed to cross-review
- FAIL (exit 1): Feed verify output back to the agent as correction context
[3] Cross-Review: Spawn QA agent to review the changes:
- QA agent reads the diff, runs checks, evaluates against acceptance criteria
- If
docs/CODE-REVIEW.md exists, QA agent uses it as the review checklist
- QA agent outputs: PASS (with optional nits) or FAIL (with specific issues)
- On FAIL: issues are fed back to the implementation agent for fixing
Loop Limits
| Counter |
Max |
On Exceeded |
| Self-check + fix cycles |
3 |
Escalate to cross-review regardless |
| Cross-review rejections |
2 |
Report to user with review history |
| Total loop iterations |
5 |
Stop recovery; preserve failed checks and return partial or failed |
Review Feedback Format
When feeding review results back to the implementation agent:
## Review Feedback (iteration {n}/{max})
**Reviewer**: {self / verify / qa-agent}
**Verdict**: FAIL
**Issues**:
1. {specific issue with file and line reference}
2. {specific issue}
**Fix instruction**: {what to change}
This replaces single-pass verification. Most "nitpicking" should happen agent-to-agent.
Human review is reserved for final approval, not catching lint errors.
Recovery Budget (after review loop exhaustion)
Maintain one per-task budget: attempts_used, attempts_remaining, and any
configured cost cap. The original attempt, each ordinary retry, and each
exploration hypothesis consume one attempt. Before starting recovery, reserve
the complete next action; do not exceed the budget or start an incomplete
exploration round.
- First remaining attempt: re-spawn with review history.
- Later attempts: choose either one different retry or a 2–3 hypothesis round
only if enough attempts and cost remain.
- On cap exhaustion, preserve all checks, review findings, and unresolved work.
The task is
partial or failed, never completed.
Clarification Debt (CD) Monitoring
Track user corrections during session execution. See ../_shared/core/session-metrics.md for full protocol.
Event Classification
When user sends feedback during session:
- clarify (+10): User answering agent's question
- correct (+25): User correcting agent's misunderstanding
- redo (+40): User rejecting work, requesting restart
Threshold Actions
| CD Score |
Action |
| CD >= 50 |
QA writes a session-scoped RCA/lesson artifact |
| CD >= 80 |
Continue independent work; ask only for a material missing decision |
redo >= 2 |
Pause only disputed dependent work and record the boundary |
Recording
After each user correction event:
[EDIT]("session-metrics-{sessionId}.md", append event to Events table)
At session end, if CD >= 50:
- Include CD summary in final report
- Trigger QA agent RCA generation
- Write
lessons-{sessionId}.md with prevention measures
References
- Prompt template:
resources/subagent-prompt-template.md
- Memory schema:
resources/memory-schema.md
- Scripts:
scripts/spawn-agent.sh, scripts/parallel-run.sh, scripts/verify.sh
- Task templates:
templates/
- Skill-to-agent mapping:
../_shared/core/skill-routing.md
- Verification:
scripts/verify.sh <agent-type>
- Session metrics:
../_shared/core/session-metrics.md
- API contract template (SSOT):
../_shared/core/api-contracts/template.md; read generated contracts from .agents/results/api-contracts/ (run artifact) or docs/plans/contracts/ (durable spec)
- Context loading:
../_shared/core/context-loading.md
- Difficulty guide:
../_shared/core/difficulty-guide.md
- Clarification protocol:
../_shared/core/clarification-protocol.md
- Context budget:
../_shared/core/context-budget.md
- Code intelligence:
../_shared/core/code-intelligence.md
- Runtime lessons:
../_shared/core/session-metrics.md
1---2name: oma-orchestration-23description: Automated multi-agent orchestration that spawns CLI subagents in parallel, coordinates through durable file state, and monitors progress. Use for orchestration, parallel execution, and automated multi-agent workflows.4---56# Orchestration - Automated Multi-Agent Coordination78## Scheduling910### Goal11Automatically orchestrate multi-agent execution with task decomposition, native/fallback dispatch, memory coordination, progress monitoring, verification, QA cross-review, retry, and result collection.1213### Intent signature14- User asks to orchestrate, run in parallel, automate multi-agent execution, or coordinate full-stack work end to end.15- Task requires multiple specialist agents and a persistent review/remediation loop.1617### When to use18- Complex feature requires multiple specialized agents working in parallel19- User wants automated execution without manually spawning agents20- Full-stack implementation spanning backend, frontend, mobile, and QA21- User says "run it automatically", "run in parallel", or similar automation requests2223### When NOT to use24- Simple single-domain task -> use the specific agent directly25- User wants step-by-step manual control -> use oma-coordination26- Quick bug fixes or minor changes2728### Expected inputs29- Complex feature or workflow request30- Project config, model/vendor routing, agent types, task constraints, and workspace/session needs31- Acceptance criteria and verification expectations3233### Expected outputs34- Orchestrator session state, task board, progress files, result files, and final summary35- Specialist agent outputs after mechanical checks, automated verify, and QA cross-review36- Review history and retry/remediation status when loops fail3738### Dependencies39- `.agents/oma-config.yaml`, `.codex/agents/*.toml`, `.gemini/agents/*.md`, or fallback `oma agent spawn`40- Memory provider config, subagent prompt template, scripts, task templates, verify script, and session metrics4142### Control-flow features43- Branches by vendor/native dispatch availability, priority tiers, agent completion/failure, verification status, QA verdict, retry limits, and clarification debt44- Spawns processes/agents and reads/writes memory/result files45- Preserves unresolved evidence when bounded recovery stops4647## Structural Flow4849### Entry501. Resolve agent vendor routing and runtime dispatch path.512. Decompose request into priority-tiered tasks.523. For each task, classify into one or more `domain_tags` by matching against the `Intent signature` block of each installed `.agents/skills/oma-*/SKILL.md`. Tasks that match no domain confidently inherit the union of their parent feature's tags.534. Build a per-task `exposed_skill_set` = skills whose name is in `domain_tags`. If `|exposed_skill_set| < 2` after classification, fall back to the full installed set (flat exposure) and record `exposure_fallback: true` in the task board.545. Create session memory and task board with `exposed_skill_set` and `exposure_fallback` per task.5556### Scenes571. **PREPARE**: Plan, setup session ID, and initialize memory files.582. **ACT**: Spawn agents by priority tier within parallelism limits.593. **VERIFY**: Run self-check, `oma verify`, and QA cross-review loop.604. **RECOVER**: Retry failed agents with review history when limits allow.615. **FINALIZE**: Collect verified claims, compile summary, and preserve progress artifacts.6263### Transitions64- If native dispatch is available for current runtime/vendor, use it.65- If vendors differ or native path is unavailable, use fallback spawn.66- If verify or QA fails, feed feedback back to the implementation agent.67- If recovery limits are exceeded, preserve review history and return `partial` or `failed`; never force completion.68- If a task's `exposed_skill_set` excludes a skill that a recovered failure indicates was needed, re-classify the task and re-dispatch with the expanded set rather than retrying against the original narrow set.6970### Failure and recovery71- Retry failed agents up to configured limits.72- Re-spawn with review history when review loop is exhausted.73- Continue independent work after recording clarification debt; ask only for a material missing decision.7475### Exit76- Success: all tasks complete, verify/review pass, and results are summarized.77- Partial success: failed agents, exhausted review loops, or clarification debt are explicit.7879## Logical Operations8081### Actions82| Action | SSL primitive | Evidence |83|--------|---------------|----------|84| Read config and task context | `READ` | oma config, routing, request |85| Classify task into domain tags | `INFER` | task text vs each skill's `Intent signature` |86| Compute exposed skill set | `SELECT` | intersection of domain tags and installed skills |87| Select dispatch path | `SELECT` | Native vs fallback |88| Write session state | `WRITE` | task board and memory files |89| Spawn agents | `CALL_TOOL` | native CLI or `oma agent spawn` |90| Poll progress | `READ` | progress/result files |91| Run verification | `CALL_TOOL` | `oma verify`, tests, QA |92| Update retry state | `UPDATE_STATE` | loop counters and CD metrics |93| Report final result | `NOTIFY` | compiled summary |9495### Tools and instruments96- Native CLI subagent dispatch, fallback spawn scripts, memory tools, verify script, QA agent97- Session metrics, prompt templates, task templates9899### Canonical command path100```bash101oma agent spawn <agent-type> <prompt-file> <session-id> --task-id <task.id> -w <workspace>102oma verify <agent-type> --workspace <workspace> --json103```104105When native runtime dispatch is available, prefer the runtime-specific native path listed in this skill before falling back to `oma agent spawn`.106107### Resource scope108| Scope | Resource target |109|-------|-----------------|110| `LOCAL_FS` | Session, task-board, progress, result, config files |111| `PROCESS` | Agent CLI processes and verify scripts |112| `MEMORY` | Session state and clarification debt |113| `CODEBASE` | Workspaces owned by spawned agents |114115### Preconditions116- Task is decomposable into specialist agent work.117- Runtime/vendor dispatch path or fallback exists.118119### Effects and side effects120- Spawns agents and writes session/progress/result artifacts.121- May cause code changes through specialist agents.122- May trigger iterative review and retries.123124### Guardrails1251. Orchestrate per-agent dispatch from the project configuration before spawning any agent.1262. If `target_vendor === current_runtime_vendor` and the runtime has a verified native path, use native dispatch.1273. Otherwise fall back to `oma agent spawn`.1284. Never exceed configured parallelism or the aggregate recovery budget. Ordinary retries and exploration hypotheses both consume it.1295. Keep session state, task-board state, progress files, claims, and receipts aligned. Use the plan task ID on every spawn and native begin/finish path.1306. Domain gating must be soft: prefer a narrower `exposed_skill_set`, but fall back to flat exposure when classification confidence is low rather than starving a task of a required specialist.131132Current native executor paths:133- Claude Code: Agent tool with `.claude/agents/{agent}.md` definitions (multiple Agent tool calls in one message run in parallel; results return synchronously — no polling)134- OpenCode: native `task` tool with `subagent_type: {agent-id}`; do not use `oma agent spawn` for same-session OpenCode work because it will not appear as a native child task135- Codex CLI: `codex exec "@agent ..."` using `.codex/agents/*.toml`136- Gemini CLI: `gemini -p "@agent ..."` using `.gemini/agents/*.md`137138### Configuration139140| Setting | Default | Description |141|---------|---------|-------------|142| MAX_PARALLEL | 3 | Max concurrent subagents |143| MAX_RECOVERY_ATTEMPTS | 3 | Total retries and exploration hypotheses per task, including the original attempt |144| POLL_INTERVAL | 30s | Status check interval |145| Turn guidance | role-specific | Checkpoint/resume signal, not a hard stop or approval boundary |146147These are workflow defaults. Resolve runtime/vendor settings from project configuration; do not depend on this skill's stale `config/cli-config.yaml` for runtime behavior.148149### Memory Configuration150151Memory provider and tool names are configurable via `.agents/mcp.json` (not the repo-root `.mcp.json`, which is the Claude Code MCP server config):152```json153{154 "memoryConfig": {155 "provider": "file",156 "basePath": ".agents/state/memories",157 "tools": {158 "read": "Read",159 "write": "Write",160 "edit": "Edit"161 }162 }163}164```165166### Workflow Phases167168**PHASE 1 - Plan**: Analyze request -> decompose tasks -> generate session ID169**PHASE 1.5 - Domain gate**: For each task, intersect `Intent signature` matches across installed skills to derive `exposed_skill_set`. Record `exposure_fallback: true` when the intersection is too small to be useful and the flat library is used instead.170**PHASE 2 - Setup**: Create `orchestrator-session-{sessionId}.md` and `task-board-{sessionId}.md` (include `exposed_skill_set` per task)171**PHASE 3 - Execute**: Spawn agents by priority tier (never exceed MAX_PARALLEL); inject only `exposed_skill_set` into each subagent's available specialist list172**PHASE 4 - Monitor**: Poll every POLL_INTERVAL; handle completed/failed/crashed agents173**PHASE 4.5 - Verify**: Run mechanical checks for every completed agent; run `oma verify {agent-type}` only for `backend`, `frontend`, `mobile`, `qa`, `debug`, and `pm`; then run QA cross-review for every completed implementation174**PHASE 5 - Collect**: Read claims and run-scoped reports for plan tasks whose checks passed; compile summary without deleting evidence.175176### Memory File Ownership177178| File | Owner | Others |179|------|-------|--------|180| `orchestrator-session-{sessionId}.md` | orchestrator | read-only |181| `task-board-{sessionId}.md` | orchestrator | read-only |182| `progress-{agentId}-{taskId}-{runId}-{sessionId}.md` | that run | orchestrator reads |183| `result-{agentId}-{taskId}-{runId}-{sessionId}.md` | that run | orchestrator reads |184185### Agent-to-Agent Review Loop (PHASE 4.5)186187After each agent completes, enter an iterative review loop, not a single-pass verification.188189### Loop Flow190191```192Agent completes work193 ↓194[1] Mechanical Self-Check: lint, type-check, tests, diff scope195 ↓196[2] Verify: For supported types, run `oma verify {agent-type} --workspace {workspace}`197 Unsupported (`db`, `refactor`, `architecture`, `tf-infra`, `docs`) → record SKIP and continue198 ↓ FAIL → Agent receives feedback, fixes, back to [1]199 ↓ PASS200[3] Cross-Review: QA agent reviews the changes201 ↓ FAIL → Agent receives review feedback, fixes, back to [1]202 ↓ PASS203Accept result204```205206### Step Details207208**[1] Mechanical Self-Check** (formerly "Self-Review"):209Before requesting external review, the implementation agent must:210- Run lint, type-check, and tests in the workspace211- Verify only planned files were modified (diff scope check)212- Fix any mechanical failures (compile errors, test failures)213214**Quality judgment is NOT performed in this step.**215Design quality, architecture alignment, and acceptance criteria satisfaction216are evaluated exclusively in [3] Cross-Review by the QA agent.217Reason: Self-evaluation bias causes agents to consistently overrate their own output218(ref: Anthropic harness design research).219220**[2] Automated Verify**:221```bash222oma verify {agent-type} --workspace {workspace} --json223```224- Run only for `backend`, `frontend`, `mobile`, `qa`, `debug`, and `pm`.225- For `db`, `refactor`, `architecture`, `tf-infra`, and `docs`, record that automated verify is unsupported and continue to QA cross-review after the mechanical checks.226- **PASS (exit 0)**: Proceed to cross-review227- **FAIL (exit 1)**: Feed verify output back to the agent as correction context228229**[3] Cross-Review**: Spawn QA agent to review the changes:230- QA agent reads the diff, runs checks, evaluates against acceptance criteria231<!-- oma-docs:ignore-start -->232- If `docs/CODE-REVIEW.md` exists, QA agent uses it as the review checklist233<!-- oma-docs:ignore-end -->234- QA agent outputs: PASS (with optional nits) or FAIL (with specific issues)235- On FAIL: issues are fed back to the implementation agent for fixing236237### Loop Limits238239| Counter | Max | On Exceeded |240|---------|-----|-------------|241| Self-check + fix cycles | 3 | Escalate to cross-review regardless |242| Cross-review rejections | 2 | Report to user with review history |243| Total loop iterations | 5 | Stop recovery; preserve failed checks and return `partial` or `failed` |244245### Review Feedback Format246247When feeding review results back to the implementation agent:248```249## Review Feedback (iteration {n}/{max})250**Reviewer**: {self / verify / qa-agent}251**Verdict**: FAIL252**Issues**:2531. {specific issue with file and line reference}2542. {specific issue}255**Fix instruction**: {what to change}256```257258This replaces single-pass verification. Most "nitpicking" should happen agent-to-agent.259Human review is reserved for final approval, not catching lint errors.260261### Recovery Budget (after review loop exhaustion)262263Maintain one per-task budget: `attempts_used`, `attempts_remaining`, and any264configured cost cap. The original attempt, each ordinary retry, and each265exploration hypothesis consume one attempt. Before starting recovery, reserve266the complete next action; do not exceed the budget or start an incomplete267exploration round.268269- First remaining attempt: re-spawn with review history.270- Later attempts: choose either one different retry or a 2–3 hypothesis round271 only if enough attempts and cost remain.272- On cap exhaustion, preserve all checks, review findings, and unresolved work.273 The task is `partial` or `failed`, never `completed`.274275### Clarification Debt (CD) Monitoring276277Track user corrections during session execution. See `../_shared/core/session-metrics.md` for full protocol.278279### Event Classification280When user sends feedback during session:281- **clarify** (+10): User answering agent's question282- **correct** (+25): User correcting agent's misunderstanding283- **redo** (+40): User rejecting work, requesting restart284285### Threshold Actions286| CD Score | Action |287|----------|--------|288| CD >= 50 | QA writes a session-scoped RCA/lesson artifact |289| CD >= 80 | Continue independent work; ask only for a material missing decision |290| `redo` >= 2 | Pause only disputed dependent work and record the boundary |291292### Recording293After each user correction event:294```295[EDIT]("session-metrics-{sessionId}.md", append event to Events table)296```297298At session end, if CD >= 50:2991. Include CD summary in final report3002. Trigger QA agent RCA generation3013. Write `lessons-{sessionId}.md` with prevention measures302303## References304- Prompt template: `resources/subagent-prompt-template.md`305- Memory schema: `resources/memory-schema.md`306- Scripts: `scripts/spawn-agent.sh`, `scripts/parallel-run.sh`, `scripts/verify.sh`307- Task templates: `templates/`308- Skill-to-agent mapping: `../_shared/core/skill-routing.md`309- Verification: `scripts/verify.sh <agent-type>`310- Session metrics: `../_shared/core/session-metrics.md`311- API contract template (SSOT): `../_shared/core/api-contracts/template.md`; read generated contracts from `.agents/results/api-contracts/` (run artifact) or `docs/plans/contracts/` (durable spec)312- Context loading: `../_shared/core/context-loading.md`313- Difficulty guide: `../_shared/core/difficulty-guide.md`314- Clarification protocol: `../_shared/core/clarification-protocol.md`315- Context budget: `../_shared/core/context-budget.md`316- Code intelligence: `../_shared/core/code-intelligence.md`317- Runtime lessons: `../_shared/core/session-metrics.md`