mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 22:49:00 +01:00
fix(runs): stop retrying a run whose setup is too large to start (#22707)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - When a managed run fails, Paperclip classifies the failure to decide
whether to retry it
> - A run whose setup exceeded the runner's durable limits failed with
`durable_prp_canonical_json_too_large`, which was classified as an
interrupted session
> - Paperclip retried it three times and then continued the task in a
fresh session that failed the same way: one agent produced 20 failed
runs in a few minutes, and the task showed a raw internal code
> - This pull request classifies oversized run setups as a permanent
failure with a plain-language action
> - The benefit is no pointless retries, and the user learns what to
change
## Linked Issues or Issue Description
**What happened?**
An agent's run setup was larger than the runner's durable control plane
accepts. Each attempt failed in seconds with
`durable_prp_canonical_json_too_large`. Paperclip scheduled retries and
fresh-session continuations that could never succeed, and the task
showed the raw code.
**Expected behavior**
A failure that the same input will always repeat is not retried. The
user sees what to change.
**Steps to reproduce**
1. Classify `new Error("durable_prp_canonical_json_too_large")` with
`nativeSessionFailureSourceCode`.
2. The disposition is `retryable_failure` with
`native_session_interrupted`.
## What Changed
- New `native-run-payload-too-large.ts`: the
`native_run_payload_too_large` code, its user-facing action, and the
matcher for `durable_prp_canonical_json_too_large` and
`command_payload_too_large`.
- `native-session-executor.ts`: classify those errors as
`native_run_payload_too_large`, treat it as permanent, and show the
action.
- `heartbeat/retries.ts`: do not schedule a retry for it.
- `native-sandbox-disk-full.ts`: a full disk does not relabel this code.
- Tests for classification, disposition and retry scheduling.
## Verification
- `npx vitest run
src/services/native-runtime/native-run-payload-too-large.test.ts
src/__tests__/heartbeat-retry-scheduling.test.ts`: 75 passed.
- Red/green: without the change, 4 of the new assertions fail.
- The underlying size mismatch is fixed separately in
paperclipai/paperclip#22705. This change makes any future deterministic
size failure stop at once instead of looping.
## Risks
- Low. Only these two deterministic size errors change classification.
All other failures keep their existing retry behavior.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), via Claude Code, with tool use.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bda1bf7b52
commit
1363b557b9
6 files changed
+68
-1
No files matched your search
@@ -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");
|
||||
|
||||
@@ -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.",
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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)));
|
||||
}
|
||||
@@ -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<string> = new Set([
|
||||
NATIVE_RUN_PAYLOAD_TOO_LARGE,
|
||||
"native_permission_declined",
|
||||
"native_provider_approval_required",
|
||||
"native_provider_usage_limit",
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user