#3840·sure

Bug: Enable Banking — same-batch duplicate when the identified version of a brand-new movement is ordered before its identifierless twin

Author: albertinisgCreated Sep 29, 2026Updated Sep 29, 2026

Before you start

  • I have removed personal / sensitive data from screenshots and logs
  • I have searched existing issues to ensure this is not a duplicate — closest is #3459/#3462 (a different transition) and #3464 (a broader "IDs are unstable" report); this is a narrower, specific ordering gap

Self hoster checklist

  • Self hosted, Docker Compose, ghcr.io/we-promise/sure:0.7.4, with the fix from #3459 applied via a local override (mirrors what #3462 proposes upstream)

Bug description

When Enable Banking returns both the identifierless and the identified version of a brand-new movement together in the same sync, and the identified one happens to be processed first, the same-movement claim added in #3459/#3462 never fires — because the candidate set of "identifierless rows a later identifier can claim" is only populated after an identifierless row has actually been imported. If the identified twin is processed before that, there is nothing to claim against yet, and both rows import as separate transactions.

This is a different case from the one #3459/#3462 fixes: that one is a day 1 → day 2 transition (identifierless today, identified tomorrow), and is tested and fixed for both same-batch orderings of that specific case (identifierless-first-in-batch, and identifierless-already-in-the-DB-from-a-prior-sync). This case is both rows brand new, same batch, and only fails when the identified one is ordered first.

Evidence

Found on my own ledger after deploying the #3459 fix locally. Four pairs, all created 2026-09-15, both halves of each pair seconds apart (same sync run):

date amount payee (redacted where personal) content-hash row created reference-keyed row created
2026-09-14 5.00 (a cafeteria purchase) 2026-09-15 00:22:45 2026-09-15 00:22:45
2026-09-14 30.00 (same merchant, different item) 2026-09-15 00:22:45 2026-09-15 00:22:45
2026-09-14 1.95 Mercadona 2026-09-15 00:22:50 2026-09-15 00:22:51
2026-09-14 60.28 Mercadona 2026-09-15 00:22:50 2026-09-15 00:22:51

All four are plain BOOK rows (extra["enable_banking"]["pending"] is nil on both sides of each pair) — not a pending-related case.

Root cause (as implemented in #3462, and identically in my local mirror of it)

EnableBankingAccount::Transactions::Processor#process iterates raw_transactions_payload in array order and only adds a row to the shared claimable-candidate set after successfully importing it:

ruby
if ext_id && EnableBankingEntry::Processor.identifierless?(transaction_data)
  shared_identifierless_external_ids.add(ext_id)
end

If the array order for this sync happens to place the identified payload before its identifierless twin — which depends entirely on the order Enable Banking's own API returned them in, not something Sure controls — the identified row is processed first, finds nothing in shared_identifierless_external_ids yet, and imports as its own transaction. The identifierless row is then processed and also imports as its own transaction (it never checks the claim mechanism at all, since claim_identifierless_predecessor! is a no-op when the incoming payload is itself identifierless).

To Reproduce

  1. Have a family with Family#known_merchant_names unrelated to this (irrelevant here).
  2. In a single EnableBankingAccount::Transactions::Processor#process run, feed raw_transactions_payload containing, for the same underlying movement, the identified payload before the identifierless one:
    ruby
    settled       = { ..., entry_reference: "2026-09-14.1", ... }
    identifierless = settled.except(:entry_reference)
    account.raw_transactions_payload = [ settled, identifierless ]
  3. Both import as separate transactions.

(Compare with the existing test in #3462, "a movement identified later in the same batch does not import twice", which orders the array [ identifierless, settled ] — the only ordering currently covered.)

Suggested direction (not proposing a patch here)

A general fix needs a first pass over the whole incoming batch to build the claimable-candidate set (which content hashes appear as identifierless anywhere in this batch) before any row is imported, rather than discovering candidates incrementally as rows are processed in array order. I don't have a patch to offer for this one — wanted to get it tracked and reproduced rather than sit on it, especially since it's already bitten a real account.