Skip to content

feat(aggregator): charges auto-matcher core — dedupe Plaid+Gmail charges, match to hub services (#1057) - #2113

Merged
dezren39 merged 1 commit into
mainfrom
queue/2990-1057-charges-match
Oct 29, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/2990-1057-charges-match

Conversation

@dezren39

@dezren39 dezren39 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Queue task 2990 / issue #1057 — step 2+4 core of the charges auto-matcher (pure module first, collector wiring next).

What this adds

  • pm-stack/aggregator/src/charges-match.ts — pure, deterministic matcher:
    • ChargeCandidate normalization for both sources (Plaid transactions and Gmail receipt/card alerts share the shape: date, merchant, amount, method).
    • Merchant normalization: strips * descriptors, id-like tokens (e.g. UC5DPA22Y4), filler (US, INC, .COM), and pure-digit tokens.
    • Cross-source dedupe on amount + normalized merchant + date within a 3-day window; Plaid is the source of record on a tie (row labelled Plaid, Plaid date/method win); Gmail-only rows labelled Gmail alert.
    • Service matching against hub service names/aliases (e.g. a ChatGPT charge labels as OpenAI); unmatched SaaS/AI-looking charges returned separately for the attention strip.
    • Non-positive candidates (refunds/inflows) ignored; no balances/debt data passes through — charge evidence only.
    • Deterministic: re-running a period republishes identical rows (the feed section is replaced, not appended), which is the idempotency the acceptance criteria require.
  • pm-stack/aggregator/test/charges-match.test.ts — 10 fixture tests covering dedupe, window edges, aliases, unmatched surfacing, and rerun determinism.

Verified

  • Step 1 (task 2990): Plaid connector connected (4 linked institutions); transactions-get shape verified live for a 14-day window. Gmail connector connected.
  • Laptop: bun test test/charges-match.test.ts test/usage.test.ts — 31 pass. Files biome-formatted (treefmt-clean).
  • tsc --noEmit in a fresh worktree reports only the pre-existing missing @types/bun in that worktree (no node_modules); no errors in the new files.

Remaining for #1057 (task 2990 stays open, parked with this resume point)

  • Collector wiring in scripts/collect-fleet-feed.ts: Plaid read + Gmail alert read for the period, candidate normalization, persisted classification state so unmatched charges surface exactly once, feed charges section + attention surfacing.
  • One live daily-collector run proving the /quota strip populates with no manual copying.

Refs #1057


View with [code]smith Autofix with [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 October 29, 2026 04:36
@coderabbitai

coderabbitai Bot commented Oct 29, 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 2 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: 048b4498-a6bf-49f3-9985-5d7c4704beda
Commits

Reviewing files that changed from the base of the PR and between 42796be and 62dde64.

Files selected for processing: 2
  • pm-stack/aggregator/src/charges-match.ts
  • pm-stack/aggregator/test/charges-match.test.ts
  • 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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T04:38:15.787315Z 62dde64 PR opened
ℹ️ 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: 62dde64762

ℹ️ 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 on lines +195 to +199
const existing = clusters.find(
(cl) =>
cl.amountUsd === candidate.amountUsd &&
cl.normalized === normalized &&
daysBetween(cl.first.at, candidate.at) <= DEDUPE_WINDOW_DAYS,

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 Preserve separate purchases from the same source

When two distinct Plaid transactions have the same merchant and amount within three days, this lookup merges them even though both are from Plaid. For example, two $20 OpenAI purchases on consecutive days, paid with different cards, produce only one $20 row; adding their Gmail alerts still leaves one row. The unconditional continue discards every additional observation after a source slot is occupied, silently understating charge evidence. Restrict cross-source matching to clusters whose slot for the incoming source is empty, preserving separate purchases and pairing their alerts one-to-one.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant