diff --git a/pm-stack/aggregator/src/quota-extract.ts b/pm-stack/aggregator/src/quota-extract.ts index 7b86d3a7de..7560a5c748 100644 --- a/pm-stack/aggregator/src/quota-extract.ts +++ b/pm-stack/aggregator/src/quota-extract.ts @@ -153,6 +153,24 @@ function dateTimeCentral(date: string, hhmm: string): string { return `${date}T${hhmm}:00${offset}`; } +/** + * Reset captures (#2470): the hand-maintained quota view can carry an + * impossible calendar date or clock time (month 13, Feb 30, day 39, + * 99:99). The shared dateTimeCentral conversion validates Gregorian + * dates and 24-hour times and throws on those; for a reset the right + * outcome is resetsAt: null with the usage window preserved — never + * the verbatim invalid string, never a discarded read, and never a + * wallLiftsAt derived from a reset that does not exist. Valid captures + * flow through the shared conversion unchanged. + */ +function resetDateTimeCentral(date: string, hhmm: string): string | null { + try { + return dateTimeCentral(date, hhmm); + } catch { + return null; + } +} + function pctWindow(name: string, pct: number, resetsAt: string | null): QuotaWindow { const rounded = Math.round(pct * 10) / 10; return { name, unit: "other", limit: 100, used: rounded, resetsAt, percent: rounded }; @@ -206,7 +224,7 @@ const extractClaude: Extractor = (s, now) => { if (!pct) return null; const reset = first(s, /weekly reset \w+ (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}) CDT/i); return { - windows: [pctWindow("weekly", Number(pct[1]), reset ? dateTimeCentral(reset[1], reset[2]) : null)], + windows: [pctWindow("weekly", Number(pct[1]), reset ? resetDateTimeCentral(reset[1], reset[2]) : null)], note: "Freshest dated read in the stewardship quota view; Claude exposes no host-side meter.", }; }; @@ -260,7 +278,7 @@ const extractMeta: Extractor = (s, now) => { }; } const reset = first(s, /[Ww]eekly reset (?:today )?(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}) CDT/); - const resetIso = reset ? dateTimeCentral(reset[1], reset[2]) : null; + const resetIso = reset ? resetDateTimeCentral(reset[1], reset[2]) : null; const burned = /burned to empty/i.test(s); if (resetIso && now.getTime() >= Date.parse(resetIso)) { return { diff --git a/pm-stack/aggregator/test/quota.test.ts b/pm-stack/aggregator/test/quota.test.ts index 99c3fb522f..1869148955 100644 --- a/pm-stack/aggregator/test/quota.test.ts +++ b/pm-stack/aggregator/test/quota.test.ts @@ -44,6 +44,34 @@ describe("quota extractors", () => { expect(p.state).toBe("healthy"); }); + test("claude and meta invalid reset captures yield resetsAt null and preserve the read (#2470)", () => { + const invalidResets = ["2026-13-28 14:00", "2026-02-30 14:00", "2026-10-39 14:00", "2026-10-28 99:99"]; + for (const reset of invalidResets) { + const claudeView = `\n### Claude\n- weekly 68% used, weekly reset Wed ${reset} CDT\n`; + const claude = extractQuotaPools(claudeView, NOW).find((p) => p.id === "anthropic:claude-pro")!; + expect(claude.windows).toHaveLength(1); + expect(claude.windows[0].percent).toBe(68); + expect(claude.windows[0].resetsAt).toBeNull(); + + const metaView = `\n### Meta Model API\n- weekly quota 46% used at 03:20 CDT. Weekly reset today ${reset} CDT.\n`; + const meta = extractQuotaPools(metaView, NOW).find((p) => p.id === "meta:high-usage")!; + expect(meta.windows).toHaveLength(1); + expect(meta.windows[0].percent).toBe(46); + expect(meta.windows[0].resetsAt).toBeNull(); + expect(meta.wallLiftsAt).toBeUndefined(); + } + }); + + test("meta feb-30 reset neither discards the read nor invents a wall lift (#2470)", () => { + const burnedView = `\n### Meta Model API\n- weekly quota 46% used at 03:20 CDT, then burned to empty by morning sessions. Weekly reset today 2026-02-30 19:00 CDT.\n`; + const meta = extractQuotaPools(burnedView, NOW).find((p) => p.id === "meta:high-usage")!; + expect(meta.windows).toHaveLength(1); + expect(meta.windows[0].percent).toBe(46); + expect(meta.windows[0].resetsAt).toBeNull(); + expect(meta.wallLiftsAt).toBeUndefined(); + expect(meta.state).toBe("healthy"); + }); + test("codex 7-day read", () => { const p = byId.get("openai:codex")!; expect(p.windows[0].percent).toBe(11);