Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pm-stack/aggregator/src/snapshot-records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ export function recordsFromProviderUsage(snap: unknown, observedBy: string): Sna
codex_usage?: { usage?: { rate_limit?: { primary_window?: unknown; secondary_window?: unknown } } };
};
const ts = typeof s.generated_at === "string" ? s.generated_at : null;
if (!ts || Number.isNaN(Date.parse(ts))) return [];
// Strict gate, same as isSnapshotRecord's isIsoDate check on r.ts:
// Date.parse alone accepts impossible dates (2026-02-30) and non-ISO
// strings the store then refuses, silently dropping the snapshot (#5140).
if (!ts || parseIsoDate(ts) === null) return [];
const out: SnapshotRecord[] = [];
if (Array.isArray(s.sessions)) {
out.push({
Expand Down
12 changes: 12 additions & 0 deletions pm-stack/aggregator/test/snapshot-writers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ describe("recordsFromProviderUsage", () => {
expect(recordsFromProviderUsage({ sessions: [] }, "check-usage")).toEqual([]);
});

test("refuses impossible and non-ISO generated_at values the store would reject (#5140)", () => {
const withTs = (generated_at: unknown) => ({ generated_at, sessions: [1] });
// Date.parse accepts the first three; isSnapshotRecord's isIsoDate gate
// does not — records built on them were silently dropped at append.
for (const bad of ["2026-02-30T10:59:33Z", "2026-04-31T10:59:33Z", "March 2, 2026", "not-a-date"]) {
expect(recordsFromProviderUsage(withTs(bad), "check-usage")).toEqual([]);
}
const ok = recordsFromProviderUsage(withTs("2026-10-26T10:59:33Z"), "check-usage");
expect(ok).toHaveLength(1);
expect(ok.every((r) => isSnapshotRecord(r))).toBe(true);
});

test("skips an invalid window without suppressing sessions or a valid companion", () => {
const snapshot = {
generated_at: "2026-10-26T10:59:33Z",
Expand Down
Loading