feat(usage): pool subscription limits per provider across accounts and environments #10300
Mergedjuliusmarmingemerged 8 commits into
main fromrefs/pull/10300/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/web/src/components/usage/UsagePage.tsx line 105Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -95,7 +96,10 @@9596 useState<ReadonlySet<EnvironmentId> | null>(null);9697 const { days: windowDays, window } = windowSelection;9798 const isPast24Hours = windowDays === 1;98- const { merged, environments, selectedEnvironments, isPending, isPartial, refresh } = useUsage(99- window,100- selectedEnvironmentIds,101- );99+ const usage = useUsage(window, selectedEnvironmentIds);100+ // Dev only: `/usage?limitsFixture=<name>` lists synthetic environments in the101+ // picker and feeds the Limits view from them, so merge rules can be eyeballed.102+ const [fixture] = useState(() => {103+ if (!import.meta.env.DEV) return null;104+ const name = new URLSearchParams(globalThis.location.search).get("limitsFixture");105+ return name ? makeLimitsFixture(name, Date.now()) : null;
- @@ -149,0 +374,21 @@374+ for (const account of accounts) {375+ for (const window of account.limits.windows) {376+ const key = `${window.kind}:${window.id}`;377+ const list = byKey.get(key);378+ if (list) list.push({ account, window });379+ else byKey.set(key, [{ account, window }]);380+ }381+ }382+ const pools = [...byKey.values()].map((unordered): LimitPoolWindow => {383+ const members = unordered.toSorted(384+ (left, right) =>385+ (resetMillis(left.window) ?? Number.POSITIVE_INFINITY) -386+ (resetMillis(right.window) ?? Number.POSITIVE_INFINITY),387+ );388+ const first = members[0]!.window;389+ const usedPercent = members.reduce((sum, m) => sum + m.window.usedPercent, 0) / members.length;390+ const elapsed = members391+ .map((m) => elapsedShare(m.window, now))392+ .filter((share): share is number => share !== null);393+ const meanElapsed =394+ elapsed.length > 0 ? elapsed.reduce((sum, share) => sum + share, 0) / elapsed.length : null;docs/user/usage.md lines 44 to 45OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -39,6 +39,7 @@39394040 ## Track subscription limits414142-**Usage → Limits** shows how much quota is left in each window and when it resets, for Codex and43-Claude subscriptions. For windows with timing data, each bar also marks how much of the window is44-left, so you can judge your pace before the next reset.42+**Usage → Limits** pools every subscription account it can see per provider, so with several Codex43+or Claude accounts across your environments and hubs you read one number per window rather than a44+list. Each window card shows how much of the pool is left, when the next reset lands and how much it45+hands back, and a bar with one segment per account, ordered by which resets soonest. The hatched
- @@ -0,0 +87,21 @@87+ return account.email ? <AccountChip email={account.email} /> : null;88+}89+90+/**91+ * Who an account is, without printing the email: the instance name when there92+ * is one, else a two-letter chip. The address itself is revealed on demand in93+ * the segment's popover.94+ */95+function AccountName({96+ account,97+ className,98+}: {99+ readonly account: LimitAccount;100+ readonly className?: string;101+}) {102+ if (account.displayName) return <span className={className}>{account.displayName}</span>;103+ if (account.email) {104+ return (105+ <span className={cn("inline-flex min-w-0 items-center", className)}>106+ <AccountChip email={account.email} />107+ </span>
- apps/web/src/components/usage/UsageLimitsPooled.tsx line 398Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +308,21 @@308+ </Popover>309+ );310+}311+312+/** Split out so the redeem hook only runs for accounts that can redeem. */313+function RedeemableSegmentPopup({314+ account,315+ window,316+ reset,317+ now,318+ redeemAt,319+ closePopover,320+}: {321+ readonly account: LimitAccount;322+ readonly window: LimitPoolMember["window"];323+ readonly reset: LimitPoolWindow["resets"][number] | undefined;324+ readonly now: number;325+ readonly redeemAt: NonNullable<LimitAccount["redeem"]>;326+ readonly closePopover: () => void;327+}) {328+ const redeem = useResetCredit(redeemAt.environmentId, redeemAt.instanceId);packages/shared/src/usageLimits.ts line 239OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -149,0 +219,21 @@219+ for (const provider of providersWithLimits(presentation.serverConfig?.providers ?? [])) {220+ if (!provider.usageLimits || limitsNotice(provider.usageLimits) !== null) continue;221+ merge(222+ accountKey(provider.driver, provider.auth.email) ??223+ `${environmentId}:${provider.instanceId}`,224+ {225+ key: `${environmentId}:${provider.instanceId}`,226+ driver: provider.driver,227+ displayName: provider.displayName?.trim() || null,228+ email: provider.auth.email,229+ plan: provider.auth.label,230+ accentColor: provider.accentColor,231+ environments: [{ environmentId, label }],232+ sourceLabel: null,233+ redeem: { environmentId, instanceId: provider.instanceId },234+ limits: provider.usageLimits,235+ },236+ );237+ }238+ }239+ for (const source of collectLimitSources(presentations)) {
github-actions[bot](GitHub profile, opens in a new tab) added labels📱 Native Change
- apps/web/src/components/usage/UsageLimitsPooled.tsx line 240Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +220,21 @@220+ account,221+ window,222+ reset,223+ color,224+ now,225+ index,226+}: {227+ readonly account: LimitAccount;228+ readonly window: LimitPoolMember["window"];229+ readonly reset: LimitPoolWindow["resets"][number] | undefined;230+ readonly color: string;231+ readonly now: number;232+ /** 1-based position in the bar, shown on the strip and its legend row to tie them together. */233+ readonly index: number;234+}) {235+ const [open, setOpen] = useState(false);236+ const remaining = remainingPercent(window);237+ const resetsIn = formatResetsIn(window, now);238+ const credits = account.redeem ? (account.limits.resetCredits?.availableCount ?? 0) : 0;239+ return (240+ <Popover open={open} onOpenChange={setOpen}>
juliusmarminge merged thisb273d1c
juliusmarminge closed this
Sign in to join this conversation.









Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
0c200c5· PR result:83eaf1b· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.