Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
f2cac8d
fix(antigravity): usage limits no longer show another account's quota…
mths-mcfs Nov 11, 2026
85d928d
Merge remote-tracking branch 'origin/main' into fix/antigravity-cli-u…
mths-mcfs Nov 17, 2026
5937e05
fix(antigravity): hide limits while the runtime cannot be resolved
mths-mcfs Nov 17, 2026
b62b866
Merge remote-tracking branch 'origin/main' into fix/antigravity-cli-u…
mths-mcfs Nov 17, 2026
e5eab57
Merge remote-tracking branch 'origin/main' into fix/antigravity-cli-u…
mths-mcfs Nov 17, 2026
ac0538d
Merge remote-tracking branch 'origin/main' into fix/antigravity-cli-u…
mths-mcfs Nov 20, 2026
5def194
fix(server): Antigravity limits no longer show old readings after a f…
mths-mcfs Nov 20, 2026
4da0a15
fix(server): Antigravity sign-out no longer republishes the previous …
mths-mcfs Nov 20, 2026
c4d780e
fix(server): a slow Antigravity health check no longer flashes old li…
mths-mcfs Nov 20, 2026
566a649
fix(server): an interrupted provider refresh no longer freezes the li…
mths-mcfs Nov 20, 2026
f3a4ef2
Revert "fix(server): an interrupted provider refresh no longer freeze…
mths-mcfs Nov 20, 2026
7f28802
Revert "fix(server): a slow Antigravity health check no longer flashe…
mths-mcfs Nov 20, 2026
981ecb8
Revert "fix(server): Antigravity sign-out no longer republishes the p…
mths-mcfs Nov 20, 2026
44d9c31
test(server): Antigravity limits test no longer depends on scheduler …
mths-mcfs Nov 20, 2026
93e70cf
fix(server): Antigravity keeps the newer limits read after the clock …
mths-mcfs Nov 20, 2026
ec71e5c
Merge branch 'main' into fix/antigravity-cli-usage-limits
mths-mcfs Nov 21, 2026
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
162 changes: 108 additions & 54 deletions apps/server/src/provider/AntigravityProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import * as Fiber from "effect/Fiber";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Ref from "effect/Ref";
import * as Schema from "effect/Schema";
import * as Stream from "effect/Stream";
Expand Down Expand Up @@ -172,10 +173,15 @@ const makeHarness = Effect.fn("makeAntigravityProviderHarness")(function* (
Effect.andThen(initialUpdate),
Effect.asVoid,
);
// Subscribe before the trigger; yield the returned pull to await the publish.
// Subscribes now, before the trigger runs (a pull would subscribe only when first pulled);
// yield the returned effect to await the publish.
const nextPublish = (predicate: (snapshot: ServerProvider) => boolean) =>
Stream.toPull(provider.snapshot.streamChanges.pipe(Stream.filter(predicate))).pipe(
Effect.map((pull) => pull.pipe(Effect.map((snapshots) => snapshots[0]))),
provider.snapshot.streamChanges.pipe(
Stream.filter(predicate),
Stream.runHead,
Effect.map(Option.getOrUndefined),
Effect.forkChild({ startImmediately: true }),
Effect.map(Fiber.join),
);
return {
provider,
Expand Down Expand Up @@ -715,59 +721,107 @@ it.layer(layerTest)("Antigravity provider snapshots", (it) => {
}),
);

it.effect(
"publishes limits, retains a successful read on failure, and clears them on sign-out",
() =>
Effect.gen(function* () {
const limits: ServerProviderUsageLimits = {
checkedAt: "2026-10-09T12:00:00.000Z",
windows: [
{
id: "3p-weekly",
kind: "weekly",
label: "Claude & GPT (shared) · Weekly",
usedPercent: 75,
},
],
};
const usage = yield* Ref.make(limits);
const harness = yield* makeHarness({ probeUsage: Ref.get(usage) });
const published = yield* harness.nextPublish((snapshot) => !!snapshot.usageLimits);
yield* harness.initialize;
expect((yield* published)?.usageLimits).toEqual(limits);
// The second health check is the one the failed background read triggers.
const checks = yield* Ref.make(0);
const failedReadApplied = yield* Deferred.make<void>();
yield* Ref.set(
harness.probe,
Ref.updateAndGet(checks, (count) => count + 1).pipe(
Effect.tap((count) =>
count === 2 ? Deferred.succeed(failedReadApplied, undefined) : Effect.void,
),
Effect.as(initializeResult),
it.effect("publishes each limits read, showing a failed read as failed until one recovers", () =>
Effect.gen(function* () {
// Read N always gets results[N], however its fiber is scheduled.
const results = yield* Effect.forEach([0, 1, 2, 3, 4, 5], () =>
Deferred.make<ServerProviderUsageLimits>(),
);
const reads = yield* Ref.make(0);
const firstReadStarted = yield* Deferred.make<void>();
const harness = yield* makeHarness({
probeUsage: Ref.getAndUpdate(reads, (count) => count + 1).pipe(
Effect.tap(() => Deferred.succeed(firstReadStarted, undefined)),
Effect.flatMap((read) => Deferred.await(results[read]!)),
),
});
// The first check has run its probe once it starts the first read.
yield* Deferred.succeed(harness.initialProbe, initializeResult);
yield* Deferred.await(firstReadStarted);
// A health check holds the refresh lock, so a refresh issued once the check that republishes
// a read has started runs after it; new commands then mark the end of what both published.
const nextCheck = yield* Ref.make<Deferred.Deferred<void> | undefined>(undefined);
yield* Ref.set(
harness.probe,
Ref.getAndSet(nextCheck, undefined).pipe(
Effect.flatMap((started) =>
started ? Deferred.succeed(started, undefined) : Effect.void,
),
Effect.as(initializeResult),
),
);
const finishRead = Effect.fn("finishRead")(function* (
read: number,
result: ServerProviderUsageLimits,
) {
const barrier = `barrier-${read}`;
const published = yield* harness.provider.snapshot.streamChanges.pipe(
Stream.takeUntil((snapshot) =>
snapshot.slashCommands.some((command) => command.name === barrier),
),
Stream.runCollect,
Effect.forkChild({ startImmediately: true }),
);
yield* Ref.set(usage, {
checkedAt: "2026-10-09T12:01:00.000Z",
windows: [],
unavailable: { reason: "probeFailed" },
});
yield* harness.provider.snapshot.refresh;
yield* Deferred.await(failedReadApplied);
expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toEqual(limits);
yield* harness.provider.onSignedOut;
expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toBeUndefined();
yield* Ref.set(usage, {
checkedAt: "2026-10-09T12:02:00.000Z",
windows: [],
unavailable: { reason: "unsupported" },
});
const unsupported = yield* harness.nextPublish(
(snapshot) => snapshot.usageLimits?.unavailable?.reason === "unsupported",
);
yield* harness.provider.snapshot.refresh;
expect((yield* unsupported)?.usageLimits?.windows).toEqual([]);
}),
const republishing = yield* Deferred.make<void>();
yield* Ref.set(nextCheck, republishing);
yield* Deferred.succeed(results[read]!, result);
yield* Deferred.await(republishing);
const refreshed = (yield* harness.provider.snapshot.refresh).usageLimits;
yield* harness.provider.onAvailableCommands([{ name: barrier, description: "Barrier" }]);
const checked = Array.from(yield* Fiber.join(published)).slice(0, -1);
return {
refreshed,
published: checked.map((snapshot) => snapshot.usageLimits),
current: (yield* harness.provider.snapshot.getSnapshot).usageLimits,
};
});
const expectShown = (
shown: Effect.Success<ReturnType<typeof finishRead>>,
expected: ServerProviderUsageLimits,
) => {
expect(shown.refreshed).toEqual(expected);
expect(shown.published).toContainEqual(expected);
expect(shown.current).toEqual(expected);
};

const limits: ServerProviderUsageLimits = {
checkedAt: "2026-10-09T12:00:00.000Z",
windows: [
{
id: "3p-weekly",
kind: "weekly",
label: "Claude & GPT (shared) · Weekly",
usedPercent: 75,
},
],
};
expectShown(yield* finishRead(0, limits), limits);
const failedRead: ServerProviderUsageLimits = {
checkedAt: "2026-10-09T12:01:00.000Z",
windows: [],
unavailable: { reason: "probeFailed" },
};
expectShown(yield* finishRead(1, failedRead), failedRead);
const recovered: ServerProviderUsageLimits = {
...limits,
checkedAt: "2026-10-09T12:01:30.000Z",
};
expectShown(yield* finishRead(2, recovered), recovered);
// A read stamped before the published one, after the clock moved back, does not replace it.
expectShown(
yield* finishRead(3, {
checkedAt: "2026-10-09T12:01:15.000Z",
windows: [{ ...limits.windows[0]!, usedPercent: 18 }],
}),
recovered,
);
const unsupported: ServerProviderUsageLimits = {
checkedAt: "2026-10-09T12:02:00.000Z",
windows: [],
unavailable: { reason: "unsupported" },
};
expectShown(yield* finishRead(4, unsupported), unsupported);
}),
);

it.effect("a quota read finishing after sign-out cannot restore account limits", () =>
Expand Down
15 changes: 9 additions & 6 deletions apps/server/src/provider/AntigravityProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,11 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func
...state,
draft: {
...state.draft,
usageLimits: resolveUsageLimitsAfterProbe({
published: state.draft.usageLimits,
probed,
}),
// A failed read shows as failed, like the managed provider's check publishes it.
usageLimits:
probed.unavailable?.reason === "probeFailed"
? probed
: resolveUsageLimitsAfterProbe({ published: state.draft.usageLimits, probed }),
},
})),
),
Expand Down Expand Up @@ -382,6 +383,8 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func
haveSettingsChanged: () => false,
initialSnapshot: () => getSnapshot,
checkProvider: checkProvider(),
// A failed read is shown as failed; the CLI token expires, so old limits would mislead.
retainUsageLimitsOnProbeFailure: false,
enrichSnapshot: ({ publishSnapshot }) =>
SubscriptionRef.changes(metadata).pipe(
Stream.runForEach((state) =>
Expand Down Expand Up @@ -556,8 +559,8 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func
onSessionStarted,
onConfigOptionsUpdated,
onAvailableCommands,
// The new sign-in may be another account. Clear and republish its limits so a failed read
// cannot fall back to them; the session start then reads the new account's limits.
// The new sign-in may be another account. Clear and republish its limits so they are not
// shown for it; the session start then reads the new account's limits.
onSignedIn: resetUsage.pipe(
Effect.andThen(
SubscriptionRef.update(metadata, (state) => {
Expand Down
13 changes: 9 additions & 4 deletions packages/provider-core/src/server/managedProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ export const makeManagedServerProvider = Effect.fn("makeManagedServerProvider")(
readonly refreshInterval?: Duration.Input;
readonly refreshOnInterval?: boolean | ((snapshot: ServerProvider) => boolean);
readonly checkProviderOnSettingsChange?: (previous: Settings, next: Settings) => boolean;
/** False publishes a failed usage probe as-is instead of keeping the last good read. */
readonly retainUsageLimitsOnProbeFailure?: boolean;
}): Effect.fn.Return<
ManagedServerProvider,
ServerSettingsError,
Expand Down Expand Up @@ -221,10 +223,13 @@ export const makeManagedServerProvider = Effect.fn("makeManagedServerProvider")(
: probedSnapshot.usageLimits === undefined &&
state.snapshot.usageLimits !== usageBeforeProbe
? state.snapshot.usageLimits
: resolveUsageLimitsAfterProbe({
published: state.snapshot.usageLimits,
probed: probedSnapshot.usageLimits,
});
: input.retainUsageLimitsOnProbeFailure === false &&
probedSnapshot.usageLimits?.unavailable?.reason === "probeFailed"
? probedSnapshot.usageLimits
: resolveUsageLimitsAfterProbe({
published: state.snapshot.usageLimits,
probed: probedSnapshot.usageLimits,
});
const workspaceId =
usageLimits === probedSnapshot.usageLimits ? undefined : state.snapshot.auth.workspaceId;
const usageAuthLabel =
Expand Down
Loading