From ea496a754c51f19513097562744494e09470d431 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sat, 21 Nov 2026 19:42:59 -0600 Subject: [PATCH] fix(aggregator): preserve retained meta quota windows --- pm-stack/aggregator/src/quota-current.ts | 14 +++++++++ .../aggregator/test/quota-current.test.ts | 31 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/pm-stack/aggregator/src/quota-current.ts b/pm-stack/aggregator/src/quota-current.ts index db4362571a..2c60b419e8 100644 --- a/pm-stack/aggregator/src/quota-current.ts +++ b/pm-stack/aggregator/src/quota-current.ts @@ -398,6 +398,20 @@ function applyEntry(pool: QuotaPool, entry: QuotaCurrentEntry, state: FreshState pool.state = poolState(pool); return false; } + // #9358: meta's base quota-view row can be a fallback transcription + // rather than the retained quota-current read. When its provider leg + // failed, keep the retained read's windows (including a zero window) + // instead of letting that older transcription mask them. Freshness + // remains stale under #1268; this does not turn a failed tick into ok. + if (pool.id === "meta" && legError && entry.retainedFromFailedTick) { + const windows = pctWindows(entry); + if (windows.length > 0) { + pool.windows = windows; + delete pool.note; + } + pool.state = "stale"; + return false; + } // #6942: a retained entry whose gatherer leg errored is that // read error surfacing, not mere staleness — but only a pool // with no dated windows of its own changes rendering for it. diff --git a/pm-stack/aggregator/test/quota-current.test.ts b/pm-stack/aggregator/test/quota-current.test.ts index 8858975a07..d0cef02960 100644 --- a/pm-stack/aggregator/test/quota-current.test.ts +++ b/pm-stack/aggregator/test/quota-current.test.ts @@ -1375,6 +1375,37 @@ describe("shell-pool stale/retained path (#6942)", () => { expect(cline.freshness).toEqual({ measuredAt: iso(5 * 60_000), source: "openchamber-quota", state: "stale" }); expect(cline.windows[0].percent).toBe(69); // dated read, not the retained gatherer value }); + + test("meta retained errored-leg read replaces its fallback windows but stays stale (#9358)", () => { + const f = legErrorFile([ + entry({ + providerId: "_muse", + serviceId: "meta", + source: "opencode-quota", + measuredAt: iso(45 * 60_000), + retainedFromFailedTick: iso(4 * 60_000), + windows: [win("5h", 0, iso(45 * 60_000)), win("weekly", 100, iso(45 * 60_000))], + }), + ]); + f.heartbeat.perProvider = { _muse: { state: "error", ms: 12, rows: 1, error: LEG_ERROR } }; + const view = baseView(); + view.pools.find((p) => p.id === "meta")!.windows = [ + { name: "weekly", unit: "other", limit: 100, used: 98, percent: 98, resetsAt: null }, + ]; + + const out = overlayQuotaCurrent(view, f, NOW); + const meta = out.pools.find((p) => p.id === "meta")!; + expect(meta.windows.map((w) => [w.name, w.percent])).toEqual([ + ["5-hour", 0], + ["weekly", 100], + ]); + expect(meta.freshness).toEqual({ + measuredAt: iso(45 * 60_000), + source: "opencode-quota", + state: "stale", + }); + expect(meta.state).toBe("stale"); + }); }); describe("spec-pool retained path with dead base windows (#7033)", () => {