Skip to content

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

Closed

Description

@dezren39

Summary

pkgs/id/src/conversion.rs — the production pure conversion layer (Phase E of #2063, landed under #5536) — builds a linked conversion batch for transfer IDs and account IDs of 0 or u128::MAX without any rejection. Both values are reserved in TigerBeetle: an ID of 0 is never a valid account/transfer ID (id must not be zero) and u128::MAX is the reserved int-max sentinel, so every leg built with one is refused outright at submission. The builder mirrors the ledger's other hard rules as typed pre-ledger ConvertErrors — ZeroAmount, SameAccount, duplicate transfer IDs — but has no ID-validity variant at all, so the failure surfaces only at ledger submission time instead of as a typed pre-ledger rejection.

Evidence (verified this run, laptop primary @2f470e0e65; conversion.rs unchanged at current main @97cd55c865)

  • build_conversion_batch (pkgs/id/src/conversion.rs:430) validates, in order: zero amount (:433), min/max bounds, rate/scale/fee terms (via convert_amount/fee_amount), same-account for the source/destination/fee legs, fee-account presence, and transfer-ID count + duplicates. A module-wide grep for u128::MAX / ID zero checks finds none for IDs: the only == 0 checks are amount_in, rate_den, and the computed amount_out. Transfer IDs are only counted and deduped; account IDs are only compared for equality between roles.
  • Probe (laptop, ~/git/fleet/probe-conversion-ids, real id crate): with an otherwise-sane request (ledgers 100/200, amount 1000, rate 3/2, min 10 / max 10_000), each of these returned Ok and built a full batch:
    • transfer_ids = [0, 22] — source leg built with id=0
    • transfer_ids = [11, 0] — destination leg built with id=0
    • transfer_ids = [u128::MAX, 22] — source leg built with id=u128::MAX
    • caller_source = 0, lp_source = u128::MAX, caller_dest = 0, lp_dest = u128::MAX — legs built debiting/crediting the reserved IDs
    • fee leg shapes: fee_account = Some(0) with fee_bps = 100 (fee 10 > 0) and transfer_ids = [11, 0, 33] — fee leg built with id=0 / crediting account 0
    • Control (all IDs ordinary) builds the expected 2-leg batch (amount_out 1500).
  • Real TigerBeetle refuses these IDs at submission: 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 established (with a probe of the in-memory backend) that TB rejects zero / int-max account and transfer IDs (IdMustNotBeZero / int-max class) while accepting ordinary IDs. The Phase F executor persists the intent first and submits exactly the batch built here, so a reserved ID becomes a persisted, submitted, refused conversion instead of a build-time rejection.

Why it matters

The module's own contract is that rejections happen before any ledger write, with typed reasons: "ConvertError — Why a conversion quote or batch cannot be built. Every variant is a rejection before any ledger write, per the failure table in #2063 §2.4." The builder already mirrors the ledger's hard rules — SameAccount mirrors AccountsMustBeDifferent, ZeroAmount mirrors AmountMustNotBeZero — and #6102 covers the one ledger-value mirror it also misses (ledger 0). ID validity is the remaining unmirrored hard rule: transfer IDs are caller-generated and persisted before submission (write-ahead discipline), so a generator or persistence bug that yields 0/MAX is exactly the class of error this layer exists to catch early; today nothing catches it until the ledger refuses the whole linked chain.

Related but distinct: #6102 covers source_ledger/dest_ledger == 0 in this same function (a ledger value, not an ID); #6135 covers InMemoryLedger accepting zero/int-max IDs (the backend oracle, not the builder); #6108 covers the tb_ledger status mappers panicking on the resulting TB statuses. Fixing any of those does not add an ID check here.

Acceptance criteria

  • build_conversion_batch rejects any transfer ID equal to 0 or u128::MAX, and any account ID (caller_source, lp_source, lp_dest, caller_dest, and a supplied fee_account) equal to 0 or u128::MAX, with a new typed ConvertError variant (e.g. InvalidTransferId { id } / InvalidAccountId { id } or equivalent), before any leg is built.
  • The rejection order stays deterministic and is documented alongside the existing validation-order note in build_conversion_batch's docs.
  • Pinning tests in pkgs/id/src/conversion.rs cover: zero and int-max in each transfer-ID position (source, fee, destination), zero and int-max in each account role, and the existing sane-ID requests still building identical batches.
  • cargo test -p id --lib conversion passes.

Scope notes

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. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 5, 2026
  6. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

  7. 292 remaining items

  8. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off to opencode claimant — Agent: queue worker (repo-worker-code), lane code-n — Session/ID: task 9988, repo-queue-worker-shift-n 2026-11-09 run. Task 9988 (small_fix) for issue #6189: add typed ID-validity rejection to build_conversion_batch; attempts 3/8 on this claim. Fresh check: issue #6189 OPEN, no held/user/owned/do-not-merge/do-not-auto-edit labels, no status/needs-triage (labels also carry a stale status:in-review alongside status/parked — pre-existing divergence, left for the fleet monitor). Execution lane row 2576 = opencode (repeat handoff). Checkpointed handed_off with handoff_reason "scheduled shift is time-bounded; claimant is the persistent execution session" (#8097 Rule 4); parking task 9988 for 20 minutes for the claimant window.

  9. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    state: picked_up
    task: 13508
    lane: code-f
    issue: #6189
    pr: #7200

    Lane code-f claimed task 13508 direct (#8187) to shepherd PR #7200. Fresh state: PR open, no hard-stop labels, Codex review has no unresolved findings; the old head's three failing checks (scripts-test, shellcheck, world snapshot) are in areas the PR diff does not touch. The PR is one commit on pkgs/id/src/conversion.rs. This shift rebases it onto current main (conflicts were additive — main's ZeroLedger checks/test plus this PR's account-ID validation/tests — resolved keeping both), runs the conversion tests, pushes, and parks as a CI wait or merges if checks go green inside the polling window.

  10. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    state: parked
    task: 13508
    lane: code-f
    issue: #6189
    pr: #7200

    Parked as a CI wait on PR #7200. This shift rebased the PR (one commit, pkgs/id/src/conversion.rs) onto current origin/main; the three conflicts were additive and were resolved keeping both sides — main's ZeroLedger checks and ledger test, plus this PR's account-ID validation and reserved-ID tests — with the validation-order doc updated to match. Verification: cargo test --lib conversion in pkgs/id — 25 passed, 0 failed, including rejects_reserved_account_ids_in_every_role, rejects_reserved_transfer_ids_in_every_leg_position, and batch_rejects_zero_ledgers_but_builds_for_sane_ledgers; rustfmt check passes; new head 5006e58 pushed with force-with-lease; Codex review has no unresolved findings. The old head's failing checks (scripts-test, shellcheck, world snapshot) are outside this PR's diff. Resume condition: PR #7200 checks complete — merge if green under the standing criteria.

  11. added a commit that references this issue on Nov 10, 2026
  12. added
    priority/lowNice to have; do when convenient
    and removed
    priority/normalOrdinary priority (the default)
    on Nov 11, 2026
  13. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Agent note — done (already_done)

  14. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 11, 2026
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/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobstatus:donetask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions