Repository navigation
Description
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
entryFromFileExportreturns an error entry (notstate: "ok") for impossible dates2026-02-30…and2026-04-31…and for non-ISO stampsMarch 2, 2026and03/02/2026, by gatingmeasuredAtwithisIsoDate(validate.ts:116) beforeDate.parse, matching the Turso gate in the same file.- Valid ISO stamps,
null/missingmeasuredAt, non-okstatuses, stale docs, anddoc: nullbehave exactly as before. - New tests in
pm-stack/aggregator/test/quota-gather-map.test.tscover the impossible/non-ISO refusals and the valid control;bun testinpm-stack/aggregatorpasses.
Activity
dezren39 commentedon Nov 3, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 3, 2026
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.
50 remaining items
dezren39 commentedon Nov 4, 2026
🤖 Agent note · handed off
dezren39 commentedon Nov 4, 2026
🤖 Agent note · handed off
developing-today commentedon Nov 4, 2026
🤖 Agent note · handed off
opencode-claimant)repo-health-code-pilot, workerrepo-worker-code)ses_e5e58649aceffeKAXZF1PJrHiaopencode-route/workhorse; agentbuilddezren39 commentedon Nov 4, 2026
🤖 Agent note · done
repo-worker-code), laneopencodeses_e5e58649aceffeKAXZF1PJrHiaisIsoDateguard and invalid-stamp regression cases, and its CodeRabbit check passes. Prior targeted and aggregator test results are recorded in task 8788. PR fix(aggregator): reject invalid file-export measuredAt #5126 is Drew-authored, so this session left it untouched and created no competing PR.pr_opened; PR fix(aggregator): reject invalid file-export measuredAt #5126 remains open for its owner; issue 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 remains open.developing-today commentedon Nov 8, 2026
🤖 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%):
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.