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): do not treat billing or disk quota as rate limit
xpeng5278-web2d29e170415e
diff --git a/packages/agent-runtime/src/agent-errors.test.ts b/packages/agent-runtime/src/agent-errors.test.tsindex 01e45fcfa..e58766c62 100644--- a/packages/agent-runtime/src/agent-errors.test.ts+++ b/packages/agent-runtime/src/agent-errors.test.ts@@ -318,6 +318,39 @@ describe("classifyAgentError", () => {});});+ // Spending, credit, billing, and disk quotas do not recover by backing off.+ // A bare "quota" match used to mark them PROVIDER_RATE_LIMITED and retriable.+ it.each([+ "Your organization has exceeded its monthly spending quota",+ "Your credit quota is exhausted. Please top up.",+ "Billing quota exceeded for this project",+ "disk quota exceeded",+ ])("does not retry exhausted account or disk quota: %s", (message) => {+ const classified = classifyAgentError(new Error(message));+ expect(classified).not.toMatchObject({+ code: "PROVIDER_RATE_LIMITED",+ retriable: true,+ });+ expect(classified).toMatchObject({+ code: "PROVIDER_ERROR",+ retriable: false,+ });+ });++ it.each([+ "Rate limit exceeded",+ "insufficient_quota",+ "Too many requests",+ "quota exceeded",+ "insufficient_quota: You exceeded your current quota, please check your plan and billing details.",+ "insufficient_quota: Billing quota exceeded",+ ])("keeps throughput quota wording retryable: %s", (message) => {+ expect(classifyAgentError(new Error(message))).toMatchObject({+ code: "PROVIDER_RATE_LIMITED",+ retriable: true,+ });+ });+it("keeps context checkpoint failures distinct from provider failures", () => {expect(classifyAgentError(diff --git a/packages/agent-runtime/src/agent-errors.ts b/packages/agent-runtime/src/agent-errors.tsindex 20a761956..d1b4a77da 100644--- a/packages/agent-runtime/src/agent-errors.ts+++ b/packages/agent-runtime/src/agent-errors.ts@@ -36,8 +36,27 @@ const CONTEXT_PATTERN =* reports its tokens-per-minute throttle as "Throttling error: Too many tokens,* please wait before trying again.", which `CONTEXT_PATTERN` would otherwise* read as an overflow (pi-ai's `isContextOverflow` excludes it the same way).+ *+ * A bare `quota` must not be included. It also matches account and filesystem+ * exhaustion ("monthly spending quota", "credit quota is exhausted", "Billing+ * quota exceeded", "disk quota exceeded"). Those failures do not recover by+ * backing off, but `/quota/` classified them as `PROVIDER_RATE_LIMITED` and+ * the runtime retried them up to about ten times. Throughput quotas stay+ * here: `insufficient_quota`, plus `quota exceeded` after+ * `EXHAUSTED_QUOTA_PATTERN` has taken the account and disk phrases.+ */+const RATE_LIMIT_PATTERN =+ /rate.?limit|too many requests|insufficient_quota|quota.?exceeded|overloaded|throttl/i;++/**+ * Spending, credit, billing, and disk quotas are terminal. Checked before+ * `RATE_LIMIT_PATTERN` so "quota exceeded" inside those phrases is not read+ * as a throughput throttle. `insufficient_quota` does not match this+ * pattern: the underscore is a word character, so the provider code alone+ * is not an account or disk failure.*/-const RATE_LIMIT_PATTERN = /rate.?limit|too many requests|quota|overloaded|throttl/i;+const EXHAUSTED_QUOTA_PATTERN =+ /\b(?:billing|spending|credit|disk)\s+quotas?\b/i;/*** Whether a provider message reports a context overflow.@@ -531,6 +550,14 @@ export function classifyAgentError(err: unknown): ClassifiedAgentError {if (/invalid[ _]api[ _]key|api key not valid|unauthorized|authentication|permission denied/i.test(rawMessage)) {return result("PROVIDER_UNAUTHORIZED", false);}+ // Account and disk exhaustion cannot be repaired by the rate-limit budget.+ // `insufficient_quota` is a throughput code and wins when both appear.+ if (+ EXHAUSTED_QUOTA_PATTERN.test(rawMessage) &&+ !/insufficient_quota/i.test(rawMessage)+ ) {+ return result("PROVIDER_ERROR", false);+ }if (RATE_LIMIT_PATTERN.test(rawMessage)) {return result("PROVIDER_RATE_LIMITED", true);}