diff --git a/doc/2026-11-14_design_id5823.md b/doc/2026-11-14_design_id5823.md new file mode 100644 index 0000000000..1583f2cd2f --- /dev/null +++ b/doc/2026-11-14_design_id5823.md @@ -0,0 +1,526 @@ +# Design record — id5823: currency backend port + invariant test-suite contract + +- Issue: #5823 (design, from #5676 decomposition item 1) +- Parent: #5676 — Currency scaling: autoscaling service, Redis → multi-Turso → + TigerBeetle path (staged path and invariants are fixed there and are **not** + re-decided here) +- Programme: epic #2056; relatives #2043 (currencies v1), #2063 (conversion + engine), #2290 (RateAuthorisation), #2040 (TigerBeetle backend investigation) +- Siblings consuming this record: #5824 (Stage A, `doc/2026-11-08_design_id5824.md`), + #5828 (conversion & RateAuthorisation, `doc/2026-11-05_design_id5828.md`), + #5829 (verification programme, `doc/2026-11-08_design_id5829.md`) +- Status: decision recorded (queue task 16768, 2026-11-14). Implementation + timing is a separate decision, as the parent issue states. This record + contains no implementation code. + +## 1. Decision in one paragraph + +The currency backend port is the PoC seam in `pkgs/id/src/currency_poc/` +**formalised and generalised**: the `LedgerBackend` trait shape proven by the +conversion-executor PoC (#2289) — batched account creation, batched transfers +with linked-chain atomicity, per-item typed results, caller-generated +write-ahead IDs, and fallible lookups — becomes the port every currency stage +implements, extended with the three things the PoC never needed: a pending +(hold) transfer lifecycle, balances that include pending amounts, and an +ordered per-account history surface. A backend is called a **currency +backend** if and only if it passes the invariant test-suite contract in §4, +run **unmodified** against it through the port alone: one suite, one pass +rule, no per-stage waivers. The suite's invariants are I1–I8 as operationally +restated by #5829 §3.4 — this record adopts those identifiers as the binding +vocabulary (the authority #5824 §7 reserved to this record) and supplies the +concrete conformance cases, the pass rule, and the evidence form underneath +them. No parent #5676 decision is changed (§7); the one strengthening — +holds are a required port capability, not an optional one — is recorded +explicitly in §7 rather than folded in silently. + +## 2. Where the port sits + +- The port is at the **ledger level**: accounts, transfers, balances, + history. It is not the user-facing currency API. Parent principle 1 (no + backend concept ever leaks into the user-facing API) and principle 4 + (swap, don't rewrite) both fix this boundary: the user-facing transfer + API from #5676's interface list (create transfer with idempotency key, + query balance, query history, hold/capture/release) lives **above** the + port and is identical at every stage; the port is what stage adapters + implement **below** it. +- The shared layers above the port — admission, the write-ahead intent + discipline, conversion composition (#2063/#5828), reconciliation + reporting — are written once against the port and do not know which + stage is underneath. (This is the system-under-test shape #5829 §2 + already assumes.) +- Stage adapters: Stage A is the journal+projection composite of #5824 + (its commit point is the journal append; Redis is never the authority); + Stage B is a per-shard adapter set plus a coordinator presenting one + port face (#5826 owns the sharding mechanics); Stage C is a TigerBeetle + binding. An adapter presents **one** port face regardless of how many + stores it coordinates internally. + +## 3. The port + +### 3.1 Data model (formalised from the PoC) + +- A **currency is a `ledger: u32`** (non-zero); a transfer's ledger must + equal both accounts' ledgers. Cross-ledger transfers are forbidden at + the port, permanently: conversions are composed pairs of same-ledger + transfers (per the #2040 investigation, carried by the PoC and by + #5828), never a port primitive. +- **Amounts are `u128`** in the currency's smallest unit; zero-amount + transfers are rejected (`AmountMustNotBeZero`). +- **Accounts**: caller-chosen `u128` ID (zero and int-max reserved and + rejected), `ledger`, application chart-of-accounts `code: u16`, and + balance-rule flags (`debits_must_not_exceed_credits`, + `credits_must_not_exceed_debits`). Accounts are created with zero + balances, in batches, with per-item results. +- **Transfers**: caller-generated `u128` ID, debit account, credit + account (must differ), amount, `ledger`, `code`, correlation stamp + `user_data_128`, and the `linked` chain flag (§3.2). IDs are generated + and **persisted write-ahead by the caller before submission** — the + PoC's intent discipline (`currency_poc/intent.rs`, `recovery.rs`) is + part of the port contract, not an executor habit: recovery from any + crash window is defined as lookup of pre-generated IDs (§4, cases + R1–R2), so an adapter must make a submitted transfer findable by ID + and must never mint IDs on the caller's behalf. +- **Balances** report four figures per account — debits pending, debits + posted, credits pending, credits posted. This extends the PoC's + posted-only `AccountBalance`, which was sufficient for a conversion + executor and is not sufficient once holds are port-level (§3.3); + `spendable` is derived from these four under the account's flags, + exactly as the PoC derived it from the posted pair. +- Every committed posting is stamped with its correlation value and is + retrievable by it (`try_transfers_with_user_data_128` in the PoC): + the conversion lookup the acceptance criteria of #2063 asked for is a + port obligation. + +### 3.2 Operations + +The port is one trait-shaped surface (Rust-first, as the codebase is; +the contract is the semantics, not the syntax). Operation names below +are the PoC's, retained deliberately — #5824 §7 binds naming conflicts +in this record's favour, and keeping the proven names costs nothing. + +| Operation | Contract | +| --- | --- | +| `create_accounts(batch)` | One result per submitted account, in submission order. Re-creating an identical account returns `Exists` (idempotent retry, treated as success); same ID with different fields returns `ExistsWithDifferentFields` and changes nothing. | +| `create_transfers(batch)` | One result per submitted transfer, in submission order. Contiguous runs ending at a transfer with `linked == false` form **linked chains that post atomically or not at all**. A batch ending in an unterminated chain rejects that chain atomically (final leg `LinkedEventChainOpen`, earlier legs `LinkedEventFailed`, nothing posts, legs may be resubmitted properly terminated); terminated chains earlier in the same batch are unaffected. | +| Pending lifecycle: `create_transfers` with pending flag, `post_pending(id)`, `void_pending(id)` | §3.3. | +| `try_lookup_transfer(id)` | Fallible: `Ok(Some)` / `Ok(None)` / `Err`. Absence and backend failure are different answers and must never be conflated. | +| `try_lookup_account(id)` | Same fallible shape. | +| `try_account_balance(id)` | Same fallible shape; returns the four-figure balance of §3.1. | +| `try_transfers_with_user_data_128(value)` | All **posted** transfers carrying the correlation stamp. (Pending transfers are found by ID, not by correlation — the PoC's posted-only semantics, retained.) | +| `try_account_history(id, after_sequence, limit)` | The account's postings in commit order (§3.4). This is the one operation with no PoC counterpart; it exists because invariant I5 (auditability) must be checkable through the port alone. | + +Rules binding every operation: + +- **Result-length rule (#4669):** a batch call returns exactly one + result per submitted item. Any other length is a backend failure, + never a success, and callers must treat it as such. +- **Exists-in-chain rule (#6170):** a linked chain that mixes an + idempotent `Exists` leg with new legs posts **nothing** — the `Exists` + leg reports `Exists`, every other leg `LinkedEventFailed` — because + the underlying semantics (TigerBeetle's) break a chain on any + non-created status. The single exception is a chain whose legs are + **all** identical resubmissions: per-leg `Exists`, nothing moves. A + lone unlinked transfer is a chain of one and keeps plain `Exists` + semantics. Adapters whose native store does not behave this way must + emulate it; this rule is where "same semantics, different store" is + easiest to get wrong, so the suite tests it directly (§4, A3–A4). +- **Failed-ID rule:** a transfer ID that has failed is remembered by + the backend; resubmitting it returns `IdAlreadyFailed`, never the + original (now possibly stale) error. Recovery flows depend on this + distinction (#6628). +- **Error vocabulary:** per-item results use a closed, typed error + vocabulary (the PoC's `AccountError` / `TransferError` sets are the + seed). An adapter maps native errors onto it exhaustively; an + unmapped native status surfaces as a typed `UnmodelledStatus` / + `BackendFailure`, never as success and never as a panic. The + vocabulary changes only by amendment to this record. +- **Lookups on critical paths are the `try_` forms.** The PoC's + best-effort wrappers (log-and-default) are conveniences for tests + and inspection; they are **not** part of the port contract, and no + production path may be built on a lookup that cannot distinguish + "absent" from "backend down". +- **Signature shape:** batch operations take `&mut self` in the PoC. + The port does not mandate a concurrency model; it mandates that + whatever serialisation an adapter needs is the adapter's own + business and invisible above the port. An adapter's conformance + statement (§4.4) declares its concurrency claim. + +### 3.3 Pending transfers (holds) are part of the port + +The parent interface list carries "hold/capture/release **if +supported**", and #5676's Stage C design brief names TigerBeetle's +pending/post/void two-phase transfers. A port in which holds are +optional cannot carry invariant I6 (hold integrity), and Stage B/C +designs would each invent their own hold semantics above the port — +the fork this record exists to prevent. Decided: + +- The port includes a **pending lifecycle**: a transfer may be created + **pending** (reserving funds against the debit account's balance + rule without posting), then exactly one of **posted** (via + `post_pending`) or **voided** (via `void_pending`) happens; a pending + transfer may carry a timeout after which it voids itself. Posting or + voiding twice, posting a voided transfer, and voiding a posted one + are typed errors, and repeating the *same* terminal action with the + same ID is an idempotent `Exists`-class outcome, per the suite (§4, + H2). +- Pending amounts appear in the four-figure balance (§3.1) and are + never spendable by a second transfer: the balance rule evaluates + posted + pending debits together (I2/I6). +- How an adapter implements pending is its own design: TigerBeetle + natively; Stage A as journaled state in the regular store with the + projection reflecting reservations (#5824's journal-first ordering + is unchanged — a hold is a journal entry like any other); Stage B + per its saga record. The port fixes the **semantics**; §7 records + the "if supported" strengthening explicitly. + +### 3.4 History, events, and ordering + +- Every posting (including pending creation, post, and void) is an + entry in the adapter's history for both affected accounts, in + **commit order**, carrying a per-adapter monotonic sequence. + `try_account_history` pages through it deterministically. +- The events other ID subsystems consume (#5676's interface list, I8) + are emitted from this same history: one event per posting, in + history order per account. An adapter may not emit an event for a + posting its history does not contain, nor contain a posting it + never emits an event for. Event *transport* is above the port; + event *fidelity* is a port obligation. +- Balance reads: the port does not fix a consistency level for reads + above it — #5824 already ruled for Stage A (read-your-committed- + writes for posting decisions; stated-staleness reads only for + explicitly approximate consumers), and the equivalent ruling per + stage belongs to the stage records. The port fixes only that the + four-figure balance an adapter returns is a balance the adapter can + defend from its history (I5). + +### 3.5 Relation to the PoC — formalised, then superseded as the standard + +- **Formalised (kept, now contractual):** the trait shape and operation + names; the data model of §3.1 as far as the PoC took it; linked-chain + atomicity including the unterminated-chain and Exists-in-chain rules; + the result-length rule; the failed-ID rule; write-ahead caller IDs; + the intent/recovery pattern as the defined crash semantics. +- **Extended (new in this record):** pending lifecycle (§3.3); + four-figure balances; per-account sequenced history (§3.4); the + closed error vocabulary as a versioned contract; the conformance + gate itself (§4). +- **Superseded:** from this record on, the standard is **this record + plus the suite**, not the PoC code. `currency_poc` remains a PoC + under the #2056 programme rule; its two implementations + (`InMemoryLedger`, and `TigerBeetleLedger` in `tb_ledger.rs` behind + `currency-poc-tb`) are the first two candidate adapters and its + scenario tests (`currency_poc/tests.rs`, the #2063 §4 cases) are the + suite's seed corpus (§4.5) — evidence and starting material, not the + definition. When implementation is scheduled, the port moves out of + `currency_poc` into its production home as a follow-on (§8); nothing + production-shaped is built on the PoC module itself. + +### 3.6 Stage-declared semantics + +The port is identical at every stage; two things are **declared per +stage**, in the adapter's conformance statement, before the suite runs: + +- **Outcome vocabulary for multi-leg operations.** Stage A and C claim + the atomic outcomes of #5828 (`POSTED` / `FAILED_ATOMIC`); Stage B + additionally declares its pending-settlement saga outcomes for + cross-shard operations. Invariant I3 is "atomicity **as declared**": + the suite judges a stage against its declared outcomes, never + against atomicity it does not claim (#5829 §3.2, same rule for its + oracle). +- **Balance-read consistency** actually provided (§3.4). + +Nothing else may vary. A difference not declared here is a +non-conformance, not a stage personality. + +## 4. The invariant test-suite contract + +### 4.1 Form + +- The suite is **one executable suite** that drives a backend **only + through the port** (§3). It knows no adapter internals, no native + client, no store-specific query language. +- The adapter under test supplies exactly one thing: a **factory** + that produces a fresh, empty backend per case (or per case class, + where a case says so). Setup beyond the factory — accounts, + currencies, funds — happens through the port, in the open. +- The suite is the **conformance gate**: within the #5829 verification + programme it runs unmodified as **leg 0**, before that programme's + generative, crash-injection, and load legs. Those legs are the + programme's; this contract owns the gate they build on, and does not + restate them. +- The **in-memory reference backend is the control**: it must pass + every case trivially. A case that fails against the control has a + broken case (or a broken oracle assumption), not a broken adapter, + and is fixed by suite amendment (§4.5) before it gates anyone + (#5829 §2, adopted). + +### 4.2 The invariants + +The suite exists to prove #5676 principle 3 — double-entry invariants +are backend-independent — in the operational form #5829 §3.4 fixed: + +- **I1 Conservation:** per currency, the sum of all balances changes + only by explicit issuance/retirement — never by a transfer, + conversion, crash, or retry. +- **I2 Balance rule:** no account goes negative beyond its currency's + stated rules (the port form: the account's balance-rule flags hold + against posted + pending debits/credits at every observable point). +- **I3 Atomicity as declared:** an operation reaches exactly one of + its stage's declared outcomes; no partial legs are observable + outside declared pending states. +- **I4 Idempotency:** re-submitting a committed idempotency key (port + form: a committed transfer/account ID with identical fields) is a + no-op returning the original outcome, indefinitely. +- **I5 Auditability:** the observable history replays to the current + balances — the ledger is its own proof. +- **I6 Hold integrity:** held funds are neither spendable twice nor + stranded: every hold eventually posts, voids, or expires by its + stated rule, under crashes and retries alike. +- **I7 Conversion integrity:** at the port level — a conversion's legs + are findable by their correlation stamp, agree in amount/ledger per + leg, and post all-or-nothing as one linked chain. (End-to-end + conversion semantics — rate authorisation records, cap reservation — + live above the port and are #5828's and the programme's to test; the + port-level claim is the composition primitive they rest on.) +- **I8 Event fidelity:** emitted events match postings one-for-one, in + order per account (§3.4). + +### 4.3 Case catalogue + +Case IDs are this record's vocabulary (per #5824 §7 authority). Every +case states its invariant, its scenario through the port, and its pass +condition. The catalogue is the minimum gate; §4.5 governs growth. + +**Accounts and balances (AB)** + +| ID | Inv. | Scenario → pass condition | +| --- | --- | --- | +| AB1 | I2/I5 | Create accounts across two ledgers → all balances read back as four zeros; history empty. | +| AB2 | I4 | Re-create an identical account → `Exists`, state unchanged; same ID, different fields → `ExistsWithDifferentFields`, state unchanged. | +| AB3 | — | Zero / int-max account IDs, zero ledger, zero code → typed rejection per the error vocabulary; nothing created. | +| AB4 | I2 | Fund an account, then transfer exactly its spendable balance → posts; one unit more → `DebitsMustNotExceedCredits` (resp. credits-side flag), nothing posts. | + +**Transfers and chains (TC)** + +| ID | Inv. | Scenario → pass condition | +| --- | --- | --- | +| TC1 | I1/I5 | Simple transfer → balances move by exactly the amount on both sides; history on both accounts records it; conservation holds. | +| TC2 | I1 | Zero amount, same-account, unknown debit/credit account, cross-ledger pair → each typed-rejected, nothing posts, balances untouched. | +| TC3 | I3 | Linked chain of 3 legs where leg 2 violates its balance rule → no leg posts, all balances untouched, results report the failing leg + `LinkedEventFailed` for the rest. | +| TC4 | I3 | Batch ending in an unterminated chain → that chain rejected atomically (final leg `LinkedEventChainOpen`); a terminated chain earlier in the same batch **has** posted. Resubmitting the open chain properly terminated then posts it. | +| TC5 | I4 | Identical resubmission of a posted transfer → `Exists`, no movement; same ID with different fields → `ExistsWithDifferentFields`, no movement. | +| TC6 | I4 | Resubmission of a failed transfer's ID → `IdAlreadyFailed`, regardless of whether the original failure's cause has been fixed. | +| TC7 | — | Reserved transfer IDs (zero, int-max) and reserved account IDs inside a transfer → typed rejection (not "account not found"), nothing posts. | + +**Exists-in-chain (A — the adapter trap, §3.2)** + +| ID | Inv. | Scenario → pass condition | +| --- | --- | --- | +| A1 | I3/I4 | Chain mixing one already-posted (`Exists`) leg with new legs → nothing posts; `Exists` leg reports `Exists`, new legs `LinkedEventFailed`. | +| A2 | I4 | Chain whose legs are all identical resubmissions → per-leg `Exists`, nothing moves, balances unchanged. | +| A3 | I4 | Lone unlinked resubmission → plain `Exists` (chain-of-one keeps single-transfer semantics). | +| A4 | — | Duplicate transfer ID twice inside one new chain → rejected as `Exists`/`ExistsWithDifferentFields` per field equality; the ID is journaled at most once and balances reflect at most one posting. | + +**Holds (H)** + +| ID | Inv. | Scenario → pass condition | +| --- | --- | --- | +| H1 | I6/I2 | Create pending hold → posted balances unmoved, pending figures reflect the reservation, spendable drops by the held amount; a second transfer that would need the held funds is rejected. | +| H2 | I6 | Post the hold → amounts move pending → posted exactly once; repeating `post_pending` is the idempotent outcome, not a second movement. Void after post → typed error. | +| H3 | I6 | Void the hold → reservation released in full, spendable restored; posting after void → typed error. | +| H4 | I6 | Hold with timeout → after expiry the reservation is released without any client action; the held funds are spendable again; a late `post_pending` is a typed error. | +| H5 | I1/I6 | Hold + post + void sequences interleaved with plain transfers on one account → conservation holds at every step and no balance figure ever goes negative against the flags. | + +**Idempotency, lookup, and recovery (R)** + +| ID | Inv. | Scenario → pass condition | +| --- | --- | --- | +| R1 | I4 | Crash window 1: intent persisted, crash before submit → recovery finds no transfers by the pre-generated IDs and submits them exactly once. | +| R2 | I3/I4 | Crash window 2: submit succeeded, ack lost → recovery finds the posted transfers by ID and by correlation stamp, and resubmits nothing. | +| R3 | — | Backend fault injected during a `try_` lookup → the lookup returns `Err`, never `Ok(None)` or an empty result; after the fault clears, the same lookup returns the true answer. (This case is why best-effort wrappers are not the contract.) | +| R4 | I7 | Posted conversion (linked same-ledger pair per leg) → `try_transfers_with_user_data_128(conversion_id)` returns exactly the posted legs, in submission order, and no pending or failed legs. | +| R5 | — | Result-length discipline: the suite's fault adapter (a port-shaped wrapper that truncates a batch result vector) sits between suite and backend for this case → the harness must surface a backend failure, never a pass. This case tests the *caller's* obligation under #4669 as part of conformance evidence. | + +**History and events (E)** + +| ID | Inv. | Scenario → pass condition | +| --- | --- | --- | +| E1 | I5 | After a mixed scripted workload, replaying `try_account_history` for every account from sequence 0 reconstructs exactly the balances `try_account_balance` reports. | +| E2 | I8 | The emitted event stream for the same workload matches history one-for-one per account, in order, with matching amounts and correlation stamps. | +| E3 | I1 | Conservation audit: summing history-derived balances per currency before and after the workload (including holds posted, voided, and expired, and failed chains) differs only by the workload's explicit issuance/retirement entries. | + +### 4.4 Pass rule and conformance evidence + +- **Pass = every case in the current catalogue, run unmodified, + passes.** No waivers, no adapter-specific case edits, no + "passes except". A case may carry a **stage-conditional + expectation** only where §3.6 declares the semantics differ (in + practice: I3 outcome vocabulary for Stage B cross-shard + operations), and the conditional expectation must be written in + the adapter's conformance statement **before** the run — never + negotiated after a failure. +- An adapter is called a currency backend when it has a **current + conformance statement**: adapter build identifier, suite version + (this record's date + catalogue version), the §3.6 declarations, + per-case results, and the environment the run executed in. The + statement is published with the adapter (the #5829 programme + consumes these as leg-0 evidence). +- A failure is a finding against the adapter — or, if it reproduces + against the in-memory control, against the suite (§4.1). Either + way it is recorded with its minimal repro; a red gate is a + publishable result, not a private embarrassment (the programme's + oracle-first rule, #5829 decision 2, applies to the gate too). + +### 4.5 Suite evolution + +- Cases are **added or strengthened** by amendment to this record + (or its successor record); a case is never silently weakened or + deleted — a wrong case is retired by an amendment that says why, + and the retired ID is never reused. +- The seed corpus is the PoC's scenario suite: the #2063 §4 cases + already encoded in `currency_poc/tests.rs` (posted conversion + findable by `user_data_128`; atomic failure moving nothing; both + crash windows without double-posting; LP pre-flight rejection; + the write-ahead intent cases) are lifted into the catalogue's + form when the suite is implemented — several catalogue cases + above (R1, R2, R4, TC3) are those scenarios generalised from + conversions to the port as a whole. +- Every failure found by the #5829 programme's generative leg that + shrinks to a deterministic port-level repro is **promoted** into + this catalogue by amendment — the gate grows from evidence, the + same regression-corpus discipline #5829 §3.5 sets for the + programme. + +## 5. Invariants implementation must hold + +For whoever implements the port, an adapter, or the suite — the +checklist form of §§3–4: + +1. Balanced postings only: every posted chain's legs sum to zero per + currency; a chain posts completely or not at all (subject only to + §3.6 declared outcomes). +2. Result vectors are exactly one-per-item, in order; anything else + is a backend failure (#4669). +3. `Exists` means identical-and-already-there; different fields under + a taken ID are an error, never an overwrite — for accounts, + transfers, chains (A1–A3), and pending terminal actions alike. +4. Failed transfer IDs are remembered and refuse resubmission as + `IdAlreadyFailed`. +5. IDs are caller-generated and write-ahead; reserved IDs (zero, + int-max) are rejected with typed errors ahead of any existence + lookup. +6. Critical-path lookups distinguish absent from unavailable + (`try_` forms); no production path uses a defaulting lookup. +7. Holds reserve against posted + pending together, resolve exactly + once (post, void, or timeout), and never strand funds (I6). +8. History is complete, sequenced, and sufficient to reconstruct + every balance (I5); events mirror history exactly (I8). +9. Cross-ledger movement never appears as a single transfer; + conversions compose same-ledger legs under one correlation stamp + (I7). +10. No backend concept (Redis keys, Turso shards, TigerBeetle wire + types) appears in the port's types or errors as seen from above + the port — the error vocabulary and this data model are the whole + surface. +11. RateAuthorisation (#2290) and conversion composition (#2063) + stay above the port: the port records the authorisation + reference a transfer carries (in its metadata/correlation + surface) but never decides authorisation itself (#5828 boundary, + unchanged). + +## 6. Alternatives rejected + +- **The user-facing transfer API as the port.** Rejected: it would + bake today's service shape into every backend and leak stage + differences upward — the exact failure parent principles 1 and 4 + exist to prevent. The API's stability is the *goal*; the port is + the mechanism, one level down. +- **A generic storage/repository port** (get/put rows, adapters + interpret). Rejected: every invariant in §4.2 would move above the + port and be re-implemented per stage — conservation, chain + atomicity, and idempotency are properties of the ledger operations + themselves, and a CRUD seam cannot state them, let alone let one + suite prove them once. +- **Per-stage ports with a translation layer.** Rejected: the suite + would fork per stage (the same reasoning by which #5829 rejected + per-stage suites), "backend-independent invariants" would become a + claim about three different contracts, and the translation layer + becomes a fourth, unowned backend. +- **Promoting `currency_poc` to the production port as-is.** + Rejected: it is conversion-shaped (no holds, no history, posted-only + balances), it is explicitly a PoC under the #2056 programme rule + ("nothing production-shaped may be built on top of it without a + review round" — `currency_poc/mod.rs`), and until this record there + was no conformance gate for it to pass. This record *is* the review + round; §3.5 states what survives it. +- **TigerBeetle's wire protocol as the literal port** (adapters speak + to a TB-shaped service API, error codes and all). Rejected as + stated — the port adopts TigerBeetle's *semantics* where they are + the proven ones (chains, flags, pending lifecycle) but its types + and error vocabulary are this record's own (§3.2): a Stage A + journal has no honest mapping for every TB wire status, and forcing + one manufactures `UnmodelledStatus` noise exactly where clarity + matters. (The PoC already works this way — its errors are "a subset + of TigerBeetle's result codes", modelled, not wired.) +- **The suite as a documentation checklist** (conformance by review + instead of execution). Rejected: parent principle 3 says the + invariants are "proven by tests run against every backend", and + #5829's oracle-first rule refuses verdicts that can only be reached + by eyeballing. A checklist is how 371 unreviewed findings shipped + in another part of this fleet; a gate either executes or it is + decoration. + +## 7. Parent-decision changes + +**None.** This record decides only what #5676's decomposition item 1 +delegated to #5823 — the port's shape and the suite's contract — and +stays inside the parent's staged path, its interface list, and its +invariant set (principle 3 is §4.2 verbatim in operational form). +Stage-specific open questions remain their owners': Stage A's +system-of-record question was #5824's (answered there); scaling +triggers are #5825's; shard key and directory are #5826's; Stage B +conversion atomicity mechanics are #5826/#5828's; TigerBeetle timing +is #5827's. This record answers none of them. + +One strengthening is recorded explicitly, as the parent issue's terms +require: #5676's interface list says "hold/capture/release **if +supported**". Section 3.3 makes the pending/hold lifecycle a +**required** port capability at every stage (natively or emulated). +This is a decision *within* the delegated contract — a port contract +is precisely where "supported" gets defined — and it changes no stage +design's substance: #5824's journal holds Stage A holds without +amendment, and #5827's Stage C mapping assumes pending transfers +throughout. If the parent owners instead read "if supported" as +"optional forever", that reading is a #5676 amendment and should be +recorded there, not forked from here. + +Naming authority, per #5824 §7: where a sibling record's naming +conflicts with this record's port vocabulary or case identifiers, +**this record's naming supersedes** — without re-opening any sibling's +substantive decisions (§1–§4 of #5824 stand untouched; #5829's leg 0 +is this suite; #5828's outcome vocabulary is adopted in §3.6). + +## 8. Follow-ons (named, filed when implementation is scheduled) + +Implementation timing is a separate decision (parent issue, and this +record's packet), so — following the convention of the #5829 record +§10 — these are named here and filed as issues when the corresponding +implementation is scheduled, not filed speculatively now: + +1. **Port formalisation:** move `LedgerBackend` out of `currency_poc` + into its production home, with the §3 extensions (pending + lifecycle, four-figure balances, sequenced history) and the closed + error vocabulary as versioned types. +2. **Suite implementation:** the executable conformance suite of §4 — + factory harness, the case catalogue, the R5 fault-adapter — with + the PoC scenario tests lifted in as the seed corpus (§4.5). The + in-memory backend is its first adapter and control. +3. **First conformance runs:** publish conformance statements (§4.4) + for the in-memory backend and the TigerBeetle binding + (`tb_ledger` + the #2289 harness cluster), then for the Stage A + composite when Stage A implementation is scheduled — giving the + #5829 programme its leg-0 evidence from the first stage onward. + +Until then, #5823 closes on this record: the port and the contract +are settled, and what remains is implementation scheduling, which +was never this issue's question.