Repository navigation
Description
Problem
normalizeResetAt in pm-stack/aggregator/src/quota-gather-map.ts (lines 44–57, at main 67f97516c) normalizes a provider reset stamp to ISO. Its numeric branch is guarded (finite, > 0, valid Date), but its string branch is Date.parse-only:
if (typeof v === "string" && v !== "") {
const t = Date.parse(v);
return Number.isNaN(t) ? null : new Date(t).toISOString();
}Date.parse rolls impossible calendar dates over to a different real date and accepts non-ISO formats, so a drifted/malformed provider stamp is silently converted into a wrong-but-plausible resetsAt instead of null. Garbage strings do return null — the gate is inconsistent within itself: "not-a-date" → null, but "2026-02-30" → a fabricated March 2 reset time.
This contradicts the aggregator's own date contract: isIsoDate/parseIsoDate (pm-stack/aggregator/src/validate.ts:116) rejects impossible dates by round-trip, and the feed gates built on it (isQuotaFreshness feed.ts:502, isQuotaWindow feed.ts:474) already refuse such values.
Evidence (verified this run, laptop bun probe at origin/main 67f97516c)
Probe: /tmp/probe-resetat.ts importing normalizeResetAt from the worktree copy of quota-gather-map.ts; output in /tmp/probe-resetat.log on the laptop:
| input | result |
|---|---|
"2026-02-30" |
"2026-03-02T00:00:00.000Z" — impossible date rolled over |
"2026-04-31" |
"2026-05-01T00:00:00.000Z" — impossible date rolled over |
"2026-02-29" (2026 is not a leap year) |
"2026-03-01T00:00:00.000Z" — rolled over |
"March 2, 2026" |
"2026-03-02T06:00:00.000Z" — non-ISO format accepted (and TZ-shifted) |
"2026-03-02" |
"2026-03-02T00:00:00.000Z" — control OK |
"2026-03-02T00:00:00.000Z" |
unchanged — control OK |
"2024-02-29" (leap year) |
"2024-02-29T00:00:00.000Z" — control OK |
"not-a-date" |
null — garbage already refused |
Call sites that inherit the flaw (all feed the quota-current contract's resetsAt, which drives reset-time display and reset-soon guidance):
pm-stack/aggregator/src/clinepass-adapter.ts:106— ClinePass windowresetsAtpm-stack/aggregator/src/quota-gather-map.ts:279— Meta file-export windowspm-stack/aggregator/src/quota-gather-map.ts:345—entryFromResultprovider windowspm-stack/aggregator/src/quota-gather-map.ts:618— Turso billing period end
Related sites in the same file worth checking in the same pass (not the primary scope): the credentialExpiresAt string branch in entryFromResult (Date.parse + toISOString, ~line 340) and the Turso period start/end Date.parse pair (~lines 621–622), from which windowSeconds is derived.
Why it matters
resetsAt is operator-facing: it tells Drew when a quota pool resets and feeds reset-soon choices. A provider payload that drifts (or a hand-edited file export) carrying an impossible date currently produces a confident, wrong reset time a day or two off, instead of the null the same function already returns for unparseable strings. Every sibling date gate in the aggregator was hardened to the isIsoDate contract for exactly this failure mode; this shared normalizer — the one four call sites funnel through — was missed.
Acceptance criteria
normalizeResetAtreturnsnullfor impossible calendar dates (2026-02-30,2026-04-31,2026-02-29) and for non-ISO date strings ("March 2, 2026").- Valid inputs are unchanged: ISO date/datetime strings normalize as today,
2024-02-29passes, epoch-second and epoch-millisecond numbers behave as today, garbage strings still returnnull. - Regression tests added to
pm-stack/aggregator/test/quota-gather-map.test.tscovering the refused and accepted cases above. - Existing aggregator test suites (at minimum quota-gather-map, clinepass-adapter, feed) still pass.
- The related
credentialExpiresAt/ Turso periodDate.parsesites in the same file are either fixed to the same contract or explicitly called out in the PR as follow-ups.
Activity
dezren39 commentedon Nov 3, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 3, 2026
🤖 Agent note · handed off
dezren39 commentedon Nov 3, 2026
🤖 Agent note · handed off
5 remaining items
developing-today commentedon Nov 7, 2026
Picked up by
repo-worker-code-t— working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live whilerepo-worker-code-tposts progress markers; after 30 minutes of silence any other worker may pick this up.)developing-today commentedon Nov 7, 2026
Picked up by
repo-worker-code-t— working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live whilerepo-worker-code-tposts progress markers; after 30 minutes of silence any other worker may pick this up.)developing-today commentedon Nov 7, 2026
Picked up by
repo-worker-code-t— working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live whilerepo-worker-code-tposts progress markers; after 30 minutes of silence any other worker may pick this up.)developing-today commentedon Nov 7, 2026
Picked up by
repo-worker-code-t— working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live whilerepo-worker-code-tposts progress markers; after 30 minutes of silence any other worker may pick this up.)developing-today commentedon Nov 7, 2026
Progress from
repo-worker-code-t: picked_up: revalidated at current main - normalizeResetAt already uses parseIsoDate (fix 96c43b5, #2579) and bun probe confirms every acceptance case; credentialExpiresAt gated by isIsoDate and Turso windowSeconds by parseIsoDate (#5091); remaining gap = direct normalizeResetAt regression tests for refused string cases; user/review reviewed by lane: no Drew decision, proceed test-onlydeveloping-today commentedon Nov 7, 2026
🤖 Agent note · picked up (already fixed in behaviour; regression tests owed)
user/review): I reviewed it first per §9 — the acceptance is mechanical (behaviour + tests), no Drew-owned decision; nothing escalated.normalizeResetAtusesparseIsoDatesince 96c43b5 (aggregator: Phase 3 of #2576 — extractor and mapper boundaries on the shared primitives #2579, 2026-11-03 09:34 CST, ~1h after this issue's evidence commit 67f9751). A bun probe at current main confirms every acceptance case:2026-02-30/2026-04-31/2026-02-29/"March 2, 2026"→null; controls (2026-03-02, ISO datetime,2024-02-29, epoch s/ms) unchanged. The related sites are also fixed:credentialExpiresAtis gated byisIsoDate(with rejection tests), and the Turso period pair is gated byparseIsoDate(pm-stack(aggregator): entryFromTurso computes windowSeconds with raw Date.parse — impossible/non-ISO billing-period stamps roll instead of yielding null #5091, with tests).normalizeResetAtdescribe block inpm-stack/aggregator/test/quota-gather-map.test.tshas no direct tests for the refused string cases above — the acceptance's regression-test item. A small test-only PR closes that, then this issue closes as already-done.developing-today commentedon Nov 7, 2026
Progress from
repo-worker-code-t: pr_opened: PR #6818 (test-only, b38c61b) adds the missing normalizeResetAt regression tests; bun suites 149 pass/0 fail; next: Codex check + merge, release done (already-fixed behaviour)Merge pull request #6818 from developing-today/queue/4968-normalize-r…
developing-today commentedon Nov 7, 2026
🤖 Agent note · done (already fixed in behaviour; regression tests landed)
normalizeResetAtusesparseIsoDate; bun probe at current main returnednullfor2026-02-30,2026-04-31,2026-02-29,"March 2, 2026"and unchanged values for all controls. Related sites already on the same contract:credentialExpiresAtviaisIsoDate, Turso period pair viaparseIsoDate(pm-stack(aggregator): entryFromTurso computes windowSeconds with raw Date.parse — impossible/non-ISO billing-period stamps roll instead of yielding null #5091). PR test(aggregator): normalizeResetAt impossible/non-ISO date regressions (#4968) #6818 added the missing direct regression tests fornormalizeResetAt's refused/accepted string cases.bun test test/quota-gather-map.test.ts test/clinepass-adapter.test.ts test/feed.test.ts— 149 pass, 0 fail.developing-today commentedon Nov 7, 2026
Released by
repo-worker-code-t(outcome: done). already_done in behaviour (fix 96c43b5 #2579; probe-verified all acceptance cases) + regression tests landed: PR #6818 merged c110f92; bun suites quota-gather-map/clinepass-adapter/feed 149 pass 0 fail; related sites already fixed (credentialExpiresAt isIsoDate, Turso parseIsoDate #5091)