Skip to content

pm-stack(aggregator): parseQuotaCurrent accepts impossible and non-ISO measuredAt — entry and window measuredAt are typeof-only, unlike the isIsoDate gates on resetsAt/credentialExpiresAt in the same functions #4987

Closed

Description

@dezren39

Problem

pm-stack/aggregator/src/quota-current.ts gates the gatherer's quota-current.json with parseQuotaCurrent. In the same two gate functions, some date fields are held to the shared real-calendar rule and the most load-bearing one is not:

  • window resetsAt must pass isIsoDate (quota-current.ts:61)
  • entry credentialExpiresAt must pass isIsoDate (quota-current.ts:80)
  • entry measuredAt is only typeof value.measuredAt === "string" (quota-current.ts:75)
  • window measuredAt is only typeof value.measuredAt === "string" (quota-current.ts:62)

measuredAt is the field the whole overlay runs on: entryState (quota-current.ts:137) classifies an entry fresh/stale from Date.parse(entry.measuredAt), newestFirst (quota-current.ts:161) picks the winning entry by it, and applyEntry (quota-current.ts:208) stamps it verbatim onto the pool as its displayed freshness.

Date.parse rolls day-overflow dates over and accepts non-ISO strings, so a gatherer entry stamped 2026-02-30T12:00:00.000Z passes the gate, parses as March 2, and — at a wall-clock time near March 2 — classifies as a fresh "ok" read: its windows replace the pool's windows, the pool recomputes healthy, and the freshness stamp shown for the pool is a date that never existed. A stamp of March 2, 2026 passes the same way. Every sibling date field in the same gate, and the shared validate.ts contract (parseIsoDate/isIsoDate: impossible calendar dates FAIL instead of rolling over), say this input is malformed.

Verified this run (laptop bun probe, origin/main 314fbbe)

Probe /tmp/probe-qc.ts on the laptop (log /tmp/probe-qc.log), driving parseQuotaCurrent and overlayQuotaCurrent directly:

impossible-entry+window 2026-02-30   providersKept=1 dropped=0 winKept=1
noniso-entry "March 2, 2026"         providersKept=1 dropped=0 winKept=1
contrast credentialExpiresAt 2026-02-30 (measuredAt valid)  providersKept=null (entry refused)
contrast window resetsAt 2026-02-30 (measuredAts valid)     providersKept=1 winKept=0 (window dropped)
control leap 2024-02-29              providersKept=1 dropped=0 winKept=1
overlay freshness={"measuredAt":"2026-02-30T12:00:00.000Z","source":"probe","state":"ok"} poolState=healthy windows=1

The overlay case: an entry stamped 2026-02-30T12:00:00.000Z, viewed at 2026-03-02T12:05:00Z, is classified fresh, replaces the pool's windows, sets the pool healthy, and displays the impossible stamp verbatim as the pool's freshness.

Why it matters

quota-current.json is written by an external gatherer process on a 15-minute tick; a skewed, hand-edited, or drifted write is exactly what this gate exists to isolate (the file's own history: #1541 future-dated reads, #2253 garbage stamps winning the stale-path pick, #2416 malformed windows). Those fixes finite-gated the consumers of measuredAt, but the gate still admits stamps that name no real instant — and the rollover makes them more dangerous than garbage: a garbage stamp parses to NaN and loses, while an impossible stamp parses to a real, possibly-fresh instant and wins, wearing a freshness label that never existed.

Acceptance criteria

  • isQuotaCurrentEntry refuses (drops, per the gate's existing per-entry isolation) an entry whose measuredAt is not a real ISO calendar date/time, using the shared isIsoDate primitive from validate.ts — e.g. 2026-02-30T12:00:00.000Z, 2026-04-31T12:00:00.000Z, March 2, 2026 are refused; this matches the existing treatment of credentialExpiresAt in the same function.
  • isQuotaCurrentWindow applies the same rule to a window's measuredAt, matching its existing resetsAt rule — a malformed window drops without dropping its entry's valid windows.
  • Real timestamps still validate, including leap dates (2024-02-29T12:00:00.000Z) and the new Date().toISOString() shapes the gatherer writes — the existing tests in pm-stack/aggregator/test/quota-current.test.ts stay green.
  • New tests in pm-stack/aggregator/test/quota-current.test.ts cover the impossible-date and non-ISO refusals for both the entry and the window, plus a leap-date control that is kept.

Dedup / related

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
    queue/queuedHas a queued task in the Supabase agent queue
    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 (new-issue-creator-code-a)
    • Session / ID: new-issue-creator-code-a run 2026-11-03 09:05 CST
    • Found via: filed this run
    • Task: parseQuotaCurrent's entry/window gates check measuredAt with typeof only while the same functions isIsoDate-gate resetsAt and credentialExpiresAt — an impossible stamp (2026-02-30) rolls over in Date.parse, classifies fresh, and is displayed verbatim as pool freshness. Verified by laptop bun probe at origin/main 314fbbe (log /tmp/probe-qc.log on the laptop).
    • Expectation: effort s — small_fix via the queue; done when both measuredAt fields use the shared isIsoDate primitive and the new quota-current tests cover impossible/non-ISO refusals plus a leap control.
    • Links: evidence in the issue body; queue packet packet-4987-fix.json (repo-health-code-pilot)
  3. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed
    queue/queuedHas a queued task in the Supabase agent queue
    on Nov 3, 2026
  4. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

    • Agent: queue worker (repo-worker-code), lane B (code-b)
    • Session / ID: queue task 8161
    • Found via: queue claim in repo-health-code-pilot
    • Task: Add the isIsoDate gate to entry and window measuredAt in pm-stack/aggregator/src/quota-current.ts plus regression tests.
    • Expectation: branch + PR; verified fresh against current main — both measuredAt checks are still typeof-only while resetsAt/credentialExpiresAt in the same functions use isIsoDate.
  5. dezren39 commented on Nov 3, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — fixed and merged

    • Agent: queue worker (repo-worker-code), lane B (code-b)
    • Session / ID: queue task 8161
    • Result: PR fix(aggregator): gate quota-current measuredAt with isIsoDate (#4987) #4996 merged (squash, ffad69a). Entry and window measuredAt in pm-stack/aggregator/src/quota-current.ts now go through isIsoDate, matching the resetsAt/credentialExpiresAt gates in the same functions.
    • Tests: 3 new regression tests in test/quota-current.test.ts (impossible/non-ISO entry dropped with siblings surviving; impossible/non-ISO window dropped without dropping valid windows; leap date 2024-02-29 still validates). Laptop bun test test/quota-current.test.ts: 42 pass, 0 fail. Codex review failed on usage limits with zero findings (disposition on PR fix(aggregator): gate quota-current measuredAt with isIsoDate (#4987) #4996); CodeRabbit skipped.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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