From fa43e1b4300581f0387802f909ece5230ab0e9ef Mon Sep 17 00:00:00 2001 From: rune-oai <157205701+rune-gh@users.noreply.github.com> Date: Wed, 2 Dec 2026 17:18:00 -0800 Subject: [PATCH 1/3] fix(web): date far-off pool times and drop +0% from untouched resets A plan reset four weeks out read "+0%, Fri 8:00 AM": the weekday alone is ambiguous beyond six days, and a window with nothing used gains nothing. Co-Authored-By: Claude Opus 5.5 --- web/src/features/quota/components/QuotaPoolCard.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/web/src/features/quota/components/QuotaPoolCard.tsx b/web/src/features/quota/components/QuotaPoolCard.tsx index 02583469f80..3788cb61b27 100644 --- a/web/src/features/quota/components/QuotaPoolCard.tsx +++ b/web/src/features/quota/components/QuotaPoolCard.tsx @@ -41,7 +41,7 @@ import { type PoolView, type PoolWindowChoice, } from '../poolModel'; -import { formatDuration, formatMonthDay, formatWeekdayTime, POOL_UNITS } from '../poolFormat'; +import { formatDuration, formatMonthDay, formatResetInstant, POOL_UNITS } from '../poolFormat'; import { formatPlanName, formatWeight, planKey } from '../poolPrefs'; import { windowLabel } from '../poolWindowLabels'; import type { PlanWeightsMode } from '../hooks/usePlanWeights'; @@ -271,7 +271,7 @@ export function QuotaPoolCard(props: QuotaPoolCardProps) { : collecting ? t('quota_pool.collecting_data') : view.poolEmptyAt !== null - ? formatWeekdayTime(view.poolEmptyAt, locale) + ? formatResetInstant(view.poolEmptyAt, now, locale) : notBy, }, { @@ -289,7 +289,10 @@ export function QuotaPoolCard(props: QuotaPoolCardProps) { key: 'next-reset', label: t('quota_pool.stat_next_reset'), value: view.nextReset - ? `${units.signed(view.nextReset.amount)}, ${formatWeekdayTime(view.nextReset.at, locale)}` + ? // A reset that restores nothing (an untouched window) shows just when it comes. + units.signed(view.nextReset.amount) === units.signed(0) + ? formatResetInstant(view.nextReset.at, now, locale) + : `${units.signed(view.nextReset.amount)}, ${formatResetInstant(view.nextReset.at, now, locale)}` : '—', }, { From cb2a572ca7ccf5b1d510f73f7ce1b98ffffec7fd Mon Sep 17 00:00:00 2001 From: rune-oai <157205701+rune-gh@users.noreply.github.com> Date: Wed, 2 Dec 2026 17:30:34 -0800 Subject: [PATCH 2/3] fix(web): clear Now marker, honest Antigravity pools, plainer empty-time wording MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Now is a solid full-height rule with a chip; jump labels keep clear of it. - Several lines on one chart: no "… empty …" captions over the lines; the table above already names each time. An already-empty pool reads "Empty now". - "Not by Dec 13" becomes "Lasts past Dec 13". - An account that keeps reporting but no longer lists a window (Antigravity dropped one account's Claude/GPT group) leaves that pool and the table, instead of its last reading being carried forward for days. - Antigravity readings that refill before their reset and fall straight back (seen while an account was failing with 403s) are dropped; lasting early resets are kept. - Dev fixture: `&pool=live` renders a saved hub history. Co-Authored-By: Claude Opus 5.5 --- .../features/quota/__fixtures__/devFixture.ts | 22 ++++- web/src/features/quota/accountRows.ts | 12 ++- .../quota/components/PoolChart.module.scss | 15 ++- .../features/quota/components/PoolChart.tsx | 94 +++++++++++++------ .../quota/components/QuotaPoolCard.tsx | 4 +- web/src/features/quota/poolModel.ts | 49 ++++++++++ web/src/i18n/locales/en.json | 4 +- web/tests/quotaAccountRowsRetired.test.ts | 30 ++++++ web/tests/quotaPoolModel.test.ts | 43 +++++++++ 9 files changed, 235 insertions(+), 38 deletions(-) create mode 100644 web/tests/quotaAccountRowsRetired.test.ts diff --git a/web/src/features/quota/__fixtures__/devFixture.ts b/web/src/features/quota/__fixtures__/devFixture.ts index a8dbe2c7ba6..88fa2d0a605 100644 --- a/web/src/features/quota/__fixtures__/devFixture.ts +++ b/web/src/features/quota/__fixtures__/devFixture.ts @@ -5,7 +5,8 @@ * `&providers=two` to record only Claude and Codex (no xAI/Antigravity pools), * `&pool=owner` for the owner's hub (Claude Pro + Max 5x, Codex Plus + prolite, * one Antigravity account with four group windows, one xAI weekly window), - * and `&weights=off` to simulate a hub without server-side plan weights + * `&pool=live` for a hub's real `quota-history` response saved (untracked) as + * `__fixtures__/live.local.json`, and `&weights=off` to simulate a hub without server-side plan weights * (`/routing/plan-weights` 404, weights kept in the browser). Loaded through a dynamic import * guarded by `import.meta.env.DEV`, so production bundles never contain it. * @@ -49,7 +50,24 @@ export function installQuotaHistoryFixture(): void { const params = new URLSearchParams(window.location.search); const historyOff = params.get('history') === 'off'; const weightsOff = params.get('weights') === 'off'; - if (params.get('pool') === 'owner') { + const liveDump = Object.values( + import.meta.glob('./live.local.json', { eager: true, import: 'default' }) + )[0] as { now: number; accounts: never[]; samples: never[] } | undefined; + if (params.get('pool') === 'live' && liveDump) { + fixture.payload.now = liveDump.now; + fixture.payload.accounts = liveDump.accounts; + fixture.payload.samples = liveDump.samples; + fixture.credentials.files = (liveDump.accounts as Array>).map( + (account) => ({ + name: `${account.provider}-${account.auth_index}.json`, + type: account.provider, + provider: account.provider, + email: account.label, + auth_index: account.auth_index, + status: 'active', + }) + ) as never; + } else if (params.get('pool') === 'owner') { const owner = buildOwnerPoolHistory(fixture.payload.now); fixture.payload.accounts = owner.accounts; fixture.payload.samples = owner.samples; diff --git a/web/src/features/quota/accountRows.ts b/web/src/features/quota/accountRows.ts index 90c83f3b4a8..6b82b4ce83e 100644 --- a/web/src/features/quota/accountRows.ts +++ b/web/src/features/quota/accountRows.ts @@ -8,6 +8,7 @@ import type { QuotaBudget, QuotaHistory, QuotaHistorySample } from '@/services/api'; import { claudePlanIncludesFable } from '@/utils/quota/claudePlans'; import { + HOUR_MS, MINUTE_MS, isLivePoolProvider, nextResetAfter, @@ -80,17 +81,26 @@ export const ROW_WINDOW_KEYS = { const EPSILON = 1e-6; -/** Latest successful reading of one window key at or before `now`. */ +/** Readings that keep arriving without a window this long mean the account lost it. */ +const RETIRED_WINDOW_MS = 6 * HOUR_MS; + +/** + * Latest successful reading of one window key at or before `now`; null when + * the account's later readings stopped listing the window (it was retired). + */ export function readWindow( samples: readonly QuotaHistorySample[], key: string, now: number ): WindowReading | null { + let latestReading = -Infinity; for (let i = samples.length - 1; i >= 0; i -= 1) { const sample = samples[i]; if (sample.t > now || sample.error) continue; + latestReading = Math.max(latestReading, sample.t); const window = sample.windows[key]; if (!window || window.usedPercent == null) continue; + if (latestReading - sample.t > RETIRED_WINDOW_MS) return null; const passed = window.resetsAt !== null && window.resetsAt <= now; return { remaining: passed ? 100 : Math.min(100, Math.max(0, 100 - window.usedPercent)), diff --git a/web/src/features/quota/components/PoolChart.module.scss b/web/src/features/quota/components/PoolChart.module.scss index 857dfde2a01..2b2ee076518 100644 --- a/web/src/features/quota/components/PoolChart.module.scss +++ b/web/src/features/quota/components/PoolChart.module.scss @@ -74,16 +74,27 @@ stroke-width: 3px; } -.nowRule, .hoverRule { stroke: var(--border-strong); stroke-width: 1; shape-rendering: crispEdges; } +/* Now: a solid full-height rule with a chip on top, the strongest mark on the chart. */ +.nowRule { + stroke: var(--foreground); + stroke-opacity: 0.75; + stroke-width: 1.5; +} + +.nowChip { + fill: var(--foreground); +} + .nowLabel { - fill: var(--muted-foreground); + fill: var(--card); font-size: var(--text-xs); + font-weight: 600; } .nowDot, diff --git a/web/src/features/quota/components/PoolChart.tsx b/web/src/features/quota/components/PoolChart.tsx index fa07497c271..6423108a475 100644 --- a/web/src/features/quota/components/PoolChart.tsx +++ b/web/src/features/quota/components/PoolChart.tsx @@ -44,9 +44,11 @@ export interface PoolChartProps { const HEIGHT = 300; const COMPACT_HEIGHT = 220; const COMPACT_WIDTH = 560; -const MARGIN = { top: 28, right: 12, bottom: 26, left: 44 }; +const MARGIN = { top: 34, right: 12, bottom: 26, left: 44 }; const DEFAULT_WIDTH = 960; const LABEL_MIN_GAP_X = 40; +/** The Now chip sits this far above the plot. */ +const NOW_CHIP_OFFSET = 18; const linePath = ( points: readonly SeriesPoint[], @@ -151,10 +153,15 @@ export function PoolChart({ return labels.filter((_, index) => index % step === 0); }, [days, locale, spanEnd, spanStart, width]); - // Jump annotations over every line, greedily thinned so labels never overlap. + const nowVisible = now >= spanStart && now <= spanEnd; + const nowX = plotLeft + ((now - spanStart) / span) * (plotRight - plotLeft); + + // Jump annotations over every line, greedily thinned so labels never overlap + // each other or the Now chip. const jumpLabels = useMemo(() => { if (compact) return []; const out: { x: number; y: number; label: string; color: string }[] = []; + const nowChip = nowVisible ? { x: nowX, y: plotTop - NOW_CHIP_OFFSET } : null; series .flatMap((line) => line.view.jumps.map((jump) => ({ jump, color: line.color }))) .sort((a, b) => a.jump.t - b.jump.t) @@ -163,19 +170,29 @@ export function PoolChart({ const jy = plotBottom - (Math.min(Math.max(jump.value, 0), yMax) / yMax) * (plotBottom - plotTop); const labelY = Math.max(plotTop - 6, jy - 9); - const clash = out.some( - (other) => Math.abs(other.x - jx) < LABEL_MIN_GAP_X && Math.abs(other.y - labelY) < 14 + const clash = [...out, ...(nowChip ? [nowChip] : [])].some( + (other) => Math.abs(other.x - jx) < LABEL_MIN_GAP_X && Math.abs(other.y - labelY) < 16 ); if (clash || jx < plotLeft || jx > plotRight) return; out.push({ x: jx, y: labelY, label: units.signed(jump.amount), color }); }); return out; - }, [compact, plotBottom, plotLeft, plotRight, plotTop, series, span, spanStart, units, yMax]); - - const nowVisible = now >= spanStart && now <= spanEnd; - const nowX = x(now); - - // "Empty" markers, stacked upward so two lines emptying close together stay legible. + }, [ + compact, + nowVisible, + nowX, + plotBottom, + plotLeft, + plotRight, + plotTop, + series, + span, + spanStart, + units, + yMax, + ]); + + // "Empty" markers: a ring per line where its pool runs dry. const empties = series .map((line) => ({ line, at: line.view.poolEmptyAt })) .filter((item): item is { line: PoolChartSeries; at: number } => item.at !== null); @@ -343,8 +360,28 @@ export function PoolChart({ {nowVisible && ( - - + + + {t('quota_pool.now', { defaultValue: 'Now' })} {series @@ -362,25 +399,22 @@ export function PoolChart({ )} - {empties.map(({ line, at }, index) => ( + {empties.map(({ line, at }) => ( - - {single - ? t('quota_pool.empty_at', { - defaultValue: 'Empty {{time}}', - time: formatWeekdayTime(at, locale), - }) - : t('quota_pool.empty_at_series', { - defaultValue: '{{label}} empty {{time}}', - label: line.label, - time: formatWeekdayTime(at, locale), - })} - + {/* Several lines: the table above names each empty time; captions would cover the lines. */} + {single && ( + + {t('quota_pool.empty_at', { + defaultValue: 'Empty {{time}}', + time: formatWeekdayTime(at, locale), + })} + + )} { if (sample.error) return; + latestReading = Math.max(latestReading, sample.t); const window: QuotaHistoryWindow | undefined = sample.windows[windowKey]; if (!window || window.usedPercent == null) return; points.push({ @@ -517,7 +519,12 @@ export function buildAccountTracks( periodHours: window.periodHours, }); }); + if (provider === 'antigravity') dropTransientRefills(points); if (points.length === 0) return; + // The account still reports but no longer lists this window (Antigravity + // drops a model group an account loses): it has left this pool, and its + // last reading must not be carried forward. + if (latestReading - points[points.length - 1].t > retireGraceMs(history)) return; tracks.push({ authIndex: account.authIndex, label: account.label || account.authIndex, @@ -535,6 +542,48 @@ export function buildAccountTracks( return tracks; } +/** How long a window may go unreported before it counts as retired. */ +const retireGraceMs = (history: QuotaHistory): number => + Math.max(CURRENT_WINDOW_GRACE_MS, 3 * history.intervalSeconds * 1000); + +/** A refill at least this large before the previous reading's reset is suspect. */ +const SUSPECT_REFILL_POINTS = 20; +/** Readings returning to within this many points of the earlier level undo the refill. */ +const REFILL_UNDONE_POINTS = 10; +const REFILL_SLACK_MS = 10 * MINUTE_MS; + +/** + * Antigravity sometimes answers with every window untouched while an account + * is failing, then returns to the real figures; those readings would draw a + * spike. Remove a run of readings that refills before the previous reading's + * reset and is followed by a reading back near the earlier level. A refill + * that lasts (Antigravity does reset some windows early) is kept. In place. + */ +export function dropTransientRefills(points: TrackPoint[]): void { + const kept: TrackPoint[] = []; + let i = 0; + while (i < points.length) { + const previous = kept[kept.length - 1]; + const suspect = (point: TrackPoint) => + previous !== undefined && + previous.resetsAt !== null && + point.t < previous.resetsAt - REFILL_SLACK_MS && + point.remaining - previous.remaining >= SUSPECT_REFILL_POINTS; + if (suspect(points[i])) { + let end = i; + while (end < points.length && suspect(points[end])) end += 1; + const after = points[end]; + if (after && after.remaining <= previous!.remaining + REFILL_UNDONE_POINTS) { + i = end; + continue; + } + } + kept.push(points[i]); + i += 1; + } + points.splice(0, points.length, ...kept); +} + /** Capacity of one account in pool percent: 100 × its share of the heaviest plan. */ export const accountCapacity = (track: Pick): number => 100 * track.share; diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index e41d00af26d..abe4c61f642 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -1745,7 +1745,6 @@ "projected_lower": "projected", "recorded_lower": "recorded", "chart_summary_series": "{{label}}: {{current}} of {{max}} left", - "empty_at_series": "{{label}} empty {{time}}", "tooltip_series_left": "{{label}}: {{value}} left", "series_window": "Window", "series_left": "Left", @@ -1781,7 +1780,8 @@ "accounts_count": "{{count}} accounts", "of_max": "of {{max}}", "plan_unknown": "No plan", - "not_by": "Not by {{date}}", + "not_by": "Lasts past {{date}}", + "pool_empty_now": "Empty now", "empty_now": "now", "in_duration": "in {{duration}}", "stat_pool_empty": "Estimated pool empty", diff --git a/web/tests/quotaAccountRowsRetired.test.ts b/web/tests/quotaAccountRowsRetired.test.ts new file mode 100644 index 00000000000..dd4cee7e138 --- /dev/null +++ b/web/tests/quotaAccountRowsRetired.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, test } from 'bun:test'; +import { readWindow } from '@/features/quota/accountRows'; +import type { QuotaHistorySample } from '@/services/api'; + +const H = 3_600_000; +const NOW = Date.UTC(2026, 11, 2, 12); +const sample = (t: number, windows: Record): QuotaHistorySample => ({ + t, + authIndex: 'a', + error: '', + windows: Object.fromEntries( + Object.entries(windows).map(([key, used]) => [ + key, + { usedPercent: used, resetsAt: NOW + 48 * H, periodHours: 168 }, + ]) + ), +}); + +describe('readWindow', () => { + test('a window the account stopped listing has no reading', () => { + const samples = [sample(NOW - 20 * H, { gone: 0, kept: 10 }), sample(NOW - H, { kept: 20 })]; + expect(readWindow(samples, 'gone', NOW)).toBeNull(); + expect(readWindow(samples, 'kept', NOW)?.remaining).toBe(80); + }); + + test('a window missing from only the latest few readings keeps its reading', () => { + const samples = [sample(NOW - 3 * H, { flaky: 40 }), sample(NOW - H, {})]; + expect(readWindow(samples, 'flaky', NOW)?.remaining).toBe(60); + }); +}); diff --git a/web/tests/quotaPoolModel.test.ts b/web/tests/quotaPoolModel.test.ts index b4d8e460d06..432a58add42 100644 --- a/web/tests/quotaPoolModel.test.ts +++ b/web/tests/quotaPoolModel.test.ts @@ -631,6 +631,49 @@ describe('pools for every provider', () => { expect(poolChartWindows('xai', xai)).toEqual(['monthly']); }); + test('an Antigravity spike that falls straight back is dropped, a lasting early reset is kept', () => { + const reset = NOW + 30 * H; + const h = history( + [{ id: 'g', provider: 'antigravity' }], + [ + sample(NOW - 5 * H, 'g', { group_x_weekly: { used: 70, resetsAt: reset } }), + // Every window reported untouched while the account was failing. + sample(NOW - 4 * H, 'g', { group_x_weekly: { used: 0, resetsAt: NOW + 160 * H } }), + sample(NOW - 3 * H, 'g', { group_x_weekly: { used: 0, resetsAt: NOW + 161 * H } }), + sample(NOW - 2 * H, 'g', { group_x_weekly: { used: 72, resetsAt: reset } }), + ] + ); + const [track] = buildAccountTracks(h, 'antigravity', 'group_x_weekly'); + expect(track.points.map((point) => point.remaining)).toEqual([30, 28]); + const early = history( + [{ id: 'g', provider: 'antigravity' }], + [ + sample(NOW - 5 * H, 'g', { group_x_weekly: { used: 100, resetsAt: reset } }), + sample(NOW - 4 * H, 'g', { group_x_weekly: { used: 0, resetsAt: NOW + 160 * H } }), + sample(NOW - 3 * H, 'g', { group_x_weekly: { used: 5, resetsAt: NOW + 160 * H } }), + ] + ); + expect(buildAccountTracks(early, 'antigravity', 'group_x_weekly')[0].points).toHaveLength(3); + }); + + test('an account that stops listing a window leaves that pool', () => { + const h = history( + [ + { id: 'a', provider: 'antigravity' }, + { id: 'b', provider: 'antigravity' }, + ], + [ + sample(NOW - 20 * H, 'a', { group_x_weekly: { used: 0 }, group_y_weekly: { used: 10 } }), + sample(NOW - H, 'a', { group_y_weekly: { used: 20 } }), + sample(NOW - H, 'b', { group_x_weekly: { used: 100 }, group_y_weekly: { used: 50 } }), + ] + ); + expect(buildAccountTracks(h, 'antigravity', 'group_x_weekly').map((t) => t.authIndex)).toEqual([ + 'b', + ]); + expect(buildAccountTracks(h, 'antigravity', 'group_y_weekly')).toHaveLength(2); + }); + test('a provider that reports only a short window still gets its line', () => { const h = history( [{ id: 's', provider: 'muse' }], From f21f52bb522cc48e357ba0186eaded1e8bcb72a9 Mon Sep 17 00:00:00 2001 From: rune-oai <157205701+rune-gh@users.noreply.github.com> Date: Wed, 2 Dec 2026 18:53:53 -0800 Subject: [PATCH 3/3] fix(web): show the 7-day average burn when it differs from the recent burn The projection blends the recent burn with the 7-day average, so a pool that has been idle for a few hours still slopes down. Showing the average under the recent figure explains that slope. Co-Authored-By: Claude Opus 5.5 --- .../quota/components/QuotaPoolCard.module.scss | 7 +++++++ .../features/quota/components/QuotaPoolCard.tsx | 17 ++++++++++++++++- web/src/i18n/locales/en.json | 1 + 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/web/src/features/quota/components/QuotaPoolCard.module.scss b/web/src/features/quota/components/QuotaPoolCard.module.scss index b133ce17007..6ca57fbc12e 100644 --- a/web/src/features/quota/components/QuotaPoolCard.module.scss +++ b/web/src/features/quota/components/QuotaPoolCard.module.scss @@ -264,6 +264,13 @@ color: var(--muted-foreground); } +.burnAverage { + display: block; + color: var(--muted-foreground); + font-size: var(--text-xs); + font-weight: 400; +} + .seriesHint { display: block; color: var(--muted-foreground); diff --git a/web/src/features/quota/components/QuotaPoolCard.tsx b/web/src/features/quota/components/QuotaPoolCard.tsx index fa05315b0b0..a2b2cfbe0b7 100644 --- a/web/src/features/quota/components/QuotaPoolCard.tsx +++ b/web/src/features/quota/components/QuotaPoolCard.tsx @@ -257,6 +257,21 @@ export function QuotaPoolCard(props: QuotaPoolCardProps) { notBy ); + // The projection leans on the 7-day average further out, so show it when it differs. + const burnValue = (view: PoolView): ReactNode => { + const recent = units.rate(view.burnRate); + const sustained = units.rate(view.burnEstimate.sustainedRate); + if (sustained === recent) return recent; + return ( + <> + {recent} + + {t('quota_pool.burn_week_average', { rate: sustained })} + + + ); + }; + // Labels follow the main window; every line uses the same burn window. const limited = primary?.view.burnEstimate.confidence === 'limited'; const statsFor = (view: PoolView): StatItem[] => { @@ -305,7 +320,7 @@ export function QuotaPoolCard(props: QuotaPoolCardProps) { value: !hasTracks ? '—' : view.burnEstimate.ready - ? units.rate(view.burnRate) + ? burnValue(view) : t('quota_pool.collecting_data'), }, ]; diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index abe4c61f642..eeb066ffdc0 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -1790,6 +1790,7 @@ "stat_next_reset": "Next reset", "stat_burn": "Burn, last {{hours}}h", "stat_burn_limited": "Burn, last {{hours}}h · limited data", + "burn_week_average": "{{rate}} on average over 7 days", "collecting_data": "Collecting data", "no_samples": "No readings for this window yet. Refresh to take one.", "no_reading": "No quota reading for these accounts yet.",