Skip to content

Commit 5d886d9

Browse files
committed
fix(server): atomically capture session revision and skip quota probe on sign-out
1 parent 2d44dc9 commit 5d886d9

2 files changed

Lines changed: 79 additions & 33 deletions

File tree

‎apps/server/src/provider/Layers/AntigravityProvider.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,4 +743,46 @@ it.layer(testLayer)("Antigravity provider snapshots", (it) => {
743743
}),
744744
),
745745
);
746+
747+
it.effect("does not restore usageLimits if signed out before quota probe completes", () =>
748+
Effect.scoped(
749+
Effect.gen(function* () {
750+
const quotaGate = yield* Deferred.make<void>();
751+
const quotaContinue = yield* Deferred.make<void>();
752+
const quotaDone = yield* Deferred.make<void>();
753+
754+
let gateArmed = false;
755+
const harness = yield* makeHarness({
756+
usageLimits: Effect.gen(function* () {
757+
if (!gateArmed) {
758+
return undefined;
759+
}
760+
yield* Deferred.succeed(quotaGate, undefined);
761+
yield* Deferred.await(quotaContinue);
762+
yield* Deferred.succeed(quotaDone, undefined);
763+
return {
764+
checkedAt: "2026-09-09T03:00:00.000Z",
765+
windows: [{ id: "stale_quota", kind: "session", label: "Stale", usedPercent: 50 }],
766+
};
767+
}),
768+
});
769+
yield* harness.initialize;
770+
gateArmed = true;
771+
772+
yield* harness.provider.onSessionStarted(started);
773+
yield* Deferred.await(quotaGate);
774+
775+
// Sign out while quota probe is still running in background
776+
yield* harness.provider.onSignedOut;
777+
778+
// Release the deferred quota effect
779+
yield* Deferred.succeed(quotaContinue, undefined);
780+
yield* Deferred.await(quotaDone);
781+
782+
const finalSnapshot = yield* harness.provider.snapshot.getSnapshot;
783+
expect(finalSnapshot.auth.status).toBe("unauthenticated");
784+
expect(finalSnapshot.usageLimits).toBeUndefined();
785+
}),
786+
),
787+
);
746788
});

‎apps/server/src/provider/Layers/AntigravityProvider.ts‎

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -270,47 +270,51 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func
270270
const before = yield* SubscriptionRef.get(metadata);
271271
const supportsTextGeneration = yield* options.supportsTextGeneration;
272272
const updatedAt = DateTime.formatIso(yield* DateTime.now);
273-
yield* SubscriptionRef.update(metadata, (state) => {
273+
const updatedRevision = yield* SubscriptionRef.modify(metadata, (state) => {
274274
if (state.authRevision !== before.authRevision) {
275-
return state;
275+
return [Option.none<number>(), state] as const;
276276
}
277+
const newRevision = state.authRevision + 1;
277278
const { message: _previousMessage, ...draft } = state.draft;
278279
const workspaces = draft.workspaceSnapshots ?? [];
279280
const workspace = cwd ? workspaces.find((entry) => entry.cwd === cwd) : undefined;
280-
return {
281-
authRevision: state.authRevision + 1,
282-
draft: {
283-
...draft,
284-
installed: true,
285-
status: settings.enabled ? "ready" : "disabled",
286-
version: started.initializeResult.agentInfo?.version || draft.version,
287-
auth: {
288-
status: "authenticated",
289-
type: options.auth?.type ?? "oauth-personal",
290-
label: options.auth?.label ?? "Google account",
281+
return [
282+
Option.some(newRevision),
283+
{
284+
authRevision: newRevision,
285+
draft: {
286+
...draft,
287+
installed: true,
288+
status: settings.enabled ? "ready" : "disabled",
289+
version: started.initializeResult.agentInfo?.version || draft.version,
290+
auth: {
291+
status: "authenticated",
292+
type: options.auth?.type ?? "oauth-personal",
293+
label: options.auth?.label ?? "Google account",
294+
},
295+
checkedAt: updatedAt,
296+
models: buildAntigravityModelsFromSession(started.sessionSetupResult),
297+
supportsTextGeneration,
298+
...(cwd
299+
? {
300+
workspaceSnapshots: [
301+
...workspaces.filter((entry) => entry.cwd !== cwd),
302+
{
303+
cwd,
304+
checkedAt: updatedAt,
305+
slashCommands: workspace?.slashCommands ?? draft.slashCommands,
306+
skills: workspace?.skills ?? discoveredSkills.get(cwd) ?? [],
307+
},
308+
].slice(-MAX_WORKSPACE_SNAPSHOTS),
309+
}
310+
: {}),
291311
},
292-
checkedAt: updatedAt,
293-
models: buildAntigravityModelsFromSession(started.sessionSetupResult),
294-
supportsTextGeneration,
295-
...(cwd
296-
? {
297-
workspaceSnapshots: [
298-
...workspaces.filter((entry) => entry.cwd !== cwd),
299-
{
300-
cwd,
301-
checkedAt: updatedAt,
302-
slashCommands: workspace?.slashCommands ?? draft.slashCommands,
303-
skills: workspace?.skills ?? discoveredSkills.get(cwd) ?? [],
304-
},
305-
].slice(-MAX_WORKSPACE_SNAPSHOTS),
306-
}
307-
: {}),
308-
},
309-
} satisfies AntigravityProviderState;
312+
} satisfies AntigravityProviderState,
313+
] as const;
310314
});
311315

312-
const revision = (yield* SubscriptionRef.get(metadata)).authRevision;
313-
if (options.usageLimits) {
316+
if (Option.isSome(updatedRevision) && options.usageLimits) {
317+
const revision = updatedRevision.value;
314318
yield* options.usageLimits.pipe(
315319
Effect.catchCause(() => Effect.succeed(undefined)),
316320
Effect.flatMap((usageLimits) =>

0 commit comments

Comments
 (0)