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
7 changes: 7 additions & 0 deletions apps/mobile/src/features/usage/UsageLimitsPooled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
collectExternalUsageLinks,
collectLimitNotices,
cursorUsageWindowDetails,
poolCheckedLabel,
} from "@t3tools/shared/usageLimitsCopy";
import { msg, T, useGT, useMessages, Var } from "gt-react-native";
import { Fragment, type ReactNode, useId, useState } from "react";
Expand Down Expand Up @@ -501,6 +502,7 @@ export function UsageLimitsSection({
) : null}
{pools.map((pool) => {
const windows = displayLimitWindows(pool);
const checked = poolCheckedLabel(pool, now, m);
return (
<Fragment key={pool.driver}>
<View className="gap-3">
Expand All @@ -509,6 +511,11 @@ export function UsageLimitsSection({
<Text className="text-base font-t3-medium text-foreground">
{providerClients.get(pool.driver)?.label ?? pool.driver}
</Text>
{checked ? (
<Text className="ml-auto text-xs tabular-nums text-foreground-tertiary">
{checked}
</Text>
) : null}
</View>
{windows.map((window) => {
const details =
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "Keine Limits gemeldet.",
"e27d2cb964df5dd5": "{source}: Keine Konten gemeldet.",
"1b503134018285f4": "{days} T. {hours} Std.",
"1b316942cffcbb5f": "gerade geprüft",
"57b04d7ee40cfb03": "vor {duration} geprüft",
"164c674cf062933a": "{label} · noch {count} · läuft ab in {expires}",
"9c82c39589c23938": "{label} · noch {count}",
"ea4eaa756c937d3a": "Einlösen",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "No limits reported.",
"e27d2cb964df5dd5": "{source}: No accounts reported.",
"1b503134018285f4": "{days}d {hours}h",
"1b316942cffcbb5f": "checked just now",
"57b04d7ee40cfb03": "checked {duration} ago",
"164c674cf062933a": "{label} · {count} left · expires in {expires}",
"9c82c39589c23938": "{label} · {count} left",
"ea4eaa756c937d3a": "Use",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "No se informaron límites.",
"e27d2cb964df5dd5": "{source}: no se informaron cuentas.",
"1b503134018285f4": "{days} d {hours} h",
"1b316942cffcbb5f": "comprobado ahora mismo",
"57b04d7ee40cfb03": "comprobado hace {duration}",
"164c674cf062933a": "{label} · quedan {count} · caduca en {expires}",
"9c82c39589c23938": "{label} · quedan {count}",
"ea4eaa756c937d3a": "Usar",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "Aucune limite signalée.",
"e27d2cb964df5dd5": "{source} : aucun compte signalé.",
"1b503134018285f4": "{days} j {hours} h",
"1b316942cffcbb5f": "vérifié à l'instant",
"57b04d7ee40cfb03": "vérifié il y a {duration}",
"164c674cf062933a": "{label} · {count} restants · expire dans {expires}",
"9c82c39589c23938": "{label} · {count} restants",
"ea4eaa756c937d3a": "Utiliser",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "報告された上限はありません。",
"e27d2cb964df5dd5": "{source}: 報告されたアカウントはありません。",
"1b503134018285f4": "{days}日{hours}時間",
"1b316942cffcbb5f": "たった今確認",
"57b04d7ee40cfb03": "{duration}前に確認",
"164c674cf062933a": "{label} · 残り {count} · {expires}後に期限切れ",
"9c82c39589c23938": "{label} · 残り {count}",
"ea4eaa756c937d3a": "使用",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "보고된 한도가 없습니다.",
"e27d2cb964df5dd5": "{source}: 보고된 계정이 없습니다.",
"1b503134018285f4": "{days}일 {hours}시간",
"1b316942cffcbb5f": "방금 확인함",
"57b04d7ee40cfb03": "{duration} 전에 확인함",
"164c674cf062933a": "{label} · {count}개 남음 · {expires} 후 만료",
"9c82c39589c23938": "{label} · {count}개 남음",
"ea4eaa756c937d3a": "사용",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "Nenhum limite informado.",
"e27d2cb964df5dd5": "{source}: nenhuma conta informada.",
"1b503134018285f4": "{days}d {hours}h",
"1b316942cffcbb5f": "verificado agora mesmo",
"57b04d7ee40cfb03": "verificado há {duration}",
"164c674cf062933a": "{label} · {count} restantes · expira em {expires}",
"9c82c39589c23938": "{label} · {count} restantes",
"ea4eaa756c937d3a": "Usar",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "Лимиты не сообщаются.",
"e27d2cb964df5dd5": "{source}: аккаунты не найдены.",
"1b503134018285f4": "{days} д {hours} ч",
"1b316942cffcbb5f": "проверено только что",
"57b04d7ee40cfb03": "проверено {duration} назад",
"164c674cf062933a": "{label} · осталось {count} · истекает через {expires}",
"9c82c39589c23938": "{label} · осталось {count}",
"ea4eaa756c937d3a": "Использовать",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "Inga gränser rapporterades.",
"e27d2cb964df5dd5": "{source}: inga konton rapporterades.",
"1b503134018285f4": "{days} d {hours} h",
"1b316942cffcbb5f": "kontrollerat nyss",
"57b04d7ee40cfb03": "kontrollerat för {duration} sedan",
"164c674cf062933a": "{label} · {count} kvar · går ut om {expires}",
"9c82c39589c23938": "{label} · {count} kvar",
"ea4eaa756c937d3a": "Använd",
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/i18n/translations/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "没有报告限额。",
"e27d2cb964df5dd5": "{source}:未报告任何账户。",
"1b503134018285f4": "{days} 天 {hours} 小时",
"1b316942cffcbb5f": "刚刚检查",
"57b04d7ee40cfb03": "{duration}前检查",
"164c674cf062933a": "{label} · 剩余 {count} 个 · {expires} 后过期",
"9c82c39589c23938": "{label} · 剩余 {count} 次",
"ea4eaa756c937d3a": "使用",
Expand Down
79 changes: 72 additions & 7 deletions apps/server/src/provider/AntigravityProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@
}),
);

it.effect(

Check failure on line 718 in apps/server/src/provider/AntigravityProvider.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck and fork tests

src/provider/AntigravityProvider.test.ts > Antigravity provider snapshots > publishes limits, retains a successful read on failure, and clears them on sign-out

Error: Test timed out in 120000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ Array.<anonymous> src/provider/AntigravityProvider.test.ts:718:6
"publishes limits, retains a successful read on failure, and clears them on sign-out",
() =>
Effect.gen(function* () {
Expand All @@ -735,6 +735,17 @@
const published = yield* harness.nextPublish((snapshot) => !!snapshot.usageLimits);
yield* harness.initialize;
expect((yield* published)?.usageLimits).toEqual(limits);
// A new session renews the CLI sign-in, so its start re-reads quota.
const renewed: ServerProviderUsageLimits = {
checkedAt: "2026-10-09T12:00:30.000Z",
windows: [{ ...limits.windows[0]!, usedPercent: 50 }],
};
yield* Ref.set(usage, renewed);
const republishedAfterSession = yield* harness.nextPublish(
(snapshot) => snapshot.usageLimits?.checkedAt === renewed.checkedAt,
);
yield* harness.provider.onSessionStarted(started);
expect((yield* republishedAfterSession)?.usageLimits).toEqual(renewed);
// The second health check is the one the failed background read triggers.
const checks = yield* Ref.make(0);
const failedReadApplied = yield* Deferred.make<void>();
Expand All @@ -754,7 +765,7 @@
});
yield* harness.provider.snapshot.refresh;
yield* Deferred.await(failedReadApplied);
expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toEqual(limits);
expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toEqual(renewed);
yield* harness.provider.onSignedOut;
expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toBeUndefined();
yield* Ref.set(usage, {
Expand Down Expand Up @@ -796,26 +807,80 @@
}),
);

it.effect("reports ready and starts sessions while one shared quota read is pending", () =>
it.effect("a session start rejected by an auth-required clear does not restore quota", () =>
Effect.gen(function* () {
const limits: ServerProviderUsageLimits = {
checkedAt: "2026-10-09T12:00:00.000Z",
windows: [{ id: "gemini-5h", kind: "session", label: "Gemini · 5-hour", usedPercent: 10 }],
};
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);
// Hold the session start at its capability check, clear the account, then let it finish.
const atGate = yield* Deferred.make<void>();
const gate = yield* Deferred.make<void>();
yield* Ref.set(
harness.safety,
Deferred.succeed(atGate, undefined).pipe(
Effect.andThen(Deferred.await(gate)),
Effect.as(true),
),
);
const sessionStart = yield* harness.provider.onSessionStarted(started).pipe(Effect.forkChild);
yield* Deferred.await(atGate);
yield* harness.provider.onAuthRequired;
expect((yield* harness.provider.snapshot.getSnapshot).usageLimits).toBeUndefined();
// The second health check is the one the post-clear background read triggers.
const checks = yield* Ref.make(0);
const readApplied = yield* Deferred.make<void>();
yield* Ref.set(
harness.probe,
Ref.updateAndGet(checks, (count) => count + 1).pipe(
Effect.tap((count) =>
count === 2 ? Deferred.succeed(readApplied, undefined) : Effect.void,
),
Effect.as(initializeResult),
),
);
yield* Deferred.succeed(gate, undefined);
yield* Fiber.join(sessionStart);
yield* harness.provider.snapshot.refresh;
yield* Deferred.await(readApplied);
const snapshot = yield* harness.provider.snapshot.getSnapshot;
expect(snapshot.usageLimits).toBeUndefined();
expect(snapshot.auth.status).toBe("unauthenticated");
}),
);

it.effect("reports ready while session starts restart a pending quota read", () =>
Effect.gen(function* () {
const reads = yield* Ref.make(0);
const readStarted = yield* Deferred.make<void>();
const readStarted = [
yield* Deferred.make<void>(),
yield* Deferred.make<void>(),
yield* Deferred.make<void>(),
];
const readResult = yield* Deferred.make<ServerProviderUsageLimits>();
const harness = yield* makeHarness({
probeUsage: Ref.update(reads, (count) => count + 1).pipe(
Effect.andThen(Deferred.succeed(readStarted, undefined)),
probeUsage: Ref.updateAndGet(reads, (count) => count + 1).pipe(
Effect.tap((count) => Deferred.succeed(readStarted[count - 1]!, undefined)),
Effect.andThen(Deferred.await(readResult)),
),
});
const published = yield* harness.nextPublish((snapshot) => !!snapshot.usageLimits);
yield* harness.initialize;
yield* Deferred.await(readStarted);
yield* Deferred.await(readStarted[0]!);
yield* harness.provider.onSessionStarted(started, "/workspace");
yield* Deferred.await(readStarted[1]!);
yield* harness.provider.onSessionStarted(started, "/other");
yield* Deferred.await(readStarted[2]!);
const ready = yield* harness.provider.snapshot.getSnapshot;
expect(ready).toMatchObject({ status: "ready", auth: { status: "authenticated" } });
expect(ready.usageLimits).toBeUndefined();
expect(yield* Ref.get(reads)).toBe(1);
// Each session start replaces the read that predates its renewed sign-in.
expect(yield* Ref.get(reads)).toBe(3);
const limits = {
checkedAt: "2026-10-09T12:00:00.000Z",
windows: [{ id: "gemini-5h", kind: "session", label: "Gemini · 5-hour", usedPercent: 10 }],
Expand Down
36 changes: 23 additions & 13 deletions apps/server/src/provider/AntigravityProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,30 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func
const usageRead = yield* FiberHandle.make();
const republish = yield* Deferred.make<Effect.Effect<ServerProvider>>();
const scope = yield* Effect.scope;
const refreshUsage = Effect.fn("AntigravityProvider.refreshUsage")(function* () {
// A restart interrupts a read that started before the CLI sign-in was renewed.
const refreshUsage = Effect.fn("AntigravityProvider.refreshUsage")(function* (refreshOptions?: {
readonly restart?: boolean;
}) {
if (!options.probeUsage || (yield* PublishingUsage)) return;
yield* FiberHandle.run(
usageRead,
options.probeUsage.pipe(
Effect.flatMap((probed) =>
SubscriptionRef.update(metadata, (state) => ({
...state,
draft: {
...state.draft,
usageLimits: resolveUsageLimitsAfterProbe({
published: state.draft.usageLimits,
probed,
}),
},
})),
SubscriptionRef.update(metadata, (state) =>
// A cleared account must not get quota back from a read that outlived the clear.
state.draft.auth.status === "unauthenticated"
? state
: {
...state,
draft: {
...state.draft,
usageLimits: resolveUsageLimitsAfterProbe({
published: state.draft.usageLimits,
probed,
}),
},
},
),
),
// Enrichment cannot change published limits; a health check publishes them.
Effect.andThen(
Expand All @@ -283,7 +291,7 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func
),
),
// Store the fiber before it runs, so a sign-out during the read can interrupt it.
{ onlyIfMissing: true, startImmediately: false },
{ onlyIfMissing: refreshOptions?.restart !== true, startImmediately: false },
);
});
const resetUsage = Effect.gen(function* () {
Expand Down Expand Up @@ -442,7 +450,9 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func
},
} satisfies AntigravityProviderState;
});
if (!before.draft.usageLimits || before.draft.usageLimits.unavailable) yield* refreshUsage();
// Starting a session renews the CLI sign-in, so re-read quota even when a reading exists.
const accepted = yield* SubscriptionRef.get(metadata);
if (accepted.draft.auth.status === "authenticated") yield* refreshUsage({ restart: true });
});

const onConfigOptionsUpdated = Effect.fn("AntigravityProvider.onConfigOptionsUpdated")(function* (
Expand Down
15 changes: 15 additions & 0 deletions apps/web/src/components/usage/UsageLimitsPooled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from "react";

import { ensureLocalApi } from "../../localApi";
import { useNowMinute } from "../../hooks/useNowMinute";
import { usePrimarySettings } from "../../hooks/useSettings";
import { cn } from "../../lib/utils";
import { formatUpcomingTimestamp } from "../../timestampFormat";
Expand All @@ -43,6 +44,7 @@ import {
collectLimitNotices,
cursorUsageWindowDetails,
formatResetsIn,
poolCheckedLabel,
resetCreditChoices,
} from "@t3tools/shared/usageLimitsCopy";

Expand Down Expand Up @@ -636,6 +638,18 @@ function PoolWindowCard({
);
}

// The page freezes `now` between refreshes, so the age ticks on its own minute clock.
function PoolCheckedAt({ pool }: { readonly pool: LimitPool }) {
const nowMinute = useNowMinute();
const m = useMessages();
const checked = poolCheckedLabel(pool, Date.parse(`${nowMinute}:00Z`), m);
return checked ? (
<span className="ml-auto text-xs font-normal tabular-nums text-muted-foreground">
{checked}
</span>
) : null;
}

function PoolSection({ pool, now }: { readonly pool: LimitPool; readonly now: number }) {
const color = barColor(pool.driver);
const label = providerClients.get(pool.driver)?.label ?? String(pool.driver);
Expand All @@ -652,6 +666,7 @@ function PoolSection({ pool, now }: { readonly pool: LimitPool; readonly now: nu
iconClassName="size-4 text-foreground/80"
/>
{label}
<PoolCheckedAt pool={pool} />
</h2>
{windows.map((window) => {
const details =
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "Keine Limits gemeldet.",
"e27d2cb964df5dd5": "{source}: Keine Konten gemeldet.",
"1b503134018285f4": "{days} T. {hours} Std.",
"1b316942cffcbb5f": "gerade geprüft",
"57b04d7ee40cfb03": "vor {duration} geprüft",
"164c674cf062933a": "{label} · noch {count} · läuft ab in {expires}",
"9c82c39589c23938": "{label} · noch {count}",
"ea4eaa756c937d3a": "Einlösen",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "No limits reported.",
"e27d2cb964df5dd5": "{source}: No accounts reported.",
"1b503134018285f4": "{days}d {hours}h",
"1b316942cffcbb5f": "checked just now",
"57b04d7ee40cfb03": "checked {duration} ago",
"164c674cf062933a": "{label} · {count} left · expires in {expires}",
"9c82c39589c23938": "{label} · {count} left",
"ea4eaa756c937d3a": "Use",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "No se informaron límites.",
"e27d2cb964df5dd5": "{source}: no se informaron cuentas.",
"1b503134018285f4": "{days} d {hours} h",
"1b316942cffcbb5f": "comprobado ahora mismo",
"57b04d7ee40cfb03": "comprobado hace {duration}",
"164c674cf062933a": "{label} · quedan {count} · caduca en {expires}",
"9c82c39589c23938": "{label} · quedan {count}",
"ea4eaa756c937d3a": "Usar",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "Aucune limite signalée.",
"e27d2cb964df5dd5": "{source} : aucun compte signalé.",
"1b503134018285f4": "{days} j {hours} h",
"1b316942cffcbb5f": "vérifié à l'instant",
"57b04d7ee40cfb03": "vérifié il y a {duration}",
"164c674cf062933a": "{label} · {count} restants · expire dans {expires}",
"9c82c39589c23938": "{label} · {count} restants",
"ea4eaa756c937d3a": "Utiliser",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "報告された上限はありません。",
"e27d2cb964df5dd5": "{source}: 報告されたアカウントはありません。",
"1b503134018285f4": "{days}日{hours}時間",
"1b316942cffcbb5f": "たった今確認",
"57b04d7ee40cfb03": "{duration}前に確認",
"164c674cf062933a": "{label} · 残り {count} · {expires}後に期限切れ",
"9c82c39589c23938": "{label} · 残り {count}",
"ea4eaa756c937d3a": "使用",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "보고된 한도가 없습니다.",
"e27d2cb964df5dd5": "{source}: 보고된 계정이 없습니다.",
"1b503134018285f4": "{days}일 {hours}시간",
"1b316942cffcbb5f": "방금 확인함",
"57b04d7ee40cfb03": "{duration} 전에 확인함",
"164c674cf062933a": "{label} · {count}개 남음 · {expires} 후 만료",
"9c82c39589c23938": "{label} · {count}개 남음",
"ea4eaa756c937d3a": "사용",
Expand Down
2 changes: 2 additions & 0 deletions apps/web/src/i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,8 @@
"4897e228d3185c96": "Nenhum limite informado.",
"e27d2cb964df5dd5": "{source}: nenhuma conta informada.",
"1b503134018285f4": "{days}d {hours}h",
"1b316942cffcbb5f": "verificado agora mesmo",
"57b04d7ee40cfb03": "verificado há {duration}",
"164c674cf062933a": "{label} · {count} restantes · expira em {expires}",
"9c82c39589c23938": "{label} · {count} restantes",
"ea4eaa756c937d3a": "Usar",
Expand Down
Loading
Loading