diff --git a/apps/server/src/provider/antigravityUsageLimits.test.ts b/apps/server/src/provider/antigravityUsageLimits.test.ts index 9defd9df90dce..360b913412ca8 100644 --- a/apps/server/src/provider/antigravityUsageLimits.test.ts +++ b/apps/server/src/provider/antigravityUsageLimits.test.ts @@ -656,11 +656,21 @@ describe("Antigravity subscription limits", () => { it.effect("does not make network requests for API keys or missing sign-ins", () => Effect.gen(function* () { - for (const options of [{ authMethod: "gemini-api-key" as const }, { missingToken: true }]) { - const { probe, requests } = yield* fixture(options); - expect((yield* probe).unavailable?.reason).toBe("unsupported"); - expect(requests).toEqual([]); - } + const apiKey = yield* fixture({ authMethod: "gemini-api-key" }); + const apiLimits = yield* apiKey.probe; + expect(apiLimits.unavailable).toEqual({ + reason: "unsupported", + message: + "Not applicable: Antigravity API keys and Agent Platform are billed by Google. T3 has no quota window for them.", + }); + expect(apiKey.requests).toEqual([]); + const signedOut = yield* fixture({ missingToken: true }); + const signedOutLimits = yield* signedOut.probe; + expect(signedOutLimits.unavailable).toEqual({ + reason: "unsupported", + message: "Sign in with Google to see limits.", + }); + expect(signedOut.requests).toEqual([]); }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))), ); }); diff --git a/apps/server/src/provider/antigravityUsageLimits.ts b/apps/server/src/provider/antigravityUsageLimits.ts index ede0e5c47d20e..852225d3c9205 100644 --- a/apps/server/src/provider/antigravityUsageLimits.ts +++ b/apps/server/src/provider/antigravityUsageLimits.ts @@ -234,14 +234,19 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")( const startedGeneration = generation; const checkedAt = DateTime.formatIso(yield* DateTime.now); if (input.authMethod !== "oauth-personal" && input.authMethod !== "oauth-business") { - return makeUnavailableUsageLimits({ checkedAt, reason: "unsupported" }); + return makeUnavailableUsageLimits({ + checkedAt, + reason: "unsupported", + message: + "Not applicable: Antigravity API keys and Agent Platform are billed by Google. T3 has no quota window for them.", + }); } if (!(yield* fs.exists(tokenPath))) { cached = undefined; return makeUnavailableUsageLimits({ checkedAt, reason: "unsupported", - message: "Sign in with Google to see Antigravity limits.", + message: "Sign in with Google to see limits.", }); } const token = yield* fs.readFileString(tokenPath).pipe(Effect.flatMap(decodeTokenFile)); diff --git a/apps/server/src/usage/magpieQuotas.test.ts b/apps/server/src/usage/magpieQuotas.test.ts index 1776dc2ce9b6f..4689da5c75ba3 100644 --- a/apps/server/src/usage/magpieQuotas.test.ts +++ b/apps/server/src/usage/magpieQuotas.test.ts @@ -62,6 +62,20 @@ const entries = [ error: "this key has no OpenCode Go subscription: Go belongs to the member who subscribed, in that workspace", }, + { + provider: "magpie-go", + name: "Magpie Go", + kind: "plan", + user: "oc-billed", + error: "Payment Required", + }, + { + provider: "magpie-go", + name: "Magpie Go", + kind: "plan", + user: "oc-other", + error: "no workspace subscription on this account", + }, { provider: "claude", user: "second@example.com", error: "upstream timed out" }, ]; @@ -101,20 +115,34 @@ describe("magpieQuotasToAccounts", () => { ]); }); - it("marks standing refusals not applicable and passing failures as failed reads", () => { - const [, , team, go, timedOut] = accounts; - expect(team!.email).toBe("first@example.com · Team"); - expect(team!.usageLimits.unavailable).toEqual({ + it("drops a Go key with no subscription and keeps payment and failed reads", () => { + expect(accounts.map((account) => account.id)).toEqual([ + "claude:first@example.com", + "codex:first@example.com", + "codex:first@example.com · Team", + "magpie-go:oc-billed", + "magpie-go:oc-other", + "claude:second@example.com", + ]); + const team = accounts[2]!; + const billed = accounts[3]!; + const other = accounts[4]!; + const timedOut = accounts[5]!; + expect(team.email).toBe("first@example.com · Team"); + expect(team.usageLimits.unavailable).toEqual({ + reason: "unsupported", + message: "Payment Required.", + }); + expect(billed.driver).toBe("opencode"); + expect(billed.usageLimits.unavailable).toEqual({ reason: "unsupported", message: "Payment Required.", }); - expect(go!.driver).toBe("opencode"); - expect(go!.email).toBeUndefined(); - expect(go!.usageLimits.unavailable).toEqual({ + expect(other.usageLimits.unavailable).toEqual({ reason: "unsupported", - message: "This key has no OpenCode Go subscription.", + message: "No workspace subscription on this account.", }); - expect(timedOut!.usageLimits.unavailable?.reason).toBe("probeFailed"); + expect(timedOut.usageLimits.unavailable?.reason).toBe("probeFailed"); }); }); diff --git a/apps/server/src/usage/magpieQuotas.ts b/apps/server/src/usage/magpieQuotas.ts index 0098b6ee46c14..a118b69a04463 100644 --- a/apps/server/src/usage/magpieQuotas.ts +++ b/apps/server/src/usage/magpieQuotas.ts @@ -151,6 +151,11 @@ function isStandingRefusal(error: string): boolean { ); } +/** OpenCode's own sentence for a key that was never subscribed. */ +function isDeadGoSubscription(error: string): boolean { + return /this key has no opencode go subscription/i.test(error); +} + /** Magpie's sentences run long; the first clause names the reason. */ function shortReason(error: string): string { const first = error.split(/[:;]\s/)[0]!.trim(); @@ -167,6 +172,9 @@ export function magpieQuotasToAccounts( for (const entry of entries) { const driver = driverFor(entry.provider); if (!driver) continue; + if (driver === "opencode" && entry.error && isDeadGoSubscription(entry.error)) { + continue; + } const user = entry.user?.trim() || entry.name?.trim() || entry.provider; const id = `${entry.provider}:${user}`; if (seen.has(id)) continue; diff --git a/packages/shared/src/usageLimits.test.ts b/packages/shared/src/usageLimits.test.ts index 6e21b53ff83eb..7dd8084e302c7 100644 --- a/packages/shared/src/usageLimits.test.ts +++ b/packages/shared/src/usageLimits.test.ts @@ -1948,12 +1948,45 @@ describe("owners and not-applicable usage", () => { expect(groups.map((group) => group.owner)).toEqual(["Unassigned"]); }); + it("says when Antigravity has no quota window", () => { + const billed = provider({ + instanceId: ProviderInstanceId.make("antigravity-api"), + driver: ProviderDriverKind.make("antigravity"), + displayName: "Antigravity", + usageLimits: { + checkedAt, + windows: [], + unavailable: { + reason: "unsupported", + message: + "Not applicable: Antigravity API keys and Agent Platform are billed by Google. T3 has no quota window for them.", + }, + }, + }); + const view = new Map([ + [ + EnvironmentId.make("env-a"), + { entry: { target: { label: "Crown" } }, serverConfig: { providers: [billed] } }, + ], + ]); + expect(collectNotApplicable(view)).toEqual([ + { + environment: "Crown", + subject: "Antigravity", + reason: + "Antigravity API keys and Agent Platform are billed by Google. T3 has no quota window for them.", + }, + ]); + expect(collectLimitNotices(view)).toEqual([]); + }); + it("lists not-applicable usage apart from failures, and a billing refusal as a notice", () => { const view = presentations(); expect(collectNotApplicable(view)).toEqual([ { environment: "Crown", subject: "Magpie Codex", reason: "gateway reports it." }, ]); expect(collectLimitNotices(view)).toEqual([ + "Antigravity: Sign in with Google to see limits.", "Magpie · owner.a@example.com · Team: the vendor says payment is required, so this subscription's billing needs attention.", "Magpie · k: Upstream timed out.", ]); diff --git a/packages/shared/src/usageLimits.ts b/packages/shared/src/usageLimits.ts index 07121759317df..7c1d84e498db2 100644 --- a/packages/shared/src/usageLimits.ts +++ b/packages/shared/src/usageLimits.ts @@ -490,9 +490,20 @@ export function collectLimitNotices(presentations: LimitPresentations): readonly for (const presentation of presentations.values()) { const environmentLabel = presentation.entry.target.label; for (const provider of providersWithLimits(presentation.serverConfig?.providers ?? [])) { - if (provider.usageLimits?.unavailable?.reason === "unsupported") continue; - const notice = provider.usageLimits ? limitsNotice(provider.usageLimits) : null; const name = provider.displayName?.trim() || String(provider.driver); + const unavailable = provider.usageLimits?.unavailable; + if (unavailable?.reason === "unsupported") { + const message = unavailable.message?.trim(); + if ( + provider.driver === "antigravity" && + message && + !message.startsWith(NOT_APPLICABLE_PREFIX) + ) { + notices.add(`${label(environmentLabel, name)}: ${message}`); + } + continue; + } + const notice = provider.usageLimits ? limitsNotice(provider.usageLimits) : null; if (notice) notices.add(`${label(environmentLabel, name)}: ${notice}`); } for (const source of presentation.serverConfig?.usageLimitSources ?? []) {