Skip to content
Open
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
126 changes: 126 additions & 0 deletions apps/server/src/provider/antigravityUsageLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,132 @@ describe("Antigravity usage limits", () => {
}).pipe(Effect.scoped),
);

// regression: #48279 weekly-exhausted Antigravity groups mark 5h disabled with a stale fraction
it.effect(
"treats a disabled 5-hour bucket as exhausted and inherits its group's weekly reset",
() =>
Effect.gen(function* () {
if (yield* HostProcess.isWindows) return;
const payload = {
status: "SUCCESS",
command: {
name: "usage",
data: {
groups: [
{
name: "Gemini Models",
buckets: [
{
id: "gemini-weekly",
name: "Weekly Limit Remaining",
window: "weekly",
remaining_fraction: 0,
reset_time: "2026-12-08T11:55:08Z",
},
{
id: "gemini-5h",
name: "Five Hour Limit Remaining",
window: "5h",
disabled: true,
remaining_fraction: 0.9899866580963135,
},
],
},
{
name: "Claude and GPT models",
buckets: [
{
id: "3p-weekly",
name: "Weekly Limit Remaining",
window: "weekly",
remaining_fraction: 0.1,
reset_time: "2026-12-04T16:32:52Z",
},
{
id: "3p-5h",
name: "Five Hour Limit Remaining",
window: "5h",
remaining_fraction: 1,
reset_time: "1970-01-01T00:00:00Z",
},
],
},
],
},
},
};
const limits = yield* probeWith({
script: `printf '%s' ${shellQuote(JSON.stringify(payload))}`,
});
expect(limits.unavailable).toBeUndefined();
expect(limits.windows).toEqual([
{
id: "3p-5h",
kind: "session",
label: "Claude and GPT models · 5-hour",
usedPercent: 0,
windowDurationMins: 300,
},
{
id: "gemini-5h",
kind: "session",
label: "Gemini Models · 5-hour",
usedPercent: 100,
resetsAt: "2026-12-08T11:55:08.000Z",
},
{
id: "3p-weekly",
kind: "weekly",
label: "Claude and GPT models · Weekly",
usedPercent: 90,
resetsAt: "2026-12-04T16:32:52.000Z",
windowDurationMins: 10080,
},
{
id: "gemini-weekly",
kind: "weekly",
label: "Gemini Models · Weekly",
usedPercent: 100,
resetsAt: "2026-12-08T11:55:08.000Z",
windowDurationMins: 10080,
},
]);

const withoutFraction = {
status: "SUCCESS",
command: {
name: "usage",
data: {
groups: [
{
name: "Claude and GPT models",
buckets: [
{
id: "3p-5h",
name: "Five Hour Limit Remaining",
window: "5h",
disabled: true,
},
],
},
],
},
},
};
const standalone = yield* probeWith({
script: `printf '%s' ${shellQuote(JSON.stringify(withoutFraction))}`,
});
expect(standalone.windows).toEqual([
{
id: "3p-5h",
kind: "session",
label: "Claude and GPT models · 5-hour",
usedPercent: 100,
},
]);
}).pipe(Effect.scoped),
);

it.effect.each([
{
name: "a runtime older than 1.5.22",
Expand Down
44 changes: 35 additions & 9 deletions apps/server/src/provider/antigravityUsageLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const UsageBucket = Schema.Struct({
id: Schema.String,
name: Schema.optional(Schema.String),
window: Schema.optional(Schema.String),
disabled: Schema.optional(Schema.Boolean),
remaining_fraction: Schema.optional(Schema.Number),
reset_time: Schema.optional(Schema.String),
});
Expand Down Expand Up @@ -67,6 +68,14 @@ const WINDOWS: Record<
weekly: { kind: "weekly", label: "Weekly", mins: 7 * 24 * 60 },
};

function parseResetTime(resetTime: string | undefined): string | undefined {
const reset = DateTime.make(resetTime ?? "");
// An untouched bucket reports the Unix epoch: its window has not started.
return Option.isSome(reset) && DateTime.toEpochMillis(reset.value) > 0
? DateTime.formatIso(reset.value)
: undefined;
}

/** Maps `agy usage --json` output; groups such as Gemini and Claude/GPT are metered apart. */
function antigravityUsageOutputToLimits(
stdout: string,
Expand All @@ -82,23 +91,40 @@ function antigravityUsageOutputToLimits(
}
const windows: ServerProviderUsageWindow[] = [];
for (const group of decoded.value.command.data.groups) {
for (const bucket of group.buckets ?? []) {
const buckets = group.buckets ?? [];
const spentWeeklyReset = buckets
.filter(
(bucket) =>
bucket.window === "weekly" &&
(bucket.disabled === true ||
(bucket.remaining_fraction !== undefined &&
Number.isFinite(bucket.remaining_fraction) &&
clampPercent((1 - bucket.remaining_fraction) * 100) >= 100)),
)
.map((bucket) => parseResetTime(bucket.reset_time))
.find((value) => value !== undefined);
for (const bucket of buckets) {
const disabled = bucket.disabled === true;
const fraction = bucket.remaining_fraction;
if (fraction === undefined || !Number.isFinite(fraction)) continue;
const usedPercent = disabled
? 100
: fraction !== undefined && Number.isFinite(fraction)
? clampPercent((1 - fraction) * 100)
: null;
if (usedPercent === null) continue;
const window = WINDOWS[bucket.window ?? ""];
const reset = DateTime.make(bucket.reset_time ?? "");
// An untouched bucket reports the Unix epoch: its window has not started.
// A weekly-disabled 5h bucket omits reset_time and keeps a stale remaining_fraction.
const resetsAt =
Option.isSome(reset) && DateTime.toEpochMillis(reset.value) > 0
? DateTime.formatIso(reset.value)
: undefined;
disabled && window?.kind === "session"
? (spentWeeklyReset ?? parseResetTime(bucket.reset_time))
: parseResetTime(bucket.reset_time);
windows.push({
id: bucket.id,
kind: window?.kind ?? "other",
label: `${group.name?.trim() || "Antigravity"} · ${window?.label ?? (bucket.name?.trim() || "Quota")}`,
usedPercent: clampPercent((1 - fraction) * 100),
usedPercent,
...(resetsAt ? { resetsAt } : {}),
...(window ? { windowDurationMins: window.mins } : {}),
...(window && !disabled ? { windowDurationMins: window.mins } : {}),
});
}
}
Expand Down
Loading
Loading