Repository navigation
Conversation
Some banks send two different rows with the same reference on one day, or the same row twice across pages. Both used the same id, so the insert hit the unique key and the whole link failed. Exact repeats are now dropped. A different row with a taken id gets its amount and text added, which gives the same id on every sync. The shared save step also drops repeated ids, so one bad row can't fail a link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
minimus7
left a comment
There was a problem hiding this comment.
Nice fix, the link works again. Two things in uniqueIds before merging.
| const key = JSON.stringify([r.plaid_transaction_id, r.date, r.amount, r.name]); | ||
| if (same.has(key)) continue; | ||
| same.add(key); | ||
| if (!seen.has(r.plaid_transaction_id)) { seen.set(r.plaid_transaction_id, r); continue; } |
There was a problem hiding this comment.
Whoever comes first keeps the bank id, so if the bank sends the two rows in the other order next sync, the ids swap. Tried it: [Coffee, Lunch] gives x = Coffee, but [Lunch, Coffee] gives x = Lunch. Coffee's saved row then gets Lunch's amount (keeping Coffee's category), and both show up again as new rows. Sorting rows that share an id by amount and name first would keep it stable.
| * same id on every sync. The first row keeps the bank's id, so rows saved before this stay matched. */ | ||
| export function uniqueIds(rows: FeedTxn[]): FeedTxn[] { | ||
| const seen = new Map<string, FeedTxn>(); | ||
| const same = new Set<string>(); // bank id, day, amount and text: the same row sent again |
There was a problem hiding this comment.
This also drops two real identical purchases (two $5 coffees on the same day with the reused ref). Maybe only treat it as a repeat when it comes from a different page?
| const accountId = new Map((saved ?? []).map((a) => [a.plaid_account_id, a.id])); | ||
| const txns = feed.filter((t) => accountId.has(t.account_ref)); | ||
| // One row per id: a repeated id in one batch would fail the whole insert. Providers make their ids unique first. | ||
| const txns = [...new Map(feed.filter((t) => accountId.has(t.account_ref)).map((t) => [t.plaid_transaction_id, t])).values()]; |
There was a problem hiding this comment.
Fine as a backstop. Could log when it drops something so we know which provider sent bad ids.
… page Review follow-up on uniqueIds. - Rows that share an id are ordered by day, amount and text before ids are given out, so each row keeps its id when the bank sends them in another order. - A row is dropped as a repeat only when an earlier page already held it. The same row twice on one page is two real payments, so both stay. - saveFeed logs how many rows it dropped for repeated ids. Count and provider only, no ids, amounts or text. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
This reply and commit 6b869a4 were written by Claude (Claude Code) on canyild's behalf, not by canyild personally. Thanks for the review. All three are in 6b869a4.
Two limits are left that I want to be open about:
A fix for 1 would be to never use the bare Checked with |
What broke
Linking a real bank through Enable Banking failed with "That bank didn't connect." The server log showed:
The bank sent no
transaction_id, soebTxnusedentry_reference. That bank reuses one reference for different rows on the same day. Both rows got the same id, the insert failed, and the whole link failed with it. It happened again on every retry.The fix
feeds.ts: newuniqueIds(), run on Enable Banking rows. An exact repeat (same id, day, amount and text) is dropped. A different row with a taken id gets|amount|textadded. That id comes out the same on every sync, so rows don't double up later. The first row keeps the bank's id, so rows already saved stay matched.sync.ts:saveFeedkeeps one row per id before inserting, so one bad row can't fail a link for any provider.feeds.test.ts: covers dropped repeats, stable new ids, and same amount and text on another day.Checked
node src/lib/providers/feeds.test.ts,npx tsc --noEmitandnpm run linton the changed files pass.🤖 Generated with Claude Code