Skip to content

fix(import): a producer's event_id is the identity of a fleet row (E0-11) - #1165

Merged
hyperpolymath merged 1 commit into
mainfrom
fix/e0-11-read-event-id
Nov 15, 2026
Merged

hyperpolymath merged 1 commit into
mainfrom
fix/e0-11-read-event-id

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

What

When a fleet row carries an event_id, the import uses it as the identity of the row.
A row with no event_id keeps the provisional identity, so old logs give the same
result as today.

Work order: E0-11 (depends on E0-08, ruled; E0-09 merged). Authority: issue 984, steps
6 and 8; docs/design/e0-receipt.adoc sections 4 and 5.2.

The change (lib/learning_scheduler.ex only)

  • fleet_identity/3: a valid producer event_id is the fleet_import_id and is passed
    to record_fleet_outcome, which stores it as the row's event_id with
    event_id_source: "producer"; the receipt then names the producer's id. No event_id
    field: the old fleet_source_id(line, n) locator.
  • An event_id that is present and not a valid ADR-008 v8 id (a string that is not one,
    a v7 id, uppercase, null, a number) is not imported. It is logged with its line
    number and the later rows are imported.
  • A record with "kind":"start" is skipped before classification. Without that, a start
    record would be classified as an audit row and stored.
  • lib/outcome_tracker.ex needed no change: E0-09 already lets only the fleet import
    bring a producer id, and only a valid one.

Evidence

  • Before: 7 new tests, 6 fail (45 tests, 6 failures); the replay test and the
    "no event_id" test pass, as regression guards should. After: 45 tests, 0 failures.
  • mix test: 3495 tests, 0 failures (246 excluded). The older replay and
    identical-attempt tests pass unchanged. mix format --check-formatted: clean.
    check-uuid-v8.sh --strict on a clean export: exit 0.
  • Mutations (each restored): ignore the producer id -> 5 tests fail; do not skip start
    records -> 2 fail; fall back to the provisional id on an invalid one -> 1 fails.

Not done, and limits

  • The work order names 5 tests; there are 7 (a replay/cold-start check and the receipt
    check were added). The test for "same ids as before" is a guard, not a failing test.
  • Nothing writes event_id yet. The producer side is E0-12 (gitbot-fleet), which
    also has to find out whether the runner has uuid-v8 or Bun. Until then every real row
    takes the provisional path. This PR is inert against today's fleet logs, which is the
    intended compatibility.
  • fix-attempts.jsonl is never read as outcomes, as the design says; only a stray start
    record in the outcome file is handled.
  • A malicious or buggy producer can reuse an id. A second row with an id already
    imported is treated as a replay and dropped, so a producer could suppress an event by
    repeating its id. A producer id equal to a Hypatia-minted local event_id would also
    collide in the receipt log (P1 holds, but that row would get no receipt of its own).
    The ids are 128-bit and minted by trusted fleet bots, so I did not add a check, but it
    is not covered. Say if you want a follow-up.
  • The choreographic-types result in the work order (a sender cannot know receipt) is a
    design rule here, not something this change proves.

Process notes

  • scripts/api-agents/run-work-order.sh E0-11 --dry-run exits 0 (Sonnet, medium effort,
    cap USD 6). This session was switched to Opus 5.5 at high effort, above what the work
    order names; 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.

…-11)

When a fleet row carries an event_id, the import uses it as the identity of the
row (fleet_import_id) and stores it as the row's event_id with event_id_source
"producer", so the receipt names the producer's id. A row with no event_id keeps
the provisional locator of its line, so old logs give the same ids as before.
A row whose event_id is present and not a valid ADR-008 version 8 id is not
imported: it is logged with its line number and the rows after it still are.
A record with "kind":"start" is skipped before classification, so it is not
stored, does not count as imported, and cannot make the outcome row with the
same event_id look like a replay (design of E0-08, section 5.2).

Tests: seven new tests in test/learning_scheduler_test.exs (the five of the work
order, a replay check and the receipt). Ids are generated, never written as
literals, because the estate UUID gate refuses a non-v8 literal.

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

  • Bug Fixes
    • Fleet imports now skip start records and avoid importing the same event more than once when it has a valid producer ID.
    • Rows with invalid IDs are skipped and logged, while subsequent valid rows continue to import.
    • Rows without producer IDs retain line-based identification, and distinct IDs allow otherwise identical rows to be imported separately.
    • Replaying previously imported events no longer imports them again.

Fleet imports now use valid producer event_id values as row identities and include them in receipt context. The importer skips start records and rows with invalid IDs. Tests cover duplicate handling, replay, fallback identity, and receipt contents.

Changes: Fleet ingestion

Layer / File(s) Summary
Fleet event ID import behaviour
lib/learning_scheduler.ex, test/learning_scheduler_test.exs
The importer uses valid producer IDs for row identity and receipt context. It skips start records and invalid IDs. Tests cover duplicate and distinct IDs, replay, line-based fallback identity, and receipt contents.

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

Change: Feature

Possibly related PRs

Suggested reviewers: claude

Merge Risk: Low · up to 4fe39

Fleet imports now use a producer's event_id as the row identity. If a producer ever sends an ID that matches an existing local outcome, a duplicate outcome could be recorded and counted without its own receipt. No producer writes event_id today, so this is unlikely to occur soon. It is worth fixing before producers start emitting IDs.

- [ ] 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 15:10
@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-15T15:12:59.718652Z 4fe39fd Draft marked ready
🔒 Security Review ✅ Completed 2026-11-15T15:15:01.625238Z 4fe39fd 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 6de3764 into main Nov 15, 2026
98 of 99 checks passed
@hyperpolymath
hyperpolymath deleted the fix/e0-11-read-event-id branch November 15, 2026 15:13
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