Skip to content

id(currency_poc): InMemoryLedger posts new legs behind an Exists head leg in a linked chain — real TigerBeetle breaks the chain and posts nothing #6170

Closed

Description

@dezren39

Summary

The two LedgerBackend implementations disagree on a linked chain whose first leg is an idempotent resubmission (Exists) and whose later legs are new:

  • InMemoryLedger (pkgs/id/src/currency_poc/ledger.rs, validate_and_stage + create_transfers): an Exists leg is treated as non-failing — "An idempotent Exists leg does not fail the chain" — so the remaining new legs stage, commit, and move balances, reported Ok(()).
  • Real TigerBeetle breaks a linked chain on any non-Created status. That is the repo's own documented semantics in pkgs/id/src/currency_poc/tb_ledger.rs (create_transfers, the PR feat(id/currency_poc): bind LedgerBackend to the official TigerBeetle Rust client (#2289) #5072 linked-chain-retry comment): a resubmitted chain reports Exists for its first leg and LinkedEventFailed for every later leg. The binding compensates only for the whole-chain-already-posted pattern (it verifies every stored leg is identical before rewriting the later legs to Exists). A mixed chain — first leg Exists, later legs genuinely new — is not compensated: on the live backend those new legs report LinkedEventFailed and nothing new posts.

So the same create_transfers call posts money on the in-memory reference backend and posts nothing on TigerBeetle. The executor layer cannot paper over this: executor::submit and the recovery scanner both accept per-leg Err(Exists) as success, so code tested green against InMemoryLedger for a mixed-chain resubmission silently behaves differently against the live cluster.

Evidence (verified this run, laptop probe @ 231eb9c)

Probe: ~/git/fleet/probe-linked-exists on the laptop — a crate against the real id crate (pkgs/id), InMemoryLedger, all accounts on ledger 100, issuer-funded:

  • chain1 [601,602] (601: user→LP 100, linked=true; 602: LP→dest 100): [Ok(()), Ok(())] — balances user {debits 100, credits 1000}, LP {100, 100}, dest {0, 100}.
  • Mixed chain [601 identical, 603, 604] (603: LP→user 50, linked=true; 604: user→dest 50): [Err(Exists), Ok(()), Ok(())] — lookup_transfer(603) = Some((603, 50)), lookup_transfer(604) = Some((604, 50)), balances move to user {150, 1050}, LP {150, 100}, dest {0, 150}. The new legs posted behind an Exists head leg.
  • Control — whole-chain identical resubmit of chain1: [Err(Exists), Err(Exists)], balances unchanged. The divergence is specifically the mixed shape, not idempotent resubmission in general.

TigerBeetle-side evidence is in-repo and already pinned by live tests: tb_ledger.rs documents the chain-break on any non-Created status, and tests.rs (live_same_request_twice_posts_once, ~line 1653) records that TigerBeetle reports Exists + LinkedEventFailed for a resubmitted chain — the pattern the binding must translate. No equivalent translation exists for InMemoryLedger, because it never produces it.

Why it matters

InMemoryLedger is the reference oracle every currency_poc scenario test runs against in CI (the live-TB tests are #[ignore]d). A parity gap here means the test suite can certify executor/recovery behavior — e.g. a resubmission path that reuses an already-posted leg ID alongside new legs — that the real backend rejects atomically. That is exactly the class of divergence #6150 (failed-ID memory) and #6135 (ID validity) already filed for this backend; this is the linked-chain member of the same family, and it is not covered by either (nor by #4669's short-result-vector issue or #6108's tb_ledger status-mapper panics).

Acceptance criteria

  • The two backends agree on the mixed chain [Exists leg, new leg, ...]: either InMemoryLedger fails the new legs with LinkedEventFailed and posts nothing (matching TigerBeetle + the tb_ledger compensation contract), or the trait contract in ledger.rs is amended to state the Exists-leg semantics explicitly and the tb_ledger binding is extended to implement them — with the decision recorded on this issue
  • A pinning test in pkgs/id/src/currency_poc/tests.rs covers the mixed chain on InMemoryLedger (first leg byte-identical to a posted transfer, later legs new): result vector, lookup_transfer for the new legs, and balances all match the chosen semantics
  • The whole-chain identical-resubmit control stays all-Exists and moves nothing on both backends
  • cargo test -p id currency_poc passes

Related

Activity

  1. developing-today commented on Nov 5, 2026

    @developing-today
    Contributor
  2. 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)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    on Nov 5, 2026
  3. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (new-issue-creator-code-a)
    • Session / ID: cron new-issue-creator-code-a run 2026-11-05 02:35 CST
    • Found via: filed this run
    • Task: Filed this issue — the two LedgerBackend implementations disagree on a mixed linked chain (Exists head leg + new legs): InMemoryLedger posts the new legs, real TigerBeetle breaks the chain (tb_ledger.rs PR feat(id/currency_poc): bind LedgerBackend to the official TigerBeetle Rust client (#2289) #5072 comment) and posts nothing. Verified this run on the laptop @231eb9ccb1 with probe ~/git/fleet/probe-linked-exists (real id crate): chain1 [601,602] posts; mixed [601 identical, 603, 604] returned [Err(Exists), Ok, Ok] with 603/604 stored and balances moved; whole-chain identical resubmit control stayed all-Exists and moved nothing.
    • Expectation: effort s — triage picks the parity direction (InMemory fails new legs with LinkedEventFailed, or trait contract + tb binding amended), then a pinning test follows.
    • Links: evidence body in goal workspace hidden_files/issue-id-inmem-linked-exists-chain.md; queue packet packet-6170-triage.json
  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 5, 2026
  5. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

    • Agent: queue worker (repo-worker-code), lane code-a
    • Session / ID: task 9958
    • Found via: queue claim
    • Task: Triage and fix the linked-chain Exists-leg parity gap on id(currency_poc): InMemoryLedger posts new legs behind an Exists head leg in a linked chain — real TigerBeetle breaks the chain and posts nothing #6170 (packet scope includes the implementing change and the pinning test). Execution lane: direct — working this myself.
    • Decision (recorded per the acceptance criteria): Option A — InMemoryLedger matches TigerBeetle. TigerBeetle is the live backend and its chain-break semantics are fixed by the real system: a linked chain breaks on ANY non-Created leg, so a mixed chain [Exists leg, new leg, ...] posts nothing and its new legs report LinkedEventFailed. The reference backend must mirror the live one, not the reverse. The trait-surface contract is the one tb_ledger.rs already implements (PR feat(id/currency_poc): bind LedgerBackend to the official TigerBeetle Rust client (#2289) #5072): raw TigerBeetle reports [Exists, LinkedEventFailed, ...] for a resubmitted chain, and the binding compensates ONLY the whole-chain-identical-resubmit pattern back to per-leg Exists after verifying every stored leg. So InMemoryLedger will: (1) fail a mixed chain atomically — the Exists leg reports Exists, every other leg LinkedEventFailed, nothing posts, no balances move; (2) keep the whole-chain identical resubmit at per-leg Exists with nothing moving (the compensated surface both backends present). The create_transfers trait doc in ledger.rs will state these Exists-leg semantics explicitly.
    • Expectation: branch + PR with the ledger.rs change and a pinning test in tests.rs covering the mixed chain (result vector, lookup_transfer for the new legs, balances) plus the whole-chain resubmit control; cargo test -p id currency_poc green.
    • Links: task 9958 in queue repo-health-code-pilot
  6. 3 remaining items

  7. added
    status/parkedDeliberately paused with a recorded resume condition
    queue/claimedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 5, 2026
  8. added a commit that references this issue on Nov 5, 2026
  9. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

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

Metadata

Metadata

Assignees

No one assigned

    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/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