Repository navigation
feat(abi): Idris2 model of the E0 receipt, with fixtures and a mirror test (E0-10) - #1164
Conversation
… test (E0-10)
src/Hypatia/ABI/Receipt.idr (%default total, no proof-bypass primitive) states
and proves the five properties of docs/design/e0-receipt.adoc section 8:
P1 no two receipts of a ledger share an event_id (append refuses a duplicate
and keeps the ledger of distinct ids distinct)
P2 a receipt cannot claim more than its evidence (its verdict is the gate's,
or a withdrawal with a parent; a verified receipt has a row digest and an
observation; a credited success is evidenced; the gate never answers
withdrawn)
P3 a revision keeps the history
P4 a fill never overwrites; it changes only fields that were gaps
P5 missing_evidence is exact over the 14 names of the closed set
The model covers the Idris2 types, not the Elixir run time. An event_id is a
natural number with a structural equality. P3 and P4 have no run-time
counterpart yet (E0-07). The model has no retraction: a withdrawal is a
revision, so neither retraction by position nor by name is proved.
scripts/check-verdicts.sh: the module is scanned for escape hatches; the gate now
reports 11 positive controls (5 before) and 21 expected rejections (15 before).
Each property has an accepted and a refused fixture; ReceiptP2GateTable pins all
24 entries of the gate table to verdict_for of schema/receipt.ncl.
test/receipt_model_mirror_test.exs holds the emitter to P1, P2 and P5. It reads
the gate table and the field list from Receipt.idr, so the model and the test
cannot drift. It pins two differences as tests of their own: Receipt.write
returns :ok for a duplicate event_id where the model answers Left
DuplicateEventId; and Receipt.build/2 does not refuse a verified row with no
observation (the model and the Nickel contract do).
verification/proof-ledger.jsonl: six rows, each with its trust boundary. The
census quoted in README, AFFIRMATION and EXPLAINME moves from 27 of 47 to 33 of
53 (scripts/proof-ledger.sh claims).
Co-Authored-By: Claude <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. Summary
Merge Risk:
|
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…ced verified receipt (E0-29) (#1170) ## What `Receipt.write/3` now refuses what the Idris2 model of E0-10 refuses. These are the two differences that I reported on #1164, closed by your rulings of 2026-11-15: **1A** (a duplicate receipt write is an error) and **2A** (add the guard in `Receipt.write`). Work order: **E0-29**, added here with its index row (`docs/operations/e0-closeout/`). ## The change * `Receipt.write/3` returns `{:error, :duplicate_event_id}` for an `event_id` that already has a receipt, and writes nothing (the model's `Left DuplicateEventId`). It used to return `:ok`. * `Receipt.check/1`: a `verified` receipt must have at least one observation and a 64-hex row digest, else `{:error, :verified_without_evidence}`. `write/3` calls it. `build/2` is unchanged and still not a smart constructor; `check/1` is what refuses. * A refusal is logged as `receipt_refused event_id=... reason=...` (the row is stored, no receipt is written), through one helper, `Receipt.report_failure/2`, used by `OutcomeTracker`, `Receipt.repair/2` and the neural path. Any other failure stays `receipt_pending`. * The mirror test, the header comment of `Receipt.idr` and the trust boundary of the P1 and P2 ledger rows now say that the two differences are gone. ## Evidence * Before: 8 tests fail (the work order's (a) to (d) and the 4 tests that pinned the old behaviour). After: `mix test` 3544 tests, 0 failures (246 excluded). * `check-verdicts.sh` (11 / 21), `proof-ledger.sh check`, `render --check` and `claims`: pass. Only the 2 intended ledger rows changed; every other row is byte-identical. `mix format --check-formatted`, `check-readme-claims.sh`, strict UUID gate on a clean export: pass. * Mutations (each restored): duplicate no longer refused (5 fail); guard removed from `write/3` (2); `check/1` never refuses (4); observations not required (4); refusals logged as pending (2). **My first attempt at the last one did nothing**: `mix format` had re-wrapped the line that my pattern matched, so it reported 0 failures. I noticed, checked that the mutation had not applied, and reran it properly. ## Stop-and-ask findings (please read) 1. **A test of E0-09 drove a path that the guard refuses.** "A verified update on the neural path" wrote a `verified` receipt with no observation, because the neural evidence is a bare claim. Under ruling 2A that receipt is refused. I changed the test to say so: the update still reaches the coordinator, its receipt is refused and logged. I did not invent an observation for it. **It is not reachable in production today**, because `FleetDispatcher.trusted_verification/1` returns `nil`, so no neural outcome is qualified. But when a trusted source exists it must bring an observation, or its receipts stay refused. 2. **The id-collision case is now loud.** A fleet row whose producer `event_id` equals an existing receipt's id (flagged on #1165) is stored, and its receipt is now refused with `receipt_refused ... duplicate_event_id`, instead of silently getting none. Test (d) covers it. 3. **A refused `verified` row is retried every cycle.** `Receipt.repair/2` skips ids that have a receipt, but a row whose receipt the guard refuses has none, so each learning cycle tries it again and logs `receipt_refused` again. That is loud on purpose (the row is a data defect), but it is noise until the row is fixed. No production path makes such a row. 4. **The caller that relied on `:ok`?** None: `persist_outcome` mints a fresh id for each row, the import skips by its seen set before it writes, and `repair/2` checks first. ## Not done * The Nickel contract tests still skip in CI where `nickel` is absent (the CI step is a separate PR). * `build/2` is not a smart constructor. Making it one would change its return type for every caller; I did not. ## Process notes * `scripts/api-agents/run-work-order.sh E0-29 --dry-run` exits 0 (Sonnet, medium effort, cap USD 8). This session was switched to Opus 5.5 at high effort; I did not choose that. * **Cost: unknown to me**; please read it in the Anthropic Console. * Draft. Not merged, approved or marked ready by me. Co-authored-by: Claude <noreply@anthropic.com>



What
An Idris2 model of the E0 receipt,
src/Hypatia/ABI/Receipt.idr, that states andproves the five properties of
docs/design/e0-receipt.adocsection 8. The verdictgate (
scripts/check-verdicts.sh) checks it, with fixtures that it must accept andfixtures that it must refuse. A mirror test holds the emitter of E0-09 to the model.
Work order: E0-10. Depends on E0-09 (merged, #1161).
Status of each property (machine register)
Kernel: Idris 2 0.7.0,
idris2 --build src/abi/hypatia-abi.ipkgwith--totaland%default total. Holes: none. Axioms and postulates: none. A grep forbelieve_me,assert_total,postulate,partial,coveringin the new files finds nothing.event_idappendRefusesDuplicate,appendFresh,appendKeepsUniqueverdictIsGate,verifiedHasEvidence,noVerifiedWithoutObservations,creditedSuccessIsEvidenced,withdrawnHasParent,gateNeverWithdrawn,gateSuccessInverseappendKeepsHistory,reviseKeepsHistory,reviseKeepsClaimfillNeverOverwrites,fillChangesOnlyGaps,fillValueIsFromExtra,reviseNeverOverwritesmissing_evidenceis exactmissingIff,missingEmptyIff,receiptMissingExactTrust base: the Idris 2 kernel, and
base(Data.List,Data.List.Elem,Data.Maybe). The model uses no libraryDecEq: event ids are naturals with astructural equality written in the module (a first draft used
isElemand could notbe evaluated by the fixtures, so I replaced it). The Prelude's Nat literal
elaboration contains an
assert_total, visible in a compiler diagnostic; it islibrary trust, not a use by this module.
What the model is not
event_id, a digest and a field value are naturals.The real values are ADR-008 strings. The ledger row of each property says so.
Retraction.idrretracts by position and the run time by name.This module has no retraction. A withdrawal is a revision (an appended receipt with
verdict
Withdrawnand a parent), byevent_id. Neither the positional nor the namedretraction is proved, and idempotence or order-independence of a withdrawal is not
claimed (the design says so too).
missing_evidence. The model proves membership andemptiness. Sortedness and absence of duplicates are checked by the Nickel contract and
the mirror test.
Two differences between the model and the run time (please rule)
The stop rule of the work order says to report a property that does not hold, and not
to weaken it. I have not weakened anything. Both are pinned as tests of their own, so a
change is noticed.
Receipt.write/3of anevent_idthat already has a receipt writesnothing and returns
:ok(an idempotent replay). The model answersLeft DuplicateEventId. The ledger is unchanged in both, which is the property. If youwant a refusal to be an error at run time, that is a decision for E0-07's replay rules.
build/2is not a smart constructor. The model cannot build averifiedreceipt without a row digest and an observation, and the Nickel contract refuses one.
But
Receipt.build/2on a hand-madeverifiedrow with no hit counts and no rescanreturns
observations == %{}. Counter-example at the run time:build(row("verified", "success"), ctx). No production entry point makes such a row: a fleet row classifies asverifiedonly withbefore_hits > 0andafter_hits == 0(the mirror test runs 3 x 3 x3 x 2 x 6 = 324 fleet records through
classify_fleet_recordand checks everyverifiedone), a rescan-verified local row carriesrescan,record_outcome/5rewrites acaller's
verified, and the neural path's trusted verification isniltoday. But theguarantee is held by the callers and by the contract, not by
build/2orwrite/3.A guard in
write/3(refuse, logreceipt_pending) is about ten lines. I did not add it:E0-10 is the model, and what a refused receipt does to the repair loop is your call.
Evidence
bash scripts/check-verdicts.sh:PASS: ABI package, 11 positive control(s), 21 expected rejection(s). Before: 5 and 15, as the work order measured. Also run from a cleangit archiveof the commit.ReceiptP2GateTablepins all 24 entries of the gate toverdict_forofschema/receipt.ncl. Each refusal is a false claim about one property, refused at itsinvaliddeclaration with a recorded diagnostic.mix test: 3487 tests, 0 failures (246 excluded).test/receipt_model_mirror_test.exs:12 tests, in the run. Elixir 1.19.4 (see process notes).
scripts/proof-ledger.sh check,render --checkandclaims: pass. 53 rows (6 new).mix format --check-formattedon the new test;check-uuid-v8.sh --stricton a cleanexport: exit 0;
scripts/check-readme-claims.sh: pass; self-scan: the same 15structured_formatfindings asmain, none on a changed file.Mutation checks
Model (Idris), each restored byte-identical:
fillNeverOverwrites)appendRefusesDuplicate,appendKeepsUnique)elemGapIfKeeps,gapIfElem)verifiedneeds no observationcredit,verifiedHasEvidence)ReceiptP2GateTablefixture catches it. I added that fixture because of this result: the theorems hold of any table that never answersWithdrawn, and the table itself was not pinned.Mirror test, each restored: an Idris gate row changed, a field dropped from
allFields,the emitter no longer crediting false positives, the emitter no longer naming
tool_version, andwrite/3no longer checking for an existing receipt. All five fail a test.Not done / differences from the work order
README.adoc,AFFIRMATION.adocandEXPLAINME.adoc. I changed only the census phrase in each (27 proven of 47 -> 33 of 53),because
scripts/proof-ledger.sh claimsfails otherwise. No licence file or SPDX headeris touched.
nickel, which CI does not install (the receipt contracttests skip loudly there). Not changed here.
Process notes
scripts/api-agents/run-work-order.sh E0-10 --dry-runexits 0 and would run--agent e0-supervisor --model opus --effort high --max-budget-usd 25 --max-turns 250, which iswhat this session is.
scripts/dev/install-toolchain.sh --with-idris2(the pinned, checksum-verified source build). That script also moved the local Elixir
from 1.17.3 to 1.19.4 (its current pin, which is CI's); the format gate now matches CI.