Skip to content

pm-stack(aggregator): entryFromFileExport launders impossible and non-ISO measuredAt — Date.parse rolls 2026-02-30 to Mar 2 and accepts 'March 2, 2026' #5118

Closed

Description

@dezren39

Problem

entryFromFileExport in pm-stack/aggregator/src/quota-gather-map.ts:271 gates a file-export document's measuredAt with raw Date.parse and a NaN check only:

const measuredMs = doc.measuredAt ? Date.parse(doc.measuredAt) : Number.NaN;
if (doc.status !== "ok" || Number.isNaN(measuredMs)) { /* error entry */ }
const measuredAt = new Date(measuredMs).toISOString();

Date.parse rolls impossible calendar dates forward and accepts non-ISO strings, so a corrupt or hand-written export stamp is silently rewritten to a different day and published as a successful (state: "ok") quota-current entry — stamped onto the entry and onto every window it carries. The same file already gates both Turso billing-period stamps with isIsoDate before Date.parse (quota-gather-map.ts:636-637, #5091), and parseQuotaCurrent gates its measuredAt with isIsoDate (#4987); this mapper is the remaining raw-Date.parse gate for a measuredAt in the quota path.

Evidence (verified this run, origin/main dd04e9cd4)

Laptop bun probe calling entryFromFileExport with a status-ok doc (one weekly window at 42%):

input measuredAt result
2026-02-30T12:00:00Z state ok, stored as 2026-03-02T12:00:00.000Z
2026-04-31T12:00:00Z state ok, stored as 2026-05-01T12:00:00.000Z
March 2, 2026 state ok, stored as 2026-03-02T06:00:00.000Z (TZ-dependent)
03/02/2026 state ok, stored as 2026-03-02T06:00:00.000Z (TZ-dependent)
not-a-date error entry (correct)
null error entry (correct)
2026-11-03T12:00:00Z state ok, unchanged (correct)

Callers are live and neither pre-validates the stamp: scripts/gather-quota.ts:566 (runFileExport — JSON.parse of the producer's latest.json cast straight to FileExportDoc) and src/token-adapter.ts:294 (its fail-closed check validates the windows, not measuredAt).

Why it matters

The entry's measuredAt is what freshness/age derivations read for the file-export convention (#1301) — the pattern other laptop exports follow. An impossible stamp that rolls forward (Feb 30 → Mar 2) makes a stale or corrupt export read as measured later than it was, and a non-ISO stamp's stored value depends on the host time zone, so the same document yields different quota-current entries on different hosts. Garbage stamps already produce the right outcome (an error entry, never zeros); impossible/non-ISO stamps should take the same path instead of being laundered into a plausible date.

Acceptance criteria

  • entryFromFileExport returns an error entry (not state: "ok") for impossible dates 2026-02-30… and 2026-04-31… and for non-ISO stamps March 2, 2026 and 03/02/2026, by gating measuredAt with isIsoDate (validate.ts:116) before Date.parse, matching the Turso gate in the same file.
  • Valid ISO stamps, null/missing measuredAt, non-ok statuses, stale docs, and doc: null behave exactly as before.
  • New tests in pm-stack/aggregator/test/quota-gather-map.test.ts cover the impossible/non-ISO refusals and the valid control; bun test in pm-stack/aggregator passes.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    source/creatorFiled by the new-issue-creator job
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    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 14:05 CST
    • Found via: filed this run
    • Task: entryFromFileExport (quota-gather-map.ts:271) gates a file-export doc's measuredAt with raw Date.parse/NaN-only, so impossible dates roll forward (2026-02-30 -> Mar 2) and non-ISO strings parse TZ-dependently, and the rewritten stamp is published as a state:"ok" quota-current entry; gate it with isIsoDate like the Turso stamps in the same file (pm-stack(aggregator): entryFromTurso computes windowSeconds with raw Date.parse — impossible/non-ISO billing-period stamps roll instead of yielding null #5091)
    • Expectation: effort s — small_fix packet enqueued to repo-health-code-pilot; done = error entry for impossible/non-ISO stamps, valid controls unchanged, new quota-gather-map tests green
    • Links: evidence in the issue body (laptop bun probe at origin/main dd04e9cd4)
  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:v1
    state: picked_up
    worker: repo-worker-code
    task: 8788
    lane: aea12c82-c5af-4e5a-9b66-f8e360f87177
    Picked up for the scoped measuredAt validation fix. Issue #5118 is open with no hard-stop labels; no open PR referencing it was found. The packet scope is limited to entryFromFileExport and its tests, using the existing isIsoDate helper.

  5. 50 remaining items

  6. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  7. added
    queue/claimedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 4, 2026
  8. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · handed off

  9. developing-today commented on Nov 4, 2026

    @developing-today
    Contributor

    🤖 Agent note · handed off

    • Agent: OpenCode claimant (opencode-claimant)
    • Queue task: task 8788 (repo-health-code-pilot, worker repo-worker-code)
    • Issue: #5118
    • Session: ses_e5e58649aceffeKAXZF1PJrHia
    • Route: opencode-route/workhorse; agent build
    • Expectation: this bound session works only task 8788, revalidates fresh state, heartbeats, and records a terminal queue state with this same session id.
  10. dezren39 commented on Nov 4, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

  11. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · done (triage) — already fixed on current main, verified closure

    Verdict — bug no longer reproduces on current main; closing with evidence

    Code (origin/main, laptop primary at 2aca793): entryFromFileExport no longer gates with raw Date.parse. pm-stack/aggregator/src/quota-gather-map.ts:330 now reads const measured = parseIsoDate(doc.measuredAt); if (doc.status !== "ok" || measured === null) -> error entry. parseIsoDate (pm-stack/aggregator/src/validate.ts:66) enforces the ISO-8601 shape with a regex AND re-checks real calendar days (daysInMonth/leap years), so impossible dates fail instead of rolling over.

    Behaviour probe (bun, calling entryFromFileExport from current main with a status-ok doc, one weekly window at 42%):

    • 2026-02-30T12:00:00Z -> error entry
    • 2026-04-31T12:00:00Z -> error entry
    • March 2, 2026 -> error entry
    • 03/02/2026 -> error entry
    • not-a-date -> error entry
    • null -> error entry
    • 2026-11-03T12:00:00Z -> state ok, stored unchanged (correct)

    Every row of the original evidence table now behaves correctly. This is an explicit verified closure with evidence (the triage-doctrine exit for a bug fixed upstream by the parseIsoDate refactor, #5091/#2576 family), not a triage-completion closure.

    PR #5126 is superseded: its code change (isIsoDate gate on the old Date.parse line) targets code that no longer exists on main, and its one unique item — a regression test for these exact stamps — is behaviour already covered for the shared validator (e.g. events.test.ts:287 uses the same 2026-02-30 / March 2, 2026 / 03/02/2026 inputs). Closing PR #5126 as superseded with that salvage note on the PR.

    No fix packet is enqueued: there is no remainder.

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)meta/protocol-gapAn agent touched this without the required agent-note comment or labels; needs review of whypriority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted testsuser/reviewNeeds a user-look: Muse reviews first and handles what it can

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions