Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): 优化 Codex 用量上限提示 (#2902)
Dash620800b40292
diff --git a/apps/desktop/src/renderer/__tests__/usageLimitRecovery.test.ts b/apps/desktop/src/renderer/__tests__/usageLimitRecovery.test.tsindex 82f8acab02..f907164400 100644--- a/apps/desktop/src/renderer/__tests__/usageLimitRecovery.test.ts+++ b/apps/desktop/src/renderer/__tests__/usageLimitRecovery.test.ts@@ -31,7 +31,36 @@ describe('usage limit recovery detection', () => {},NOW,),- ).toEqual({ resetAtMs: NOW + 75 * 60_000 });+ ).toEqual({ resetAtMs: NOW + 75 * 60_000, isAccountUsageLimit: true });+ });++ it('extracts the organization plan and reset time from the Codex 429 payload', () => {+ expect(+ extractUsageLimitRecoveryHint(+ {+ message:+ 'API Error: Request rejected (429) · {"error":{"type":"usage_limit_reached","message":"The usage limit has been reached","plan_type":"business","resets_at":1788220709,"eligible_promo":null,"resets_in_seconds":1264528}}',+ },+ Date.parse('2026-08-17T00:00:00.000Z'),+ ),+ ).toEqual({+ resetAtMs: Date.parse('2026-08-31T23:58:29.000Z'),+ isAccountUsageLimit: true,+ planType: 'business',+ });+ });++ it('does not classify a transient Codex 429 as an account usage limit', () => {+ expect(+ extractUsageLimitRecoveryHint(+ {+ errorStatus: 429,+ codexErrorInfo: { responseTooManyFailedAttempts: { httpStatusCode: 429 } },+ message: 'Too many requests',+ },+ NOW,+ ),+ ).toEqual({ resetAtMs: null });});it('parses the real Claude session-limit wording with a named timezone', () => {diff --git a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsxindex 69fb6b1fe9..d99c6aaac2 100644--- a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx+++ b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx@@ -43,6 +43,7 @@ import { isNetworkishErrorMessage, parseReconnectAttemptMessage } from '@/utils/import { isOverloadErrorMessage, parseOverloadRetryProgress } from '@/utils/overloadError';import { isQuotaExhaustedErrorMessage } from '@/utils/quotaError';import { parseTerminalRateLimitRetryProgress } from '@/utils/rateLimitRetry';+import type { UsageLimitRecoveryHint } from '@/lib/usageLimitRecovery';import { ERROR_REASON_I18N_KEYS } from './errorReasonI18n';import {CLAUDE_GATEWAY_OPUS_PLAN_MISMATCH_REASON,@@ -62,6 +63,8 @@ interface ErrorBannerProps {onSilentStopContinue?: () => void;/** 账号用量限制:打开预填好的一次性 Automation,由用户确认后创建。 */onContinueAfterUsageReset?: () => void;+ /** 已识别的账号用量限制及恢复时间;用于替换上游 429 JSON 为可读提示。 */+ usageLimitRecovery?: UsageLimitRecoveryHint | null;/** 当前 session 的 agent kind。codex 的 401 / Missing bearer 必须 hide Retry,* 否则 retry 撞同一个 in-memory auth retry-loop 产生重复失败 turn。 */agentKind?: 'cc' | 'codex' | 'pi';@@ -115,6 +118,7 @@ export function ErrorBanner({onCancel,onSilentStopContinue,onContinueAfterUsageReset,+ usageLimitRecovery,agentKind,remoteHostId,deviceLinkDeviceId,@@ -130,7 +134,7 @@ export function ErrorBanner({style,className,}: ErrorBannerProps) {- const { t } = useTranslation();+ const { t, i18n } = useTranslation();const { confirm } = useConfirmDialog();const promptCodexSessionExpired = useCodexSessionExpiredPrompt({// 横幅已说明影响范围;用户点击“重新连接 ChatGPT”后直接进入浏览器连接流程,@@ -260,6 +264,24 @@ export function ErrorBanner({const overloadRetryProgress = parseOverloadRetryProgress(error);const errorReasonI18nKey = errorReason ? ERROR_REASON_I18N_KEYS[errorReason] : undefined;const terminalRateLimitRetryProgress = parseTerminalRateLimitRetryProgress(error, errorReason);+ const isCodexUsageLimitError =+ agentKind === 'codex' && usageLimitRecovery?.isAccountUsageLimit === true;+ const usageLimitResetDate =+ usageLimitRecovery?.resetAtMs && Number.isFinite(usageLimitRecovery.resetAtMs)+ ? new Date(usageLimitRecovery.resetAtMs)+ : null;+ const usageLimitResetAt =+ usageLimitResetDate && Number.isFinite(usageLimitResetDate.getTime())+ ? new Intl.DateTimeFormat(i18n?.resolvedLanguage ?? i18n?.language, {+ dateStyle: 'medium',+ timeStyle: 'short',+ }).format(usageLimitResetDate)+ : null;+ const isOrganizationCodexPlan = ['business', 'enterprise', 'team'].includes(+ usageLimitRecovery?.planType?.toLowerCase() ?? '',+ );+ const canContinueAfterUsageReset =+ Boolean(onContinueAfterUsageReset) && (agentKind !== 'codex' || isCodexUsageLimitError);// Retry 的显示条件与网络错误文案必须共用同一个判定。外部发起的 turn(例如// scheduler / goal)失败时没有安全的 recovery target,errorRetryText 会是 null;// 此时不能一边隐藏按钮,一边仍提示用户“点击重试”。@@ -324,6 +346,23 @@ export function ErrorBanner({// 「配额或余额不足,请检查供应商账户」对网关用户是半句话:账户就在 Cindy 里,// 该说的是「去充值」而不是「去检查」。右端的内联出口负责「去哪充」。displayError = t('chat.errorBanner.gatewayQuotaExhausted');+ } else if (isCodexUsageLimitError) {+ // Codex 会把整段 429 JSON 放进 message。用户需要的是「哪个账号受限」和+ // 「什么时候恢复」;原始响应仍保留在下方的可展开区域供排障。+ if (usageLimitResetAt) {+ displayError = t(+ isOrganizationCodexPlan+ ? 'chat.errorBanner.codexOrganizationUsageLimitWithReset'+ : 'chat.errorBanner.codexUsageLimitWithReset',+ { resetAt: usageLimitResetAt },+ );+ } else {+ displayError = t(+ isOrganizationCodexPlan+ ? 'chat.errorBanner.codexOrganizationUsageLimit'+ : 'chat.errorBanner.codexUsageLimit',+ );+ }} else if (terminalRateLimitRetryProgress) {// daemon 已耗尽内部 retry budget 的终态 429,由 maker-core 做受限外层重投。// 它不是模型容量过载,也不是用户网络异常;独立文案避免误导用户切模型或查网络。@@ -516,6 +555,7 @@ export function ErrorBanner({)}{(isNetworkishError ||isOverloadError ||+ isCodexUsageLimitError ||terminalRateLimitRetryProgress ||isClaudeGatewayOpusPlanMismatch ||isClaudeSubscriptionOpusPlanMismatch) && (@@ -639,7 +679,7 @@ export function ErrorBanner({{t('chat.errorBanner.silentStopContinue')}</button>)}- {onContinueAfterUsageReset && (+ {canContinueAfterUsageReset && onContinueAfterUsageReset && (<buttontype="button"data-split-pane-route-action=""diff --git a/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsx b/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsxindex 799d1202b6..4ecd8ff3b4 100644--- a/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsx+++ b/apps/desktop/src/renderer/components/chat/InterruptedTurnBanner.tsx@@ -30,10 +30,11 @@* --error-fg / --error-fg-strong(与 ErrorMessageCard 同组),不硬编码 Tailwind red。*/-import { useState } from 'react';+import { useMemo, useState } from 'react';import { CirclePause, Play, X } from 'lucide-react';import { useTranslation } from 'react-i18next';import { cn } from '@/lib/utils';+import { extractUsageLimitRecoveryHint } from '@/lib/usageLimitRecovery';import { ErrorBanner } from './ErrorBanner';export function InterruptedTurnBanner({@@ -90,7 +91,9 @@ export function InterruptedTurnBanner({title={t('chat.interruptedBanner.continueTitle')}><Play size={12} />- {sending ? t('chat.interruptedBanner.continuing') : t('chat.interruptedBanner.continueAction')}+ {sending+ ? t('chat.interruptedBanner.continuing')+ : t('chat.interruptedBanner.continueAction')}</button><buttontype="button"@@ -150,6 +153,11 @@ export function ErrorTailErrorBanner({className?: string;style?: React.CSSProperties;}) {+ const usageLimitRecovery = useMemo(+ () => extractUsageLimitRecoveryHint({ message: errorText }),+ [errorText],+ );+return (<ErrorBannererror={errorText}@@ -158,6 +166,7 @@ export function ErrorTailErrorBanner({onRetry={() => void onContinue()}onCancel={onDismiss}onSilentStopContinue={onSilentStopContinue}+ usageLimitRecovery={usageLimitRecovery}agentKind={agentKind}remoteHostId={remoteHostId}deviceLinkDeviceId={deviceLinkDeviceId}diff --git a/apps/desktop/src/renderer/components/chat/__tests__/ErrorBannerCodexOAuth.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/ErrorBannerCodexOAuth.test.tsxindex 1f11412408..7e5e6a7a84 100644--- a/apps/desktop/src/renderer/components/chat/__tests__/ErrorBannerCodexOAuth.test.tsx+++ b/apps/desktop/src/renderer/components/chat/__tests__/ErrorBannerCodexOAuth.test.tsx@@ -5,6 +5,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';import { CODEX_RESUME_NOT_READY_WIRE_MESSAGE } from '@cindy/maker-shared/agent-input-projection';import { ErrorBanner } from '../ErrorBanner';+import { ErrorTailErrorBanner } from '../InterruptedTurnBanner';import { useCodexAuth } from '@/hooks/useCodexAuth';import { useCodexSessionExpiredPrompt } from '@/hooks/useCodexSessionExpiredPrompt';import {@@ -136,12 +137,7 @@ describe('ErrorBanner OpenAI connection recovery', () => {it('localizes the Codex resume preflight marker without exposing the host envelope', () => {const error = `LAZY_CREATE_FAILED: ${CODEX_RESUME_NOT_READY_WIRE_MESSAGE}`;render(- <ErrorBanner- error={error}- retryText="retry this turn"- onRetry={vi.fn()}- agentKind="codex"- />,+ <ErrorBanner error={error} retryText="retry this turn" onRetry={vi.fn()} agentKind="codex" />,);expect(screen.getByText('chat.errorBanner.codexResumeNotReady')).toBeTruthy();@@ -812,13 +808,17 @@ describe('ErrorBanner OpenAI connection recovery', () => {const onContinueAfterUsageReset = vi.fn();const { rerender } = render(<ErrorBanner- error="Usage limit reached"+ error="usageLimitExceeded"retryText="retry this turn"onRetry={vi.fn()}+ agentKind="codex"onContinueAfterUsageReset={onContinueAfterUsageReset}+ usageLimitRecovery={{ resetAtMs: null, isAccountUsageLimit: true }}/>,);+ expect(screen.getByText('chat.errorBanner.codexUsageLimit')).toBeTruthy();+ expect(screen.queryByText('usageLimitExceeded')).toBeNull();const continueButton = screen.getByRole('button', {name: 'chat.errorBanner.continueAfterReset',});@@ -834,6 +834,105 @@ describe('ErrorBanner OpenAI connection recovery', () => {).toBeNull();});+ it('explains an organization Codex limit and keeps the raw 429 response available', () => {+ const rawError =+ 'API Error: Request rejected (429) · {"error":{"type":"usage_limit_reached","plan_type":"business","resets_at":1788220709}}';+ render(+ <ErrorBanner+ error={rawError}+ retryText="retry this turn"+ onRetry={vi.fn()}+ agentKind="codex"+ usageLimitRecovery={{+ resetAtMs: Date.parse('2026-08-31T23:58:29.000Z'),+ isAccountUsageLimit: true,+ planType: 'business',+ }}+ />,+ );++ expect(screen.getByText('chat.errorBanner.codexOrganizationUsageLimitWithReset')).toBeTruthy();+ expect(screen.queryByText(rawError)).toBeNull();++ fireEvent.click(screen.getByRole('button', { name: 'chat.errorBanner.networkShowRaw' }));+ expect(screen.getByText(rawError)).toBeTruthy();+ });++ it('falls back to the no-reset-time copy for an out-of-range reset timestamp', () => {+ render(+ <ErrorBanner+ error="usageLimitExceeded"+ retryText="retry this turn"+ onRetry={vi.fn()}+ agentKind="codex"+ usageLimitRecovery={{+ resetAtMs: Number.MAX_VALUE,+ isAccountUsageLimit: true,+ planType: 'business',+ }}+ />,+ );++ expect(screen.getByText('chat.errorBanner.codexOrganizationUsageLimit')).toBeTruthy();+ expect(+ screen.queryByText('chat.errorBanner.codexOrganizationUsageLimitWithReset'),+ ).toBeNull();+ });++ it('keeps a transient Codex 429 on its normal rate-limit path', () => {+ const rawError = 'Too many requests (429)';+ render(+ <ErrorBanner+ error={rawError}+ retryText="retry this turn"+ onRetry={vi.fn()}+ agentKind="codex"+ onContinueAfterUsageReset={vi.fn()}+ usageLimitRecovery={{ resetAtMs: null }}+ />,+ );++ expect(screen.getByText(rawError)).toBeTruthy();+ expect(screen.queryByText('chat.errorBanner.codexUsageLimit')).toBeNull();+ expect(+ screen.queryByRole('button', { name: 'chat.errorBanner.continueAfterReset' }),+ ).toBeNull();+ });++ it('rebuilds the organization usage-limit hint for a persisted error tail', () => {+ const rawError =+ 'API Error: Request rejected (429) · {"error":{"type":"usage_limit_reached","plan_type":"business"}}';+ render(+ <ErrorTailErrorBanner+ errorText={rawError}+ onContinue={vi.fn()}+ onDismiss={vi.fn()}+ agentKind="codex"+ />,+ );++ expect(screen.getByText('chat.errorBanner.codexOrganizationUsageLimit')).toBeTruthy();+ expect(screen.queryByText(rawError)).toBeNull();++ fireEvent.click(screen.getByRole('button', { name: 'chat.errorBanner.networkShowRaw' }));+ expect(screen.getByText(rawError)).toBeTruthy();+ });++ it('does not relabel another agent usage limit as a Codex account limit', () => {+ render(+ <ErrorBanner+ error="You've hit your Claude session limit"+ retryText="retry this turn"+ onRetry={vi.fn()}+ agentKind="cc"+ usageLimitRecovery={{ resetAtMs: null }}+ />,+ );++ expect(screen.getByText("You've hit your Claude session limit")).toBeTruthy();+ expect(screen.queryByText('chat.errorBanner.codexUsageLimit')).toBeNull();+ });+it('replaces the misleading Claude Pro error with its XD Gateway attribution', () => {render(<ErrorBannerdiff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsxindex e0500c3991..6fdeea2bba 100644--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSessionView.tsx@@ -4214,6 +4214,7 @@ export function CCAgentSessionView({onContinueAfterUsageReset={usageLimitRecovery && !remoteDeviceId ? handleContinueAfterUsageReset : undefined}+ usageLimitRecovery={usageLimitRecovery}onCancel={handleDismissError}agentKind={session?.agentKind}remoteHostId={session?.remoteHostId ?? undefined}diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 770afc92c4..cb9c76dea1 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -6257,6 +6257,10 @@"retry": "Retry","continueAfterReset": "Continue After Reset","continueAfterResetTitle": "Create a one-time Automation to continue this task after usage resets",+ "codexOrganizationUsageLimitWithReset": "The connected Codex account is managed by your organization and has reached its usage limit. Usage is expected to reset at {{resetAt}}.",+ "codexOrganizationUsageLimit": "The connected Codex account is managed by your organization and has reached its usage limit. Wait for the limit to reset, or switch to another available account before retrying.",+ "codexUsageLimitWithReset": "The connected Codex account has reached its usage limit. Usage is expected to reset at {{resetAt}}.",+ "codexUsageLimit": "The connected Codex account has reached its usage limit. Wait for the limit to reset, or switch to another available account before retrying.","gatewayQuotaExhausted": "Your Cindy AI balance is used up. Add funds to continue.","viewBalance": "View balance","viewBalanceTitle": "Open Usage & Billing to check your balance and add funds",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex c13b316ca2..5b50fb0270 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -6254,6 +6254,10 @@"retry": "再試行","continueAfterReset": "リセット後に続行","continueAfterResetTitle": "利用上限のリセット後にこのタスクを続行する一回限りの自動化を作成",+ "codexOrganizationUsageLimitWithReset": "接続中の Codex アカウントは組織によって管理されており、利用上限に達しました。{{resetAt}} にリセットされる見込みです。",+ "codexOrganizationUsageLimit": "接続中の Codex アカウントは組織によって管理されており、利用上限に達しました。上限のリセットを待つか、別の利用可能なアカウントに切り替えてから再試行してください。",+ "codexUsageLimitWithReset": "接続中の Codex アカウントは利用上限に達しました。{{resetAt}} にリセットされる見込みです。",+ "codexUsageLimit": "接続中の Codex アカウントは利用上限に達しました。上限のリセットを待つか、別の利用可能なアカウントに切り替えてから再試行してください。","gatewayQuotaExhausted": "Cindy AI の残高が不足しています。チャージすると続行できます。","viewBalance": "残高を見る","viewBalanceTitle": "「使用量と請求」を開いて残高を確認・チャージ",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 136efe7a4b..74e17d5f47 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -6254,6 +6254,10 @@"retry": "다시 시도","continueAfterReset": "재설정 후 계속","continueAfterResetTitle": "사용량 제한 재설정 후 현재 작업을 계속할 일회성 자동화 만들기",+ "codexOrganizationUsageLimitWithReset": "현재 연결된 Codex 계정은 조직에서 관리하며 사용량 한도에 도달했습니다. {{resetAt}}에 한도가 재설정될 예정입니다.",+ "codexOrganizationUsageLimit": "현재 연결된 Codex 계정은 조직에서 관리하며 사용량 한도에 도달했습니다. 한도 재설정을 기다리거나 사용 가능한 다른 계정으로 전환한 후 다시 시도하세요.",+ "codexUsageLimitWithReset": "현재 연결된 Codex 계정이 사용량 한도에 도달했습니다. {{resetAt}}에 한도가 재설정될 예정입니다.",+ "codexUsageLimit": "현재 연결된 Codex 계정이 사용량 한도에 도달했습니다. 한도 재설정을 기다리거나 사용 가능한 다른 계정으로 전환한 후 다시 시도하세요.","gatewayQuotaExhausted": "Cindy AI 잔액이 부족합니다. 충전한 후 계속하세요.","viewBalance": "잔액 보기","viewBalanceTitle": "「사용량 및 청구」를 열어 잔액을 확인하고 충전",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 46c89df36e..681bea1951 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -6254,6 +6254,10 @@"retry": "重试","continueAfterReset": "恢复后继续","continueAfterResetTitle": "创建一次性自动化,在用量恢复后继续当前任务",+ "codexOrganizationUsageLimitWithReset": "当前连接的是企业 Codex 账号,已达到用量上限,预计于 {{resetAt}} 恢复。",+ "codexOrganizationUsageLimit": "当前连接的是企业 Codex 账号,已达到用量上限。请等待用量上限重置,或切换其他可用账号后再重试。",+ "codexUsageLimitWithReset": "当前连接的 Codex 账号已达到用量上限,预计于 {{resetAt}} 恢复。",+ "codexUsageLimit": "当前连接的 Codex 账号已达到用量上限。请等待用量上限重置,或切换其他可用账号后再重试。","gatewayQuotaExhausted": "Cindy AI 余额不足,请充值后继续","viewBalance": "查看余额","viewBalanceTitle": "打开「用量和计费」查看余额并充值",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.jsonindex 4458f97fc6..360ae33ff2 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-TW/common.json@@ -6253,6 +6253,10 @@"retry": "重試","continueAfterReset": "恢復後繼續","continueAfterResetTitle": "建立一次性自動化,在用量恢復後繼續當前任務",+ "codexOrganizationUsageLimitWithReset": "目前連線的是企業 Codex 帳號,已達到用量上限,預計於 {{resetAt}} 恢復。",+ "codexOrganizationUsageLimit": "目前連線的是企業 Codex 帳號,已達到用量上限。請等待用量上限重置,或切換其他可用帳號後再重試。",+ "codexUsageLimitWithReset": "目前連線的 Codex 帳號已達到用量上限,預計於 {{resetAt}} 恢復。",+ "codexUsageLimit": "目前連線的 Codex 帳號已達到用量上限。請等待用量上限重置,或切換其他可用帳號後再重試。","gatewayQuotaExhausted": "Cindy AI 餘額不足,請充值後繼續","viewBalance": "檢視餘額","viewBalanceTitle": "開啟「用量和計費」檢視餘額並充值",diff --git a/apps/desktop/src/renderer/lib/usageLimitRecovery.ts b/apps/desktop/src/renderer/lib/usageLimitRecovery.tsindex 6c8b73d260..f836a8806a 100644--- a/apps/desktop/src/renderer/lib/usageLimitRecovery.ts+++ b/apps/desktop/src/renderer/lib/usageLimitRecovery.ts@@ -9,6 +9,10 @@export interface UsageLimitRecoveryHint {resetAtMs: number | null;+ /** True only when upstream explicitly identifies account-cycle exhaustion, not a generic 429. */+ isAccountUsageLimit?: boolean;+ /** Upstream subscription plan when the provider exposes it (for example `business`). */+ planType?: string;}type UnknownRecord = Record<string, unknown>;@@ -31,6 +35,8 @@ const RETRY_AFTER_SECONDS_KEYS = new Set(['retry_after','retry_after_seconds',]);+const PLAN_TYPE_KEYS = new Set(['plantype', 'plan_type']);+const EXPLICIT_ACCOUNT_USAGE_LIMIT_PATTERN = /\busage_limit_reached\b|\busageLimitExceeded\b/;function asRecord(value: unknown): UnknownRecord | null {return value !== null && typeof value === 'object' && !Array.isArray(value)@@ -108,6 +114,25 @@ function parseStructuredResetAt(records: readonly UnknownRecord[], nowMs: numberreturn null;}+function normalizePlanType(value: unknown): string | null {+ if (typeof value !== 'string') return null;+ const normalized = value.trim().toLowerCase();+ return normalized && normalized.length <= 64 ? normalized : null;+}++function parsePlanType(records: readonly UnknownRecord[], text: string): string | null {+ for (const record of records) {+ for (const [rawKey, value] of Object.entries(record)) {+ if (!PLAN_TYPE_KEYS.has(rawKey.toLowerCase())) continue;+ const normalized = normalizePlanType(value);+ if (normalized) return normalized;+ }+ }++ const textMatch = text.match(/["']?plan[_-]?type["']?\s*[:=]\s*["']?([a-z0-9_-]+)["']?/i);+ return normalizePlanType(textMatch?.[1]);+}+function parseRelativeResetAt(text: string, nowMs: number): number | null {const relative = text.match(/(?:resets?|retry(?:\s+after)?|try\s+again)\s+(?:in\s+)?(?:(\d+)\s*d(?:ays?)?\s*)?(?:(\d+)\s*h(?:ours?)?\s*)?(?:(\d+)\s*m(?:in(?:ute)?s?)?\s*)?(?:(\d+)\s*s(?:ec(?:ond)?s?)?)?/i,@@ -269,9 +294,11 @@ export function extractUsageLimitRecoveryHint(return null;}+ const isAccountUsageLimit = EXPLICIT_ACCOUNT_USAGE_LIMIT_PATTERN.test(text);const isUsageLimit =sdkError === 'rate_limit' ||codexErrorInfo === 'usageLimitExceeded' ||+ isAccountUsageLimit ||root.usageLimit === true ||status === 429 ||/\b(?:rate.?limit|usage.?limit|too\s+many\s+requests|quota\s+(?:exceeded|exhausted)|you(?:'|’)ve\s+hit\s+your\s+(?:(?:session|weekly)\s+)?limit)\b/i.test(@@ -279,7 +306,10 @@ export function extractUsageLimitRecoveryHint();if (!isUsageLimit) return null;+ const planType = parsePlanType(records, text);return {resetAtMs: parseStructuredResetAt(records, nowMs) ?? parseTextResetAt(text, nowMs),+ ...(isAccountUsageLimit ? { isAccountUsageLimit: true } : {}),+ ...(planType ? { planType } : {}),};}