Skip to content

Free guide

Review generated code against business invariants

Review the patch from the point of view of a caller, a support lead and the person on call.

Why it matters

Passing syntax checks prove little about who can post a change, what happens on retry or how a historical report behaves. A product manager knows the business promises; a developer can locate where the code enforces them.

Core concepts

Read forward from a user action

Find each normal entry point. Follow the changed value through validation, persistence, downstream consumers and display. Search for all readers of a changed enum or column. A clean patch can break old clients.

Read backward from a bad outcome

Choose an unacceptable outcome such as applying the same credit twice. Locate the guard that prevents it. Ask what happens if two workers act at once or one disappears after the write. Separate a concrete finding from a hypothetical risk.

Review the data lifecycle

Consider older rows, nulls, partial imports, time zones and historical definitions. Ask whether a migration can be rerun safely and whether the outcome can be reconciled. Review tests to see whether they assert a user result or only a helper call.

Report decisions a maintainer can act on

Write a finding with a specific path, triggering condition, impact and proposed check. Distinguish release blockers from future cleanup. A second agent can inspect independent evidence, but a human still owns the merge decision.

Try it step by step

  1. State three invariants before opening the diff.
  2. Trace the most important one through old and new paths. Test one normal, one legacy and one failure case.
  3. Write a short review that prioritizes observable breakage. Verify suggested fixes against the original requirement.

Review by invariant: owner, source of truth, valid transition, duplicate prevention, historical meaning and observable failure.

Worked example

Fictional example: A table gains a new verified_at field. The patch filters historical records on verified_at being present. Existing rows were valid before that field existed. A reviewer asks for a migration strategy and reconciliation totals.

Code review prompt
Review this patch against [business invariants] and its existing callers.
Trace the changed field from entry point to persistence and reporting.
Check real risks in legacy data, concurrency, partial failures and retries.
For each finding give a path, trigger, user impact and focused regression.
Distinguish verified findings from questions. Return the review before making edits.

Common mistake

Approving because the code reads well or because a second model agreed. Independent checks need their own evidence.

Practice exercise

Draft one actionable finding for a retry that sends the same confirmation twice. Include conditions, business impact and a check that would fail on the original code.

Check your understanding

Which review comment is most actionable?

  1. Try to clean this up
  2. The filter hides old active records with null verified_at; add a legacy fixture
  3. The code seems risky
Show answer

The filter hides old active records with null verified_at; add a legacy fixture. The comment names the condition, observed outcome and a way to demonstrate a correction.

Takeaway

A valuable review names a specific way a user could get the wrong result.

Further reading

Browse more lessons