diff --git a/server/src/__tests__/heartbeat-retry-scheduling.test.ts b/server/src/__tests__/heartbeat-retry-scheduling.test.ts index e29d44ef727..15ae4940933 100644 --- a/server/src/__tests__/heartbeat-retry-scheduling.test.ts +++ b/server/src/__tests__/heartbeat-retry-scheduling.test.ts @@ -274,6 +274,15 @@ describeEmbeddedPostgres("heartbeat bounded retry scheduling", () => { expect(await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.retryOfRunId, runId))).toHaveLength(0); }); + it("does not repeat a run whose setup is too large to start", async () => { + const runId = randomUUID(), companyId = randomUUID(), agentId = randomUUID(); + const now = new Date("2026-04-20T12:00:00.000Z"); + await seedRetryFixture({ runId, companyId, agentId, now, errorCode: "native_run_payload_too_large" }); + expect(await heartbeat.scheduleBoundedRetry(runId, { now, random: () => 0 })) + .toMatchObject({ outcome: "not_scheduled", reason: expect.stringContaining("too large to start") }); + expect(await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.retryOfRunId, runId))).toHaveLength(0); + }); + it("still retries a runner that exited for another reason", async () => { const runId = randomUUID(), companyId = randomUUID(), agentId = randomUUID(); const now = new Date("2026-04-20T12:00:00.000Z"); diff --git a/server/src/services/heartbeat/retries.ts b/server/src/services/heartbeat/retries.ts index 828c4bbd06b..cfa979a7f45 100644 --- a/server/src/services/heartbeat/retries.ts +++ b/server/src/services/heartbeat/retries.ts @@ -93,6 +93,7 @@ import type { AppendHeartbeatRunEventInput } from "../heartbeat-run-events.js"; import type { evaluateAgentInvokabilityFromDb } from "../agent-invokability.js"; import { currentRunFailureText } from "../native-runtime/native-exact-resume-failure.js"; import { NATIVE_SANDBOX_DISK_FULL, NATIVE_SANDBOX_DISK_FULL_ACTION } from "../native-runtime/native-sandbox-disk-full.js"; +import { NATIVE_RUN_PAYLOAD_TOO_LARGE, NATIVE_RUN_PAYLOAD_TOO_LARGE_ACTION } from "../native-runtime/native-run-payload-too-large.js"; import type { createHeartbeatRunState } from "./run-state.js"; import type { createHeartbeatRunPreparation } from "./run-preparation.js"; import type { createRunDispatch, PostCommitEffect } from "../../modules/run-dispatch/index.js"; @@ -546,6 +547,10 @@ export function createHeartbeatRetries(db: Db, dependencies: HeartbeatRetryDepen return { outcome: "not_scheduled" as const, reason: NATIVE_SANDBOX_DISK_FULL_ACTION, issueId: readNonEmptyString(run.contextSnapshot?.issueId) }; } + if (run.errorCode === NATIVE_RUN_PAYLOAD_TOO_LARGE) { + return { outcome: "not_scheduled" as const, reason: NATIVE_RUN_PAYLOAD_TOO_LARGE_ACTION, + issueId: readNonEmptyString(run.contextSnapshot?.issueId) }; + } if (run.errorCode === "provider_tool_definition_invalid") { return { outcome: "not_scheduled" as const, reason: "Repair the invalid tool definitions before starting a new attempt.", diff --git a/server/src/services/native-runtime/native-run-payload-too-large.test.ts b/server/src/services/native-runtime/native-run-payload-too-large.test.ts new file mode 100644 index 00000000000..7d1ea68541a --- /dev/null +++ b/server/src/services/native-runtime/native-run-payload-too-large.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, it } from "vitest"; +import { nativeSessionFailureDisposition, nativeSessionFailureSourceCode } from "./native-session-executor.js"; +import { NATIVE_RUN_PAYLOAD_TOO_LARGE } from "./native-run-payload-too-large.js"; + +describe("a native run whose setup is too large for the runner", () => { + it.each([ + "durable_prp_canonical_json_too_large", + "runner_ingress_unavailable: command_payload_too_large", + ])("stops on the first attempt for %s instead of retrying the same setup", message => { + const code = nativeSessionFailureSourceCode(new Error(message)); + expect(code).toBe(NATIVE_RUN_PAYLOAD_TOO_LARGE); + expect(nativeSessionFailureDisposition(1, new Date(), code)).toEqual({ + phase: "terminal_failure", failureCode: NATIVE_RUN_PAYLOAD_TOO_LARGE, nextAttemptAt: null }); + }); + + it("finds the oversized setup inside a wrapped runner failure", () => { + const wrapped = new Error("runner_ingress_unavailable: runnerd exited", { cause: new Error("durable_prp_canonical_json_too_large") }); + expect(nativeSessionFailureSourceCode(wrapped)).toBe(NATIVE_RUN_PAYLOAD_TOO_LARGE); + const aggregate = new AggregateError([new Error("unrelated"), new Error("command_payload_too_large")], "transport failed"); + expect(nativeSessionFailureSourceCode(aggregate)).toBe(NATIVE_RUN_PAYLOAD_TOO_LARGE); + }); + + it("keeps naming the oversized setup when the sandbox disk is also full", () => { + expect(nativeSessionFailureSourceCode(new Error("durable_prp_canonical_json_too_large"), true)).toBe(NATIVE_RUN_PAYLOAD_TOO_LARGE); + }); +}); diff --git a/server/src/services/native-runtime/native-run-payload-too-large.ts b/server/src/services/native-runtime/native-run-payload-too-large.ts new file mode 100644 index 00000000000..7b67fb944ab --- /dev/null +++ b/server/src/services/native-runtime/native-run-payload-too-large.ts @@ -0,0 +1,17 @@ +export const NATIVE_RUN_PAYLOAD_TOO_LARGE = "native_run_payload_too_large" as const; + +export const NATIVE_RUN_PAYLOAD_TOO_LARGE_ACTION = + "This agent's run setup is too large to start. Its connected tools, its instructions or its skills and context " + + "together exceed what one run can carry. Paperclip does not repeat this automatically, because the same setup " + + "would fail again. Turn off connectors or skills this agent does not need, or shorten its instructions, then press Retry."; + +const RUN_PAYLOAD_TOO_LARGE = /durable_prp_canonical_json_too_large|command_payload_too_large/; + +export function isNativeRunPayloadTooLarge(error: unknown, depth = 0): boolean { + if (typeof error === "string") return RUN_PAYLOAD_TOO_LARGE.test(error); + if (!error || typeof error !== "object" || depth > 5) return false; + const value = error as { cause?: unknown; errors?: unknown; message?: unknown }; + if (typeof value.message === "string" && RUN_PAYLOAD_TOO_LARGE.test(value.message)) return true; + return isNativeRunPayloadTooLarge(value.cause, depth + 1) + || (Array.isArray(value.errors) && value.errors.slice(0, 3).some(item => isNativeRunPayloadTooLarge(item, depth + 1))); +} diff --git a/server/src/services/native-runtime/native-sandbox-disk-full.ts b/server/src/services/native-runtime/native-sandbox-disk-full.ts index 4dd676d932f..c13731ff606 100644 --- a/server/src/services/native-runtime/native-sandbox-disk-full.ts +++ b/server/src/services/native-runtime/native-sandbox-disk-full.ts @@ -1,6 +1,7 @@ import { JsonRpcCallError, PLUGIN_RPC_ERROR_CODES } from "@paperclipai/plugin-sdk"; import { isSandboxDiskFullFailure } from "../../vendor/paperclip-runner/index.js"; import { isSandboxDiskFullText } from "./remote-runner-disk-reserve.js"; +import { NATIVE_RUN_PAYLOAD_TOO_LARGE } from "./native-run-payload-too-large.js"; export const NATIVE_SANDBOX_DISK_FULL = "sandbox_disk_full" as const; @@ -10,6 +11,7 @@ export const NATIVE_SANDBOX_DISK_FULL_ACTION = + "for example by deleting build output, caches or dependencies it no longer needs, then press Retry."; const CODES_THAT_KEEP_THEIR_MEANING: ReadonlySet = new Set([ + NATIVE_RUN_PAYLOAD_TOO_LARGE, "native_permission_declined", "native_provider_approval_required", "native_provider_usage_limit", diff --git a/server/src/services/native-runtime/native-session-executor.ts b/server/src/services/native-runtime/native-session-executor.ts index f4eab528a35..8ea78f0d81e 100644 --- a/server/src/services/native-runtime/native-session-executor.ts +++ b/server/src/services/native-runtime/native-session-executor.ts @@ -8,6 +8,7 @@ import { nativeLeaseHolder, notifyNativeTokenLeaseClaimed } from "./native-token import { captureRemoteNativeProviderArtifacts, shareNativeProviderArtifactCapture } from "./native-provider-artifact-capture.js"; import { NativeSessionDiagnostics, nativeSessionDiagnostics, type NativeDiagnosticLease } from "./native-session-diagnostics.js"; import { NATIVE_SANDBOX_DISK_FULL, NATIVE_SANDBOX_DISK_FULL_ACTION, nativeSandboxDiskFullSourceCode } from "./native-sandbox-disk-full.js"; +import { isNativeRunPayloadTooLarge, NATIVE_RUN_PAYLOAD_TOO_LARGE, NATIVE_RUN_PAYLOAD_TOO_LARGE_ACTION } from "./native-run-payload-too-large.js"; import { runFailureMessage } from "@paperclipai/shared"; import { recordAgentProviderRateLimits } from "../agent-provider-rate-limits.js"; import { nativePostResultFailureCategory, type NativePostResultFailureCategory } from "./native-post-result-failure.js"; @@ -9087,7 +9088,8 @@ export function nativeSessionFailureDisposition( sourceFailureCode === NATIVE_PROVIDER_SESSION_CLOSED || sourceFailureCode === NATIVE_PROVIDER_STARTUP_REJECTED || sourceFailureCode === NATIVE_CONTROLLER_JOURNAL_BEHIND_RUNNER || - sourceFailureCode === NATIVE_SANDBOX_DISK_FULL; + sourceFailureCode === NATIVE_SANDBOX_DISK_FULL || + sourceFailureCode === NATIVE_RUN_PAYLOAD_TOO_LARGE; const permissionDeclined = sourceFailureCode === "native_permission_declined"; const exhausted = permanentFailure || permissionDeclined || attempt >= 3; return { @@ -9289,6 +9291,7 @@ function classifyNativeSessionFailure( error: unknown, ): | "native_permission_declined" + | typeof NATIVE_RUN_PAYLOAD_TOO_LARGE | "native_provider_terminal_failed" | "native_governed_wait_settlement_pending" | typeof NATIVE_PROVIDER_STATE_INCOMPATIBLE @@ -9371,6 +9374,7 @@ function classifyNativeSessionFailure( if (runnerClosedTurnStartSession(error)) return NATIVE_PROVIDER_SESSION_CLOSED; const message = error instanceof Error ? error.message : String(error); if (/"code":"controller_sequence_mismatch"/.test(message)) return NATIVE_CONTROLLER_JOURNAL_BEHIND_RUNNER; + if (isNativeRunPayloadTooLarge(error)) return NATIVE_RUN_PAYLOAD_TOO_LARGE; if (/^(?:runner_ingress_unavailable: runnerd exited unexpectedly with code 1: )?runner_task_admission_rejected: (session_state_unavailable|account_binding_mismatch)$/.test(message)) { return "runner_task_admission_rejected"; } @@ -13610,6 +13614,8 @@ async function executePaperclipNativeSessionAttempt( ? "The computer provider rejected access. Restore the environment's credentials or permissions before retrying. Automatic retries are stopped." : sourceFailureCode === NATIVE_SANDBOX_DISK_FULL ? NATIVE_SANDBOX_DISK_FULL_ACTION + : sourceFailureCode === NATIVE_RUN_PAYLOAD_TOO_LARGE + ? NATIVE_RUN_PAYLOAD_TOO_LARGE_ACTION : sourceFailureCode === "native_provider_terminal_failed" ? "The provider session is permanently unusable. Verify stopped execution, completed actions, and task context before starting a linked continuation." : sourceFailureCode === "native_governed_wait_settlement_pending" @@ -13902,6 +13908,8 @@ async function executePaperclipNativeSessionAttempt( ? "The computer provider rejected access. Restore the environment's credentials or permissions before retrying. Automatic retries are stopped." : sourceFailureCode === NATIVE_SANDBOX_DISK_FULL ? NATIVE_SANDBOX_DISK_FULL_ACTION + : sourceFailureCode === NATIVE_RUN_PAYLOAD_TOO_LARGE + ? NATIVE_RUN_PAYLOAD_TOO_LARGE_ACTION : sourceFailureCode === "native_provider_terminal_failed" ? "Verify that the failed provider stopped and reconcile its action outcomes. A linked continuation can proceed only after these checks succeed." : sourceFailureCode === "native_provider_model_rejected" && !recoveryEvidence.providerSessionEstablished