Skip to content

id(currency_poc): InMemoryLedger accepts and posts zero / int-max account and transfer IDs real TigerBeetle refuses — the reference backend is a broken oracle for ID validity #6135

Closed

Description

@dezren39

Summary

pkgs/id/src/currency_poc/ledger.rs — InMemoryLedger, the in-memory LedgerBackend the conversion-executor scenarios run against in CI and the module's stated reference for a real client binding — accepts and posts account and transfer IDs that real TigerBeetle refuses outright: 0 and u128::MAX (TigerBeetle reserves both: IdMustNotBeZero / IdMustNotBeIntMax in the pinned tigerbeetle = "=0.17.9" crate, the statuses #6108 catalogues). The pure batch builder accepts the same shapes, so a conversion that "posts" in every in-memory scenario can never post on a real cluster.

  • create_accounts (ledger.rs, impl LedgerBackend for InMemoryLedger): the only validation is ledger == 0 → LedgerMustNotBeZero. There is no check on account.id (grep: zero occurrences of id == 0 in the file).
  • validate_and_stage (ledger.rs): checks amount == 0, same-account, and ledger mismatch — but never transfer.id, debit_account_id, or credit_account_id against 0/u128::MAX.
  • The error enums have no variant for it: AccountError (ledger.rs:84–92) and TransferError (ledger.rs:97–126) model zero ledger and zero amount, but no zero/int-max ID.
  • build_conversion_batch (pkgs/id/src/conversion.rs:430ff): transfer IDs are checked for count and duplicates only — an explicit 0 (or u128::MAX) leg ID builds fine, as do account IDs of 0 in any of the five account fields. (The sibling ledger-0 builder gap is id(conversion): build_conversion_batch accepts ledger 0 — builds a batch that can never post, with no typed pre-ledger rejection #6102.)

Evidence (verified this run, laptop probe against the real id crate)

Probe: ~/git/fleet/probe-inmem-zero-id on the laptop (path dependency on pkgs/id, built and run on the laptop; the two source files are unchanged on current main — last touch ecf15d3 / be67273):

  • create_accounts(&[Account { id: 0, ledger: 100, .. }]) → [Ok(())]; lookup_account(0) → Some(0)
  • create_accounts(&[Account { id: u128::MAX, ledger: 100, .. }]) → [Ok(())]
  • Transfer id: 0 between two normal accounts → [Ok(())]; it posts (credit balance 500) and lookup_transfer(0) → Some((0, 500))
  • Transfer id: u128::MAX → [Ok(())]; lookup_transfer(u128::MAX) → Some(5)
  • build_conversion_batch with transfer_ids: [0, 1002] → Ok, leg IDs [0, 1002], and the in-memory backend posts both legs [Ok(()), Ok(())]; with caller_source: 0 → Ok, leg 0 debit account 0
  • Controls — the zero checks that DO exist all fire: account ledger: 0 → Err(LedgerMustNotBeZero); transfer amount: 0 → Err(AmountMustNotBeZero); transfer ledger: 0 → Err(LedgerMismatch)

On the real backend these same inputs return IdMustNotBeZero (account status 6 / transfer status 5) and IdMustNotBeIntMax (transfer status 6, plus the debit/credit account-ID variants 8–11) — today those statuses hit the panic catch-all in tb_ledger.rs (#6108); after #6108 they will be typed errors the in-memory backend still never produces.

Why it matters

InMemoryLedger is the test oracle for the executor: the #2063 §4 scenario coverage (posted conversion findable by user_data_128, atomic failure, crash recovery, pre-flight) runs against it. An oracle that accepts strictly more than the real system proves scenarios the real system rejects — ID-generation bugs (a default/unset ID of 0, an int-max sentinel leaking through) pass every in-memory test and only fail against a live cluster, the most expensive place to discover them. The module doc presents this backend as "implementing the TigerBeetle semantics the PoC depends on" and "usable as a reference for a real client binding" — ID validity is one of those semantics.

Acceptance criteria

  • InMemoryLedger::create_accounts refuses id == 0 and id == u128::MAX with typed AccountError variants (e.g. IdMustNotBeZero / IdMustNotBeIntMax), mirroring TigerBeetle's verdicts
  • InMemoryLedger::create_transfers refuses transfer id == 0 / u128::MAX and debit/credit account IDs of 0 / u128::MAX with typed TransferError variants, before any staging; a linked chain containing such a leg fails atomically like any other validation failure
  • build_conversion_batch rejects 0 / u128::MAX in transfer_ids and in any account field with a typed ConvertError, in its documented deterministic validation order (consistent with the direction of id(conversion): build_conversion_batch accepts ledger 0 — builds a batch that can never post, with no typed pre-ledger rejection #6102)
  • Pinning tests cover every refused shape on both backends' shared types, plus controls: ordinary IDs still post, and the existing ledger-0 / amount-0 refusals are unchanged
  • cargo test -p id --lib currency_poc and the conversion tests pass

Related

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    on Nov 5, 2026
  2. developing-today commented on Nov 5, 2026

    @developing-today
    Contributor
  3. added
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    on Nov 5, 2026
  4. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  5. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    Enqueue note: the triage packet for issue #6135 was submitted to the repo-health-code-pilot queue twice during filing bookkeeping (the first call's output was truncated before its task id was visible); the second call returned task 9934. If the dedupe key did not collapse the two submissions, a duplicate triage task for this issue may exist — the second claimant/monitor should supersede it. Confirmed task: task 9934, dedupe key repo-health:v1:triage:developing-today/code:issue:6135.

  6. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  7. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    and removed on Nov 5, 2026
  8. 10 remaining items

  9. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · blocked

  10. dezren39 commented on Nov 9, 2026

    @dezren39
    MemberAuthor

    Dropped-thread catcher — blocked-claim validation (2026-11-09T23:40Z)

    Claim checked: queue task 9934 blocked this issue as a packet defect on 2026-11-05 — the packet said kind=triage, but the issue's acceptance requires implementing typed ID validation in InMemoryLedger and build_conversion_batch plus regression tests (agent note, 2026-11-05T09:04Z). Nothing has moved on the issue since that note.

    Live evidence: the issue is fully specified with file:line evidence (issue body): create_accounts validates only ledger == 0; validate_and_stage never checks transfer.id / debit_account_id / credit_account_id against 0/u128::MAX; AccountError (ledger.rs:84–92) and TransferError (ledger.rs:97–126) model no zero/int-max ID variant. No external blocker, no missing decision, no Drew act — only the packet kind was wrong. Same packet-defect class already validated on opencode#1977 and opencode#2206.

    Action: the blocked state is stale. A fix-kind packet for this issue (implementation scope: ID validation in create_accounts, validate_and_stage, and build_conversion_batch, with regression tests) was prepared by the catcher (packet-6135-fix.json, dedupe repo-health:v1:fix:developing-today/code:issue:6135); the direct repo-queue enqueue currently routes code-pilot packets to the shadow queue, so this issue is instead being routed through the pilot feeder: status/blocked + queue/blocked removed, queue/queued added. Task 9934's blocker explicitly requested this fix-kind re-enqueue.

  11. added and removed
    status/blockedQueue or user escalation state
    queue/blockedQueue or user escalation state
    on Nov 9, 2026
  12. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    Released to the queue under Drew's 2026-11-13 unblock-all order (main chat, 23:53 CT). Task(s) 15203 moved from blocked/parked to queued in the fleet unblock-all pass (worker main-unblock-all-2026-11-13). Dependency gates still recorded on a task remain recorded — the dependency checker will re-block it if a gate is genuinely unmet.

  13. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (already_done)

    Verdict — already done at current main; every acceptance item verified

    Fresh verification this shift at origin/main (verify worktree at 1f6abda, code reads at e19c1a2):

    1. InMemoryLedger::create_accounts refuses reserved IDs: pkgs/id/src/currency_poc/ledger.rs checks account.id == 0 → AccountError::IdMustNotBeZero and account.id == u128::MAX → AccountError::IdMustNotBeIntMax (typed variants added with the id(currency_poc/tb_ledger): status mappers panic on unmodelled-but-ordinary TigerBeetle statuses (zero/int-max IDs, closed accounts) the in-memory backend accepts #6108 status mapping, commit 0952685).
    2. create_transfers / validate_and_stage refuses them before staging: transfer id, debit_account_id, and credit_account_id are each checked against 0 and u128::MAX with typed TransferError variants (IdMustNotBeZero, IdMustNotBeIntMax, DebitAccountIdMustNotBeZero/IntMax, CreditAccountIdMustNotBeZero/IntMax) — ledger.rs lines 321–375.
    3. build_conversion_batch rejects reserved IDs: pkgs/id/src/conversion.rs validates every transfer ID and account ID (id == 0 || id == u128::MAX, typed ConvertError), landed in commit 9015bfa (for id(conversion): build_conversion_batch accepts zero / int-max transfer and account IDs — builds a batch real TigerBeetle refuses outright, with no typed pre-ledger rejection #6189) alongside the id(conversion): build_conversion_batch accepts ledger 0 — builds a batch that can never post, with no typed pre-ledger rejection #6102 ledger-0 rejection (fb5bb62). The executor preflight also rejects reserved transfer IDs (PR fix(id): reject reserved transfer IDs in currency_poc executor preflight (#6194) #8674, merged 2026-11-11, for id(currency_poc): executor preflight never checks transfer ID values — 0 / int-max IDs pass prepare, persist an intent, and post (in-memory) or strand as a poison Submitted record (real TigerBeetle) #6194; executor.rs cites this issue's finding).
    4. Pinning tests exist and pass: in_memory_rejects_the_reserved_id_shapes_like_tigerbeetle and reserved_transfer_ids_fail_preflight_before_persisting_intent (currency_poc/tests.rs), rejects_reserved_transfer_ids_in_every_leg_position and rejects_reserved_account_ids_in_every_role (conversion.rs). On the verify worktree (pkgs/id, via fleet-build-lock): cargo test --lib reserved — 10 passed, 0 failed; cargo test --lib conversion — 25 passed, 0 failed; cargo test --lib in_memory — 2 passed, 0 failed.
    5. Siblings id(conversion): build_conversion_batch accepts ledger 0 — builds a batch that can never post, with no typed pre-ledger rejection #6102 and id(currency_poc/tb_ledger): status mappers panic on unmodelled-but-ordinary TigerBeetle statuses (zero/int-max IDs, closed accounts) the in-memory backend accepts #6108 are both CLOSED, consistent with this state.

    Issue #6135 therefore closes as already-done: the in-memory backend and the batch builder now return the same typed verdicts as the real backend for every reserved-ID shape the issue lists. Task 15203 completes with outcome already_done.

  14. added
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    and removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 14, 2026
  15. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    Agent note · done (already_done)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)kind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions