diff --git a/pm-stack/aggregator/src/credential-lifecycle.ts b/pm-stack/aggregator/src/credential-lifecycle.ts index b8e1047f51..dd2a34000f 100644 --- a/pm-stack/aggregator/src/credential-lifecycle.ts +++ b/pm-stack/aggregator/src/credential-lifecycle.ts @@ -71,7 +71,7 @@ export function lifecycleForEntry(entry: QuotaCurrentEntry, now = new Date()): C ...(hasExpiry ? { expiresAt } : {}), ...(error ? { reason: error } : {}), }; - if (entry.providerId === "claude" && (state === "expired" || state === "expiring")) { + if ((entry.providerId === "claude" || entry.providerId === "_claude") && (state === "expired" || state === "expiring")) { const title = entry.credentialSource === "opencode" ? "Refresh Anthropic authentication in OpenCode" @@ -82,7 +82,7 @@ export function lifecycleForEntry(entry: QuotaCurrentEntry, now = new Date()): C : undefined; if (title) row.userAction = { owner: "user", title }; } - if (entry.providerId === "claude" && state === "expired" && !row.reason) { + if ((entry.providerId === "claude" || entry.providerId === "_claude") && state === "expired" && !row.reason) { row.reason = "Claude credential expiry is confirmed by its configured credential source."; } return row; diff --git a/pm-stack/aggregator/src/quota-gather-map.ts b/pm-stack/aggregator/src/quota-gather-map.ts index da3e020078..673230da70 100644 --- a/pm-stack/aggregator/src/quota-gather-map.ts +++ b/pm-stack/aggregator/src/quota-gather-map.ts @@ -102,6 +102,7 @@ export function serviceIdFor(providerId: string): string { case "deepseek": return "deepseek"; case "meta": + case "_muse": return "meta"; case "opendesign": return "opendesign"; @@ -110,6 +111,33 @@ export function serviceIdFor(providerId: string): string { } } +/** + * Canonical provider ids for snapshot entries. The quota module answers + * in its own spellings; the snapshot contract speaks the OpenCode config + * provider ids — the router matches quota readings by exact provider id + * (quota-driven skip re-admission), so an entry published under a module + * spelling never reaches the provider it describes. The fleet-built + * providers were renamed to leading-underscore config ids in the fork + * (#1823, 2026-11-07): antigravity -> _antigravity, the claude-code door + * (module: "claude") -> _claude, commandcode (module: "command-code") + * -> _commandcode, and the muse-direct door (module: "meta", the Muse + * Code High Usage reading) -> _muse. Normalize here, at the one mapping + * point every gathered result passes through. Pool/service ids are a + * separate contract and stay put: serviceIdFor carries the dual-spelling + * cases (both "claude" and "_claude" land on anthropic:claude-pro, and + * "_muse" keeps the "meta" pool). + */ +const CANONICAL_PROVIDER_IDS: Readonly> = { + antigravity: "_antigravity", + claude: "_claude", + "command-code": "_commandcode", + meta: "_muse", +}; + +export function canonicalProviderId(providerId: string): string { + return CANONICAL_PROVIDER_IDS[providerId] ?? providerId; +} + export const GATHERER_SOURCE = "opencode-quota"; /** @@ -282,7 +310,7 @@ export function entryFromFileExport( opts: { fileMtimeIso: string | null; stale: boolean }, ): QuotaCurrentEntry { const entry: QuotaCurrentEntry = { - providerId: "meta", + providerId: canonicalProviderId("meta"), providerName: "Meta", serviceId: "meta", state: "error", @@ -372,10 +400,11 @@ export function entryFromResult(result: QuotaProviderResult, tickIso: string): Q if (Number.isFinite(fetchedDate.getTime())) measuredAt = fetchedDate.toISOString(); } const state: QuotaCurrentEntry["state"] = result.ok ? "ok" : result.configured ? "error" : "unconfigured"; + const providerId = canonicalProviderId(result.providerId); const entry: QuotaCurrentEntry = { - providerId: result.providerId, - providerName: result.providerName ?? result.providerId, - serviceId: serviceIdFor(result.providerId), + providerId, + providerName: result.providerName ?? providerId, + serviceId: serviceIdFor(providerId), state, measuredAt, source: GATHERER_SOURCE, @@ -834,7 +863,8 @@ export async function mapWithConcurrency( * never retained. */ export function lastKnownEntries(prev: readonly QuotaCurrentEntry[], providerId: string): QuotaCurrentEntry[] { - return prev.filter((e) => e.providerId === providerId && e.state === "ok"); + const wanted = canonicalProviderId(providerId); + return prev.filter((e) => canonicalProviderId(e.providerId) === wanted && e.state === "ok"); } /** @@ -845,5 +875,9 @@ export function lastKnownEntries(prev: readonly QuotaCurrentEntry[], providerId: * instead of it reading as fresh until the freshness bound lapses. */ export function markRetained(entries: readonly QuotaCurrentEntry[], failedTickIso: string): QuotaCurrentEntry[] { - return entries.map((e) => ({ ...e, retainedFromFailedTick: failedTickIso })); + return entries.map((e) => ({ + ...e, + providerId: canonicalProviderId(e.providerId), + retainedFromFailedTick: failedTickIso, + })); } diff --git a/pm-stack/aggregator/test/quota-gather-map.test.ts b/pm-stack/aggregator/test/quota-gather-map.test.ts index 8a4cf7eb5b..5a1d0b4aef 100644 --- a/pm-stack/aggregator/test/quota-gather-map.test.ts +++ b/pm-stack/aggregator/test/quota-gather-map.test.ts @@ -4,6 +4,7 @@ import { ANTIGRAVITY_GEMINI_SERVICE_ID, GO_POPESDREW_SERVICE_ID, GO_DREWRYPOPE_SERVICE_ID, + canonicalProviderId, entriesWithPoolSplits, entryFromFileExport, entryFromTurso, @@ -598,6 +599,7 @@ describe("serviceIdFor", () => { expect(serviceIdFor("codex")).toBe("openai.main"); expect(serviceIdFor("deepseek")).toBe("deepseek"); expect(serviceIdFor("meta")).toBe("meta"); + expect(serviceIdFor("_muse")).toBe("meta"); expect(serviceIdFor("opendesign")).toBe("opendesign"); // The module's provider id is "command-code"; the pool (and the // OpenCode config provider) is "commandcode". Without the mapping @@ -1068,3 +1070,70 @@ describe("own-key guards on quota-gather-map lookups (#2781)", () => { } }); }); + +describe("canonicalProviderId (config-id alignment, #1823)", () => { + const TICK = "2026-10-27T05:00:00.000Z"; + + test("module spellings map to the config provider ids; others pass through", () => { + expect(canonicalProviderId("antigravity")).toBe("_antigravity"); + expect(canonicalProviderId("claude")).toBe("_claude"); + expect(canonicalProviderId("command-code")).toBe("_commandcode"); + expect(canonicalProviderId("meta")).toBe("_muse"); + expect(canonicalProviderId("_antigravity")).toBe("_antigravity"); + expect(canonicalProviderId("opendesign")).toBe("opendesign"); + expect(canonicalProviderId("codex")).toBe("codex"); + }); + + test("entryFromResult emits the canonical id and keeps the pool service id", () => { + const ag = entryFromResult({ ...OK_RESULT, providerId: "antigravity" }, TICK); + expect(ag.providerId).toBe("_antigravity"); + expect(ag.serviceId).toBe("_antigravity"); + const claude = entryFromResult({ ...OK_RESULT, providerId: "claude" }, TICK); + expect(claude.providerId).toBe("_claude"); + expect(claude.serviceId).toBe("anthropic:claude-pro"); + const cc = entryFromResult({ ...OK_RESULT, providerId: "command-code" }, TICK); + expect(cc.providerId).toBe("_commandcode"); + expect(cc.serviceId).toBe("_commandcode"); + const meta = entryFromResult({ ...OK_RESULT, providerId: "meta" }, TICK); + expect(meta.providerId).toBe("_muse"); + expect(meta.serviceId).toBe("meta"); + }); + + test("a module-spelled Antigravity entry splits into the renamed pool rows", () => { + const entry = entryFromResult( + { + providerId: "antigravity", + providerName: "Antigravity", + ok: true, + configured: true, + fetchedAt: Date.parse(TICK), + usage: { + models: { + "gemini-2.5-pro": { + windows: { weekly: { usedPercent: 40, windowSeconds: 604_800, resetAt: 1793438427299 } }, + }, + "claude-sonnet": { + windows: { weekly: { usedPercent: 90, windowSeconds: 604_800, resetAt: 1793438427299 } }, + }, + }, + }, + }, + TICK, + ); + const splits = entriesWithPoolSplits([entry]); + expect(splits.map((e) => e.serviceId)).toEqual([ + "_antigravity", + ANTIGRAVITY_CLAUDE_GPT_SERVICE_ID, + ANTIGRAVITY_GEMINI_SERVICE_ID, + ]); + }); + + test("retention matches across the rename boundary and re-stamps the canonical id", () => { + const prevEntry = { ...entryFromResult(OK_RESULT, TICK), providerId: "claude" }; + expect(lastKnownEntries([prevEntry], "claude")).toHaveLength(1); + expect(lastKnownEntries([prevEntry], "_claude")).toHaveLength(1); + const retained = markRetained([prevEntry], "2026-10-27T06:00:00.000Z"); + expect(retained[0].providerId).toBe("_claude"); + expect(retained[0].retainedFromFailedTick).toBe("2026-10-27T06:00:00.000Z"); + }); +}); diff --git a/pm-stack/aggregator/test/token-adapter.test.ts b/pm-stack/aggregator/test/token-adapter.test.ts index ffe1b60410..e4920b3f34 100644 --- a/pm-stack/aggregator/test/token-adapter.test.ts +++ b/pm-stack/aggregator/test/token-adapter.test.ts @@ -185,7 +185,7 @@ describe("file-export adapter (the framework's first adapter)", () => { }, }); expect(out.status).toBe("ok"); - expect(out.value?.providerId).toBe("meta"); + expect(out.value?.providerId).toBe("_muse"); expect(out.value?.serviceId).toBe("meta"); expect(out.value?.source).toBe("file-export/meta-laptop"); expect(out.value?.windows.some((w) => w.name === "5h" && w.pctOfLimit === 12.5)).toBe(true);