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
20 changes: 15 additions & 5 deletions apps/server/src/provider/antigravityUsageLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
);
});
9 changes: 7 additions & 2 deletions apps/server/src/provider/antigravityUsageLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
46 changes: 37 additions & 9 deletions apps/server/src/usage/magpieQuotas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
];

Expand Down Expand Up @@ -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");
});
});

Expand Down
8 changes: 8 additions & 0 deletions apps/server/src/usage/magpieQuotas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions packages/shared/src/usageLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
]);
Expand Down
15 changes: 13 additions & 2 deletions packages/shared/src/usageLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? []) {
Expand Down
Loading