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 contract | With fail-closed discovery | |
|---|---|---|
| Input | A sentence in the team chat | Rules + acceptance criteria + testable scenarios |
| Definition of done | A subjective demo | Falsifiable scenarios |
| When rework shows up | Mid-implementation | In the request lint |
| Handoff | “Check the history” | A canonical record the whole team reads the same way |
| Spikes | Mixed into delivery | Explicit: outside the gate or converted afterwards |
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.