Skip to content

pm-stack(aggregator): normalizeResetAt accepts impossible and non-ISO reset dates — its string branch is Date.parse-only, rolling 2026-02-30 to Mar 2 instead of returning null #4968

Closed

Description

@dezren39

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 window resetsAt
  • pm-stack/aggregator/src/quota-gather-map.ts:279 — Meta file-export windows
  • pm-stack/aggregator/src/quota-gather-map.ts:345 — entryFromResult provider windows
  • pm-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

  • normalizeResetAt returns null for 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-29 passes, epoch-second and epoch-millisecond numbers behave as today, garbage strings still return null.
  • Regression tests added to pm-stack/aggregator/test/quota-gather-map.test.ts covering the refused and accepted cases above.
  • Existing aggregator test suites (at minimum quota-gather-map, clinepass-adapter, feed) still pass.
  • The related credentialExpiresAt / Turso period Date.parse sites in the same file are either fixed to the same contract or explicitly called out in the PR as follow-ups.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    priority/lowNice to have; do when convenient
    app/pm-stackpm-stack (Pad/Grist) in developing-today/code
    on Nov 3, 2026
  2. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (lane A, slug new-issue-creator-code-a)
    • Session / ID: cron new-issue-creator-code-a, run 2026-11-03 08:35 CST
    • Found via: filed this run
    • Task: Filed after verifying on the laptop at origin/main 67f9751: normalizeResetAt (pm-stack/aggregator/src/quota-gather-map.ts:44-57) string branch is Date.parse-only — bun probe (/tmp/probe-resetat.log on laptop) showed 2026-02-30 → 2026-03-02, 2026-04-31 → 2026-05-01, 2026-02-29 → 2026-03-01, "March 2, 2026" accepted; garbage → null and leap/ISO controls OK. Fix packet enqueued to repo-health-code-pilot.
    • Expectation: effort/s — small-fix: gate the string branch on the aggregator's isIsoDate contract (validate.ts:116) so impossible/non-ISO stamps return null; regression tests in test/quota-gather-map.test.ts.
    • Links: evidence in the issue body; packet packet-4968-fix.json in the goal hidden_files.
  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 3, 2026
  4. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  5. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

    • Agent: opencode-claimant
    • Session / ID: ses_e5e5d22ab54ffee4nB9PyxJLlH · queue task 8116
    • Route: opencode-route/workhorse · build
  6. 5 remaining items

  7. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor

    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 while repo-worker-code-t posts progress markers; after 30 minutes of silence any other worker may pick this up.)

  8. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor

    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 while repo-worker-code-t posts progress markers; after 30 minutes of silence any other worker may pick this up.)

  9. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor

    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 while repo-worker-code-t posts progress markers; after 30 minutes of silence any other worker may pick this up.)

  10. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor

    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 while repo-worker-code-t posts progress markers; after 30 minutes of silence any other worker may pick this up.)

  11. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor

    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-only

  12. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor

    🤖 Agent note · picked up (already fixed in behaviour; regression tests owed)

  13. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor

    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)

  14. added a commit that references this issue on Nov 7, 2026
  15. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor

    🤖 Agent note · done (already fixed in behaviour; regression tests landed)

  16. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor

    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)

  17. removed
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    user/reviewNeeds a user-look: Muse reviews first and handles what it can
    on Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/pm-stackpm-stack (Pad/Grist) in developing-today/codekind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions