Stop burning the sprint in the dark: the contract that comes before the code

By William Pereira ·

The request arrives incomplete: “do the export”. Someone implements it. Then the demo surfaces the questions that should have come first — limits, permissions, failures. The code wasn't badly wrong; the contract never existed.

Fail-closed discovery is a simple idea: a change only enters “ready to build” when the rules, criteria and test scenarios pass a mechanical gate. If the gate fails, you refine the request — you don't promote it “so we can keep moving”.

This holds with or without AI. With AI, the cost of generating code went down; the cost of generating the wrong thing is still high. Without a contract, you're only speeding up rework.

With a contract vs without one

No explicit contractWith fail-closed discovery
InputA sentence in the team chatRules + acceptance criteria + testable scenarios
Definition of doneA subjective demoFalsifiable scenarios
When rework shows upMid-implementationIn the request lint
Handoff“Check the history”A canonical record the whole team reads the same way
SpikesMixed into deliveryExplicit: outside the gate or converted afterwards
Flow: the request goes through the contract gate; if it fails, it is refined; if it passes, implementation and demo
Fail-closed discovery: the gate decides whether the request is ready to build.

What the literature helps justify

The classic cost-of-change curve, popularized by Barry Boehm, points in the same direction: requirement defects found late tend to cost far more than those fixed near their origin. Steve McConnell sums up the industrial intuition — prevention early — and discusses the high ranges reported in industry for requirements that escape into the field, always with the caveat that the multiplier depends on context.

Boehm and Victor Basili, revisiting the topic, added nuance: in small, non-critical systems the ratio can be much lower than the “always a hundred times” myth. The direction, however, remains: failing early is cheaper than failing in the demo. Useful reads: An Ounce of Prevention (McConnell) and Boehm and Basili's article on defect reduction (“Software defect reduction top 10 list”).

This doesn't require waterfall or a hundred-page document. It requires a minimal falsifiable artifact before you spend the sprint — the opposite of an endless specification and the opposite of “the code is the specification”.

Pros

  • PO, TL and dev discuss the same text.
  • Ambiguity rework moves to the start, where it's cheaper.
  • Bugs and chores can take lighter tracks; ambiguous features pay for the full gate.
  • The mechanical gate takes “it's almost ready” out of the conversation.

Cons

  • Writing good rules costs upfront time.
  • A weak gate (cosmetic fields) turns into theater.
  • Political urgencies will hate the “it didn't pass” — you need leadership sponsorship.
  • Teams that never practiced acceptance criteria will find the lint “bureaucratic” at first.

In practice

Define a short template: type, severity, business rules, acceptance criteria and a list of tests in “given → result” format. A script or a human checklist fails if a field is missing or if medium severity doesn't have the minimum number of scenarios. Only then do you open a branch.

A mental example: “filter by date in the listing” without a contract leaves timezone and interval inclusivity to the demo. With a contract, that's written down and has at least one error scenario. Half-day spikes can stay outside the gate — as long as the team admits, out loud, that there's no contract yet.

If you want to see an open source implementation of these patterns — one I maintain and use day to day — the repo is at github.com/pereirawe/codex-flow.

Back to blog