From 841d4ca4ee2db5d60a7c1e00b90c56c918f963c6 Mon Sep 17 00:00:00 2001 From: Tim Biggs Date: Sat, 21 Nov 2026 20:36:36 +0000 Subject: [PATCH 1/3] fix(usage): Antigravity limits refresh on session start and show their age Starting an Antigravity session renews the 1.5.x CLI sign-in that the quota probe reads, but the provider only re-read quota when no reading existed, so Limits kept showing a stale reading without saying so. Re-read on every session start, and label each pooled Limits section on web and mobile with the age of its stalest reading. Co-Authored-By: Claude --- .../src/features/usage/UsageLimitsPooled.tsx | 7 ++++ apps/mobile/src/i18n/translations/de.json | 2 ++ apps/mobile/src/i18n/translations/en.json | 2 ++ apps/mobile/src/i18n/translations/es.json | 2 ++ apps/mobile/src/i18n/translations/fr.json | 2 ++ apps/mobile/src/i18n/translations/ja.json | 2 ++ apps/mobile/src/i18n/translations/ko.json | 2 ++ apps/mobile/src/i18n/translations/pt-BR.json | 2 ++ apps/mobile/src/i18n/translations/ru.json | 2 ++ apps/mobile/src/i18n/translations/sv.json | 2 ++ apps/mobile/src/i18n/translations/zh.json | 2 ++ .../src/provider/AntigravityProvider.test.ts | 13 ++++++- .../src/provider/AntigravityProvider.ts | 3 +- .../components/usage/UsageLimitsPooled.tsx | 7 ++++ apps/web/src/i18n/translations/de.json | 2 ++ apps/web/src/i18n/translations/en.json | 2 ++ apps/web/src/i18n/translations/es.json | 2 ++ apps/web/src/i18n/translations/fr.json | 2 ++ apps/web/src/i18n/translations/ja.json | 2 ++ apps/web/src/i18n/translations/ko.json | 2 ++ apps/web/src/i18n/translations/pt-BR.json | 2 ++ apps/web/src/i18n/translations/ru.json | 2 ++ apps/web/src/i18n/translations/sv.json | 2 ++ apps/web/src/i18n/translations/zh.json | 2 ++ packages/shared/src/usageLimits.test.ts | 34 ++++++++++++++++++- packages/shared/src/usageLimitsCopy.ts | 18 ++++++++++ 26 files changed, 119 insertions(+), 3 deletions(-) diff --git a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx index 96d8f922340f7..db0f05e23019f 100644 --- a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx +++ b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx @@ -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"; @@ -501,6 +502,7 @@ export function UsageLimitsSection({ ) : null} {pools.map((pool) => { const windows = displayLimitWindows(pool); + const checked = poolCheckedLabel(pool, now, m); return ( @@ -509,6 +511,11 @@ export function UsageLimitsSection({ {providerClients.get(pool.driver)?.label ?? pool.driver} + {checked ? ( + + {checked} + + ) : null} {windows.map((window) => { const details = diff --git a/apps/mobile/src/i18n/translations/de.json b/apps/mobile/src/i18n/translations/de.json index 2fc89b4d1171d..7da71c2ba5434 100644 --- a/apps/mobile/src/i18n/translations/de.json +++ b/apps/mobile/src/i18n/translations/de.json @@ -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", diff --git a/apps/mobile/src/i18n/translations/en.json b/apps/mobile/src/i18n/translations/en.json index 4e6ca74ec9ac9..6c552a91896c3 100644 --- a/apps/mobile/src/i18n/translations/en.json +++ b/apps/mobile/src/i18n/translations/en.json @@ -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", diff --git a/apps/mobile/src/i18n/translations/es.json b/apps/mobile/src/i18n/translations/es.json index 410b8bd0891a9..e0aadd76a6b73 100644 --- a/apps/mobile/src/i18n/translations/es.json +++ b/apps/mobile/src/i18n/translations/es.json @@ -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", diff --git a/apps/mobile/src/i18n/translations/fr.json b/apps/mobile/src/i18n/translations/fr.json index 1eb1bfe555fbd..bc24d01f337c9 100644 --- a/apps/mobile/src/i18n/translations/fr.json +++ b/apps/mobile/src/i18n/translations/fr.json @@ -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", diff --git a/apps/mobile/src/i18n/translations/ja.json b/apps/mobile/src/i18n/translations/ja.json index bca3f5cd07f1e..d69eddf77045a 100644 --- a/apps/mobile/src/i18n/translations/ja.json +++ b/apps/mobile/src/i18n/translations/ja.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "報告された上限はありません。", "e27d2cb964df5dd5": "{source}: 報告されたアカウントはありません。", "1b503134018285f4": "{days}日{hours}時間", + "1b316942cffcbb5f": "たった今確認", + "57b04d7ee40cfb03": "{duration}前に確認", "164c674cf062933a": "{label} · 残り {count} · {expires}後に期限切れ", "9c82c39589c23938": "{label} · 残り {count}", "ea4eaa756c937d3a": "使用", diff --git a/apps/mobile/src/i18n/translations/ko.json b/apps/mobile/src/i18n/translations/ko.json index 8b1c9c3051e1a..ab802ab736888 100644 --- a/apps/mobile/src/i18n/translations/ko.json +++ b/apps/mobile/src/i18n/translations/ko.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "보고된 한도가 없습니다.", "e27d2cb964df5dd5": "{source}: 보고된 계정이 없습니다.", "1b503134018285f4": "{days}일 {hours}시간", + "1b316942cffcbb5f": "방금 확인함", + "57b04d7ee40cfb03": "{duration} 전에 확인함", "164c674cf062933a": "{label} · {count}개 남음 · {expires} 후 만료", "9c82c39589c23938": "{label} · {count}개 남음", "ea4eaa756c937d3a": "사용", diff --git a/apps/mobile/src/i18n/translations/pt-BR.json b/apps/mobile/src/i18n/translations/pt-BR.json index b027677a9cc33..678b8c48ef60e 100644 --- a/apps/mobile/src/i18n/translations/pt-BR.json +++ b/apps/mobile/src/i18n/translations/pt-BR.json @@ -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", diff --git a/apps/mobile/src/i18n/translations/ru.json b/apps/mobile/src/i18n/translations/ru.json index 5566d68d101e4..1fe3c063ed6fc 100644 --- a/apps/mobile/src/i18n/translations/ru.json +++ b/apps/mobile/src/i18n/translations/ru.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Лимиты не сообщаются.", "e27d2cb964df5dd5": "{source}: аккаунты не найдены.", "1b503134018285f4": "{days} д {hours} ч", + "1b316942cffcbb5f": "проверено только что", + "57b04d7ee40cfb03": "проверено {duration} назад", "164c674cf062933a": "{label} · осталось {count} · истекает через {expires}", "9c82c39589c23938": "{label} · осталось {count}", "ea4eaa756c937d3a": "Использовать", diff --git a/apps/mobile/src/i18n/translations/sv.json b/apps/mobile/src/i18n/translations/sv.json index 352d805285e15..04045130f9269 100644 --- a/apps/mobile/src/i18n/translations/sv.json +++ b/apps/mobile/src/i18n/translations/sv.json @@ -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", diff --git a/apps/mobile/src/i18n/translations/zh.json b/apps/mobile/src/i18n/translations/zh.json index df184643184f5..4c7d71389f02a 100644 --- a/apps/mobile/src/i18n/translations/zh.json +++ b/apps/mobile/src/i18n/translations/zh.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "没有报告限额。", "e27d2cb964df5dd5": "{source}:未报告任何账户。", "1b503134018285f4": "{days} 天 {hours} 小时", + "1b316942cffcbb5f": "刚刚检查", + "57b04d7ee40cfb03": "{duration}前检查", "164c674cf062933a": "{label} · 剩余 {count} 个 · {expires} 后过期", "9c82c39589c23938": "{label} · 剩余 {count} 次", "ea4eaa756c937d3a": "使用", diff --git a/apps/server/src/provider/AntigravityProvider.test.ts b/apps/server/src/provider/AntigravityProvider.test.ts index 522be29a8b187..d4d0bd90314bb 100644 --- a/apps/server/src/provider/AntigravityProvider.test.ts +++ b/apps/server/src/provider/AntigravityProvider.test.ts @@ -735,6 +735,17 @@ it.layer(layerTest)("Antigravity provider snapshots", (it) => { 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(); @@ -754,7 +765,7 @@ it.layer(layerTest)("Antigravity provider snapshots", (it) => { }); 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, { diff --git a/apps/server/src/provider/AntigravityProvider.ts b/apps/server/src/provider/AntigravityProvider.ts index b3b68d46e8ba8..66345c5c88525 100644 --- a/apps/server/src/provider/AntigravityProvider.ts +++ b/apps/server/src/provider/AntigravityProvider.ts @@ -442,7 +442,8 @@ 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. + yield* refreshUsage(); }); const onConfigOptionsUpdated = Effect.fn("AntigravityProvider.onConfigOptionsUpdated")(function* ( diff --git a/apps/web/src/components/usage/UsageLimitsPooled.tsx b/apps/web/src/components/usage/UsageLimitsPooled.tsx index c3932252691e5..5a938b8bb4e92 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.tsx @@ -43,6 +43,7 @@ import { collectLimitNotices, cursorUsageWindowDetails, formatResetsIn, + poolCheckedLabel, resetCreditChoices, } from "@t3tools/shared/usageLimitsCopy"; @@ -641,6 +642,7 @@ function PoolSection({ pool, now }: { readonly pool: LimitPool; readonly now: nu const label = providerClients.get(pool.driver)?.label ?? String(pool.driver); const windows = displayLimitWindows(pool); const m = useMessages(); + const checked = poolCheckedLabel(pool, now, m); return (

@@ -652,6 +654,11 @@ function PoolSection({ pool, now }: { readonly pool: LimitPool; readonly now: nu iconClassName="size-4 text-foreground/80" /> {label} + {checked ? ( + + {checked} + + ) : null}

{windows.map((window) => { const details = diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index d137c9575c8ef..4ea05c9bb2b74 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -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", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index 20f3f33250f23..3dd9f17dcdf96 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -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", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index 466f7e37ffa5d..fafbe7fa5bb3c 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -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", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index 579ae257a5c32..1ae56070edfea 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -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", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index d418d4753f17d..ed73966ad60b0 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "報告された上限はありません。", "e27d2cb964df5dd5": "{source}: 報告されたアカウントはありません。", "1b503134018285f4": "{days}日{hours}時間", + "1b316942cffcbb5f": "たった今確認", + "57b04d7ee40cfb03": "{duration}前に確認", "164c674cf062933a": "{label} · 残り {count} · {expires}後に期限切れ", "9c82c39589c23938": "{label} · 残り {count}", "ea4eaa756c937d3a": "使用", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index 9f5343afc9173..1d35973218c7c 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "보고된 한도가 없습니다.", "e27d2cb964df5dd5": "{source}: 보고된 계정이 없습니다.", "1b503134018285f4": "{days}일 {hours}시간", + "1b316942cffcbb5f": "방금 확인함", + "57b04d7ee40cfb03": "{duration} 전에 확인함", "164c674cf062933a": "{label} · {count}개 남음 · {expires} 후 만료", "9c82c39589c23938": "{label} · {count}개 남음", "ea4eaa756c937d3a": "사용", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index f9613764f383e..f69a7ff8afe87 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -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", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index 356b1a3f25580..73bd522210e47 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "Лимиты не сообщаются.", "e27d2cb964df5dd5": "{source}: аккаунты не найдены.", "1b503134018285f4": "{days} д {hours} ч", + "1b316942cffcbb5f": "проверено только что", + "57b04d7ee40cfb03": "проверено {duration} назад", "164c674cf062933a": "{label} · осталось {count} · истекает через {expires}", "9c82c39589c23938": "{label} · осталось {count}", "ea4eaa756c937d3a": "Использовать", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index 7e8a59ee1407c..14d77c3e102d6 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -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", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index 82feffe66e815..1e79b7fe4adbb 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -1259,6 +1259,8 @@ "4897e228d3185c96": "没有报告限额。", "e27d2cb964df5dd5": "{source}:未报告任何账户。", "1b503134018285f4": "{days} 天 {hours} 小时", + "1b316942cffcbb5f": "刚刚检查", + "57b04d7ee40cfb03": "{duration}前检查", "164c674cf062933a": "{label} · 剩余 {count} 个 · {expires} 后过期", "9c82c39589c23938": "{label} · 剩余 {count} 次", "ea4eaa756c937d3a": "使用", diff --git a/packages/shared/src/usageLimits.test.ts b/packages/shared/src/usageLimits.test.ts index 6b553fe5f1555..57479eb50ea5d 100644 --- a/packages/shared/src/usageLimits.test.ts +++ b/packages/shared/src/usageLimits.test.ts @@ -26,7 +26,7 @@ import { usesChatGptSharing, resolveNewThreadModelSelection, } from "./usageLimits.ts"; -import { collectLimitNotices } from "./usageLimitsCopy.ts"; +import { collectLimitNotices, poolCheckedLabel } from "./usageLimitsCopy.ts"; const now = Date.parse("2026-09-03T12:00:00.000Z"); @@ -294,6 +294,38 @@ describe("pools", () => { expect(accounts[0]?.limits.windows[0]?.usedPercent).toBe(55); }); + it("labels a pool with the age of its stalest reading", () => { + const account = (email: string, at: string) => + provider({ + driver: claude, + instanceId: ProviderInstanceId.make("claude"), + auth: { status: "authenticated", email }, + usageLimits: { checkedAt: at, windows: [{ ...window, usedPercent: 40 }] }, + }); + const poolsFor = (providers: readonly ServerProvider[]) => + collectLimitPools( + collectLimitAccounts( + new Map([[EnvironmentId.make("env-a"), { ...laptop, serverConfig: { providers } }]]), + ), + now, + ); + const stale = poolsFor([ + account("a@example.com", "2026-09-03T11:30:00.000Z"), + account("b@example.com", checkedAt), + ])[0]!; + expect(poolCheckedLabel(stale, now)).toBe("checked 1h 0m ago"); + const fresh = poolsFor([account("a@example.com", "2026-09-03T11:59:30.000Z")])[0]!; + expect(poolCheckedLabel(fresh, now)).toBe("checked just now"); + const unreadable = { + ...fresh, + accounts: fresh.accounts.map((entry) => ({ + ...entry, + limits: { ...entry.limits, checkedAt: "not-a-date" }, + })), + }; + expect(poolCheckedLabel(unreadable, now)).toBeNull(); + }); + it("uses the freshest reported plan even when the newest quota has no plan", () => { const snapshot = (label: string | undefined, checkedAt: string, usedPercent: number) => provider({ diff --git a/packages/shared/src/usageLimitsCopy.ts b/packages/shared/src/usageLimitsCopy.ts index ea9eafaf55ce1..520017b1263ef 100644 --- a/packages/shared/src/usageLimitsCopy.ts +++ b/packages/shared/src/usageLimitsCopy.ts @@ -131,6 +131,24 @@ export function formatDuration(ms: number, resolve: MFunctionType = mFallback): return resolve(msg("{minutes}m", { minutes })); } +/** How old a pool's stalest reading is, or null when no reading carries a usable time. @public */ +export function poolCheckedLabel( + pool: LimitPool, + now: number, + resolve: MFunctionType = mFallback, +): string | null { + const oldest = Math.min(...pool.accounts.map((account) => Date.parse(account.limits.checkedAt))); + if (!Number.isFinite(oldest)) return null; + const age = now - oldest; + if (age < MINUTE) return resolve(msg("checked just now", { $context: "usage limits" })); + return resolve( + msg("checked {duration} ago", { + duration: formatDuration(age, resolve), + $context: "usage limits", + }), + ); +} + /** @public */ export function resetCreditChoices( credits: ServerProviderResetCredits, From 253f0b10d00b04dde0360f42f1fdbf96bd64d264 Mon Sep 17 00:00:00 2001 From: Tim Biggs Date: Sat, 21 Nov 2026 21:02:03 +0000 Subject: [PATCH 2/3] fix(usage): keep Antigravity quota age and refresh honest Restart an in-flight quota read on session start so the renewed sign-in is always re-read, ignore malformed checkedAt values when computing a pool's age, and tick the web age label on a minute clock since the page freezes its now between refreshes. Co-Authored-By: Claude --- .../src/provider/AntigravityProvider.test.ts | 19 ++++++++++++------ .../src/provider/AntigravityProvider.ts | 9 ++++++--- .../components/usage/UsageLimitsPooled.tsx | 20 +++++++++++++------ packages/shared/src/usageLimits.test.ts | 8 ++++++++ packages/shared/src/usageLimitsCopy.ts | 7 +++++-- 5 files changed, 46 insertions(+), 17 deletions(-) diff --git a/apps/server/src/provider/AntigravityProvider.test.ts b/apps/server/src/provider/AntigravityProvider.test.ts index d4d0bd90314bb..357a637e1a784 100644 --- a/apps/server/src/provider/AntigravityProvider.test.ts +++ b/apps/server/src/provider/AntigravityProvider.test.ts @@ -807,26 +807,33 @@ it.layer(layerTest)("Antigravity provider snapshots", (it) => { }), ); - it.effect("reports ready and starts sessions while one shared quota read is pending", () => + 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(); + const readStarted = [ + yield* Deferred.make(), + yield* Deferred.make(), + yield* Deferred.make(), + ]; const readResult = yield* Deferred.make(); 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 }], diff --git a/apps/server/src/provider/AntigravityProvider.ts b/apps/server/src/provider/AntigravityProvider.ts index 66345c5c88525..132b9f0fd884d 100644 --- a/apps/server/src/provider/AntigravityProvider.ts +++ b/apps/server/src/provider/AntigravityProvider.ts @@ -255,7 +255,10 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func const usageRead = yield* FiberHandle.make(); const republish = yield* Deferred.make>(); 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, @@ -283,7 +286,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* () { @@ -443,7 +446,7 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func } satisfies AntigravityProviderState; }); // Starting a session renews the CLI sign-in, so re-read quota even when a reading exists. - yield* refreshUsage(); + yield* refreshUsage({ restart: true }); }); const onConfigOptionsUpdated = Effect.fn("AntigravityProvider.onConfigOptionsUpdated")(function* ( diff --git a/apps/web/src/components/usage/UsageLimitsPooled.tsx b/apps/web/src/components/usage/UsageLimitsPooled.tsx index 5a938b8bb4e92..daeebf6e03a07 100644 --- a/apps/web/src/components/usage/UsageLimitsPooled.tsx +++ b/apps/web/src/components/usage/UsageLimitsPooled.tsx @@ -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"; @@ -637,12 +638,23 @@ 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 ? ( + + {checked} + + ) : 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); const windows = displayLimitWindows(pool); const m = useMessages(); - const checked = poolCheckedLabel(pool, now, m); return (

@@ -654,11 +666,7 @@ function PoolSection({ pool, now }: { readonly pool: LimitPool; readonly now: nu iconClassName="size-4 text-foreground/80" /> {label} - {checked ? ( - - {checked} - - ) : null} +

{windows.map((window) => { const details = diff --git a/packages/shared/src/usageLimits.test.ts b/packages/shared/src/usageLimits.test.ts index 57479eb50ea5d..d14a5f0558772 100644 --- a/packages/shared/src/usageLimits.test.ts +++ b/packages/shared/src/usageLimits.test.ts @@ -316,6 +316,14 @@ describe("pools", () => { expect(poolCheckedLabel(stale, now)).toBe("checked 1h 0m ago"); const fresh = poolsFor([account("a@example.com", "2026-09-03T11:59:30.000Z")])[0]!; expect(poolCheckedLabel(fresh, now)).toBe("checked just now"); + const withUnreadable = (pool: typeof stale, at: string) => ({ + ...pool, + accounts: pool.accounts.map((entry, index) => + index === 0 ? { ...entry, limits: { ...entry.limits, checkedAt: at } } : entry, + ), + }); + // One malformed wire timestamp must not hide the readable readings' age. + expect(poolCheckedLabel(withUnreadable(stale, "not-a-date"), now)).toBe("checked 1h 0m ago"); const unreadable = { ...fresh, accounts: fresh.accounts.map((entry) => ({ diff --git a/packages/shared/src/usageLimitsCopy.ts b/packages/shared/src/usageLimitsCopy.ts index 520017b1263ef..1cae2570c38ea 100644 --- a/packages/shared/src/usageLimitsCopy.ts +++ b/packages/shared/src/usageLimitsCopy.ts @@ -137,8 +137,11 @@ export function poolCheckedLabel( now: number, resolve: MFunctionType = mFallback, ): string | null { - const oldest = Math.min(...pool.accounts.map((account) => Date.parse(account.limits.checkedAt))); - if (!Number.isFinite(oldest)) return null; + const readable = pool.accounts + .map((account) => Date.parse(account.limits.checkedAt)) + .filter(Number.isFinite); + if (readable.length === 0) return null; + const oldest = Math.min(...readable); const age = now - oldest; if (age < MINUTE) return resolve(msg("checked just now", { $context: "usage limits" })); return resolve( From 1593011ad4e57a42ca25705bdfc3f86927197a55 Mon Sep 17 00:00:00 2001 From: Tim Biggs Date: Sat, 21 Nov 2026 21:30:25 +0000 Subject: [PATCH 3/3] fix(server): a cleared Antigravity account never regains quota A session start held at its capability check could finish after an auth-required clear and republish quota for the cleared account. Only refresh when the accepted state is authenticated, and drop quota writes that land on an unauthenticated draft. Co-Authored-By: Claude --- .../src/provider/AntigravityProvider.test.ts | 47 +++++++++++++++++++ .../src/provider/AntigravityProvider.ts | 28 ++++++----- 2 files changed, 64 insertions(+), 11 deletions(-) diff --git a/apps/server/src/provider/AntigravityProvider.test.ts b/apps/server/src/provider/AntigravityProvider.test.ts index 357a637e1a784..f5c0c11d1b1e3 100644 --- a/apps/server/src/provider/AntigravityProvider.test.ts +++ b/apps/server/src/provider/AntigravityProvider.test.ts @@ -807,6 +807,53 @@ it.layer(layerTest)("Antigravity provider snapshots", (it) => { }), ); + 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(); + const gate = yield* Deferred.make(); + 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(); + 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); diff --git a/apps/server/src/provider/AntigravityProvider.ts b/apps/server/src/provider/AntigravityProvider.ts index 132b9f0fd884d..a9718e463589a 100644 --- a/apps/server/src/provider/AntigravityProvider.ts +++ b/apps/server/src/provider/AntigravityProvider.ts @@ -264,16 +264,21 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func 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( @@ -446,7 +451,8 @@ export const makeAntigravityProvider = Effect.fn("makeAntigravityProvider")(func } satisfies AntigravityProviderState; }); // Starting a session renews the CLI sign-in, so re-read quota even when a reading exists. - yield* refreshUsage({ restart: true }); + const accepted = yield* SubscriptionRef.get(metadata); + if (accepted.draft.auth.status === "authenticated") yield* refreshUsage({ restart: true }); }); const onConfigOptionsUpdated = Effect.fn("AntigravityProvider.onConfigOptionsUpdated")(function* (