Code Review
Mission
Produce the deepest review that is practical for the requested scope. Findings and coverage evidence are the primary output. Praise, style preferences, and broad refactor suggestions are secondary.
The coordinating agent owns scope, final judgment, de-duplication, severity, and the persisted report. Subagents provide bounded analysis; never copy their conclusions into the report without independent synthesis.
Required Resources
- Read references/subagent-orchestration.md before delegating review work.
- Write the report from references/report-template.md.
- Validate generation
0withpython3 scripts/validate_review_report.py <report-path>. Validate generation1with the additional--parent-report <generation-0-report> --parent-resolution <resolution-report>arguments.
Hard Gates
- Before substantive review, assess scope and risk in the coordinator using the baseline, changed-file inventory, diff size, and known constraints.
- Delegate that assessment only when uncertain decomposition or independent risk analysis would materially improve the plan. Choose specialists by their coverage benefit and context-sharing cost; tool availability alone does not justify delegation.
- If the environment has no subagent primitive, record
Subagent unavailableand execute the same assessment protocol in the coordinator. Never claim a subagent ran when it did not. - Keep every review subagent read-only. Do not edit files, stage, commit, push, reset, checkout, rebase, or mutate Git state.
- Keep the review phase read-only. If the user also requested fixes, finish and freeze the report, then continue within that existing implementation authorization without requiring a separate request. A review-only request ends with the report.
- Put every report in a review chain. Use generation
0for the frozen initial scope and generation1only for the implementation delta plus affected execution chains after areceiving-code-reviewresolution. - Treat generation
1as terminal: write the report, return remaining findings to the user or product owner, and do not automatically invokereceiving-code-review. Any later work requires an explicit user request and a new generation0chain. - Do not classify a disputed product choice as
Blocker,Major, orMinorwithout an authoritative expected-behavior basis. UseQuestionwhen product intent is unconfirmed.
Scope and Identity
- Resolve the requested scope: working tree, staged diff, commit range, branch diff, pull request, file set, or pasted code.
- Choose the narrowest reasonable scope when none is explicit. Prefer staged changes when present; otherwise compare the working tree with
HEAD. - Record the baseline and target precisely. Use commit SHAs when available.
- Create a review chain ID and record generation, trigger, parent resolution ID/path, and scope mode. Generation
1must read the complete parent resolution before reviewing. - Compute a scope fingerprint when practical from the baseline, target, changed paths, and normalized diff hash. Record why a fingerprint is unavailable.
- Read requirements, issue text, PR description, design notes, migrations, relevant contracts, and settled parent-resolution decisions before judging intent.
- Freeze generation
0scope. For generation1, review the implementation delta and only the callers, callees, contracts, and execution chains it can affect; do not reopen the full original discovery frontier. - Do not silently widen scope. Mark unrelated context as supporting evidence or a follow-up rather than a finding in the current chain.
Orchestration
- Assess the scope identity, diff inventory, change statistics, touched subsystems, known requirements, and environment limitations in the coordinator or a justified read-only assessor.
- Record a structured decision:
Single reviewerorParallel specialists, with rationale, risk dimensions, proposed partitions, overlap plan, and verification needs. UseCoordinator assessment - <reason>when no assessment subagent was needed; the coordinator may also be the single reviewer. - Follow the decision unless concrete new evidence invalidates it. Record any override and reason.
- For parallel review, assign bounded, non-identical ownership. Typical angles include:
- correctness, state, data flow, and API contracts
- security, privacy, auth, permissions, and trust boundaries
- tests, regressions, error paths, concurrency, and reliability
- migrations, persistence, compatibility, integrations, performance, and operations
- framework- or domain-specific semantics
- Require each specialist to return candidate findings, covered areas, dismissed candidates, uncertainty, and evidence pointers.
- Re-read the relevant code and evidence for every candidate that could enter the final report. Resolve conflicts explicitly and assign final
F#,T#, andA#IDs only in the coordinator.
Deep Review Contract
Review beyond changed lines whenever risk can propagate. Trace far enough to evaluate:
- callers, callees, shared utilities, adapters, and alternate entry points
- input validation, authorization, trust boundaries, secrets, privacy, and unsafe external effects
- state transitions, persistence, migrations, serialization, compatibility, rollback, and data loss
- retries, idempotency, ordering, caching, concurrency, races, timeouts, partial failure, and cleanup
- public API, CLI, UI, generated output, configuration, dependency, and deployment contracts
- positive, negative, boundary, regression, integration, and migration test coverage
- runtime behavior through focused, non-destructive commands when it materially changes confidence
- requirements and intentional behavior changes so intended changes are not misreported as defects
Establish an expected-behavior basis before accepting a finding:
- Prefer explicit current user or product-owner decisions and acceptance criteria.
- Then use public contracts, approved design or migration decisions, and security, privacy, compliance, or data-integrity invariants.
- Treat tests, current code, and history as behavioral evidence, not product authority by themselves.
- When the disagreement is a product choice and no authoritative basis is available, emit an approval-affecting
Questionwith a settlement criterion instead of a defect. - In generation
1, inheritIntentional,Disproved,Stale, andDuplicatedecisions from the parent resolution. Reopen the same semantic issue only when relevant code, the governing contract, or material evidence changed. Recordkind:<code|contract|evidence>; ref:<concrete source>; change:<concrete delta>; placeholder references or changes such asNone,unknown, or template text do not authorize reopening.
Use search, history, blame, runtime checks, or targeted tests only when they strengthen evidence. Passing lint, typecheck, or unrelated tests is hygiene evidence, not proof of behavioral safety.
Stop only when every changed review-relevant or unknown-impact area is accounted for, meaningful candidates have been adjudicated, and remaining blind spots are explicit.
Completeness Contract
- Enumerate every distinct finding reasonably discoverable within the reviewed scope, not only the top risks.
- Maintain a
Review Coverage Ledgerwith stableA#area IDs. Map every changed review-relevant or unknown-impact area to:Finding F#Reviewed - no issue foundNot review-relevantNot covered
- Give every standalone test gap a stable
T#ID and severity. - Give every
F#andT#a canonical semantic issue key. Usebehavior; entry=<semantic entry>; contract=<stable expectation>; effect=<terminal failure>for findings andtest-gap; entry=<semantic entry>; contract=<stable expectation>; gap=<missing coverage>for standalone test gaps. Exclude line numbers, report-local IDs, generation, and current implementation symbols. Compute its fingerprint asifp-sha256:<sha256 of the exact UTF-8 issue key>so the same claim can be recognized across generations. - Record meaningful dismissed or merged candidates in
Subagent Candidate Adjudicationor the evidence appendix. - Mark the report
Incompleteand identify exact uncovered surfaces when context, credentials, runtime, diff size, or other limits prevent complete coverage. - Never present a partial review as complete.
Findings and Evidence
Count one finding per distinct failure mode, affected contract, security boundary, data risk, or approval decision. Merge repeated manifestations of the same defect; split materially different impacts.
Prioritize:
- crashes, incorrect results, stale or lost data, availability failures, and broken edge cases
- user-visible, API, CLI, persistence, auth, permission, retry, ordering, caching, and integration regressions
- injection, unsafe deserialization, auth bypass, secret exposure, SSRF, XSS, CSRF, overbroad access, and unsafe filesystem or dependency use
- missing tests for risky changed behavior, especially fixes, permissions, migrations, concurrency, and failures
- maintainability only when it creates a concrete review risk
For every accepted finding:
- tie the claim to a location, behavior path, output, missing test, or coverage gap
- separate verified facts from inference
- state assumptions and reduce confidence when proof is incomplete
- include exactly one or two primary code links in
Look here first - record which reviewer proposed it and how the coordinator verified it
- record the structured expected-behavior basis, canonical issue key, and verified semantic issue fingerprint
Do not invent defects. A clean result still requires a full coverage ledger, strongest blind spot, and verification record.
Severity and Recommendation
Use Blocker, Major, Minor, and Question as defined in the report template.
Map unresolved findings and standalone test gaps to the recommendation in this order:
- Any
Blocker->Block. - Otherwise any
Major->Changes requested. - Otherwise any approval-affecting
Question->Discuss. - Otherwise any review-relevant or unknown-impact
Not coveredarea ->Discuss. - Otherwise any
Minor->Pass with caveat. - Otherwise ->
Pass.
Downgrade an unproven suspected blocker rather than retaining a hand-wavy Blocker. Do not use Question for curiosity that cannot affect approval.
Persistence and Handoff
- Always write a fresh Markdown report using the canonical
code-reviewreport contract. - Generate a unique report ID and filename. Follow an existing repository report convention; otherwise use
tmp/reviews/YYYY-MM-DD-code-review-report-<random-id>.md. - Never overwrite an existing report.
- Persist scope identity, scope fingerprint, orchestration decision, specialist assignments, candidate adjudication, findings, test gaps, coverage, evidence, and a
Receiving Handoffsection. - Persist review-chain identity, generation, trigger, parent review and resolution, semantic issue keys and fingerprints, expected-behavior bases, and inherited-settlement reconciliation.
- Treat the completed review report as a fixed input artifact. Do not rewrite it during receiving or implementation; record later dispositions and code changes in a separate
receiving-code-reviewresolution report linked by Report ID. - A generation
0report may be ready forreceiving-code-reviewwhileAutomatic receiving permittedisNo: readiness describes the artifact, not user authorization. UseYesonly for a ready report with user-authorized continuation; review-only requests useNo. A generation1report must use a terminal handoff and must not be consumed automatically. - Partition every non-Question finding and standalone test gap exactly once into actionable or deferred handoff IDs. List every
QuestionandNot coveredarea in its matching open-ID field. - Run the validator and fix every error before claiming the report is complete.
Workflow
- Resolve review-chain identity, generation, trigger, scope, baseline, target, and minimal diff inventory.
- Assess orchestration in the coordinator or delegate the assessment when justified.
- Record and execute the single-reviewer or specialist plan.
- Build the semantic diff inventory and
A#coverage areas. - Trace changed control, data, security, persistence, integration, and test paths.
- Run focused verification where it materially improves confidence.
- Collect candidate findings and specialist coverage results.
- Independently verify, de-duplicate, challenge, and classify every candidate against its expected-behavior basis and inherited settlements.
- Assign final
F#,T#, andA#IDs plus semantic issue fingerprints. - Derive the recommendation from unresolved items and coverage.
- Write the canonical report from the template.
- Run
scripts/validate_review_report.pyand correct all failures. - Return a short summary with report path, recommendation, completion, severity counts, orchestration mode, and top risks.
Final Self-Check
- The report records the actual assessment mode and rationale: coordinator, delegated assessor, or unavailable fallback.
- The orchestration decision is supported by scope and risk, not arbitrary agent count.
- Every specialist candidate was verified, rejected, merged, or retained with evidence.
- Every changed review-relevant or unknown-impact area has an
A#row. - Every
F#andT#has an authoritative expected-behavior basis or is an explicitQuestion, plus a unique semantic issue fingerprint. - Generation and handoff are consistent: generation
0may allow receiving; generation1is terminal and links its parent resolution. - Every indexed finding has one matching card and every
Finding F#area references a real finding. - Every
Not coveredrow has a reason and concrete next step. - Recommendation mapping is exact.
- The report validator passes.
- Git state is unchanged.