Skip to content

fix(receipt): the writer refuses a duplicate event_id and an unevidenced verified receipt (E0-29) - #1170

Merged
hyperpolymath merged 2 commits into
mainfrom
fix/e0-29-receipt-write-refusals
Nov 15, 2026
Merged

hyperpolymath merged 2 commits into
mainfrom
fix/e0-29-receipt-write-refusals

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

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 fix(import): a producer's event_id is the identity of a fleet row (E0-11) #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.

…ced 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 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 31376525-d916-4abc-89ca-a1587e9092e4
Commits

Reviewing files that changed from the base of the PR and between 820c1c7 and 0fe4502.

Files selected for processing: 10

  • docs/operations/e0-closeout/README.adoc
  • docs/operations/e0-closeout/work-orders/E0-29-receipt-write-refusals.adoc
  • lib/fleet_dispatcher.ex
  • lib/hypatia/receipt.ex
  • lib/outcome_tracker.ex
  • src/Hypatia/ABI/Receipt.idr
  • test/receipt_model_mirror_test.exs
  • test/receipt_test.exs
  • verification/PROOF-STATUS.adoc
  • verification/proof-ledger.jsonl

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Receipt writes now reject duplicate event IDs without creating an additional receipt.
    • Verified receipts without valid observation evidence are refused, including when updating through the neural processing path.
    • Receipt refusals are logged distinctly from other write failures.
  • Documentation
    • Updated operational guidance and verification notes to describe duplicate handling and verified-receipt requirements.

Receipt writing now rejects duplicate event IDs and verified receipts without valid evidence. Callers log these refusals separately from other write errors. Tests and proof records describe the updated behaviour.

Changes: Receipt Write Refusals

Layer / File(s) Summary
Writer refusal rules
docs/operations/e0-closeout/README.adoc, docs/operations/e0-closeout/work-orders/*, lib/hypatia/receipt.ex
Receipt.write/3 returns {:error, :duplicate_event_id} for duplicate event IDs. It checks verified receipts for observations and a valid row digest before writing.
Caller refusal reporting
lib/hypatia/receipt.ex, lib/fleet_dispatcher.ex, lib/outcome_tracker.ex
Receipt-write errors use report_failure/2. Duplicate-ID and verified-evidence refusals are logged as receipt_refused; other errors remain receipt_pending.
Behaviour tests and proof records
src/Hypatia/ABI/Receipt.idr, test/receipt*_test.exs, verification/*
Tests cover duplicate writes, evidence validation, caller logging, and model alignment. The proof records and module notes describe the updated runtime behaviour.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Receipt.write
  participant Receipt.check
  participant receipt_log
  Caller->>Receipt.write: Submit receipt
  Receipt.write->>Receipt.check: Validate verified evidence
  Receipt.check-->>Receipt.write: Return validation result
  Receipt.write-->>Caller: Return write result
  Caller->>receipt_log: Report receipt-write failure
Loading

Possibly related PRs

  • hyperpolymath/hypatia#1161: Adds the receipt write path and wires receipts into the outcome-tracking and neural paths changed here.

Suggested reviewers: claude

Merge Risk: Minimal · previous review 820c1

Receipt writing now refuses duplicate event IDs and verified receipts that lack evidence, and callers log these refusals separately. No new merge-blocking risk was found. A narrow concurrent-writer race existed before this change and is not made worse by it.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Receipt.write/3 now refuses a duplicate event_id and an unevidenced verified receipt. It matches the raw summary and the objectives, and it references the work order E…
Description check Passed The description explains what changed: Receipt.write/3 refusing duplicate event IDs, the Receipt.check/1 validator for verified receipts, the receipt_refused logging through report_failure/2, the test…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: Receipt.write/3 now refuses a duplicate event_id and an unevidenced verified receipt. It matches the raw summary and the objectives, and it references the work order E0-29. It is long (97 characters), but it is specific and accurate.

Full details: Description check

Explanation

The description explains what changed: Receipt.write/3 refusing duplicate event IDs, the Receipt.check/1 validator for verified receipts, the receipt_refused logging through report_failure/2, the test and ledger updates, the evidence from test runs, and the neural-path test change. It is detailed and directly related to the changeset.

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 10e655d5-74f8-499f-8b5e-5a544c6b40af
Commits

Reviewing files that changed from the base of the PR and between 4de4d69 and 820c1c7.

Files selected for processing: 10

  • docs/operations/e0-closeout/README.adoc
  • docs/operations/e0-closeout/work-orders/E0-29-receipt-write-refusals.adoc
  • lib/fleet_dispatcher.ex
  • lib/hypatia/receipt.ex
  • lib/outcome_tracker.ex
  • src/Hypatia/ABI/Receipt.idr
  • test/receipt_model_mirror_test.exs
  • test/receipt_test.exs
  • verification/PROOF-STATUS.adoc
  • verification/proof-ledger.jsonl

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 8

  • GitHub Check: Rust Coverage
  • GitHub Check: Integration Tests
  • GitHub Check: CodeRabbit
  • GitHub Check: stress-test
  • GitHub Check: Build AsciiDoc
  • GitHub Check: Rust Dependency Audit
  • GitHub Check: Container Security (Trivy) (deploy/Containerfile)
  • GitHub Check: Build AsciiDoc
Additional context used

Learnings: 5

Learning: 2026-11-14T20:32:08.559Z

Learnt from: CR
Repo: hyperpolymath/hypatia PR: 0
File: .claude/skills/work-order-write/SKILL.md:0-0
Timestamp: 2026-11-14T20:32:08.559Z
Learning: Source excerpt:
# Write a work order

## Check the work order before you hand it over

- Add the work order to the table in its folder index.

Applied to files:

  • docs/operations/e0-closeout/README.adoc
Learning: 2026-11-14T20:32:08.559Z

Learnt from: CR
Repo: hyperpolymath/hypatia PR: 0
File: .claude/skills/work-order-write/SKILL.md:0-0
Timestamp: 2026-11-14T20:32:08.559Z
Learning: Source excerpt:
# Write a work order

## The six parts

- **Steps.** In order. Step 1 measures the facts again. Where behaviour
  changes, the test comes before the change.

Applied to files:

  • docs/operations/e0-closeout/work-orders/E0-29-receipt-write-refusals.adoc
Learning: 2026-11-14T20:32:08.559Z

Learnt from: CR
Repo: hyperpolymath/hypatia PR: 0
File: .claude/skills/work-order-write/SKILL.md:0-0
Timestamp: 2026-11-14T20:32:08.559Z
Learning: Source excerpt:
# Write a work order

## The six parts

- **Facts measured.** Commit, path, function, line, and how you measured.

Applied to files:

  • docs/operations/e0-closeout/work-orders/E0-29-receipt-write-refusals.adoc
Learning: 2026-11-14T20:32:08.559Z

Learnt from: CR
Repo: hyperpolymath/hypatia PR: 0
File: .claude/skills/work-order-write/SKILL.md:0-0
Timestamp: 2026-11-14T20:32:08.559Z
Learning: Source excerpt:
# Write a work order

## The six parts

- **Stop and ask.** Each design question that the work order does not answer,
  each fact that the work rests on, and the cost cap.

Applied to files:

  • docs/operations/e0-closeout/work-orders/E0-29-receipt-write-refusals.adoc
Learning: 2026-11-14T20:32:08.559Z

Learnt from: CR
Repo: hyperpolymath/hypatia PR: 0
File: .claude/skills/work-order-write/SKILL.md:0-0
Timestamp: 2026-11-14T20:32:08.559Z
Learning: Source excerpt:
# Write a work order

Start from `docs/operations/e0-closeout/templates/work-order.adoc`. Keep the
six headings and their order. The `:wo-...:` header lines are read by the
launch script, so keep one value on each line.

Applied to files:

  • docs/operations/e0-closeout/work-orders/E0-29-receipt-write-refusals.adoc

@linear-code
linear-code Bot marked this pull request as ready for review November 15, 2026 17:55
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T17:55:54.971417Z
We couldn’t complete this review. Comment @codex review to try again.
820c1c7 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 enabled auto-merge (squash) November 15, 2026 18:27
@sonarqubecloud

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath merged commit 2158498 into main Nov 15, 2026
104 checks passed
@hyperpolymath
hyperpolymath deleted the fix/e0-29-receipt-write-refusals branch November 15, 2026 18:30
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