Code Review
Overview
Execute a rigorous, risk-first code review workflow and produce actionable findings.
Prioritize bugs and behavior regressions over style preferences.
Required Inputs
- Review target: PR, commit range, branch diff, or specific files
- Project context: language/framework, runtime, and critical flows (if known)
- Scope constraints: full review or focused areas (security, performance, API, tests)
If context is missing, infer from repository and changed files, then state assumptions.
Workflow
- Define review boundaries.
- Build a risk map from touched components and data flows.
- Inspect code paths for correctness and regression risks.
- Validate non-functional risks (security, reliability, performance).
- Evaluate tests and observability coverage.
- Report findings ordered by severity.
Step 1: Define Review Boundaries
- Read the diff first, then open surrounding code for context.
- Distinguish change types: feature, bugfix, refactor, migration, dependency bump, config-only.
- Identify high-impact zones: auth, payments, data persistence, concurrency, caching, error handling, external integrations.
Step 2: Build a Risk Map
- Trace entry points to side effects:
- API request -> validation -> business logic -> DB/queue/cache updates
- Background job/scheduler -> idempotency/locking/retry paths
- UI event -> API calls -> state transitions -> user-visible behavior
- Flag unsafe changes early:
- Contract changes without versioning or migration path
- Data model changes without backfill/migration rollback plan
- Removed guards or authorization checks
Step 3: Inspect for Defects and Regressions
Use references/review-checklist.md for a complete checklist.
Focus on:
- Logic errors and broken invariants
- Off-by-one or boundary mistakes
- Incorrect null/empty/error handling
- Race conditions, deadlocks, and ordering issues
- Inconsistent read/write behavior and transaction boundaries
- Backward compatibility and API/schema mismatches
Use references/language-risk-cues.md for language-specific bug patterns.
Step 4: Validate Security, Reliability, and Performance
- Security:
- AuthN/AuthZ enforced on all protected paths
- Input validation and output encoding are preserved
- Secrets and sensitive data are not exposed in logs/errors
- Reliability:
- Retries are bounded and idempotent
- Timeouts/circuit breakers are set for network calls
- Failure paths avoid partial writes and silent corruption
- Performance:
- Query counts, complexity, and N+1 risks are understood
- Unbounded loops, allocations, or payload growth are avoided
- Caching invalidation behavior remains correct
Step 5: Evaluate Tests and Operability
- Verify tests cover changed behavior and critical failure modes.
- Confirm regressions are reproducible by tests where possible.
- Check logging, metrics, tracing, and alerting impact for changed code paths.
- Mark missing tests as findings when risk is material.
Severity Model
P0: Critical bug/security/data-loss risk; likely production incident.
P1: High-impact correctness/reliability issue with significant user or business impact.
P2: Medium-risk defect or regression risk; should be fixed before merge when practical.
P3: Low-risk improvement, maintainability concern, or clarity gap.
If uncertain, prefer lower confidence rather than inflated severity.
Output Contract
Report findings first, ordered by severity, with this structure:
[Px] concise title
- Why this is a problem (impact and failure mode)
- Evidence with file and line reference
- Recommended fix direction
Then include:
- Open questions/assumptions
- Brief change summary
- Residual risks or testing gaps
If no material issues are found, explicitly say so and list residual risks/test gaps.
Review Discipline
- Do not block on style-only issues unless explicitly requested.
- Do not invent missing context; state assumptions.
- Prefer concrete, reproducible reasoning over speculative criticism.
- Keep suggestions actionable and scoped to the reviewed change.
1---2name: code-review3description: Perform comprehensive software code reviews focused on correctness, regressions, security, reliability, performance, and test quality. Use when asked to review pull requests, commits, branches, patches, or source files and deliver prioritized findings with severity, concrete impact, and file/line references.4---56# Code Review78## Overview910Execute a rigorous, risk-first code review workflow and produce actionable findings.11Prioritize bugs and behavior regressions over style preferences.1213## Required Inputs1415- Review target: PR, commit range, branch diff, or specific files16- Project context: language/framework, runtime, and critical flows (if known)17- Scope constraints: full review or focused areas (security, performance, API, tests)1819If context is missing, infer from repository and changed files, then state assumptions.2021## Workflow22231. Define review boundaries.242. Build a risk map from touched components and data flows.253. Inspect code paths for correctness and regression risks.264. Validate non-functional risks (security, reliability, performance).275. Evaluate tests and observability coverage.286. Report findings ordered by severity.2930## Step 1: Define Review Boundaries3132- Read the diff first, then open surrounding code for context.33- Distinguish change types: feature, bugfix, refactor, migration, dependency bump, config-only.34- Identify high-impact zones: auth, payments, data persistence, concurrency, caching, error handling, external integrations.3536## Step 2: Build a Risk Map3738- Trace entry points to side effects:39 - API request -> validation -> business logic -> DB/queue/cache updates40 - Background job/scheduler -> idempotency/locking/retry paths41 - UI event -> API calls -> state transitions -> user-visible behavior42- Flag unsafe changes early:43 - Contract changes without versioning or migration path44 - Data model changes without backfill/migration rollback plan45 - Removed guards or authorization checks4647## Step 3: Inspect for Defects and Regressions4849Use [references/review-checklist.md](references/review-checklist.md) for a complete checklist.5051Focus on:52- Logic errors and broken invariants53- Off-by-one or boundary mistakes54- Incorrect null/empty/error handling55- Race conditions, deadlocks, and ordering issues56- Inconsistent read/write behavior and transaction boundaries57- Backward compatibility and API/schema mismatches5859Use [references/language-risk-cues.md](references/language-risk-cues.md) for language-specific bug patterns.6061## Step 4: Validate Security, Reliability, and Performance6263- Security:64 - AuthN/AuthZ enforced on all protected paths65 - Input validation and output encoding are preserved66 - Secrets and sensitive data are not exposed in logs/errors67- Reliability:68 - Retries are bounded and idempotent69 - Timeouts/circuit breakers are set for network calls70 - Failure paths avoid partial writes and silent corruption71- Performance:72 - Query counts, complexity, and N+1 risks are understood73 - Unbounded loops, allocations, or payload growth are avoided74 - Caching invalidation behavior remains correct7576## Step 5: Evaluate Tests and Operability7778- Verify tests cover changed behavior and critical failure modes.79- Confirm regressions are reproducible by tests where possible.80- Check logging, metrics, tracing, and alerting impact for changed code paths.81- Mark missing tests as findings when risk is material.8283## Severity Model8485- `P0`: Critical bug/security/data-loss risk; likely production incident.86- `P1`: High-impact correctness/reliability issue with significant user or business impact.87- `P2`: Medium-risk defect or regression risk; should be fixed before merge when practical.88- `P3`: Low-risk improvement, maintainability concern, or clarity gap.8990If uncertain, prefer lower confidence rather than inflated severity.9192## Output Contract9394Report findings first, ordered by severity, with this structure:95961. `[Px]` concise title972. Why this is a problem (impact and failure mode)983. Evidence with file and line reference994. Recommended fix direction100101Then include:102- Open questions/assumptions103- Brief change summary104- Residual risks or testing gaps105106If no material issues are found, explicitly say so and list residual risks/test gaps.107108## Review Discipline109110- Do not block on style-only issues unless explicitly requested.111- Do not invent missing context; state assumptions.112- Prefer concrete, reproducible reasoning over speculative criticism.113- Keep suggestions actionable and scoped to the reviewed change.