From 820c1c7c36983508c5a297e7a16a69d657e36625 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 17:46:55 +0000 Subject: [PATCH] fix(receipt): the writer refuses a duplicate event_id and an unevidenced verified receipt (E0-29) Two differences between the running writer and the Idris2 model of E0-10 are closed, by owner rulings 1A and 2A of 2026-11-15. * Receipt.write/3 returns {:error, :duplicate_event_id} for an event_id that already has a receipt, and writes nothing. Before, it returned :ok. (P1: the model's `Left DuplicateEventId`.) * Receipt.check/1 refuses a verified receipt that has no observation or no row digest, and write/3 calls it: {:error, :verified_without_evidence}. build/2 is still not a smart constructor; check/1 is what refuses. (P2: the model cannot build one, and schema/receipt.ncl refuses it.) * A refusal is logged as receipt_refused (the row is stored, no receipt is written), through one helper, in the three callers; any other failure stays receipt_pending. A producer event_id that collides with an existing receipt is now loud instead of silently getting no receipt. The neural path's evidence has no observation, so a verified neural receipt is now refused until its trusted source brings one; the update still reaches the coordinator. No trusted source exists yet (trusted_verification/1 is nil). Adds work order E0-29 and its index row. The mirror test, the header comment of Receipt.idr and the trust boundary of the P1 and P2 ledger rows say that the two differences are gone. Co-Authored-By: Claude --- docs/operations/e0-closeout/README.adoc | 1 + .../E0-29-receipt-write-refusals.adoc | 77 ++++++++++++ lib/fleet_dispatcher.ex | 2 +- lib/hypatia/receipt.ex | 57 +++++++-- lib/outcome_tracker.ex | 4 +- src/Hypatia/ABI/Receipt.idr | 10 +- test/receipt_model_mirror_test.exs | 40 +++--- test/receipt_test.exs | 116 ++++++++++++++++-- verification/PROOF-STATUS.adoc | 4 +- verification/proof-ledger.jsonl | 4 +- 10 files changed, 267 insertions(+), 48 deletions(-) create mode 100644 docs/operations/e0-closeout/work-orders/E0-29-receipt-write-refusals.adoc diff --git a/docs/operations/e0-closeout/README.adoc b/docs/operations/e0-closeout/README.adoc index bf6e646b..0b363c0f 100644 --- a/docs/operations/e0-closeout/README.adoc +++ b/docs/operations/e0-closeout/README.adoc @@ -124,6 +124,7 @@ function name is the stable locator. Measure again before you edit. |E0-26 |The rescan judges a fix by its category and its file |S |sonnet |$8 |none |E0-27 |Only BatchRollback can record a rollback_requested row |S |sonnet |$5 |none |E0-28 |Cross-repo transfer is smoothed and anomalies report false positives |M |sonnet |$8 |none +|E0-29 |The receipt writer refuses what the model refuses |S |sonnet |$8 |none |=== The caps of `E0-01` to `E0-17` add up to $151. The estimate for that diff --git a/docs/operations/e0-closeout/work-orders/E0-29-receipt-write-refusals.adoc b/docs/operations/e0-closeout/work-orders/E0-29-receipt-write-refusals.adoc new file mode 100644 index 00000000..04fe7a61 --- /dev/null +++ b/docs/operations/e0-closeout/work-orders/E0-29-receipt-write-refusals.adoc @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 +// Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) += E0-29: The receipt writer refuses what the model refuses +:wo-id: E0-29 +:wo-repo: hyperpolymath/hypatia +:wo-size: small +:wo-agent: e0-executor +:wo-model: sonnet +:wo-effort: medium +:wo-cap-usd: 8 +:wo-max-turns: 140 +:wo-branch: fix/e0-29-receipt-write-refusals +:wo-depends: none + +== Goal + +`Receipt.write/3` answers an error for an `event_id` that already has a receipt, and +refuses to write a `verified` receipt that has no observation. These are the two +differences between the running writer and the Idris2 model of `E0-10` that the owner +has ruled on. + +== Authority + +Owner rulings of 2026-11-15 on the review of the pull request of `E0-10` (pull request +1164): 1A, "a duplicate receipt write returns an error"; and 2A, "add the guard in +`Receipt.write`". Related: `docs/design/e0-receipt.adoc`, section 8 (P1 and P2). + +== Facts measured + +Commit `4de4d69f`, measured on 2026-11-15 on a clean tree. + +* Read: `lib/hypatia/receipt.ex`, `write/3`: when `exists?/2` is true the `with` falls to + `true -> :ok`, so a second write for the same `event_id` writes nothing and returns `:ok`. + The model answers `Left DuplicateEventId` (`append` in `src/Hypatia/ABI/Receipt.idr`). +* Read: `build/2` always sets `proof_or_test_ref.row_sha256` and sets `observations` only + from the row. A `verified` row with no hit counts and a source other than a rescan gives + `observations == %{}`. The model cannot build it (`verifiedOk`) and `schema/receipt.ncl` + refuses it. `test/receipt_model_mirror_test.exs` pins both differences as known differences. +* Read: callers of `Receipt.write/3`: `OutcomeTracker.write_receipt/2` and + `Receipt.repair/2` (which checks `exists?/2` first) log `receipt_pending` on an error, and + `FleetDispatcher.write_neural_receipt/4` does the same. +* Read: no production entry point makes a `verified` row without observations (the mirror + test runs every fleet classification). + +== Steps + +. Measure the facts again. Stop if one no longer holds. +. Write the tests first: (a) a second `write/3` for an `event_id` returns + `{:error, :duplicate_event_id}` and the receipt log is unchanged; (b) `check/1` refuses a + `verified` receipt with no observation and accepts one with an observation and a row + digest, and accepts a receipt that is not `verified`; (c) `write/3` returns + `{:error, :verified_without_evidence}` for such a row and writes nothing; (d) a fleet row + whose producer `event_id` is the id of an existing receipt is stored, its receipt is + refused, and the log says `receipt_refused` and not `receipt_pending`. See them fail. +. Add `Receipt.check/1`. Make `write/3` return the two errors, and stop returning `:ok` for a + duplicate. +. Name a refusal in the log as `receipt_refused`, with the `event_id` and the reason, in the + three callers. A write that failed for another reason stays `receipt_pending`. +. Change the tests that pinned the two differences. Update the trust-boundary text of the P1 + and P2 rows of `verification/proof-ledger.jsonl`, the header comment of + `src/Hypatia/ABI/Receipt.idr` and the module doc of the mirror test. Run + `scripts/proof-ledger.sh check` and `render --write`, and `scripts/check-verdicts.sh`. + +== Acceptance + +* The new tests pass, and (a) to (d) failed before step 3. Give both outputs. +* `mix test` has 0 failures. No file that was formatted before the change is unformatted after it. +* A mutation check: remove the duplicate refusal and test (a) fails; remove the guard and + tests (b) and (c) fail. +* `scripts/check-verdicts.sh`, `scripts/proof-ledger.sh check` and `render --check` pass. + +== Stop and ask + +* A caller relies on `:ok` for a duplicate. +* A production path makes a `verified` row without an observation. Report it and do not + guard it away. +* The cost reaches the cap before the acceptance checks pass. diff --git a/lib/fleet_dispatcher.ex b/lib/fleet_dispatcher.ex index 4253e199..4dde0970 100644 --- a/lib/fleet_dispatcher.ex +++ b/lib/fleet_dispatcher.ex @@ -734,7 +734,7 @@ defmodule Hypatia.FleetDispatcher do :ok else {:error, reason} -> - Logger.warning("receipt_pending event_id=#{event_id} reason=#{inspect(reason)}") + Hypatia.Receipt.report_failure(event_id, reason) end rescue error -> diff --git a/lib/hypatia/receipt.ex b/lib/hypatia/receipt.ex index dd2ad601..ae78a686 100644 --- a/lib/hypatia/receipt.ex +++ b/lib/hypatia/receipt.ex @@ -318,8 +318,14 @@ defmodule Hypatia.Receipt do end @doc """ - Write the receipt of a stored row, once. A second call for the same `event_id` - writes nothing and returns `:ok` (a replay writes no second receipt). + Write the receipt of a stored row, once. It refuses, and writes nothing, in the two + cases that the Idris2 model of `src/Hypatia/ABI/Receipt.idr` refuses (E0-29, owner + rulings 1A and 2A): + + * `{:error, :duplicate_event_id}`: the `event_id` already has a receipt (P1; the + model's `Left DuplicateEventId`). A replay writes no second receipt, and says so. + * `{:error, :verified_without_evidence}`: the receipt is `verified` and has no + observation or no row digest (P2; see `check/1`). `row` is the row as the log holds it. For a row of the local outcome log the row is looked up by its `event_id` (`{:error, :row_not_in_log}` if it is not there: @@ -329,17 +335,54 @@ defmodule Hypatia.Receipt do @spec write(String.t(), map(), keyword()) :: :ok | {:error, term()} def write(data_root, row, opts \\ []) when is_binary(data_root) and is_map(row) do with {:ok, event_id} <- fetch_event_id(row), - false <- exists?(data_root, event_id), + :ok <- not_yet_written(data_root, event_id), {:ok, ctx} <- context(data_root, row, opts), receipt = build(row, ctx), + :ok <- check(receipt), {:ok, line} <- encode(receipt) do append(data_root, line) - else - true -> :ok - {:error, _reason} = error -> error end end + defp not_yet_written(data_root, event_id) do + if exists?(data_root, event_id), do: {:error, :duplicate_event_id}, else: :ok + end + + @doc """ + A receipt cannot claim more than its evidence (P2 of the design). A `verified` + receipt must have at least one observation and a row digest; the Nickel contract of + `schema/receipt.ncl` and the model's `verifiedOk` say the same. `build/2` builds + whatever the row gives; this is what refuses it before it is written. + """ + @spec check(map()) :: :ok | {:error, :verified_without_evidence} + def check(%{"qualification" => "verified"} = receipt) do + observations = Map.get(receipt, "observations") + digest = get_in(receipt, ["proof_or_test_ref", "row_sha256"]) + + if is_map(observations) and map_size(observations) > 0 and is_binary(digest) and + Regex.match?(~r/\A[0-9a-f]{64}\z/, digest), + do: :ok, + else: {:error, :verified_without_evidence} + end + + def check(receipt) when is_map(receipt), do: :ok + + @doc false + # Say what happened to a receipt that was not written. A refusal is final for that + # receipt (the row is stored and the log says why); any other failure is pending and + # is written when the recipe is next recomputed. + def report_failure(event_id, reason) + when reason in [:duplicate_event_id, :verified_without_evidence] do + Logger.warning( + "receipt_refused event_id=#{event_id} reason=#{inspect(reason)}: the row is stored; " <> + "no receipt is written for it" + ) + end + + def report_failure(event_id, reason) do + Logger.warning("receipt_pending event_id=#{event_id} reason=#{inspect(reason)}") + end + defp fetch_event_id(row) do case Map.get(row, "event_id") do id when is_binary(id) -> @@ -476,7 +519,7 @@ defmodule Hypatia.Receipt do {written + 1, failed} {:error, reason} -> - Logger.warning("receipt_pending event_id=#{id} reason=#{inspect(reason)}") + report_failure(id, reason) {written, failed + 1} end end diff --git a/lib/outcome_tracker.ex b/lib/outcome_tracker.ex index 3d1fec27..1c44ee12 100644 --- a/lib/outcome_tracker.ex +++ b/lib/outcome_tracker.ex @@ -376,9 +376,7 @@ defmodule Hypatia.OutcomeTracker do :ok {:error, reason} -> - Logger.warning( - "receipt_pending event_id=#{Map.get(record, "event_id")} reason=#{inspect(reason)}" - ) + Hypatia.Receipt.report_failure(Map.get(record, "event_id"), reason) end rescue error -> diff --git a/src/Hypatia/ABI/Receipt.idr b/src/Hypatia/ABI/Receipt.idr index 2e649944..4e1531bb 100644 --- a/src/Hypatia/ABI/Receipt.idr +++ b/src/Hypatia/ABI/Receipt.idr @@ -33,10 +33,12 @@ -- NAME. This module proves neither. It has no retraction: a withdrawal is a -- revision (an appended receipt with verdict `Withdrawn` and a parent), so what -- is proved here is about the append, by event_id. --- * The runtime `Receipt.write` does not return an error for a duplicate --- event_id: it writes nothing and returns :ok (an idempotent replay). The --- model's `Left DuplicateEventId` is "the ledger is unchanged"; that is the --- property, and the return value is a difference. +-- * The runtime `Receipt.write` answers `{:error, :duplicate_event_id}` for a +-- duplicate event_id and writes nothing, as the model's `Left DuplicateEventId` +-- (E0-29, owner ruling 1A; before it, the writer returned :ok). It also +-- refuses a verified receipt with no observation (`Receipt.check/1`, ruling +-- 2A), as `verifiedOk` makes the model unable to build one. `Receipt.build/2` +-- is still not a smart constructor: it builds the receipt, `check/1` refuses it. -- -- The gate table `gate` is the table of `verdict_for` in schema/receipt.ncl, which -- is the one-row case of OutcomeTracker.qualified_outcome_counts/1. diff --git a/test/receipt_model_mirror_test.exs b/test/receipt_model_mirror_test.exs index 22c92926..6bfb4404 100644 --- a/test/receipt_model_mirror_test.exs +++ b/test/receipt_model_mirror_test.exs @@ -15,16 +15,15 @@ defmodule Hypatia.ReceiptModelMirrorTest do The gate table and the list of fields are READ FROM `Receipt.idr`, not copied, so the model and this test cannot drift apart without a failure. - Two differences between the model and the run time are pinned below as - tests of their own, so that a change to either is noticed: - - * `Receipt.write/3` of an event_id that has a receipt writes nothing and - returns `:ok`; the model's `append` answers `Left DuplicateEventId`. The - ledger is unchanged in both, which is the property. - * `Receipt.build/2` does not refuse a `verified` row that has no - observations. The model cannot build one (`verifiedOk`), and the Nickel - contract refuses it. The production entry points never make one (see the - P2 tests); `build/2` is not a smart constructor. + Since E0-29 (owner rulings 1A and 2A) the writer refuses what the model refuses: + + * `Receipt.write/3` of an event_id that has a receipt returns + `{:error, :duplicate_event_id}` and writes nothing, as the model's `append` + answers `Left DuplicateEventId`. + * `Receipt.write/3` refuses a `verified` receipt that has no observation, as the + model cannot build one (`verifiedOk`) and the Nickel contract refuses it. + `Receipt.build/2` itself is still not a smart constructor: it builds the + receipt, and `Receipt.check/1` is what refuses it. """ use ExUnit.Case, async: true @@ -256,16 +255,16 @@ defmodule Hypatia.ReceiptModelMirrorTest do assert receipt["proof_or_test_ref"]["row_sha256"] =~ ~r/\A[0-9a-f]{64}\z/ end - test "KNOWN DIFFERENCE: build/2 does not refuse a verified row with no observation" do + test "build/2 still builds a verified row with no observation; check/1 and write/3 refuse it" do receipt = Receipt.build(row("QVerified", "CSuccess"), @ctx) # The model cannot build this (`verifiedOk`) and the Nickel contract refuses # it ("qualification verified needs observations and an evidence reference"). - # No production entry point makes such a row; build/2 is not a smart - # constructor. If build/2 or write/3 gains a guard, change this test and the - # trust-boundary text of the P2 row in verification/proof-ledger.jsonl. + # build/2 is not a smart constructor, so it still builds it; the writer does + # not write it (E0-29, owner ruling 2A). assert receipt["qualification"] == "verified" assert receipt["observations"] == %{} + assert {:error, :verified_without_evidence} = Receipt.check(receipt) end end @@ -366,7 +365,7 @@ defmodule Hypatia.ReceiptModelMirrorTest do {:ok, root: root} end - test "a second write for an event_id adds nothing, and returns :ok (a known difference)", %{ + test "a second write for an event_id adds nothing, and is an error, as in the model", %{ root: root } do row = row("QFailed", "CFailure") @@ -375,19 +374,20 @@ defmodule Hypatia.ReceiptModelMirrorTest do before = Receipt.all(root) assert length(before) == 1 - # The model answers Left DuplicateEventId; the run time returns :ok and - # leaves the ledger as it was. - assert :ok = Receipt.write(root, row, ctx: @ctx) + # The model answers Left DuplicateEventId; so does the writer (E0-29, ruling 1A). + assert {:error, :duplicate_event_id} = Receipt.write(root, row, ctx: @ctx) assert Receipt.all(root) == before end - test "many receipts keep distinct event_ids, and a replay of any of them adds nothing", %{ + test "many receipts keep distinct event_ids, and a replay of any of them is refused", %{ root: root } do rows = for _ <- 1..40, do: row("QFailed", "CFailure") for r <- rows, do: assert(:ok = Receipt.write(root, r, ctx: @ctx)) - for r <- Enum.take_random(rows, 15), do: assert(:ok = Receipt.write(root, r, ctx: @ctx)) + + for r <- Enum.take_random(rows, 15), + do: assert({:error, :duplicate_event_id} = Receipt.write(root, r, ctx: @ctx)) ids = Receipt.all(root) |> Enum.map(& &1["event_id"]) assert length(ids) == 40 diff --git a/test/receipt_test.exs b/test/receipt_test.exs index f39524b5..4811bc11 100644 --- a/test/receipt_test.exs +++ b/test/receipt_test.exs @@ -379,13 +379,22 @@ defmodule Hypatia.ReceiptTest do :crypto.hash(:sha256, source_line) |> Base.encode16(case: :lower) end - test "a verified update on the neural path", %{root: root, data: data} do - neural(root, "verified") - assert_receive {:coordinator, _, "success"}, 500 + # E0-29 (owner ruling 2A): the evidence of the neural path is a bare claim, with + # nothing observed. A `verified` receipt needs an observation, so it is refused + # until the trusted source of the neural path brings one. The update still + # reaches the coordinator. (No trusted source exists today: `trusted_verification/1` + # is nil, so a real finding never gets here.) + test "a verified update on the neural path learns, and its receipt is refused", + %{root: root, data: data} do + log = + ExUnit.CaptureLog.capture_log(fn -> + neural(root, "verified") + assert_receive {:coordinator, _, "success"}, 500 + end) - assert [r] = Receipt.all(data) - assert r["verdict"] == "credited_success" - assert r["source"]["kind"] == "neural_path" + assert Receipt.all(data) == [] + assert log =~ "receipt_refused" + assert log =~ "verified_without_evidence" end test "a qualified failure on the local rescan path (a caller's own failed claim)", %{ @@ -510,19 +519,108 @@ defmodule Hypatia.ReceiptTest do assert length(Receipt.all(data)) == 1 end - test "writing the receipt of a row twice writes one", %{data: data} do + test "writing the receipt of a row again is refused and writes nothing", %{data: data} do {:ok, _} = OutcomeTracker.record_outcome("recipe-p2", "o/r", "f", :failure, %{ "verification" => "failed" }) + # record_outcome/5 already wrote the receipt of the row. [row] = rows(data) - assert :ok = Receipt.write(data, row) - assert :ok = Receipt.write(data, row) + assert {:error, :duplicate_event_id} = Receipt.write(data, row) + assert {:error, :duplicate_event_id} = Receipt.write(data, row) assert length(Receipt.all(data)) == 1 end end + # E0-29 (owner rulings 1A and 2A): the writer refuses what the Idris2 model refuses. + describe "what the writer refuses" do + defp unevidenced_verified_row do + fixture_row() + |> Map.drop(["exit_code", "before_hits", "after_hits", "verdict"]) + |> Map.put("verification", "verified") + |> Map.put("outcome", "success") + end + + test "a second write for an event_id is an error, and the receipt log is unchanged", %{ + data: data + } do + row = Map.put(fixture_row(), "event_id", Hypatia.EventId.generate()) + + assert :ok = Receipt.write(data, row, ctx: fixture_ctx()) + before = File.read!(hd(Path.wildcard(Path.join(data, "receipts/*.jsonl")))) + + assert {:error, :duplicate_event_id} = Receipt.write(data, row, ctx: fixture_ctx()) + assert File.read!(hd(Path.wildcard(Path.join(data, "receipts/*.jsonl")))) == before + assert length(Receipt.all(data)) == 1 + end + + test "check/1 refuses a verified receipt with no observation, and only that" do + bare = Receipt.build(unevidenced_verified_row(), fixture_ctx()) + assert bare["qualification"] == "verified" + assert bare["observations"] == %{} + assert {:error, :verified_without_evidence} = Receipt.check(bare) + + # with an observation it passes + evidenced = + Receipt.build(Map.put(unevidenced_verified_row(), "after_hits", 0), fixture_ctx()) + + assert :ok = Receipt.check(evidenced) + + # a receipt that is not verified needs none + failed = + unevidenced_verified_row() + |> Map.merge(%{"verification" => "failed", "outcome" => "failure"}) + |> Receipt.build(fixture_ctx()) + + assert failed["observations"] == %{} + assert :ok = Receipt.check(failed) + + # an evidence reference that is not a digest does not count + no_digest = put_in(evidenced, ["proof_or_test_ref", "row_sha256"], "xyz") + assert {:error, :verified_without_evidence} = Receipt.check(no_digest) + end + + test "write/3 refuses a verified row with no observation and writes nothing", %{data: data} do + row = Map.put(unevidenced_verified_row(), "event_id", Hypatia.EventId.generate()) + + assert {:error, :verified_without_evidence} = + Receipt.write(data, row, ctx: fixture_ctx()) + + assert Receipt.all(data) == [] + refute File.exists?(Path.join(data, "receipts")) + end + + test "a producer event_id that is the id of an existing receipt is stored and its receipt is refused, loudly", + %{root: root, data: data} do + {:ok, local} = + OutcomeTracker.record_outcome("recipe-p3", "o/r", "f", :failure, %{ + "verification" => "failed" + }) + + taken = local["event_id"] + assert [_] = Receipt.all(data) + + write_fleet(root, [fleet_row("recipe-p4", "verified", %{"event_id" => taken})]) + + log = + ExUnit.CaptureLog.capture_log(fn -> + send(self(), {:poll, LearningScheduler.ingest_fleet_outcomes(nil)}) + end) + + assert_received {:poll, {1, _}} + + # both rows are stored; the receipt of the first is the only receipt + assert length(rows(data)) == 2 + assert [receipt] = Receipt.all(data) + assert receipt["assertion"]["recipe_id"] == "recipe-p3" + + assert log =~ "receipt_refused event_id=#{taken}" + assert log =~ "duplicate_event_id" + refute log =~ "receipt_pending event_id=#{taken}" + end + end + describe "the store of the row" do test "a receipt goes into the store of its row, also after the data root changes", %{ root: root, diff --git a/verification/PROOF-STATUS.adoc b/verification/PROOF-STATUS.adoc index 43b66143..0e8b5b6e 100644 --- a/verification/PROOF-STATUS.adoc +++ b/verification/PROOF-STATUS.adoc @@ -352,13 +352,13 @@ Checked against PROOF-POLICY as pinned by `+metadatastician/standards 3-practice |proven |Idris2 0.7.0, idris2 --build src/abi/hypatia-abi.ipkg (--total) |`+src/Hypatia/ABI/Receipt.idr+`: `+appendRefusesDuplicate+`, `+appendFresh+`, `+appendKeepsUnique+`, `+decElem+`, `+decNat+` -|Over the Idris2 types. An event_id is a natural number with a structural decidable equality; the real ids are ADR-008 strings. The run time is held to the append by test/receipt_model_mirror_test.exs, not proved: Receipt.write writes nothing and returns ok where the model answers Left DuplicateEventId (the ledger is unchanged in both). Concurrent writers and the file system are outside the model +|Over the Idris2 types. An event_id is a natural number with a structural decidable equality; the real ids are ADR-008 strings. The run time is held to the append by test/receipt_model_mirror_test.exs, not proved: Receipt.write returns {:error, :duplicate_event_id} and writes nothing, as the model answers Left DuplicateEventId (E0-29, owner ruling 1A). Concurrent writers and the file system are outside the model |P2: the verdict of a receipt is the answer of the gate for its qualification and claimed outcome, or a withdrawal that names a parent; a verified receipt has a row digest and at least one observation; a receipt that credits a success is evidenced; the gate never answers withdrawn and credits a success only for a verified, claimed success |proven |Idris2 0.7.0, idris2 --build src/abi/hypatia-abi.ipkg (--total) |`+src/Hypatia/ABI/Receipt.idr+`: `+verdictIsGate+`, `+verifiedHasEvidence+`, `+noVerifiedWithoutObservations+`, `+creditedSuccessIsEvidenced+`, `+withdrawnHasParent+`, `+gateNeverWithdrawn+`, `+gateSuccessInverse+` -|Over the Idris2 types. The model cannot build a verified receipt without an observation, but Receipt.build/2 does not refuse one: the Nickel contract of schema/receipt.ncl does, and the production entry points never make one (the mirror test runs every fleet classification and the rescan path; it pins the build/2 difference as a known difference). Whether the real gate computes the table is checked by the mirror test and by tests/accept/ReceiptP2GateTable.idr, not proved +|Over the Idris2 types. The model cannot build a verified receipt without an observation. Receipt.build/2 is not a smart constructor and still builds one; Receipt.check/1 refuses it and Receipt.write refuses to write it (E0-29, owner ruling 2A), as does the Nickel contract of schema/receipt.ncl. The production entry points never make one (the mirror test runs every fleet classification and the rescan path). Whether the real gate computes the table is checked by the mirror test and by tests/accept/ReceiptP2GateTable.idr, not proved |The gate table of the receipt model has the 24 entries that verdict_for gives in schema/receipt.ncl, which is the one-row case of OutcomeTracker.qualified_outcome_counts/1 |proven diff --git a/verification/proof-ledger.jsonl b/verification/proof-ledger.jsonl index fca993a6..7b070bca 100644 --- a/verification/proof-ledger.jsonl +++ b/verification/proof-ledger.jsonl @@ -45,8 +45,8 @@ {"axioms":[],"bounds":"","checker":"Agda 2.8.0.2, builtins only, --safe --without-K --cubical-compatible (--double-check in the file)","file":"verification/proofs/agda/E0ModelTables.agda","id":"e0-model-tables","kind":"engineering","lane":"agda","names":["gateAgrees","fleetAgrees","stageAgrees"],"obligation":"The Agda model of the gate, the fleet classifier and the stage and tier gives the same answer as the running Elixir on every row of a generated table: 124 gate rows, 1033 fleet classification rows and 121 stage rows","status":"proven","trust_boundary":"A finite table, not a refinement proof: inputs outside it are not covered. The table is generated from the running Elixir by test/e0_agda_mirror_test.exs, which fails when the committed file is stale; Agda checks the model against the table, and the ExUnit test, not Agda, ties the table to the code"} {"axioms":[],"bounds":"","checker":"Agda 2.8.0.2, builtins only, --safe --without-K --cubical-compatible (--double-check in the file)","file":"verification/proofs/agda/E0Agreement.agda","id":"e0-agreement-checkers","kind":"engineering","lane":"agda","names":["eqOutcome-sound","eqVerification-sound","eqBucket-sound","eqFleet-sound","eqStage-sound","eqTier-sound","checkGate-sound","checkFleet-sound","checkStage-sound"],"obligation":"The equality functions on the finite types of the E0 model are sound, so that the table check of e0-model-tables cannot pass by accident","status":"proven","trust_boundary":"Equality on enumerated finite types only"} {"axioms":[],"bounds":"","checker":"Agda 2.8.0.2, builtins only, --safe --without-K --cubical-compatible (--double-check in the file)","file":"verification/proofs/agda/E0ImportInstance.agda","id":"e0-import-instance","kind":"engineering","lane":"agda","names":["first-pass","second-pass","twice","failed","retried"],"obligation":"The import model is instantiated with natural-number ids, so its parameter and hypotheses are satisfiable and its theorems apply to a concrete log (non-vacuity)","status":"proven","trust_boundary":"One concrete instance with small ids; not a claim about the real id function"} -{"axioms":[],"bounds":"","checker":"Idris2 0.7.0, idris2 --build src/abi/hypatia-abi.ipkg (--total)","file":"src/Hypatia/ABI/Receipt.idr","id":"abi-receipt-p1-unique-event-id","kind":"engineering","lane":"idris2","names":["appendRefusesDuplicate","appendFresh","appendKeepsUnique","decElem","decNat"],"obligation":"P1 of the E0 receipt design: appending a receipt whose event_id is already in the ledger is refused and leaves the ledger unchanged; appending one whose id is not in it succeeds; a ledger of distinct event_ids stays one","status":"proven","trust_boundary":"Over the Idris2 types. An event_id is a natural number with a structural decidable equality; the real ids are ADR-008 strings. The run time is held to the append by test/receipt_model_mirror_test.exs, not proved: Receipt.write writes nothing and returns ok where the model answers Left DuplicateEventId (the ledger is unchanged in both). Concurrent writers and the file system are outside the model"} -{"axioms":[],"bounds":"","checker":"Idris2 0.7.0, idris2 --build src/abi/hypatia-abi.ipkg (--total)","file":"src/Hypatia/ABI/Receipt.idr","id":"abi-receipt-p2-no-claim-beyond-evidence","kind":"engineering","lane":"idris2","names":["verdictIsGate","verifiedHasEvidence","noVerifiedWithoutObservations","creditedSuccessIsEvidenced","withdrawnHasParent","gateNeverWithdrawn","gateSuccessInverse"],"obligation":"P2: the verdict of a receipt is the answer of the gate for its qualification and claimed outcome, or a withdrawal that names a parent; a verified receipt has a row digest and at least one observation; a receipt that credits a success is evidenced; the gate never answers withdrawn and credits a success only for a verified, claimed success","status":"proven","trust_boundary":"Over the Idris2 types. The model cannot build a verified receipt without an observation, but Receipt.build/2 does not refuse one: the Nickel contract of schema/receipt.ncl does, and the production entry points never make one (the mirror test runs every fleet classification and the rescan path; it pins the build/2 difference as a known difference). Whether the real gate computes the table is checked by the mirror test and by tests/accept/ReceiptP2GateTable.idr, not proved"} +{"axioms":[],"bounds":"","checker":"Idris2 0.7.0, idris2 --build src/abi/hypatia-abi.ipkg (--total)","file":"src/Hypatia/ABI/Receipt.idr","id":"abi-receipt-p1-unique-event-id","kind":"engineering","lane":"idris2","names":["appendRefusesDuplicate","appendFresh","appendKeepsUnique","decElem","decNat"],"obligation":"P1 of the E0 receipt design: appending a receipt whose event_id is already in the ledger is refused and leaves the ledger unchanged; appending one whose id is not in it succeeds; a ledger of distinct event_ids stays one","status":"proven","trust_boundary":"Over the Idris2 types. An event_id is a natural number with a structural decidable equality; the real ids are ADR-008 strings. The run time is held to the append by test/receipt_model_mirror_test.exs, not proved: Receipt.write returns {:error, :duplicate_event_id} and writes nothing, as the model answers Left DuplicateEventId (E0-29, owner ruling 1A). Concurrent writers and the file system are outside the model"} +{"axioms":[],"bounds":"","checker":"Idris2 0.7.0, idris2 --build src/abi/hypatia-abi.ipkg (--total)","file":"src/Hypatia/ABI/Receipt.idr","id":"abi-receipt-p2-no-claim-beyond-evidence","kind":"engineering","lane":"idris2","names":["verdictIsGate","verifiedHasEvidence","noVerifiedWithoutObservations","creditedSuccessIsEvidenced","withdrawnHasParent","gateNeverWithdrawn","gateSuccessInverse"],"obligation":"P2: the verdict of a receipt is the answer of the gate for its qualification and claimed outcome, or a withdrawal that names a parent; a verified receipt has a row digest and at least one observation; a receipt that credits a success is evidenced; the gate never answers withdrawn and credits a success only for a verified, claimed success","status":"proven","trust_boundary":"Over the Idris2 types. The model cannot build a verified receipt without an observation. Receipt.build/2 is not a smart constructor and still builds one; Receipt.check/1 refuses it and Receipt.write refuses to write it (E0-29, owner ruling 2A), as does the Nickel contract of schema/receipt.ncl. The production entry points never make one (the mirror test runs every fleet classification and the rescan path). Whether the real gate computes the table is checked by the mirror test and by tests/accept/ReceiptP2GateTable.idr, not proved"} {"axioms":[],"bounds":"","checker":"Idris2 0.7.0, idris2 --build src/abi/hypatia-abi.ipkg (--total)","file":"src/Hypatia/ABI/Receipt.idr","id":"abi-receipt-gate-table","kind":"engineering","lane":"idris2","names":["gate"],"obligation":"The gate table of the receipt model has the 24 entries that verdict_for gives in schema/receipt.ncl, which is the one-row case of OutcomeTracker.qualified_outcome_counts/1","status":"proven","trust_boundary":"A finite table, pinned by tests/accept/ReceiptP2GateTable.idr (24 equations) and compared with the emitter by test/receipt_model_mirror_test.exs, which reads the table from this file. Idris2 checks the equations; it does not show that the Elixir gate computes the table"} {"axioms":[],"bounds":"","checker":"Idris2 0.7.0, idris2 --build src/abi/hypatia-abi.ipkg (--total)","file":"src/Hypatia/ABI/Receipt.idr","id":"abi-receipt-p3-revision-keeps-history","kind":"engineering","lane":"idris2","names":["appendKeepsHistory","reviseKeepsHistory","reviseKeepsClaim","reviseFill"],"obligation":"P3: appending a receipt, including a revision that names the receipt it revises, keeps every receipt of the ledger before it; a revision keeps the qualification, claimed outcome and verdict of the receipt it revises and names it as its parent","status":"proven","trust_boundary":"Over the Idris2 types only. No run-time code builds a revision, a fill or a withdrawal yet (E0-07), so the mirror test has nothing to hold for P3. A withdrawal is modelled as a revision (an appended receipt), by event_id; retraction by position (Retraction.idr) and by name (the run time) is not proved here. Idempotence and order-independence of a withdrawal are not claimed"} {"axioms":[],"bounds":"","checker":"Idris2 0.7.0, idris2 --build src/abi/hypatia-abi.ipkg (--total)","file":"src/Hypatia/ABI/Receipt.idr","id":"abi-receipt-p4-fill-never-overwrites","kind":"engineering","lane":"idris2","names":["fillNeverOverwrites","fillChangesOnlyGaps","fillValueIsFromExtra","reviseNeverOverwrites","fillBody"],"obligation":"P4: a gap-filling revision keeps every present field, changes a field only if it was in missing_evidence, and every value it holds is the old one or one that came from the filler into a gap","status":"proven","trust_boundary":"Over the Idris2 types only. Field values are natural numbers. No run-time code builds a fill yet (E0-07), so P4 has no run-time counterpart and the mirror test does not cover it"}