fix(antigravity): shorten usage pool labels and drop duplicate weekly row (#43457)

agy names its quota buckets "Weekly Limit Remaining" / "Five Hour Limit
Remaining", so the usage roster, provider card and mobile showed those raw
names beside used percentages and truncated the reset caption.
getUsageWindowSections also appended the derived weekly rollup after
Antigravity's per-pool weekly buckets, showing the weekly value twice.

Label grouped pools from their group and window length on desktop and
mobile (as the status bar already did) through shared helpers in
grouped-usage-pool, strip the direction suffix from parsed bucket names,
and drop the weekly rollup only when it repeats a listed 10,080-minute
bucket's usage and reset.

Fixes #43453

Co-authored-by: ASH <7201776+asunghong@users.noreply.github.com>
Co-authored-by: Neil <neil@stably.ai>
This commit is contained in:
ASH
2026-11-16 22:32:02 -08:00
committed by GitHub
co-authored by ASH Neil
parent dc88463694
commit 59c0a7239a
13 changed files with 325 additions and 80 deletions
+33 -16
View File
@@ -2,8 +2,14 @@ import { View } from 'react-native'
import { formatWindowLabel } from '../../../src/shared/agent-usage/rate-limits/rate-limit-window-label'
import {
getUsageWindowSections,
WEEKLY_WINDOW_MINUTES,
type UsageWindowSection
} from '../../../src/shared/agent-usage/display/usage-provider-windows'
import {
formatPoolLabel,
isGroupedUsagePool,
type UsagePoolSibling
} from '../../../src/shared/agent-usage/display/grouped-usage-pool'
import { UsageBar } from './usage/UsageBar'
import { getUsageBarState, getWindowResetLabel } from './usage/usage-selectors'
import type { ProviderRateLimits } from './accounts-snapshot'
@@ -13,26 +19,12 @@ import { spacing } from '../theme/mobile-theme'
import { themedStyleSheet } from '../theme/themed-styles'
const SESSION_WINDOW_MINUTES = 300
const WEEKLY_WINDOW_MINUTES = 10_080
const EMPTY_SECTIONS: UsageWindowSection[] = [
{ kind: 'session', window: null },
{ kind: 'weekly', window: null }
]
// The desktop roster's labels, except 5h and 7d use mobile's translated copy (desktop shows 7d as "wk").
function getWindowLabel(section: UsageWindowSection, t: Translate): string {
if (section.kind === 'bucket') {
return section.name
}
if (section.kind === 'fableWeekly') {
return t('accounts.screen.fableWindow', 'Fable')
}
if (section.kind === 'mcp') {
return t('accounts.screen.mcpWindow', 'MCP')
}
const minutes =
section.window?.windowMinutes ??
(section.kind === 'session' ? SESSION_WINDOW_MINUTES : WEEKLY_WINDOW_MINUTES)
function formatWindowLength(minutes: number, t: Translate): string {
if (minutes === SESSION_WINDOW_MINUTES) {
return t('accounts.screen.sessionWindow', '5h')
}
@@ -42,6 +34,30 @@ function getWindowLabel(section: UsageWindowSection, t: Translate): string {
return formatWindowLabel(minutes)
}
// The desktop roster's labels, except 5h and 7d use mobile's translated copy (desktop shows 7d as "wk").
function getWindowLabel(
section: UsageWindowSection,
buckets: readonly UsagePoolSibling[],
t: Translate
): string {
if (section.kind === 'bucket') {
return isGroupedUsagePool(section.window)
? formatPoolLabel(section.window, buckets, (minutes) => formatWindowLength(minutes, t))
: section.name
}
if (section.kind === 'fableWeekly') {
return t('accounts.screen.fableWindow', 'Fable')
}
if (section.kind === 'mcp') {
return t('accounts.screen.mcpWindow', 'MCP')
}
return formatWindowLength(
section.window?.windowMinutes ??
(section.kind === 'session' ? SESSION_WINDOW_MINUTES : WEEKLY_WINDOW_MINUTES),
t
)
}
/** One bar per usage window desktop shows for this provider. */
export function ProviderUsageWindows({
limits,
@@ -56,6 +72,7 @@ export function ProviderUsageWindows({
showEmptyWindows?: boolean
}) {
const t = useMobileTranslation()
const buckets = limits?.buckets ?? []
const sections = (limits ? getUsageWindowSections(limits) : EMPTY_SECTIONS).filter(
(section) => showEmptyWindows || section.window !== null
)
@@ -72,7 +89,7 @@ export function ProviderUsageWindows({
return (
<UsageBar
key={`${name}:${occurrence}`}
label={getWindowLabel(section, t)}
label={getWindowLabel(section, buckets, t)}
usedPercent={bar.usedPercent}
unavailable={bar.unavailable}
loading={bar.loading}
@@ -0,0 +1,39 @@
import { describe, expect, it } from 'vitest'
import { parseAntigravityUsageEnvelope } from './antigravity-usage-response'
describe('parseAntigravityUsageEnvelope', () => {
it("strips agy's 'Limit Remaining' suffix from bucket names", () => {
const reading = parseAntigravityUsageEnvelope({
status: 'SUCCESS',
command: {
name: 'usage',
data: {
groups: [
{
name: 'Gemini Models',
buckets: [
{
id: 'gemini-weekly',
name: 'Weekly Limit Remaining',
window: 'weekly',
remaining_fraction: 0.58
},
{
id: 'gemini-5h',
name: 'Five Hour Limit Remaining',
window: '5h',
remaining_fraction: 1
}
]
}
]
}
}
})
expect(reading?.buckets.map((bucket) => bucket.name)).toEqual([
'Gemini Models · Weekly',
'Gemini Models · Five Hour'
])
})
})
@@ -2,6 +2,7 @@ import type {
RateLimitBucket,
RateLimitWindow
} from '../../../../shared/agent-usage/rate-limits/rate-limit-types'
import { stripPoolDirectionSuffix } from '../../../../shared/agent-usage/display/grouped-usage-pool'
import { deriveMostConstrainedWindow } from '../../rate-limit-bucket-summary'
/** Parse command.data from agy print envelopes (verified 1.2.11); response text rounds fractions and loses ids/disabled flags. */
@@ -61,10 +62,11 @@ function parseResetsAt(value: unknown): number | null {
/** Group names distinguish identical quota labels; append bucket names only for multiple windows. */
function formatBucketName(groupName: string, bucketName: string | null, siblings: number): string {
if (siblings <= 1 || !bucketName) {
const label = stripPoolDirectionSuffix(bucketName)
if (siblings <= 1 || !label) {
return groupName
}
return `${groupName} · ${bucketName}`
return `${groupName} · ${label}`
}
function parseBucket(
@@ -31,7 +31,8 @@ import { translate } from '@/i18n/i18n'
import { useTranslate, useIntlLocale, type Translate } from '@/i18n/use-translate'
import { getStatusBarUsageSections } from '../composition/status-bar-usage-sections'
import { GroupedPoolUsage } from './usage-grouped-pools'
import { formatStatusBarSectionLabel, isGroupedUsagePool } from './usage-pool-label'
import { formatStatusBarSectionLabel } from './usage-pool-label'
import { isGroupedUsagePool } from '../../../../../shared/agent-usage/display/grouped-usage-pool'
import { useResetCountdownClock } from '@/hooks/useResetCountdownClock'
import { useNow } from '@/hooks/use-now'
@@ -243,20 +243,18 @@ export function UsageRow({
) : null}
{showDetails ? (
<div className="flex flex-wrap items-center gap-x-2.5 gap-y-1 pl-[30px]">
{sections.map((section) => (
<DetailMetric
key={section.label}
section={section}
label={shortUsageLabel(p, section)}
display={display}
title={scopedUsageTitle(
p,
{ ...section, label: shortUsageLabel(p, section) },
display,
t
)}
/>
))}
{sections.map((section) => {
const label = shortUsageLabel(p, section, false, t)
return (
<DetailMetric
key={section.label}
section={section}
label={label}
display={display}
title={scopedUsageTitle(p, { ...section, label }, display, t)}
/>
)
})}
</div>
) : null}
</div>
@@ -0,0 +1,51 @@
import { describe, expect, it } from 'vitest'
import type {
ProviderRateLimits,
RateLimitBucket
} from '../../../../../shared/agent-usage/rate-limits/rate-limit-types'
import { getWindowSections } from './provider-usage-panel'
import { shortUsageLabel, usedSections } from './usage-headline-sections'
function pool(group: string, windowName: string, windowMinutes: number): RateLimitBucket {
return {
name: `${group} · ${windowName}`,
group,
windowName,
usedPercent: 0,
windowMinutes,
resetsAt: null,
resetDescription: null
}
}
describe('Antigravity pool labels', () => {
it('labels pools by group and window length instead of agy remaining-limit names', () => {
const p: ProviderRateLimits = {
provider: 'antigravity',
session: { usedPercent: 0, windowMinutes: 300, resetsAt: null, resetDescription: null },
weekly: { usedPercent: 0, windowMinutes: 10_080, resetsAt: null, resetDescription: null },
buckets: [
pool('Gemini Models', 'Weekly Limit Remaining', 10_080),
pool('Gemini Models', 'Five Hour Limit Remaining', 300),
pool('Claude and GPT models', 'Weekly Limit Remaining', 10_080),
pool('Claude and GPT models', 'Five Hour Limit Remaining', 300)
],
updatedAt: 1_000,
error: null,
status: 'ok'
}
expect(getWindowSections(p).map((s) => s.label)).toEqual([
'Gemini · Weekly',
'Gemini · 5h',
'Claude/GPT · Weekly',
'Claude/GPT · 5h'
])
expect(usedSections(p).map((s) => shortUsageLabel(p, s))).toEqual([
'Gemini wk',
'Gemini 5h',
'Claude/GPT wk',
'Claude/GPT 5h'
])
})
})
@@ -1,5 +1,6 @@
import type {
ProviderRateLimits,
RateLimitBucket,
RateLimitWindow
} from '../../../../../shared/agent-usage/rate-limits/rate-limit-types'
import { formatResetDuration } from '../../../../../shared/agent-usage/rate-limits/rate-limit-reset-format'
@@ -19,12 +20,14 @@ import {
getUsageWindowSections,
type UsageWindowSection
} from '../../../../../shared/agent-usage/display/usage-provider-windows'
import { isGroupedUsagePool } from '../../../../../shared/agent-usage/display/grouped-usage-pool'
import { getProviderUsageErrorMessage, getProviderUsageStatusLabel } from './usage-error-copy'
import type { UsagePercentageDisplay } from '../../../../../shared/agent-usage/display/usage-percentage-display'
import { useResetCountdownClock } from '@/hooks/useResetCountdownClock'
import { recomputeOn } from '@/lib/recompute-on'
import { ProviderExtraUsageSection } from './provider-extra-usage-section'
import { formatWindowLabel } from './rate-limit-window-localized-label'
import { formatPoolCardLabel } from './usage-pool-label'
import { formatResetsInCaption } from './usage-reset-caption'
import { UsageBar, UsageValue } from './usage-meter'
@@ -137,16 +140,23 @@ export function getWindowSections(
p: ProviderRateLimits,
t?: Translate
): { label: string; window: RateLimitWindow | null }[] {
const buckets = p.buckets ?? []
return getUsageWindowSections(p).map((section) => ({
label: getWindowSectionLabel(section, t),
label: getWindowSectionLabel(section, buckets, t),
window: section.window
}))
}
function getWindowSectionLabel(section: UsageWindowSection, t: Translate = translate): string {
function getWindowSectionLabel(
section: UsageWindowSection,
buckets: readonly RateLimitBucket[],
t: Translate = translate
): string {
switch (section.kind) {
case 'bucket':
return section.name
return isGroupedUsagePool(section.window)
? formatPoolCardLabel(section.window, buckets, t)
: section.name
case 'session':
// Why: name the window by its length ("5h") when known, matching the roster and status bar.
return section.window && section.window.windowMinutes > 0
@@ -3,9 +3,9 @@ import type { RateLimitBucket } from '../../../../../shared/agent-usage/rate-lim
import type { UsagePercentageDisplay } from '../../../../../shared/agent-usage/display/usage-percentage-display'
import {
formatPoolGroupLabel,
formatPoolWindowLabel,
type GroupedUsagePool
} from './usage-pool-label'
} from '../../../../../shared/agent-usage/display/grouped-usage-pool'
import { formatPoolWindowLabel } from './usage-pool-label'
import { formatBareUsagePercentage } from './usage-percentage-label'
import { useTranslate } from '../../../i18n/use-translate'
@@ -9,8 +9,10 @@ import type {
RateLimitWindow
} from '../../../../../shared/agent-usage/rate-limits/rate-limit-types'
import { clampUsedPercent } from '../../../../../shared/agent-usage/display/usage-percentage-display'
import { isGroupedUsagePool } from '../../../../../shared/agent-usage/display/grouped-usage-pool'
import { getWindowSections } from './provider-usage-panel'
import { USAGE_URGENT_PERCENT } from './usage-health-tone'
import { formatPoolRosterLabel } from './usage-pool-label'
export type UsageSection = { label: string; window: RateLimitWindow }
@@ -42,8 +44,12 @@ export function providerPrimaryMaxUsed(p: ProviderRateLimits, t?: Translate): nu
export function shortUsageLabel(
p: ProviderRateLimits,
section: UsageSection,
useRemainingDuration = false
useRemainingDuration = false,
t?: Translate
): string {
if (isGroupedUsagePool(section.window)) {
return formatPoolRosterLabel(section.window, p.buckets ?? [], t)
}
if (p.buckets?.some((b) => b.name === section.label)) {
return section.label
}
@@ -89,7 +95,7 @@ export function getTightestUsageSection(
? candidate
: current
)
return { ...tightest, label: shortUsageLabel(p, tightest, true) }
return { ...tightest, label: shortUsageLabel(p, tightest, true, t) }
}
export function getUsageHeadlineSection(
@@ -102,7 +108,7 @@ export function getUsageHeadlineSection(
(section) => section.label === CURSOR_MODELS_BUCKET_NAME
)
if (primary) {
return { ...primary, label: shortUsageLabel(p, primary, true) }
return { ...primary, label: shortUsageLabel(p, primary, true, t) }
}
}
return getTightestUsageSection(p, t, scope)
@@ -124,7 +130,7 @@ export function getTopScopedSection(
const top = scoped.reduce((a, b) =>
clampUsedPercent(b.window.usedPercent) > clampUsedPercent(a.window.usedPercent) ? b : a
)
return { ...top, label: shortUsageLabel(p, top) }
return { ...top, label: shortUsageLabel(p, top, false, t) }
}
/** The most-used scoped window once it is nearly spent, so the roster can flag it beside the headline. */
@@ -10,50 +10,42 @@ import type {
RateLimitWindow
} from '../../../../../shared/agent-usage/rate-limits/rate-limit-types'
import { clampUsedPercent } from '../../../../../shared/agent-usage/display/usage-percentage-display'
import {
formatPoolGroupLabel,
formatPoolLabel,
formatPoolWindowName,
isGroupedUsagePool,
type GroupedUsagePool
} from '../../../../../shared/agent-usage/display/grouped-usage-pool'
import { WEEKLY_WINDOW_MINUTES } from '../../../../../shared/agent-usage/display/usage-provider-windows'
import { USAGE_WARNING_PERCENT } from './usage-health-tone'
export type GroupedUsagePool = RateLimitBucket & { group: string }
const WEEKLY_WINDOW_MINUTES = 10_080
export function isGroupedUsagePool(window: RateLimitWindow): window is GroupedUsagePool {
return (
'name' in window &&
typeof window.name === 'string' &&
'group' in window &&
typeof window.group === 'string' &&
window.group.length > 0
function formatShortPoolWindowName(bucket: RateLimitBucket, t: Translate = translate): string {
return formatPoolWindowName(bucket, (minutes) =>
minutes === WEEKLY_WINDOW_MINUTES
? t('auto.components.status.bar.StatusBar.5c938d39ac', 'wk')
: formatWindowLabel(minutes)
)
}
function shortenGroup(group: string): string {
const short = group
.replace(/\s+models$/i, '')
.replace(/\s+and\s+/gi, '/')
.trim()
return short || group
export function formatPoolRosterLabel(
bucket: GroupedUsagePool,
buckets: readonly RateLimitBucket[],
t: Translate = translate
): string {
return `${formatPoolGroupLabel(bucket.group, buckets)} ${formatShortPoolWindowName(bucket, t)}`.trim()
}
export function formatPoolGroupLabel(group: string, buckets: readonly RateLimitBucket[]): string {
const short = shortenGroup(group)
const collides = buckets.some(
(other) =>
other.group &&
other.group !== group &&
(other.group === short || shortenGroup(other.group) === short)
export function formatPoolCardLabel(
bucket: GroupedUsagePool,
buckets: readonly RateLimitBucket[],
t: Translate = translate
): string {
return formatPoolLabel(bucket, buckets, (minutes) =>
minutes === WEEKLY_WINDOW_MINUTES
? t('auto.components.status.bar.tooltip.252c096536', 'Weekly')
: formatWindowLabel(minutes)
)
return collides ? group : short
}
function formatPoolWindowName(bucket: RateLimitBucket, t: Translate = translate): string {
// An unmapped agy window has no length; formatWindowLabel(0) would invent "0m".
if (!(bucket.windowMinutes > 0)) {
return (bucket.windowName ?? '').replace(/\s*limit remaining$/i, '').trim()
}
if (bucket.windowMinutes === WEEKLY_WINDOW_MINUTES) {
return t('auto.components.status.bar.StatusBar.5c938d39ac', 'wk')
}
return formatWindowLabel(bucket.windowMinutes)
}
export function formatPoolWindowLabel(
@@ -61,7 +53,7 @@ export function formatPoolWindowLabel(
now?: number,
t?: Translate
): string {
const label = formatPoolWindowName(bucket, t)
const label = formatShortPoolWindowName(bucket, t)
// Show the reset once the pool turns yellow, by consumption whatever the % display.
if (clampUsedPercent(bucket.usedPercent) >= USAGE_WARNING_PERCENT && bucket.resetsAt != null) {
const countdown = formatRateLimitWindowChipLabel(bucket, now)
@@ -0,0 +1,61 @@
import type { RateLimitBucket, RateLimitWindow } from '../rate-limits/rate-limit-types'
export type GroupedUsagePool = RateLimitBucket & { group: string }
export function isGroupedUsagePool(window: RateLimitWindow): window is GroupedUsagePool {
return (
'name' in window &&
typeof window.name === 'string' &&
'group' in window &&
typeof window.group === 'string' &&
window.group.length > 0
)
}
function shortenGroup(group: string): string {
const short = group
.replace(/\s+models$/i, '')
.replace(/\s+and\s+/gi, '/')
.trim()
return short || group
}
// Structural so mobile's passthrough buckets, whose group is unknown, fit too; `name` keeps it from being a weak type.
export type UsagePoolSibling = { name: string; group?: unknown }
export function formatPoolGroupLabel(group: string, buckets: readonly UsagePoolSibling[]): string {
const short = shortenGroup(group)
const collides = buckets.some(
(other) =>
typeof other.group === 'string' &&
other.group.length > 0 &&
other.group !== group &&
(other.group === short || shortenGroup(other.group) === short)
)
return collides ? group : short
}
// agy names windows "… Limit Remaining", which contradicts percentages shown as used.
export function stripPoolDirectionSuffix(windowName: string | null | undefined): string {
return (windowName ?? '').replace(/\s*limit remaining$/i, '').trim()
}
export function formatPoolWindowName(
pool: RateLimitBucket,
formatMinutes: (minutes: number) => string
): string {
// An unmapped agy window has no length; formatting 0 minutes would invent "0m".
return pool.windowMinutes > 0
? formatMinutes(pool.windowMinutes)
: stripPoolDirectionSuffix(pool.windowName)
}
export function formatPoolLabel(
pool: GroupedUsagePool,
buckets: readonly UsagePoolSibling[],
formatMinutes: (minutes: number) => string
): string {
const group = formatPoolGroupLabel(pool.group, buckets)
const windowName = formatPoolWindowName(pool, formatMinutes)
return windowName ? `${group} · ${windowName}` : group
}
@@ -0,0 +1,56 @@
import { describe, expect, it } from 'vitest'
import type { RateLimitWindow } from '../rate-limits/rate-limit-types'
import { getUsageWindowSections } from './usage-provider-windows'
function window(usedPercent: number, windowMinutes: number): RateLimitWindow {
return { usedPercent, windowMinutes, resetsAt: null, resetDescription: null }
}
function sectionNames(sections: ReturnType<typeof getUsageWindowSections>): string[] {
return sections.map((s) => (s.kind === 'bucket' ? s.name : s.kind))
}
describe('getUsageWindowSections', () => {
it('omits the weekly rollup when buckets already report weekly windows', () => {
const sections = getUsageWindowSections({
provider: 'antigravity',
session: window(5, 300),
weekly: window(42, 10_080),
buckets: [
{ ...window(42, 10_080), name: 'Gemini Models · Weekly' },
{ ...window(5, 300), name: 'Gemini Models · Five Hour' }
]
})
expect(sectionNames(sections)).toEqual(['Gemini Models · Weekly', 'Gemini Models · Five Hour'])
})
it('keeps the weekly placeholder when weekly buckets have no rollup', () => {
const sections = getUsageWindowSections({
provider: 'cursor',
session: null,
weekly: null,
buckets: [{ ...window(30, 10_080), name: 'Seat' }]
})
expect(sectionNames(sections)).toEqual(['Seat', 'weekly'])
})
it('keeps the weekly rollup when no weekly bucket repeats it', () => {
const sections = getUsageWindowSections({
provider: 'antigravity',
session: window(5, 300),
weekly: window(42, 10_080),
buckets: [
{ ...window(30, 10_080), name: 'Gemini Models · Weekly' },
{ ...window(5, 300), name: 'Gemini Models · Five Hour' }
]
})
expect(sectionNames(sections)).toEqual([
'Gemini Models · Weekly',
'Gemini Models · Five Hour',
'weekly'
])
})
})
@@ -1,5 +1,7 @@
import type { ProviderRateLimits, RateLimitWindow } from '../rate-limits/rate-limit-types'
export const WEEKLY_WINDOW_MINUTES = 10_080
// Structural so mobile's decoded snapshot, whose provider id is any string, fits too.
type ProviderUsageWindows = {
provider: string
@@ -52,6 +54,16 @@ export function hasUsageData(provider: ProviderUsageWindows): boolean {
/** The usage windows a provider shows, in order; session and weekly stay as null placeholders. */
export function getUsageWindowSections(p: ProviderUsageWindows): UsageWindowSection[] {
if (p.buckets?.length) {
// Drop the rollup only when it repeats a listed weekly pool, as Antigravity's most-used one does.
const { weekly } = p
const weeklyDuplicatesBucket =
weekly !== null &&
p.buckets.some(
(bucket) =>
bucket.windowMinutes === WEEKLY_WINDOW_MINUTES &&
bucket.usedPercent === weekly.usedPercent &&
bucket.resetsAt === weekly.resetsAt
)
return [
...p.buckets.map((bucket) => ({
kind: 'bucket' as const,
@@ -67,7 +79,7 @@ export function getUsageWindowSections(p: ProviderUsageWindows): UsageWindowSect
}
]
: []),
{ kind: 'weekly', window: p.weekly }
...(weeklyDuplicatesBucket ? [] : [{ kind: 'weekly' as const, window: p.weekly }])
]
}
const sections: UsageWindowSection[] = [