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): stop retrying exhausted OpenCode Zen quotas
Linuxdazhaoa6b7acf7c63a
diff --git a/docs/spec/03-runtime/08-error-codes.md b/docs/spec/03-runtime/08-error-codes.mdindex 393087826..2ed4e7673 100644--- a/docs/spec/03-runtime/08-error-codes.md+++ b/docs/spec/03-runtime/08-error-codes.md@@ -377,7 +377,8 @@ exceeds max length`, xAI `maximum prompt length is`, Groq, llama.cpp, andBedrock `Input is too long for requested model`. `CONTEXT_TOO_LARGE` is neverreplayed by either retry budget, and a delegate reports it as`SUBAGENT_CONTEXT_OVERFLOW`. Explicit billing/account exhaustion codes and-messages (including `insufficient_quota`, `credit_balance_exhausted`,+messages (including OpenCode Zen's `FreeUsageLimitError`, `insufficient_quota`,+`credit_balance_exhausted`,organization/project spend-limit codes, `insufficient credits`, and`requires more credits`) map to terminal `PROVIDER_ERROR` even when the HTTPstatus is 429, and HTTP 402 is terminal `PROVIDER_ERROR` even when the bodydiff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.mdindex 87cdd459e..e3317bab6 100644--- a/docs/spec/06-delivery/04-e2e-test-plan.md+++ b/docs/spec/06-delivery/04-e2e-test-plan.md@@ -8049,7 +8049,8 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.support aborting during the wait. A builtin subagent uses afixture with the same responses. Billing/account-exhaustion fixtures alsoreturn HTTP 429 with `insufficient_quota`, `credit_balance_exhausted`,- organization usage-limit, and spend-limit codes.+ organization usage-limit, spend-limit, and OpenCode Zen+ `FreeUsageLimitError` codes.- **Steps**:1. Start an Agent turn with a setup-429 fixture whose next request succeeds.2. Repeat with a mid-stream-429 fixture whose next request succeeds.@@ -8072,8 +8073,9 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.- Explicit billing/account exhaustion is terminal `PROVIDER_ERROR` evenwhen returned with HTTP 429, including `insufficient_quota`,`credit_balance_exhausted`, organization usage-limit, and organization/- project spend-limit codes. It starts no retry and consumes neither retry- budget.+ project spend-limit codes, and OpenCode Zen's `FreeUsageLimitError`.+ It retains the provider's message and status, starts no retry, and+ consumes neither retry budget.- Setup and mid-stream failures share one budget of ten retries after theinitial attempt. A persistent fixture therefore makes eleven providerattempts, never multiplies attempts through nested pi-ai retries, anddiff --git a/packages/agent-runtime/src/agent-errors.ts b/packages/agent-runtime/src/agent-errors.tsindex c67df54a1..8c0064cd5 100644--- a/packages/agent-runtime/src/agent-errors.ts+++ b/packages/agent-runtime/src/agent-errors.ts@@ -58,7 +58,7 @@ const RATE_LIMIT_PATTERN =* phrases.*/const EXHAUSTED_QUOTA_CODE_PATTERN =- /\b(?:insufficient_quota|credit_balance_exhausted|organization_spend_limit_exceeded|project_spend_limit_exceeded|organization_usage_limit_exceeded)\b/i;+ /\b(?:insufficient_quota|credit_balance_exhausted|organization_spend_limit_exceeded|project_spend_limit_exceeded|organization_usage_limit_exceeded|FreeUsageLimitError)\b/i;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\b|\brequires\s+more\s+credits\b|\bpayment\s+required\b/i;diff --git a/packages/agent-runtime/src/provider-retry.test.ts b/packages/agent-runtime/src/provider-retry.test.tsindex 2d86ac355..bcd5adb53 100644--- a/packages/agent-runtime/src/provider-retry.test.ts+++ b/packages/agent-runtime/src/provider-retry.test.ts@@ -309,7 +309,10 @@ describe("provider rate-limit retry", () => {});});- it("does not retry billing exhaustion when the captured status is 429", async () => {+ it.each([+ '429: {"error":{"message":"You exceeded your current quota, please check your plan and billing details.","type":"insufficient_quota","code":"insufficient_quota"}}',+ '429: {"type":"FreeUsageLimitError","message":"Free usage limit reached."}',+ ])("does not retry explicit quota exhaustion on HTTP 429: %s", async (errorMessage) => {let attempts = 0;let retryableClaims = 0;const claim = vi.fn((error: ClassifiedAgentError) => {@@ -324,9 +327,7 @@ describe("provider rate-limit retry", () => {{},() => {attempts += 1;- return failedStream({- errorMessage: '429: {"error":{"message":"You exceeded your current quota, please check your plan and billing details.","type":"insufficient_quota","code":"insufficient_quota"}}',- });+ return failedStream({ errorMessage });},{ claim, headers: () => undefined, status: () => 429, sleep },);@@ -336,7 +337,7 @@ describe("provider rate-limit retry", () => {expect(attempts).toBe(1);expect(claim).toHaveBeenCalledWith(- expect.objectContaining({ code: "PROVIDER_ERROR", retriable: false }),+ expect.objectContaining({ code: "PROVIDER_ERROR", retriable: false, message: errorMessage }),"request",);expect(sleep).not.toHaveBeenCalled();