pattern Commons

Share pattern

Share the full pattern page.

Private · saved on this device

Establish Independent Checks

Ground expected behavior in defensible requirements and references so checks can challenge the implementation that produced them.

Purpose and problem

An agent implements an importer, records its output as a snapshot, and gets a green result. Existing stock has vanished. The snapshot agrees with the implementation because the implementation supplied both sides of the comparison.

Establish Independent Checks gives expected behavior a defensible source. The question is not whether an agent wrote the tests; it is whether those tests can contradict the implementation for a reason grounded in the intended behavior.

Core idea

A test oracle is the basis for deciding whether observed behavior is acceptable. Barr and colleagues’ survey describes the challenge of distinguishing correct from incorrect behavior and sources including specifications, contracts, and human domain knowledge.

Separate the source of the expected answer from the code producing the observed answer. Independence here concerns reasoning and evidence provenance, not a guarantee of statistical independence between authors or models. A second model can repeat the same mistaken assumption. The same agent can write a useful check when it derives the expectation from a reviewed contract rather than copying its output.

How it works

Establish the expectation before accepting the output

For a material claim, retain the rule, input and initial state, expected outcome, derivation, and actual observation. Choose an oracle suitable for the property:

Oracle source What needs inspection
Agreed requirement or interface contract Does it resolve the relevant case and identify the responsible decision?
Independent reference calculation Is the calculation simpler, and does it avoid the implementation’s algorithm?
Trusted fixture or reference implementation Where did its expected values come from, and does its contract match?
Invariant or input-output relation Could a wrong or constant result also satisfy this weaker property?

Check the oracle itself. A fixture generated by an old implementation can preserve an old defect. A hand calculation can contain arithmetic errors. A snapshot can be useful when its contents were deliberately reviewed against the requirement; blindly accepting a snapshot update establishes only agreement with the new output.

Google’s review guidance asks reviewers to assess test correctness and whether a broken implementation would fail. Challenge an important check with a known wrong result or the prior bug. Test setup failure, a missing dependency, or an assertion that never executes is not a reproduced product failure.

Review changes to the judge as well as the code

For a bug, reproduce the stated mismatch before repair, then run the same case and expectation afterward. Keep initial state, input, relevant configuration, and assertions constant; identify the old and new source versions and the changed implementation. Retain the outputs and the reason the earlier assertion failed.

Inspect expectation changes, newly skipped cases, reduced assertion scope, swallowed failures, and widened tolerances. A legitimate requirement update needs an explicit rationale, an authorized decision, and corresponding fixtures and compatibility review. Otherwise, making the check agree with the implementation removes its ability to challenge the mistake.

Keep implementation and its meaningful regression check reviewable together. Record source revision, test/fixture identity, environment, and execution result; a moving branch name does not identify what passed. After integration changes the code or dependencies, reassess the affected evidence. Preserve other contributors’ work when evaluating an earlier version.

GitHub’s agent application card calls for reviewing and testing generated code and verifying review feedback. That product guidance supports scrutiny, not a claim that another AI reviewer creates an independent oracle.

Worked examples

These cases are fictional. Small reference models and exact decimal calculations verify the stated results; they do not exercise a production importer, database, or coding agent.

A snapshot preserves the importer’s mistake

The create-only import contract is explicit: valid new SKUs are added, existing stock is retained, and invalid files change nothing. Initial inventory is P100: 4. This valid CSV introduces two different products:

sku,quantity
P201,3
P202,2

An engineer derives the expected inventory from the requirement before accepting the implementation’s output:

SKU Initial Imported Expected afterward
P100 4 — 4
P201 absent 3 3
P202 absent 2 2

The expected total is 4 + 3 + 2 = 9, but the individual entries also matter: a wrong allocation can preserve a total. A faulty implementation replaces the inventory map with the imported rows, yielding only P201: 3, P202: 2, total 5.

If the agent saves that output as the approved snapshot and reruns the same implementation, the comparison passes. Comparing it with the independently derived full map fails because P100 is missing. The intervention is to retain the expected map’s derivation and inspect the write behavior, not regenerate the snapshot from the faulty result.

The reference calculation exposes this omission. It does not establish atomic database updates, concurrent-write safety, or correct behavior for every CSV dialect.

The same initial inventory and CSV feed a faulty replacement implementation. Its output copied into a snapshot agrees with itself, while a separate requirement-derived fixture expects P100 to remain and rejects the missing entry.
Fictional importer and checked reference calculation. The requirement supplies the expected map independently of the implementation output. Total 9 is a supporting check, not a substitute for the SKU-level comparison; a self-derived snapshot can pass with stock missing.Open the visual for full detail.

Hold the duplicate case constant across the repair

The same contract rejects a repeated SKU within a file before any inventory write. Start again with only P100: 4, and use P201,3 followed by P201,2. The fixed expectation is rejection with {row: 2, code: "duplicate_sku"}, unchanged inventory, and zero write calls in the reference store.

Fictional reference version D0 collapses rows into a map before validating duplicates. The last P201 value wins, so the model accepts the file and writes P201: 2. The regression check fails on the intended behavior, rather than on an inability to load the test.

Reference version D1 finds repeated identifiers while their original row positions remain available and returns the error before calling the writer:

Same case and oracle D0: collapse first D1: validate first
Result accepted rejected
Issues none row 2: duplicate_sku
Inventory P100: 4; P201: 2 P100: 4
Write calls 1 0
Fixed regression assertion FAIL PASS

These outputs are reproduced by the executable teaching models. Checking only the returned error would miss an implementation that reports rejection after writing. The check therefore inspects the reference store as well as the response. The regression belongs with the correction in review; D0 and D1 are illustrative versions, not actual repository commits. A real importer still needs its storage path and failure behavior verified.

The same duplicate CSV, initial P100 stock, and rejection oracle are retained across fictional D0 and D1. D0 collapses duplicates, accepts, and writes once; D1 validates first, returns the row-2 error, retains inventory, and writes zero times.
Executed teaching-model comparison, not a production regression run. Only the duplicate-handling approach changes. The fixed assertions fail on D0 and pass on D1, including response, final inventory, and reference-store write calls; storage transactions remain outside this model.Open the visual for full detail.

A looser tolerance accepts the same wrong result

A separate display contract ROUND-1 requires two decimal places with nearest rounding and ties away from zero. Input 2.345 must display 2.35. An implementation instead uses ties-to-even and produces 2.34. Python’s Decimal rounding documentation distinguishes these modes; exact decimal reference calculations confirm the difference.

The absolute error is 0.01. An agent widens the comparison without changing the output:

Fixed output 2.34; expected 2.35 Outcome
Exact formatted value required by ROUND-1 FAIL
Absolute error ≤ 0.005 FAIL
Absolute error ≤ 0.02 PASS

The last result establishes satisfaction of the relaxed comparator, not correct rounding. Even the earlier tolerance was an indirect way to test an exact display contract. The reviewer asks whether ROUND-1 changed. If it did not, restore the meaningful assertion and correct the implementation. If the responsible owner deliberately adopts ties-to-even, record a new contract version, review affected behavior, and derive expectations from that decision. Output alone cannot authorize the change.

For approximate numerical algorithms, tolerances can be legitimate, but need task-based absolute or relative error bounds, units, and boundary cases. This display example does not prescribe equality for every floating-point computation.

Input 2.345, expected 2.35, and actual 2.34 remain fixed. Exact comparison and tolerance 0.005 fail; widening tolerance to 0.02 passes the unchanged output, although ROUND-1 still requires 2.35.
Exact decimal reference values; inclusive absolute-error comparisons. Only the acceptance predicate changes. A passing wider tolerance does not correct the fixed implementation result or authorize a rounding-policy change.Open the visual for full detail.

Assumptions for correctness

The requirement must be sufficiently clear and the oracle applicable to the tested version. Inputs, assertions, and observations must actually reach the relevant behavior. Independent derivations can still share omissions; inspect disagreements rather than automatically trusting either source. Finite examples reveal defects within their scope and cannot prove their absence elsewhere.

When to use it

Use this pattern when an agent supplies implementation and tests, a bug fix arrives already green, expectations change alongside code, or numeric tolerances determine acceptance. It is equally useful for human-authored code whose checks inherit its assumptions.

Tradeoffs and operating costs

Maintaining separate derivations, curated fixtures, and reference calculations costs effort. Full reference implementations can duplicate complexity and defects; prefer simple checks for consequential properties. Resolve ambiguity through a product or contract decision instead of multiplying tests with conflicting expectations.

Common mistakes and limitations

Coverage measures execution, not oracle validity. A second model’s agreement, a passing total, or an updated snapshot can miss the same defect. Skipping an unstable check requires a visible reason and retained obligation. A passing regression can close a bounded repair task while product acceptance, the team’s Definition of Done, integration, and release still need their own evidence. Incorporate these distinctions into existing review and backlog work; no new ceremony is required.

Related patterns

Specify Outcomes with Examples is a local draft defining intended behavior. This article establishes how checks derive and challenge their expected results.

Agree on Done is a local draft separating completion claims and obligations; independent checks supply evidence for specific claims.

Steer Through Evidence is a local draft selecting observations that change direction. This pattern scrutinizes the basis for judging those observations.

Behavioral Testing is a published model-evaluation pattern using capability-specific cases and relations; this article addresses software test-oracle provenance and regression evidence.

Sources and further reading