π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(quota): drop quota limits a plan no longer reports (#22000)
AmAzing-3eb4bc6c85a1
diff --git a/apps/server/src/services/agentQuota/__tests__/index.test.ts b/apps/server/src/services/agentQuota/__tests__/index.test.tsindex 1f8051ed6c8..3214140b997 100644--- a/apps/server/src/services/agentQuota/__tests__/index.test.ts+++ b/apps/server/src/services/agentQuota/__tests__/index.test.ts@@ -353,6 +353,34 @@ describe('AgentQuotaService.listLatestReadings', () => {expect(load.rateLimitedUntil).toBeNull();expect(load.weeklyUtil).toBe(21);});++ it('forgets the 5-hour limit once the plan stops reporting it (Max upgraded to Ultra)', async () => {+ // The Max-era sample carried a session window; every Ultra sample after+ // its reset carries none. Its row stays the newest in the session bucket.+ await service.ingestSnapshot({+ identity,+ provider: 'claude-code',+ readings: [+ { ...weeklyReading, capturedAt: now - 8 * HOUR },+ {+ capturedAt: now - 8 * HOUR,+ limitType: 'session',+ resetsAt: now - 6 * HOUR,+ scopeKey: '',+ utilization: 40,+ },+ ],+ });+ const account = await service.ingestSnapshot({+ identity: { ...identity, planTier: 'ultra' },+ provider: 'claude-code',+ readings: [weeklyReading],+ });++ const latest = await service.listLatestReadings(account.id);++ expect(latest.map((r) => r.limitType)).toEqual(['weekly_all']);+ });});describe('AgentQuotaService.recordUsage', () => {diff --git a/apps/server/src/services/agentQuota/index.ts b/apps/server/src/services/agentQuota/index.tsindex ae3cb60b069..896fc0ff00c 100644--- a/apps/server/src/services/agentQuota/index.ts+++ b/apps/server/src/services/agentQuota/index.ts@@ -5,6 +5,7 @@ import {type ClaudeCodeRoutedAccount,computeTurnCostUsd,currentUtilization,+ dropRetiredLimits,isScopedWeeklyLimit,isSessionLimit,isWeeklyAllLimit,@@ -359,21 +360,25 @@ export class AgentQuotaService {* The newest reading per limit bucket, as plain numbers. This is the display* read model: unlike `agent_quota_windows` it also carries limits the* provider reports without a `resets_at` (an untouched model-scoped weekly),- * which have no window to be projected into.+ * which have no window to be projected into. A limit the plan has since+ * dropped (a Max account upgraded to Ultra loses its 5-hour window) is left+ * out, so neither the cards nor the load balancer keep reading it.*/listLatestReadings = async (accountId: string): Promise<QuotaLimitReading[]> => {const rows = await this.snapshots.latestPerBucket(accountId);- return rows.map((row) => ({- ...readQuotaWindowMetadata(row.raw),- capturedAt: row.capturedAt.getTime(),- isActive: row.isActive ?? undefined,- limitType: row.limitType,- resetsAt: row.resetsAt?.getTime() ?? null,- scopeKey: row.scopeKey,- severity: row.severity ?? undefined,- utilization: row.utilization,- }));+ return dropRetiredLimits(+ rows.map((row) => ({+ ...readQuotaWindowMetadata(row.raw),+ capturedAt: row.capturedAt.getTime(),+ isActive: row.isActive ?? undefined,+ limitType: row.limitType,+ resetsAt: row.resetsAt?.getTime() ?? null,+ scopeKey: row.scopeKey,+ severity: row.severity ?? undefined,+ utilization: row.utilization,+ })),+ );};/**diff --git a/packages/heterogeneous-agents/src/quota/quota.test.ts b/packages/heterogeneous-agents/src/quota/quota.test.tsindex ddd7cfb90ba..937e3f825e0 100644--- a/packages/heterogeneous-agents/src/quota/quota.test.ts+++ b/packages/heterogeneous-agents/src/quota/quota.test.ts@@ -8,7 +8,7 @@ import {} from './calibration';import { computeTurnCostUsd, totalTokens } from './cost';import { selectAccount } from './loadBalancer';-import { buildClaudeQuotaWindows } from './readings';+import { buildClaudeQuotaWindows, dropRetiredLimits } from './readings';import type { QuotaLimitReading } from './types';import { CLAUDE_SESSION_WINDOW_SECONDS, windowSecondsForKind } from './types';import { findWindowAt, isWindowContaminated, projectWindows } from './windows';@@ -321,6 +321,61 @@ describe('buildClaudeQuotaWindows', () => {weekly: null,});});++ it('drops a session window the plan no longer reports (Max upgraded to Ultra)', () => {+ // Ultra has no 5-hour limit. The last Max-era session reading stays the+ // newest one in its bucket, and once its window ended it would render as+ // a refilled 5-hour meter on a plan that has none.+ const windows = buildClaudeQuotaWindows(+ [+ reading({ capturedAt: now - 8 * 3_600_000, resetsAt: now - 6 * 3_600_000 }),+ reading({ limitType: 'weekly_all', resetsAt: now + 3_600_000, utilization: 12 }),+ ],+ now,+ );++ expect(windows.session).toBeNull();+ expect(windows.weekly).toMatchObject({ usedPercent: 12 });+ });+});++describe('dropRetiredLimits', () => {+ const sampledAt = Date.parse('2026-07-12T18:00:00Z');+ const reading = (over: Partial<QuotaLimitReading> = {}): QuotaLimitReading => ({+ capturedAt: sampledAt,+ limitType: 'weekly_all',+ resetsAt: sampledAt + 3_600_000,+ scopeKey: '',+ utilization: 30,+ ...over,+ });++ it('keeps every limit of the newest sample, an idle rolled-over window included', () => {+ const idleSession = reading({ limitType: 'session', resetsAt: sampledAt - 3_600_000 });+ const readings = [idleSession, reading()];++ expect(dropRetiredLimits(readings)).toEqual(readings);+ });++ it('keeps an older limit whose window was still live at the newest sample', () => {+ const session = reading({+ capturedAt: sampledAt - 3_600_000,+ limitType: 'session',+ resetsAt: sampledAt + 3_600_000,+ });++ expect(dropRetiredLimits([session, reading()])).toContain(session);+ });++ it('drops an older limit whose window had ended before the newest sample', () => {+ const retired = reading({+ capturedAt: sampledAt - 6 * 3_600_000,+ limitType: 'session',+ resetsAt: sampledAt - 3_600_000,+ });++ expect(dropRetiredLimits([retired, reading()])).toEqual([reading()]);+ });});// ββ load balancer βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββdiff --git a/packages/heterogeneous-agents/src/quota/readings.ts b/packages/heterogeneous-agents/src/quota/readings.tsindex d87b0f3b709..864d5633ad8 100644--- a/packages/heterogeneous-agents/src/quota/readings.ts+++ b/packages/heterogeneous-agents/src/quota/readings.ts@@ -46,6 +46,23 @@ export const hasWindowRolledOver = (reading: QuotaDisplayReading, now: number):export const currentUtilization = (reading: QuotaDisplayReading, now: number): number =>hasWindowRolledOver(reading, now) ? 0 : clampPercent(reading.utilization);+/**+ * Drop the limits the provider has stopped reporting. A sample reports every+ * limit the plan has β an idle window too, against a reset already in the past+ * β so a limit missing from a sample taken after its window ended is one the+ * plan no longer has: Claude Ultra has no 5-hour limit, and an account upgraded+ * from Max keeps a last session reading that would otherwise render as a+ * refilled window forever. A limit missing while its window is still live may+ * just have landed in another batch, so it stays.+ */+export const dropRetiredLimits = <T extends QuotaDisplayReading>(readings: T[]): T[] => {+ const newestSampleAt = readings.reduce((newest, r) => Math.max(newest, r.capturedAt), 0);++ return readings.filter(+ (r) => r.capturedAt >= newestSampleAt || !hasWindowRolledOver(r, newestSampleAt),+ );+};+/*** A reading as a display window. A rolled-over window is reported as refilled* (0% used, no countdown) rather than dropped: hiding the row reads as "this@@ -104,9 +121,10 @@ export const buildClaudeQuotaWindows = (readings: QuotaDisplayReading[],now: number,): ClaudeQuotaWindows => {- const session = newestMatch(readings, isSessionLimit);- const weekly = newestMatch(readings, isWeeklyAllLimit);- const scoped = newestMatch(readings, isScopedWeeklyLimit);+ const reported = dropRetiredLimits(readings);+ const session = newestMatch(reported, isSessionLimit);+ const weekly = newestMatch(reported, isWeeklyAllLimit);+ const scoped = newestMatch(reported, isScopedWeeklyLimit);return {scopedWeekly: scopeddiff --git a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.test.ts b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.test.tsindex a1fb31a8a29..64206a0e789 100644--- a/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.test.ts+++ b/src/features/ChatInput/ControlBar/HeteroControlBar/QuotaMenu/quotaViewModel.test.ts@@ -170,6 +170,31 @@ describe('buildClaudePanelSnapshot β folding in a live sample', () => {expect(snap.weekly).toMatchObject({ usedPercent: 9 }); // live 07:00 beats persisted 06:00});+ it('drops a persisted session the live sample no longer reports (Max upgraded to Ultra)', () => {+ // Persisted while the account was on Max; that window ended hours before+ // the live Ultra sample, which reports no 5-hour limit at all.+ const afterSessionReset = sessionReset + 60 * 60_000;+ const ultraLive: ClaudeCodeQuotaSnapshot = {+ ...live,+ readings: [+ liveReading({+ capturedAt: afterSessionReset,+ limitType: 'weekly_all',+ resetsAt: reset,+ utilization: 9,+ }),+ ],+ scopedWeekly: null,+ session: null,+ updatedAt: afterSessionReset,+ };++ const snap = buildClaudePanelSnapshot(account, readings, ultraLive, afterSessionReset);++ expect(snap.session).toBeNull();+ expect(snap.weekly).toMatchObject({ usedPercent: 9 });+ });+it('fills a limit the account has no reading for from the sample', () => {const snap = buildClaudePanelSnapshot(account, [readings[1]], live, now);diff --git a/src/features/SubscriptionAccounts/AccountRow.tsx b/src/features/SubscriptionAccounts/AccountRow.tsxindex d27b65f3dc5..abfa88a6621 100644--- a/src/features/SubscriptionAccounts/AccountRow.tsx+++ b/src/features/SubscriptionAccounts/AccountRow.tsx@@ -24,7 +24,12 @@ import { usageTextColor } from '@/features/DeviceManager/DeviceHealth/shared';import { UsageBar } from '@/features/DeviceManager/DeviceHealth/UsageMeter';import { type QuotaAccount, useAgentQuotaStore } from '@/store/agentQuota';-import { type AccountStatus, deriveAccountView, type SubscriptionProvider } from './accountView';+import {+ type AccountStatus,+ deriveAccountView,+ meterWindows,+ type SubscriptionProvider,+} from './accountView';/** Column widths shared by {@link AccountRow} and {@link AccountListHeader}. */export const COLUMN_WIDTH = {@@ -325,14 +330,17 @@ const AccountRow = ({ account, active, onOpen }: AccountRowProps) => {{/* Both windows stacked in one column, so the pair reads as one quota. */}<Flexbox gap={6} style={{ flex: 'none', width: COLUMN_WIDTH.quota }}>- <WindowMeter- label={t('subscriptionAccounts.meter.session')}- value={view.session?.usedPercent}- />- <WindowMeter- label={t('subscriptionAccounts.meter.weekly')}- value={view.weekly?.usedPercent}- />+ {meterWindows(view).map((key) => (+ <WindowMeter+ key={key}+ value={view[key]?.usedPercent}+ label={+ key === 'session'+ ? t('subscriptionAccounts.meter.session')+ : t('subscriptionAccounts.meter.weekly')+ }+ />+ ))}</Flexbox><Flexboxdiff --git a/src/features/SubscriptionAccounts/accountView.test.ts b/src/features/SubscriptionAccounts/accountView.test.tsindex 884b7304999..1ce5c1b316d 100644--- a/src/features/SubscriptionAccounts/accountView.test.ts+++ b/src/features/SubscriptionAccounts/accountView.test.ts@@ -1,6 +1,6 @@import { describe, expect, it } from 'vitest';-import { deriveAccountView, matchesKeyword, sortAccounts } from './accountView';+import { deriveAccountView, matchesKeyword, meterWindows, sortAccounts } from './accountView';const NOW = Date.UTC(2026, 9, 24, 12);const HOUR = 60 * 60 * 1000;@@ -73,6 +73,22 @@ describe('deriveAccountView', () => {});});+describe('meterWindows', () => {+ const window = { resetsAt: null, usedPercent: 0 };++ it('keeps both placeholders before any reading', () => {+ expect(meterWindows({})).toEqual(['session', 'weekly']);+ });++ it('draws no 5-hour meter for a plan without that limit (Claude Ultra)', () => {+ expect(meterWindows({ weekly: window })).toEqual(['weekly']);+ });++ it('draws both meters when the plan reports both', () => {+ expect(meterWindows({ session: window, weekly: window })).toEqual(['session', 'weekly']);+ });+});+describe('sortAccounts', () => {it('lists accounts in rotation first, then by provider and name', () => {const sorted = sortAccounts([diff --git a/src/features/SubscriptionAccounts/accountView.ts b/src/features/SubscriptionAccounts/accountView.tsindex 3a8b2d7e490..4a382f07700 100644--- a/src/features/SubscriptionAccounts/accountView.ts+++ b/src/features/SubscriptionAccounts/accountView.ts@@ -91,6 +91,18 @@ export const deriveAccountView = (return { ...base, status: 'available' };};+export type AccountWindowKey = 'session' | 'weekly';++/**+ * The windows the card draws a meter for. Before any reading both stay as+ * placeholders; once the account reports, a window it does not have (Claude+ * Ultra has no 5-hour limit) gets no meter rather than a permanently empty one.+ */+export const meterWindows = (view: Pick<AccountView, AccountWindowKey>): AccountWindowKey[] => {+ if (!view.session && !view.weekly) return ['session', 'weekly'];+ return (['session', 'weekly'] as const).filter((key) => !!view[key]);+};+const PROVIDER_ORDER: Record<string, number> = { 'claude-code': 0, 'codex': 1, 'kimi-code': 2 };/** Accounts in rotation first, then grouped by provider, then by name. */