-
example of The Contract Keystone
No Duck Left Behind
Hook
a deterministic duck census rejects one manifest and turns its errors into a bounded redispatch
Thesis
A deterministic duck census at the return seam rejects a manifest that merely looks complete, returns bounded clause errors, and re-dispatches with those errors, so the receiver never authors a duck assignment.
Laws & fences
- Reconstruct the keystone at the return seam: the spec names the exact CSV shape and every supplied duck exactly once, the assertion is a deterministic census that returns bounded clause errors, and recovery rejects the manifest and re-dispatches with those errors.
- Letting the coordinator patch the manifest makes the receiver a second sorter that must invent the missing duck's assignment and choose which duplicate row to preserve; the whole candidate is rejected instead.
- The census can name a missing duck and a duplicated duck without deciding where either duck belongs; it proves only the mechanically expressible clauses, not that Moby Duck belongs on shore crew or that Professor Waddles deserves ceremonial duty.
When to reach
- Reach for it when a return looks plausible, every row recognizable and fluent, but nothing at the seam distinguishes a complete manifest from one that merely looks complete.
- Skip it for whether every useful semantic clause was captured or whether redispatch is allowed after external effects; those are Verification Asymmetry and Effect Discipline questions, and neither is part of this example.
-
The Contract Keystone
The annual bathtub parade has twelve rubber ducks and three flotillas. Each
duck arrives with a short biography; a model assigns every duck to
adventure_crew, shore_crew, or ceremonial_crew and gives a reason.
Three specimens establish the tone:
D-03 Moby Duck enormous, dramatic, afraid of deep water
D-07 Professor Waddles wears spectacles and audits breadcrumbs
D-11 Quack Sparrow tiny hat, unreliable around crackers
The complete roster lives in ducks.py. The sorter is represented
by a frozen two-attempt fixture so the failure and recovery remain
reproducible; the seam machinery around it
is executable.
The first manifest looks plausible. Every row has a recognizable duck, a valid flotilla, and a fluent reason. But Professor Waddles is absent and Moby Duck appears twice:
duck_id,flotilla,reason
D-03,shore_crew,Afraid of deep water
D-03,ceremonial_crew,Has undeniable stage presence
The receiver cannot repair the omission. It can see that D-07 is missing,
but choosing Professor Waddles's flotilla requires interpreting the biography
the sorter was asked to judge.
Reconstruct the keystone at this return seam:
spec: exact CSV shape + every supplied duck exactly once
assertion: deterministic census returns bounded clause errors
recovery: reject the manifest and re-dispatch with those errors
The nearest alternative is to let the parade coordinator patch the manifest. That makes the receiver a second sorter: it must invent Professor Waddles's assignment and choose which Moby Duck row to preserve. This example rejects the whole candidate instead.
The baseline stops after declaration:
duck biographies ──▶ sorter instructed to return CSV ──▶ coordinator trusts it
The contract is legible, but nothing at the seam distinguishes a complete manifest from one that merely looks complete. A twelve-row file can still contain eleven ducks.
The single structural shift is inserting an enforcing return seam whose failure has a declared recovery.
Spec
contract.py owns the mechanically expressible clauses:
EXPECTED_HEADER = ("duck_id", "flotilla", "reason")
ALLOWED_FLOTILLAS = frozenset(
{"adventure_crew", "shore_crew", "ceremonial_crew"}
)
MAX_ERRORS = 3
Every supplied duck_id must appear exactly once, every flotilla must come
from the allowlist, and every reason must be non-empty.
Assertion
checker.py parses the return, checks its exact header and field
rules, then compares the returned ID multiset with the supplied roster. The
first attempt produces a bounded report in contract vocabulary:
missing duck_id: D-07 Professor Waddles
duplicate duck_id: D-03 Moby Duck
The census can name both violations without deciding where either duck belongs.
Recovery
demo.py rejects that candidate and invokes the same sorting task
again with the two errors. The fresh return contains one row for Professor
Waddles and one for Moby Duck:
duck_id,flotilla,reason
D-03,shore_crew,Afraid of deep water
D-07,ceremonial_crew,Can audit the breadcrumb budget
The checker returns no errors, so the seam accepts the manifest. The receiver never authors a duck assignment.
The same roster and the same contract produce two candidates separated by one assertion:
attempt 1 ──▶ REJECT: D-07 missing; D-03 duplicated
│
└── bounded error report ──▶ fresh attempt
attempt 2 ──▶ ACCEPT: twelve ducks, twelve rows, twelve unique IDs
The declaration became operational. A failed clause now selects a defined recovery instead of becoming an inconsistency the coordinator works around.
Run the example from its directory:
python3 demo.py
The script asserts that the first return fails for exactly one missing and one duplicated duck, its report stays under the three-error bound, the sorter is invoked again rather than repaired by the receiver, and the second return passes. The checker is deterministic: the same roster, bytes, and contract produce the same verdict.
This proves only the clauses expressed in contract.py. It does
not prove that Moby Duck belongs on shore crew, that Professor Waddles deserves
ceremonial duty, or that every useful semantic clause was captured. It also
does not license redispatch after
external effects. Those are Verification Asymmetry and Effect Discipline
questions; neither is part of this example.
No duck left behind; no duck counted twice. The spec names the acceptable crossing, the assertion distinguishes a candidate from it, and recovery gives rejection somewhere to go.
Rubber ducks are furniture. The three-role loop travels to ticket manifests, batch classifications, generated files, and return envelopes. What matters is that the assertion speaks the contract's clauses and that failure selects recovery at the seam.
The relationships ledger
Evidence-bearing references
Relationships
Every connection keeps the section where it was found. The map above orients; this ledger carries the evidence.
Outbound references 0
- No outbound references.
Inbound references 2
-
in-slice · occurrence 1
The Contract Keystone
a deterministic duck census rejects one manifest and turns its errors into a bounded redispatch
Evidence: Evidence · occurrence 1
-
in-slice · occurrence 1
The Contract Keystone
a deterministic duck census rejects one manifest and turns its errors into a bounded redispatch
Evidence: Examples · occurrence 1
↑ back to the top ← the survey
Node no-duck-left-behind · corpus 31de4cb · Catalog revision 35263c4c415da742953d0462804fb14424e2244dae4c63efd27e468988de70ab