Skip to content

Commit 58a911b

Browse files
committed
fix(web): limit independent usage rows to Codex
1 parent 4d279e0 commit 58a911b

2 files changed

Lines changed: 83 additions & 44 deletions

File tree

‎apps/web/src/components/usage/UsageLimitsPooled.tsx‎

Lines changed: 75 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function Row({ label, children }: { readonly label: string; readonly children: R
132132

133133
/**
134134
* Everything about one account in one window: plan, where it is signed in,
135-
* the email on request, reset time and quota it restores, and the
135+
* the email on request, reset time and share of the pool it restores, and the
136136
* reset-credit action. Opens on hover for a glance, on click to act.
137137
*/
138138
function SegmentPopover({
@@ -194,7 +194,9 @@ function SegmentPopover({
194194
</Row>
195195
) : null}
196196
{reset && reset.restoresPercent > 0 ? (
197-
<Row label="Restores">+{reset.restoresPercent}%</Row>
197+
<Row label="Restores">
198+
+{reset.restoresPercent}% {account.driver === "codex" ? "of quota" : "of pool"}
199+
</Row>
198200
) : null}
199201
</div>
200202
{credits && redeem ? (
@@ -236,7 +238,7 @@ function PoolSegment({
236238
readonly reset: LimitPoolWindow["resets"][number] | undefined;
237239
readonly color: string;
238240
readonly now: number;
239-
/** 1-based grid position of the bar and its legend row. */
241+
/** 1-based position in the bar, shown on the strip and its legend row to tie them together. */
240242
readonly index: number;
241243
readonly showAccountName: boolean;
242244
}) {
@@ -274,6 +276,14 @@ function PoolSegment({
274276
}}
275277
/>
276278
) : null}
279+
{account.driver !== "codex" ? (
280+
<span
281+
aria-hidden
282+
className="absolute inset-0 flex items-center justify-center text-3xs leading-none font-semibold text-foreground/80 tabular-nums @2xl/pool:hidden"
283+
>
284+
{index}
285+
</span>
286+
) : null}
277287
<div className="relative hidden h-full min-w-0 items-center gap-1.5 px-2 text-xs @2xl/pool:flex">
278288
{showAccountName ? (
279289
<AccountName
@@ -301,7 +311,7 @@ function PoolSegment({
301311
</span>
302312
</div>
303313
</PopoverTrigger>
304-
<LegendRow account={account} window={window} now={now} index={index} />
314+
<LegendRow account={account} window={window} color={color} now={now} index={index} />
305315
{account.redeem ? (
306316
<RedeemableSegmentPopup
307317
account={account}
@@ -335,11 +345,13 @@ function PoolSegment({
335345
function LegendRow({
336346
account,
337347
window,
348+
color,
338349
now,
339350
index,
340351
}: {
341352
readonly account: LimitAccount;
342353
readonly window: LimitPoolMember["window"];
354+
readonly color: string;
343355
readonly now: number;
344356
readonly index: number;
345357
}) {
@@ -352,6 +364,17 @@ function LegendRow({
352364
render={<Button variant="ghost" size="compact" />}
353365
className="min-w-0 @2xl/pool:hidden"
354366
>
367+
{account.driver !== "codex" ? (
368+
<span className="relative inline-flex size-4 shrink-0 items-center justify-center rounded-sm text-3xs leading-none font-semibold text-foreground/80 tabular-nums">
369+
<span
370+
aria-hidden
371+
className="absolute inset-0 rounded-sm opacity-35"
372+
style={{ backgroundColor: color }}
373+
/>
374+
<span className="sr-only">Segment </span>
375+
<span className="relative">{index}</span>
376+
</span>
377+
) : null}
355378
<AccountName account={account} className="min-w-0 truncate font-medium text-foreground" />
356379
<span className="shrink-0 font-semibold text-foreground tabular-nums">{remaining}%</span>
357380
<span className="ms-auto flex shrink-0 items-center gap-1.5 text-2xs text-muted-foreground tabular-nums">
@@ -425,8 +448,13 @@ function RedeemableSegmentPopup({
425448
}
426449

427450
/**
428-
* An account's remaining quota and reset details. Wide, the bar carries the
429-
* details; narrow, a legend below has room for them. Both open the same popover.
451+
* One pooled window as equal-width segments, one per account, each filled by
452+
* the share of that account's quota still open. Equal widths are honest: every
453+
* account contributes the same share of the pool, whatever its plan.
454+
*
455+
* Wide, each segment carries its own label. Narrow, the bar is a bare strip
456+
* and a legend below lists the accounts in the same order; both open the
457+
* same popover.
430458
*/
431459
function PoolBar({
432460
pool,
@@ -463,7 +491,10 @@ function PoolBar({
463491
);
464492
}
465493

466-
/** One account's percentage, quota bar, reset time, and reset-credit action. */
494+
/**
495+
* Big pooled number and the segment bar. Accounts keep the same column across
496+
* windows; each segment's popover shows its own reset time and share restored.
497+
*/
467498
function PoolWindowCard({
468499
pool,
469500
color,
@@ -477,6 +508,8 @@ function PoolWindowCard({
477508
readonly label?: ReactNode;
478509
readonly description?: string | undefined;
479510
}) {
511+
// The soonest reset that hands anything back; an untouched account resets to no effect.
512+
const nextRefill = pool.resets.find((reset) => reset.restoresPercent > 0);
480513
return (
481514
<div className="grid items-center gap-x-6 gap-y-3 rounded-lg border border-border/60 p-4 md:grid-cols-[11rem_minmax(0,1fr)]">
482515
<div className="flex flex-col gap-1">
@@ -490,6 +523,11 @@ function PoolWindowCard({
490523
<span className="text-sm text-muted-foreground">left</span>
491524
{pool.pace ? <PaceIcon pace={pool.pace} /> : null}
492525
</span>
526+
{nextRefill && pool.columns.length > 1 ? (
527+
<span className="text-xs font-medium text-foreground tabular-nums">
528+
↻ +{nextRefill.restoresPercent}%
529+
</span>
530+
) : null}
493531
</div>
494532
<PoolBar pool={pool} color={color} now={now} />
495533
{description ? (
@@ -502,6 +540,11 @@ function PoolWindowCard({
502540
function PoolSection({ pool, now }: { readonly pool: LimitPool; readonly now: number }) {
503541
const color = barColor(pool.driver);
504542
const label = getDriverOption(pool.driver)?.label ?? String(pool.driver);
543+
// Codex workspaces can share an email but have independent subscription quotas.
544+
const separateAccounts = pool.driver === "codex" && pool.accounts.length > 1;
545+
const windows = separateAccounts
546+
? pool.accounts.flatMap((account) => displayLimitWindows(collectLimitPools([account], now)[0]!))
547+
: displayLimitWindows(pool);
505548
return (
506549
<section className="flex flex-col gap-3">
507550
<h2 className="flex items-center gap-2 text-sm font-medium text-foreground">
@@ -514,43 +557,37 @@ function PoolSection({ pool, now }: { readonly pool: LimitPool; readonly now: nu
514557
/>
515558
{label}
516559
</h2>
517-
{pool.accounts.flatMap((account) => {
518-
// Each account has an independent allowance; averaging percentages across
519-
// subscriptions hides which account can actually run the next request.
520-
const accountPool = collectLimitPools([account], now)[0]!;
521-
return displayLimitWindows(accountPool).map((window) => {
522-
const details =
523-
pool.driver === "cursor" ? cursorUsageWindowDetails(window.id) : undefined;
524-
return (
525-
<PoolWindowCard
526-
key={`${account.key}:${window.kind}:${window.id}`}
527-
pool={window}
528-
color={color}
529-
now={now}
530-
label={
531-
pool.accounts.length > 1 ? (
532-
<>
533-
<AccountName account={account} className="min-w-0 truncate" />
534-
<span className="shrink-0 text-muted-foreground">
535-
· {details?.label ?? window.label}
536-
</span>
537-
</>
538-
) : (
539-
details?.label
540-
)
541-
}
542-
description={details?.description}
543-
/>
544-
);
545-
});
560+
{windows.map((window) => {
561+
const details = pool.driver === "cursor" ? cursorUsageWindowDetails(window.id) : undefined;
562+
const account = separateAccounts ? window.members[0]!.account : undefined;
563+
return (
564+
<PoolWindowCard
565+
key={`${account?.key ?? ""}:${window.kind}:${window.id}`}
566+
pool={window}
567+
color={color}
568+
now={now}
569+
label={
570+
account ? (
571+
<>
572+
<AccountName account={account} className="min-w-0 truncate" />
573+
<span className="shrink-0 text-muted-foreground">· {window.label}</span>
574+
</>
575+
) : (
576+
details?.label
577+
)
578+
}
579+
description={details?.description}
580+
/>
581+
);
546582
})}
547583
</section>
548584
);
549585
}
550586

551587
/**
552-
* Accounts grouped by provider, with separate rows for each account's windows.
553-
* Instances of the same account still share one row across environments.
588+
* Accounts pooled per provider: what is open across all of them, who resets
589+
* next, and how much of the pool that hands back. Answers "can I keep going"
590+
* before "on which account".
554591
*/
555592
export function UsageLimitsPooled({
556593
presentations,

‎apps/web/src/components/usage/UsagePage.refresh.test.tsx‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ it.each([0, 1])(
180180
},
181181
);
182182

183-
it("shows independent account percentages instead of averaging their quotas", async () => {
183+
it.each(["codex", "claudeAgent", "cursor"])("shows account quotas for %s", async (driver) => {
184184
const [id, presentation] = [...state.presentations][0]!;
185185
const provider = presentation.serverConfig.providers[0];
186186
state.presentations = new Map([
@@ -191,11 +191,12 @@ it("shows independent account percentages instead of averaging their quotas", as
191191
serverConfig: {
192192
...presentation.serverConfig,
193193
providers: [
194-
["personal", "Personal", 33],
195-
["business", "Corebio", 9],
196-
].map(([accountId, displayName, usedPercent]) => ({
194+
{ accountId: "personal", displayName: "Personal", usedPercent: 33 },
195+
{ accountId: "business", displayName: "Corebio", usedPercent: 9 },
196+
].map(({ accountId, displayName, usedPercent }) => ({
197197
...provider,
198-
instanceId: ProviderInstanceId.make(String(accountId)),
198+
driver,
199+
instanceId: ProviderInstanceId.make(accountId),
199200
displayName,
200201
auth: { status: "authenticated", email: "[email protected]" },
201202
usageLimits: {
@@ -222,7 +223,8 @@ it("shows independent account percentages instead of averaging their quotas", as
222223
expect(text).toContain("Corebio");
223224
expect(text).toContain("67%");
224225
expect(text).toContain("91%");
225-
expect(text).not.toContain("79%");
226+
if (driver === "codex") expect(text).not.toContain("79%");
227+
else expect(text).toContain("79%");
226228
});
227229

228230
it("uses the current time when returning to limits from tokens", async () => {

0 commit comments

Comments
 (0)