Title: aggregator(charges-collect): parseChargeCandidates accepts impossible calendar dates — dedupe breaks and hand-fed rows are silently dropped · Issue #2194 · developing-today/code · GitHub
Open Graph Title: aggregator(charges-collect): parseChargeCandidates accepts impossible calendar dates — dedupe breaks and hand-fed rows are silently dropped · Issue #2194 · developing-today/code
X Title: aggregator(charges-collect): parseChargeCandidates accepts impossible calendar dates — dedupe breaks and hand-fed rows are silently dropped · Issue #2194 · developing-today/code
Description: Bug parseChargeCandidates (pm-stack/aggregator/src/charges-collect.ts:42), the structural validation boundary for the charges candidates state file the daily collector consumes, checks a candidate's date with a shape-only regex: if (type...
Open Graph Description: Bug parseChargeCandidates (pm-stack/aggregator/src/charges-collect.ts:42), the structural validation boundary for the charges candidates state file the daily collector consumes, checks a candidate'...
X Description: Bug parseChargeCandidates (pm-stack/aggregator/src/charges-collect.ts:42), the structural validation boundary for the charges candidates state file the daily collector consumes, checks a candidate&...
Opengraph URL: https://github.com/developing-today/code/issues/2194
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"aggregator(charges-collect): parseChargeCandidates accepts impossible calendar dates — dedupe breaks and hand-fed rows are silently dropped","articleBody":"## Bug\n\n`parseChargeCandidates` (pm-stack/aggregator/src/charges-collect.ts:42), the structural validation boundary for the charges candidates state file the daily collector consumes, checks a candidate's date with a shape-only regex:\n\n```ts\nif (typeof c.at !== \"string\" || !/^\\d{4}-\\d{2}-\\d{2}/.test(c.at)) continue;\n```\n\nThat accepts impossible calendar dates — `2026-13-45`, `2026-02-30`, `2026-00-00`, `2026-10-00` all pass as \"an ISO date\" (the function's own doc comment, charges-collect.ts:25-29). The existing test (test/charges-collect.test.ts:24) only covers the non-date string `\"not-a-date\"`, which the regex does reject.\n\nThe bad dates then corrupt both consumers in opposite directions, because both `daysBetween` implementations (charges-collect.ts:63-66, charges-match.ts:118-121) are `Math.abs(Date.parse(a) - Date.parse(b))`:\n\n- **Month 13+ (`Date.parse` → `NaN`):** in `matchCharges` (charges-match.ts:196) `NaN \u003c= DEDUPE_WINDOW_DAYS` is false, so the same real charge seen by Plaid and Gmail is never deduped — it publishes as **two rows**. In `mergeChargeRows`/`sameCharge` (charges-collect.ts:79) `NaN > DEDUPE_WINDOW_DAYS` is also false, so the window check passes vacuously — a hand-fed row is **dropped as a \"duplicate\"** of an auto row whose date is actually years away.\n- **Feb 30 / day-00 (`Date.parse` rolls over):** `Date.parse(\"2026-02-30\")` is 2026-03-02, so window arithmetic silently uses a date different from the one in the file and in the published row's `at`.\n\nThe producer writes this file with the same shape-only checks (scripts/produce-charge-candidates.ts:111 for Plaid, :207 for Gmail), so the collector's validator is the only place a real calendar check can be enforced for the file as persisted state (hand edits, an older/buggier producer, a partially migrated file).\n\n## Evidence (verified this run, main 478797cd)\n\nVerbatim copies of the shipped `charges-collect.ts` + `charges-match.ts` (sha256 identical to main) run under Bun 1.4.2 on the laptop — probe: `~/git/fleet/probe-2026-10-29-laneA-chargedates/`:\n\n```\nparse \"2026-10-28\" -> ACCEPTED at=2026-10-28 (control)\nparse \"2026-13-45\" -> ACCEPTED at=2026-13-45\nparse \"2026-02-30\" -> ACCEPTED at=2026-02-30\nparse \"2026-00-00\" -> ACCEPTED at=2026-00-00\nparse \"2026-10-00\" -> ACCEPTED at=2026-10-00\nparse \"not-a-date\" -> dropped (existing test case)\nDate.parse 2026-13-45 = NaN 2026-02-30 = 2026-03-02T00:00:00.000Z\nmatchCharges rows (plaid 2026-10-28 + gmail 2026-13-45, same merchant/amount): 2 (control, both valid: 1)\nmergeChargeRows (auto at=2026-13-45 vs hand-fed at=2020-01-01, same merchant/amount): hand-fed row DROPPED (control: kept, 2 rows)\n```\n\nCollector wiring: scripts/collect-fleet-feed.ts:421-427 — `parseChargeCandidates(JSON.parse(...))` → `matchCharges(...)` → `mergeChargeRows(auto.rows, charges ?? [])`.\n\nNote: the `at.slice(0, 10)` truncation of a full timestamp (`\"2026-10-27T14:03:00Z\"` → `\"2026-10-27\"`, test line 22) is intended behavior and is **not** part of this issue — only the calendar validity of the resulting 10 chars is.\n\n## Why it matters\n\nThis file is the charges feed's source of record for a period. A single impossible date silently (a) double-publishes a charge in the hub, or (b) suppresses a legitimate hand-fed row — the exact hand-fed rows the merge exists to preserve — with no log line either way (`parseChargeCandidates` drops malformed entries silently by design, and these entries are not even seen as malformed). Validation that only checks shape is what the function's doc promises it does not do.\n\n## Acceptance criteria\n\n- [ ] `parseChargeCandidates` rejects candidates whose `at` (after the existing 10-char slice) is not a real calendar date: month 01-12, day valid for that month/year (leap years included) — `2026-13-45`, `2026-02-30`, `2026-00-00`, `2026-10-00` are dropped; `2026-02-29` is dropped but `2024-02-29` is kept.\n- [ ] Regression tests in test/charges-collect.test.ts cover the impossible-date cases above alongside the existing `\"not-a-date\"` case, and the intended full-timestamp slice case (test line 22) keeps passing.\n- [ ] With only real dates able to enter, `matchCharges` dedupe and `mergeChargeRows` hand-fed preservation behave as in the controls above (a same-charge Plaid+Gmail pair yields 1 row; a years-apart hand-fed row is kept).\n- [ ] Triage pins whether the same calendar check is also applied at the producer's two shape-only sites (scripts/produce-charge-candidates.ts:111, :207) in this fix or as a follow-up.\n\n## Dedup\n\nChecked open + closed issues and the repo backlog this run: #2130 covers the matcher's clustering rules (same-source repeats inside the window; empty-normalized merchants merging) — different defect, in `charges-match.ts` clustering, with all-valid dates. #1057 (closed) is the feature. #2161/#2172 are config env-var validation in other components. No existing issue covers calendar validity of charge candidate dates.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-29T08:42:43Z","url":"https://github.com/developing-today/code/issues/2194"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b607876d-69ec-1fcd-3f2a-1de50bed8407 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8AD4:2A9AB5:D72194:115B154:6B0642A9 |
| html-safe-nonce | 21b2a13ed1592fdea2ea714a46f3c0df5dc0a0d055e9afc9d4756611718558f3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QUQ0OjJBOUFCNTpENzIxOTQ6MTE1QjE1NDo2QjA2NDJBOSIsInZpc2l0b3JfaWQiOiI5MzAzMDgyNDkwMjk1OTE3MjEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | adf1f59d8779d51c62aa03989f18c09cc5fe1edfac1ef668efd357e617092f5c |
| hovercard-subject-tag | issue:6096084320 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/2194/issue_layout |
| twitter:image | https://opengraph.githubassets.com/54ad849b13f16ad436931f9a9cf08fd41914bdf4c5ac9c6e2d1942a09b7569d8/developing-today/code/issues/2194 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/54ad849b13f16ad436931f9a9cf08fd41914bdf4c5ac9c6e2d1942a09b7569d8/developing-today/code/issues/2194 |
| og:image:alt | Bug parseChargeCandidates (pm-stack/aggregator/src/charges-collect.ts:42), the structural validation boundary for the charges candidates state file the daily collector consumes, checks a candidate'... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1bff4f6bfaa96dc9c42cacf315424c24ebb548b06142ced5e3aaccb2a42dd652 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ac613d3698d3d8565651455086e1f74da07bf277 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width