Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(agent-runtime): classify host capacity exhaustion distinctly from provider auth failures

Totopo27dedc5c4482b9
diff --git a/packages/agent-runtime/src/agent-errors.test.ts b/packages/agent-runtime/src/agent-errors.test.ts
index 427606724..707f33832 100644
--- a/packages/agent-runtime/src/agent-errors.test.ts
+++ b/packages/agent-runtime/src/agent-errors.test.ts
@@ -558,4 +558,32 @@ describe("classifyAgentError", () => {
).details,
).not.toHaveProperty("networkHost");
});
+
+ it("classifies host capacity exhaustion and timeout distinctly from provider failures (#1071)", () => {
+ // Error caused by host RPC slot exhaustion during credential/config resolution
+ const overloadError = new Error(
+ "API key auth failed for provider chatgpt: host RPC capacity is exhausted",
+ );
+ expect(classifyAgentError(overloadError)).toMatchObject({
+ code: "HOST_OVERLOADED",
+ retriable: true,
+ details: { origin: "host" },
+ });
+
+ const typedOverload = Object.assign(new Error("RPC failed"), {
+ errorCode: "HOST_OVERLOADED",
+ });
+ expect(classifyAgentError(typedOverload)).toMatchObject({
+ code: "HOST_OVERLOADED",
+ retriable: true,
+ details: { origin: "host" },
+ });
+
+ const unavailableError = new Error("host RPC timeout: session.appendMessage");
+ expect(classifyAgentError(unavailableError)).toMatchObject({
+ code: "HOST_UNAVAILABLE",
+ retriable: true,
+ details: { origin: "host" },
+ });
+ });
});
diff --git a/packages/agent-runtime/src/agent-errors.ts b/packages/agent-runtime/src/agent-errors.ts
index 23be7093c..05bc51886 100644
--- a/packages/agent-runtime/src/agent-errors.ts
+++ b/packages/agent-runtime/src/agent-errors.ts
@@ -8,7 +8,7 @@
* "error") and the rejected-promise paths.
*/
-import { isCertificateVerificationError } from "@pi-desktop/shared";
+import { ErrorCodes, isCertificateVerificationError } from "@pi-desktop/shared";
import { readLocalRequestErrorDetails } from "./local-request-errors.js";
export type ClassifiedAgentError = {
@@ -93,6 +93,9 @@ function hasNetworkCause(err: unknown, message: string): boolean {
function extractErrorCode(err: unknown): string | number | undefined {
let current: any = err;
for (let depth = 0; depth < 4 && current; depth += 1) {
+ if (typeof current.errorCode === "string" && /^[A-Za-z0-9_.:-]{1,64}$/.test(current.errorCode)) {
+ return current.errorCode;
+ }
if (typeof current.code === "number") {
return Number.isSafeInteger(current.code) ? current.code : undefined;
}
@@ -448,6 +451,19 @@ export function classifyAgentError(err: unknown): ClassifiedAgentError {
);
}
+ if (
+ providerCode === ErrorCodes.HOST_OVERLOADED ||
+ /host RPC capacity is exhausted|HOST_OVERLOADED/i.test(rawMessage)
+ ) {
+ return result(ErrorCodes.HOST_OVERLOADED, true, { origin: "host" });
+ }
+ if (
+ providerCode === ErrorCodes.HOST_UNAVAILABLE ||
+ /host RPC unavailable|host-core is unavailable|host RPC timeout/i.test(rawMessage)
+ ) {
+ return result(ErrorCodes.HOST_UNAVAILABLE, true, { origin: "host" });
+ }
+
// The adapter itself refuses how the request was built, so re-sending it
// produces the identical failure. Probed before the status table so a status
// some layer attached to the same message cannot re-arm the retry budget.