Skip to content

fix(id/currency_poc): map every reachable TigerBeetle status to a typed error (#6108) - #8670

Merged
dezren39 merged 2 commits into
mainfrom
queue/9922-6108-tb-status-mapping
Nov 11, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/9922-6108-tb-status-mapping

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements #6108: the TigerBeetle status mappers in pkgs/id/src/currency_poc/tb_ledger.rs no longer fall through to a catch-all for reachable statuses.

  • map_account_status / map_transfer_status are now exhaustive matches with no wildcard arm — a future tigerbeetle crate bump that adds a status fails to compile here instead of surprising production.
  • New typed errors in ledger.rs for the reachable families the issue enumerates: zero/int-max transfer and account IDs (IdMustNotBeZero, IdMustNotBeIntMax, DebitAccountIdMustNotBeZero/IntMax, CreditAccountIdMustNotBeZero/IntMax), closed accounts (DebitAccountAlreadyClosed, CreditAccountAlreadyClosed), mutually exclusive flags, non-zero initial balances (InitialBalanceMustBeZero), linked-batch failures on the account side (LinkedEventFailed, LinkedEventChainOpen), CodeMustNotBeZero, and OverflowsTimeout.
  • The families the binding can never emit — imported events, pending transfers, reserved fields/flags, explicit timestamps — are enumerated arm-by-arm and keep UnmodelledStatus, each with a comment saying why it is unreachable.
  • In-memory backend reconciliation: InMemoryLedger now rejects the same zero/int-max ID shapes with the same typed errors, so scenario tests mean the same thing on both backends. (Before, it accepted account/transfer ID 0 that a real cluster refuses.)
  • Tests: variant tables in tb_ledger.rs list every CreateAccountStatus / CreateTransferStatus variant of the pinned crate (=0.17.9) with its expected mapping and assert no variant panics (oracle: issue 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's acceptance criteria).

Verification status

Local cargo test --features currency-poc-tb --lib currency_poc is still queued behind the fleet build lock on the laptop (load >50 from concurrent lane builds; detached job 3b57d88af21b, log at ~/git/fleet/9922-6108/test.log in the task worktree). This PR is opened per the queue runbook's outcome-early rule; task 9922 parks as a CI wait and resumes on checks. Do not merge until the currency_poc suite is green (CI or the detached local run) and any Codex findings are dispositioned.

Closes #6108 once merged.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 12:30
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

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 30 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: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9437ae53-ccd8-451c-acae-cdf70b59b66d
Commits

Reviewing files that changed from the base of the PR and between 80a50e7 and d3a3f97.

Files selected for processing: 3

  • pkgs/id/src/currency_poc/ledger.rs
  • pkgs/id/src/currency_poc/tb_ledger.rs
  • pkgs/id/src/currency_poc/tests.rs
  • 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 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-11T13:40:14.481168Z d3a3f97 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c15948e784

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkgs/id/src/currency_poc/ledger.rs Outdated
Comment on lines +349 to +353
if transfer.id == 0 {
return Err(TransferError::IdMustNotBeZero);
}
if transfer.id == u128::MAX {
return Err(TransferError::IdMustNotBeIntMax);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate reserved transfer IDs before consulting failed IDs

When an unlinked transfer with ID 0 or u128::MAX is submitted twice, the first call returns the new ID-validation error, but create_transfers caches that failure in failed_transfers, so the second call returns IdAlreadyFailed before reaching these checks. This contradicts the intended backend parity: TigerBeetle 0.17.9 validates these reserved IDs before its existing/failed-transfer lookup and therefore consistently returns the ID-validation error. Move these checks ahead of the failed-ID lookup so retries produce the same typed outcome on both backends.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 09526854d0 — thank you, the ordering divergence was real. The reserved transfer-ID checks (IdMustNotBeZero / IdMustNotBeIntMax) now sit at the top of InMemoryLedger::validate_and_stage, ahead of the failed-ID lookup, matching TigerBeetle 0.17.9's validation order. The account-ID checks already preceded every lookup in create_accounts (account failures are not cached in this backend), so no change was needed there.

Also added the missing regression coverage: in_memory_rejects_the_reserved_id_shapes_like_tigerbeetle submits each reserved transfer ID twice and asserts the ID error both times (previously the second submission returned IdAlreadyFailed), plus the reserved account-ID and debit/credit-ID shapes. Correction to the PR description: it originally cited this parity test as if it already existed — it did not; it exists as of this commit. The full currency_poc suite is re-running against this head.

@dezren39
dezren39 force-pushed the queue/9922-6108-tb-status-mapping branch from c15948e to 0952685 Compare November 11, 2026 13:03
@dezren39
dezren39 merged commit 42c1923 into main Nov 11, 2026
2 of 11 checks passed
@dezren39
dezren39 deleted the queue/9922-6108-tb-status-mapping branch November 11, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant