Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(agent-runtime): treat Volcengine AccountOverdueError wording as terminal
xpeng5278-webd03fd1f27cc5
diff --git a/docs/spec/03-runtime/02-agent-runtime.md b/docs/spec/03-runtime/02-agent-runtime.mdindex 88ac9744c..0df091425 100644--- a/docs/spec/03-runtime/02-agent-runtime.md+++ b/docs/spec/03-runtime/02-agent-runtime.md@@ -231,8 +231,9 @@ the provider message in both phases, so a generic 429 body still enters the429 budget while known non-retryable classifications remain terminal. Explicitbilling/account exhaustion (including `insufficient_quota`, spend-limitcodes, Zhipu/Z.ai usage-limit code `1308`, Anthropic "credit balance is too-low", and DashScope `Arrearage` / "access denied … account is in good-standing") is terminal `PROVIDER_ERROR` even with HTTP 429. The main session and+low", DashScope `Arrearage` / "access denied … account is in good+standing", and Volcengine Ark `AccountOverdueError` / `overdue balance`)+is terminal `PROVIDER_ERROR` even with HTTP 429. The main session andbuiltin subagents use the same controller and policy.429 retries are silent at the transcript lifecycle: no intermediate assistantdiff --git a/packages/agent-runtime/src/agent-errors.test.ts b/packages/agent-runtime/src/agent-errors.test.tsindex 8a2ef513c..46d9f124e 100644--- a/packages/agent-runtime/src/agent-errors.test.ts+++ b/packages/agent-runtime/src/agent-errors.test.ts@@ -945,6 +945,118 @@ describe("classifyAgentError", () => {});});+ // Volcengine Ark reports an overdue account as AccountOverdueError+ // ("your account has an overdue balance"). pi-ai often drops the HTTP 403+ // and leaves the message, a JSON body, or error.code. Backing off cannot+ // clear the balance, so those shapes are terminal before the status table.+ // A bare "overdue" / "account" / "forbidden" is not this failure.+ it.each([+ "The request failed because your account has an overdue balance.",+ "AccountOverdueError: The request failed because your account has an overdue balance.",+ JSON.stringify({+ error: {+ code: "AccountOverdueError",+ message: "The request failed because your account has an overdue balance.",+ type: "Forbidden",+ },+ }),+ ])("treats statusless Volcengine overdue-balance text as terminal: %s", (message) => {+ expect(classifyAgentError(message)).toMatchObject({+ code: "PROVIDER_ERROR",+ retriable: false,+ });+ expect(classifyAgentError(new Error(message))).toMatchObject({+ code: "PROVIDER_ERROR",+ retriable: false,+ });+ });++ it("treats a structured AccountOverdueError code as terminal billing exhaustion", () => {+ expect(classifyAgentError(Object.assign(+ new Error("The request failed because your account has an overdue balance."),+ { code: "AccountOverdueError" },+ ))).toMatchObject({+ code: "PROVIDER_ERROR",+ retriable: false,+ details: { providerCode: "AccountOverdueError" },+ });+ // The code alone is enough when the message text was replaced.+ expect(classifyAgentError(Object.assign(+ new Error("request rejected"),+ { code: "AccountOverdueError" },+ ))).toMatchObject({+ code: "PROVIDER_ERROR",+ retriable: false,+ details: { providerCode: "AccountOverdueError" },+ });+ });++ it.each([429, 400])(+ "does not retry AccountOverdueError when HTTP %s is still attached",+ (status) => {+ expect(classifyAgentError(Object.assign(+ new Error("The request failed because your account has an overdue balance."),+ { status, code: "AccountOverdueError" },+ ))).toMatchObject({+ code: "PROVIDER_ERROR",+ retriable: false,+ details: { providerStatus: status, providerCode: "AccountOverdueError" },+ });+ },+ );++ it("does not retry an overdue-balance message reported as HTTP 429", () => {+ expect(classifyAgentError(Object.assign(+ new Error("The request failed because your account has an overdue balance."),+ { status: 429 },+ ))).toMatchObject({+ code: "PROVIDER_ERROR",+ retriable: false,+ details: { providerStatus: 429 },+ });+ });++ // Exhaustion is probed before the 403 branch, so a body that still carries+ // 403 and the overdue wording is billing-terminal. A plain 403 is not.+ it("classifies a 403 AccountOverdueError body as terminal billing exhaustion", () => {+ expect(classifyAgentError(+ "Error code: 403 - { 'error': { 'code': 'AccountOverdueError', 'message': 'The request failed because your account has an overdue balance.', 'type': 'Forbidden' } }",+ )).toMatchObject({+ code: "PROVIDER_ERROR",+ retriable: false,+ details: { providerStatus: 403 },+ });+ });++ it("does not treat unrelated overdue, account, or forbidden wording as billing exhaustion", () => {+ for (const message of [+ "overdue library book",+ "overdue",+ "account",+ "balance",+ "credits",+ "insufficient credentials",+ "Forbidden",+ "account has overdue",+ ]) {+ expect(classifyAgentError(message)).toMatchObject({+ code: "PROVIDER_ERROR",+ retriable: true,+ });+ }+ expect(classifyAgentError("403 Forbidden")).toMatchObject({+ code: "PROVIDER_UNAUTHORIZED",+ retriable: false,+ });+ expect(classifyAgentError(Object.assign(+ new Error("permission denied"),+ { status: 403 },+ ))).toMatchObject({+ code: "PROVIDER_UNAUTHORIZED",+ retriable: false,+ });+ });+it.each(["Rate limit exceeded","Too many requests",diff --git a/packages/agent-runtime/src/agent-errors.ts b/packages/agent-runtime/src/agent-errors.tsindex 1e040ce09..7b2e3c6ed 100644--- a/packages/agent-runtime/src/agent-errors.ts+++ b/packages/agent-runtime/src/agent-errors.ts@@ -51,19 +51,21 @@ const RATE_LIMIT_PATTERN =* OpenAI's `insufficient_quota` type, OpenRouter-style "insufficient credits"* / "requires more credits" / "Payment Required" wording, DeepSeek /* SiliconFlow / MiniMax "Insufficient Balance" / "account balance is- * insufficient", and explicit 429 error codes. Anthropic's "credit balance- * is too low" and DashScope's `Arrearage` code, or "Access denied" paired- * with "account is in good standing", are the same terminal exhaustion.- * Checked before the status table because those conditions do not recover- * by backing off, including when a gateway labels them HTTP 429. Generic- * "quota exceeded" wording remains eligible for rate-limit classification- * below. A bare "credits", "balance", "Access denied", or "account is in+ * insufficient", Volcengine Ark `AccountOverdueError` / "overdue balance" /+ * "account has an overdue", and explicit 429 error codes. Anthropic's+ * "credit balance is too low" and DashScope's `Arrearage` code, or+ * "Access denied" paired with "account is in good standing", are the same+ * terminal exhaustion. Checked before the status table because those+ * conditions do not recover by backing off, including when a gateway+ * labels them HTTP 429. Generic "quota exceeded" wording remains eligible+ * for rate-limit classification below. A bare "credits", "balance",+ * "overdue", "account", "forbidden", "Access denied", or "account is in* good standing" is not exhaustion, and "insufficient credentials" must* not match it either. HTTP 402 is terminal in the status table even when* the body omits these phrases.*/const EXHAUSTED_QUOTA_CODE_PATTERN =- /\b(?:insufficient_quota|credit_balance_exhausted|organization_spend_limit_exceeded|project_spend_limit_exceeded|organization_usage_limit_exceeded|FreeUsageLimitError|Arrearage)\b/i;+ /\b(?:insufficient_quota|credit_balance_exhausted|organization_spend_limit_exceeded|project_spend_limit_exceeded|organization_usage_limit_exceeded|FreeUsageLimitError|Arrearage|AccountOverdueError)\b/i;/*** Zhipu/Z.ai (open.bigmodel.cn) error code 1308: the plan usage limit is@@ -74,7 +76,7 @@ const EXHAUSTED_QUOTA_CODE_PATTERN =const ZHIPU_USAGE_LIMIT_PATTERN = /"code"\s*:\s*"?1308(?![0-9])/;const EXHAUSTED_QUOTA_MESSAGE_PATTERN =- /\b(?:billing|spending|credit|disk)\s+quotas?\b|\b(?:organization|project)\s+spend\s+limit\s+(?:reached|exceeded)\b|\bquota\b.{0,100}\b(?:plan|billing)\b|\binsufficient\s+(?:credits|balance)\b|\bbalance\s+is\s+insufficient\b|\brequires\s+more\s+credits\b|\bpayment\s+required\b|\bcredit\s+balance\s+is\s+too\s+low\b|\bArrearage\b|\baccess\s+denied\b.{0,80}\baccount\s+is\s+in\s+good\s+standing\b/i;+ /\b(?:billing|spending|credit|disk)\s+quotas?\b|\b(?:organization|project)\s+spend\s+limit\s+(?:reached|exceeded)\b|\bquota\b.{0,100}\b(?:plan|billing)\b|\binsufficient\s+(?:credits|balance)\b|\bbalance\s+is\s+insufficient\b|\brequires\s+more\s+credits\b|\bpayment\s+required\b|\bcredit\s+balance\s+is\s+too\s+low\b|\bArrearage\b|\baccess\s+denied\b.{0,80}\baccount\s+is\s+in\s+good\s+standing\b|\boverdue\s+balance\b|\baccount\s+has\s+an\s+overdue\b/i;/*** Whether a provider message reports a context overflow.