Skip to content

feat(abi): Idris2 model of the E0 receipt, with fixtures and a mirror test (E0-10) - #1164

Merged
hyperpolymath merged 1 commit into
mainfrom
feat/e0-10-receipt-idris2-model
Nov 15, 2026
Merged

hyperpolymath merged 1 commit into
mainfrom
feat/e0-10-receipt-idris2-model

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

What

An Idris2 model of the E0 receipt, src/Hypatia/ABI/Receipt.idr, that states and
proves the five properties of docs/design/e0-receipt.adoc section 8. The verdict
gate (scripts/check-verdicts.sh) checks it, with fixtures that it must accept and
fixtures 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.ipkg with --total and
%default total. Holes: none. Axioms and postulates: none. A grep for believe_me,
assert_total, postulate, partial, covering in the new files finds nothing.

Property Model (kernel-checked) Run time
P1 no two receipts share an event_id VERIFIED: appendRefusesDuplicate, appendFresh, appendKeepsUnique TESTED by the mirror test
P2 no claim beyond the evidence VERIFIED: verdictIsGate, verifiedHasEvidence, noVerifiedWithoutObservations, creditedSuccessIsEvidenced, withdrawnHasParent, gateNeverWithdrawn, gateSuccessInverse TESTED, with one known difference (below)
P3 a revision keeps the history VERIFIED: appendKeepsHistory, reviseKeepsHistory, reviseKeepsClaim none: no run-time code builds a revision yet (E0-07)
P4 a fill never overwrites VERIFIED: fillNeverOverwrites, fillChangesOnlyGaps, fillValueIsFromExtra, reviseNeverOverwrites none, as for P3
P5 missing_evidence is exact VERIFIED: missingIff, missingEmptyIff, receiptMissingExact TESTED over all 32 combinations of observations

Trust base: the Idris 2 kernel, and base (Data.List, Data.List.Elem,
Data.Maybe). The model uses no library DecEq: event ids are naturals with a
structural equality written in the module (a first draft used isElem and could not
be evaluated by the fixtures, so I replaced it). The Prelude's Nat literal
elaboration contains an assert_total, visible in a compiler diagnostic; it is
library trust, not a use by this module.

What the model is not

  • Not the Elixir run time. An 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.
  • Not retraction. Retraction.idr retracts by position and the run time by name.
    This module has no retraction. A withdrawal is a revision (an appended receipt with
    verdict Withdrawn and a parent), by event_id. Neither the positional nor the named
    retraction is proved, and idempotence or order-independence of a withdrawal is not
    claimed (the design says so too).
  • Not order or duplicates in missing_evidence. The model proves membership and
    emptiness. Sortedness and absence of duplicates are checked by the Nickel contract and
    the mirror test.
  • Nothing about confidence. A withdrawal of a failure row raises it.

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.

  1. P1, "refused". Receipt.write/3 of an event_id that already has a receipt writes
    nothing and returns :ok (an idempotent replay). The model answers
    Left DuplicateEventId. The ledger is unchanged in both, which is the property. If you
    want a refusal to be an error at run time, that is a decision for E0-07's replay rules.
  2. P2, build/2 is not a smart constructor. The model cannot build a verified
    receipt without a row digest and an observation, and the Nickel contract refuses one.
    But Receipt.build/2 on a hand-made verified row with no hit counts and no rescan
    returns observations == %{}. Counter-example at the run time: build(row("verified", "success"), ctx). No production entry point makes such a row: a fleet row classifies as
    verified only with before_hits > 0 and after_hits == 0 (the mirror test runs 3 x 3 x
    3 x 2 x 6 = 324 fleet records through classify_fleet_record and checks every
    verified one), a rescan-verified local row carries rescan, record_outcome/5 rewrites a
    caller's verified, and the neural path's trusted verification is nil today. But the
    guarantee is held by the callers and by the contract, not by build/2 or write/3.
    A guard in write/3 (refuse, log receipt_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 clean
    git archive of the commit.
  • Fixtures: 6 accepted, 6 refused; each property has at least one of each.
    ReceiptP2GateTable pins all 24 entries of the gate to verdict_for of
    schema/receipt.ncl. Each refusal is a false claim about one property, refused at its
    invalid declaration 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 --check and claims: pass. 53 rows (6 new).
  • mix format --check-formatted on the new test; check-uuid-v8.sh --strict on a clean
    export: exit 0; scripts/check-readme-claims.sh: pass; self-scan: the same 15
    structured_format findings as main, none on a changed file.

Mutation checks

Model (Idris), each restored byte-identical:

Mutation Result
fill prefers the new value kernel refuses (fillNeverOverwrites)
a duplicate id is accepted kernel refuses (appendRefusesDuplicate, appendKeepsUnique)
a present field is named missing kernel refuses (elemGapIfKeeps, gapIfElem)
verified needs no observation kernel refuses (credit, verifiedHasEvidence)
a row of the gate table is changed kernel accepts the module; only the new ReceiptP2GateTable fixture catches it. I added that fixture because of this result: the theorems hold of any table that never answers Withdrawn, 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, and write/3 no longer checking for an existing receipt. All five fail a test.

Not done / differences from the work order

  • The work order's file list does not include README.adoc, AFFIRMATION.adoc and
    EXPLAINME.adoc. I changed only the census phrase in each (27 proven of 47 -> 33 of 53),
    because scripts/proof-ledger.sh claims fails otherwise. No licence file or SPDX header
    is touched.
  • The Nickel contract tests need nickel, which CI does not install (the receipt contract
    tests skip loudly there). Not changed here.
  • The mirror test does not and cannot cover P3 and P4 (no run-time counterpart). It says so.

Process notes

  • scripts/api-agents/run-work-order.sh E0-10 --dry-run exits 0 and would run --agent e0-supervisor --model opus --effort high --max-budget-usd 25 --max-turns 250, which is
    what this session is.
  • Idris 2 0.7.0 was installed with 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.
  • Cost: unknown to me. I cannot see spend. Please read it in the Anthropic Console.
  • Draft. Not merged, approved or marked ready by me.

… 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>
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

Summary

Summary by CodeRabbit

  • Verification
    • Added a formal receipt model covering duplicate event IDs, verdict and evidence consistency, revision history, gap-filling without overwriting existing values, and exact tracking of missing fields.
    • Added checks for valid and invalid receipt scenarios, including the full verdict-gate combinations.
    • The proof ledger now records 33 proven obligations out of 53, up from 27 out of 47. Other proof-status counts are unchanged.

This change adds an Idris2 model of receipt verdicts, evidence, ledger appends and gap-filling revisions. It adds model proofs and tests, compares selected properties with runtime behaviour, registers the module, and updates proof-ledger records and totals.

Changes: Receipt model and proof coverage

Layer / File(s) Summary
Receipt constraints and evidence
src/Hypatia/ABI/Receipt.idr, tests/accept/ReceiptP2*, tests/accept/ReceiptP5MissingExact.idr, tests/reject/ReceiptP2*, tests/reject/ReceiptP5MissingOmitsAGap.idr, test/receipt_model_mirror_test.exs, verification/PROOF-STATUS.adoc, verification/proof-ledger.jsonl
Defines qualifications, claims, verdicts, receipt fields and constraints. Proofs cover the gate, evidence requirements and exact missing-field correspondence. Positive and expected-rejection tests exercise these properties. Mirror tests compare selected model properties with runtime code and contracts.
Unique-ID appends
src/Hypatia/ABI/Receipt.idr, tests/accept/ReceiptP1AppendDistinct.idr, tests/reject/ReceiptP1DuplicateAppended.idr, test/receipt_model_mirror_test.exs, verification/PROOF-STATUS.adoc, verification/proof-ledger.jsonl
Appends refuse duplicate event IDs and prepend receipts with fresh IDs. Proofs cover ID uniqueness and preservation of prior entries. Tests cover distinct and duplicate IDs; mirror tests also check runtime duplicate writes and invalid IDs.
Revisions and gap filling
src/Hypatia/ABI/Receipt.idr, tests/accept/ReceiptP3RevisionKeepsHistory.idr, tests/accept/ReceiptP4FillOnlyGaps.idr, tests/reject/ReceiptP3RevisionDropsHistory.idr, tests/reject/ReceiptP4FillOverwrites.idr, verification/PROOF-STATUS.adoc, verification/proof-ledger.jsonl
Revisions parent the old receipt and preserve its claim and ledger history. Filling retains existing values and fills gaps from the extra body. Positive and expected-rejection tests cover these model properties.
Package and proof-ledger integration
src/abi/hypatia-abi.ipkg, scripts/check-verdicts.sh, AFFIRMATION.adoc, EXPLAINME.adoc, README.adoc, verification/PROOF-STATUS.adoc
Registers the receipt module in the package and adds it to the escape-hatch scan. Updates the published proof totals from 27 of 47 to 33 of 53.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Other

Possibly related PRs

  • hyperpolymath/hypatia#1029: Establishes the proof ledger and census contract used by this change’s ledger entries and updated totals.
  • hyperpolymath/hypatia#1031: Changes the same proof-ledger census, so its baseline must be reconciled with this change’s totals.

Suggested reviewers: claude

Merge Risk: Moderate · up to 1f2e5

This PR adds a receipt model and proofs, with no change to runtime behavior. The proof ledger currently claims more than the checks establish: the "exact missing evidence" proof does not cover the event ID, and the gate-table "proven" status is not tied to the schema. Fix or reword these claims before merge so the verification record is accurate.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@sonarqubecloud

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath marked this pull request as ready for review November 15, 2026 14:55
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T14:57:55.097277Z 1f2e585 Draft marked ready
🔒 Security Review ✅ Completed 2026-11-15T14:58:54.623166Z 1f2e585 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@hyperpolymath
hyperpolymath merged commit 3770118 into main Nov 15, 2026
108 of 109 checks passed
@hyperpolymath
hyperpolymath deleted the feat/e0-10-receipt-idris2-model branch November 15, 2026 15:00
hyperpolymath added a commit that referenced this pull request Nov 15, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants