From c669cfca1768370a480b837b61e78c9139604db8 Mon Sep 17 00:00:00 2001 From: paperclipbugbot Date: Fri, 20 Nov 2026 07:22:28 -0800 Subject: [PATCH] fix(native): name a full sandbox disk that fails a run during setup (#22383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Native agent runs execute in a managed sandbox with a fixed disk size > - After a server restart, Paperclip reconnects to the running agent. The reconnect opens a new process session in the sandbox through the sandbox provider plugin > - When the agent filled the sandbox disk, the provider refuses that call with "no space left on device" > - The setup failure path did not recognize this refusal. The run failed as the generic `setup_failed`, and the task showed no useful explanation > - #22239 names `sandbox_disk_full` when the runner reports a full disk during a turn. It does not cover a refusal that reaches the setup failure path > - This pull request names that refusal `sandbox_disk_full` in the setup failure path, and keeps continuation recovery from repeating such a run > - The benefit is that the task tells the user what to do in plain language, and Paperclip does not repeat work that fills the same disk again ## Linked Issues or Issue Description Refs #22239 (names a full sandbox disk during a turn). This PR covers the setup failure path. **What happened?** A native agent ran a large dependency installation in its Daytona sandbox. A server restart then happened. The reconnect could not open a process session. The Daytona plugin returned `JsonRpcCallError` (-32002): `internal server error: failed to create session config directory: mkdir /home/daytona/.daytona/sessions/...: no space left on device`. The run failed with `setup_failed` in the `setup` phase. The Sentry report grouped it with unrelated `setup_failed` plugin errors. **Expected behavior** The run failure names `sandbox_disk_full`. The task shows the existing plain-language action (free disk space through the agent, then press Retry). Automatic retry and generic continuation recovery do not repeat the work on a sandbox of the same size. A full disk on the Paperclip host keeps its own code. **Steps to reproduce** 1. Start a native run in a managed sandbox. 2. Let the agent fill the sandbox disk. 3. Restart the server while the run is active. 4. See the reconnect fail with "no space left on device" and the run fail as `setup_failed`. ## What Changed - `native-sandbox-disk-full.ts`: add `isSandboxProviderDiskFullError`. It is true for the runner's named `sandbox_disk_full` failure, or for a plugin worker error (`JsonRpcCallError`, code `WORKER_ERROR`) whose message reports a full disk. It reads the error, its causes and the first entries of an `AggregateError`. - `run-completion.ts`: the setup failure ladder uses `sandbox_disk_full` for that error before the generic `setup_failed` fallback. Named setup codes and `storage_unavailable` keep their precedence. - `recovery/service.ts`: add `sandbox_disk_full` to the codes that generic continuation recovery does not repeat. `setup_failed` was already in this set, so the new code does not open a new automatic path. This also applies to the turn failures that #22239 names. - Tests for the helper, the setup ladder (with a real database) and the continuation classification. ## Verification - In `server/`: `pnpm vitest run src/services/heartbeat/run-completion.test.ts src/services/native-runtime/native-sandbox-disk-full.test.ts src/services/recovery/provider-failure-classification.test.ts src/__tests__/failed-continuation-continues-again.test.ts src/__tests__/heartbeat-retry-scheduling.test.ts`: 5 files, 312 tests pass. - Red check: without the `run-completion.ts` change, the new setup test fails with `errorCode: "setup_failed"`, the same code as the observed failure. Without the helper and recovery change, the helper and continuation tests fail. - The local layered typecheck could not finish: the sandbox memory limit stopped its largest layer. CI runs the typecheck. ## Risks - Low to medium. The change only renames a setup failure that was already terminal and not retried. It uses an existing code that already has retry and UI handling. - A plugin worker error that reports a full disk on the Paperclip host (not in the sandbox) gets `sandbox_disk_full`. This is unlikely: host storage failures use `storage_unavailable`, which keeps precedence. - Generic continuation recovery no longer repeats a turn failure named `sandbox_disk_full`. This matches the intent of #22239. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), with tool use and code execution. ## 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 - [ ] 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: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- .../services/heartbeat/run-completion.test.ts | 19 +++++++++++- .../src/services/heartbeat/run-completion.ts | 3 ++ .../native-sandbox-disk-full.test.ts | 31 ++++++++++++++++++- .../native-sandbox-disk-full.ts | 16 ++++++++++ .../provider-failure-classification.test.ts | 6 ++++ server/src/services/recovery/service.ts | 2 ++ 6 files changed, 75 insertions(+), 2 deletions(-) diff --git a/server/src/services/heartbeat/run-completion.test.ts b/server/src/services/heartbeat/run-completion.test.ts index a2f603c9ea4..9060da01bd9 100644 --- a/server/src/services/heartbeat/run-completion.test.ts +++ b/server/src/services/heartbeat/run-completion.test.ts @@ -31,7 +31,7 @@ import { EnvironmentRunError, environmentRunOrchestrator } from "../environment- import { ReusableSandboxResumeError } from "../reusable-sandbox-resume-error.js"; import { PluginWorkerUnavailableError } from "../plugin-worker-unavailable-error.js"; import { ReviewedChatBindingDeniedError, ReviewedChatBindingNotReadyError } from "../reviewed-chat-binding-diagnostics.js"; -import { environmentTaskErrorCodeData, JsonRpcCallError, PluginEnvironmentTaskError, PluginWorkspaceOperationError, workspaceOperationErrorData } from "@paperclipai/plugin-sdk"; +import { environmentTaskErrorCodeData, JsonRpcCallError, PLUGIN_RPC_ERROR_CODES, PluginEnvironmentTaskError, PluginWorkspaceOperationError, workspaceOperationErrorData } from "@paperclipai/plugin-sdk"; import { RUNNER_REVISION_MISMATCH_RETRY } from "../runner-revision-mismatch.js"; import { STORAGE_CREDENTIALS_REJECTED_HELD_MESSAGE, STORAGE_UNAVAILABLE_CODE, STORAGE_UNAVAILABLE_EXHAUSTED_MESSAGE, STORAGE_UNAVAILABLE_HELD_MESSAGE, STORAGE_UNAVAILABLE_MESSAGE, STORAGE_UNAVAILABLE_RETRY } from "../../storage/storage-unavailable.js"; import { withS3FailureDiagnostics } from "../../storage/s3-failure.js"; @@ -1131,6 +1131,23 @@ describe.skipIf(!support.supported && !process.env.PAPERCLIP_TEST_DATABASE_URL)( expect(f.deps.finalizeIssueCommentPolicy).not.toHaveBeenCalled(); }); + it("names a full sandbox disk that the sandbox provider reported during setup", async () => { + const f = await fixture(); + const refusal = new JsonRpcCallError({ code: PLUGIN_RPC_ERROR_CODES.WORKER_ERROR, + message: "internal server error: failed to create session config directory: " + + "mkdir /home/daytona/.daytona/sessions/paperclip-78f6ce53: no space left on device" }); + await f.completion.failRunSetup(f.setup(new Error("Could not reconnect to the running agent", { cause: refusal }))); + const failed = await read(f.run.id); + expect(failed).toMatchObject({ status: "failed", errorCode: "sandbox_disk_full" }); + expect(failed?.resultJson).not.toHaveProperty("failureCause"); + }); + + it("keeps a full disk on the Paperclip host out of the sandbox disk code", async () => { + const f = await fixture(); + await f.completion.failRunSetup(f.setup(Object.assign(new Error("ENOSPC: no space left on device, write"), { code: "ENOSPC" }))); + expect((await read(f.run.id))?.errorCode).not.toBe("sandbox_disk_full"); + }); + it("records a setup configuration gap without inventing provider work or applying comment policy", async () => { const f = await fixture(); await f.completion.failRunSetup(f.setup(new ConfigurationIncompleteFailure("missing credential", { configurationIncomplete: { reason: "missing_binding" } }))); diff --git a/server/src/services/heartbeat/run-completion.ts b/server/src/services/heartbeat/run-completion.ts index 67b57d35159..40e289dbc66 100644 --- a/server/src/services/heartbeat/run-completion.ts +++ b/server/src/services/heartbeat/run-completion.ts @@ -7,6 +7,7 @@ import { INTERRUPTED_PREPARATION_RETRY_REASON } from "../execution-recovery-atte import { PREDECESSOR_RETIREMENT_FALLBACK_KEY, readPredecessorRetirementFallback, type PredecessorRetirementFallback } from "../native-runtime/predecessor-retirement.js"; import { releaseUnchangedFallbackWorkspace } from "./predecessor-retirement-fallback.js"; import { hasNativeExecutionStartEvidence } from "../native-runtime/native-restart-recovery.js"; +import { isSandboxProviderDiskFullError, NATIVE_SANDBOX_DISK_FULL } from "../native-runtime/native-sandbox-disk-full.js"; import { withoutSqlStatementText } from "@paperclipai/shared"; import { nativeTaskSessionPublicationHandled } from "../native-runtime/native-task-session-publication.js"; import { boundOriginalMessage, describeRefusedExactResume, interruptedExactResumeCause } from "../native-runtime/native-exact-resume-failure.js"; @@ -1675,6 +1676,7 @@ export function createHeartbeatRunCompletion(db: Db, dependencies: HeartbeatRunC ? outerErr : null; const runnerRevisionMismatch = !providerDispatchStarted && run.runtimeMode === "legacy" && run.nativeSessionId === null && run.runnerInstanceId === null && isRunnerRevisionMismatch(outerErr); + const sandboxDiskFull = !storageUnavailable && isSandboxProviderDiskFullError(outerErr); // A lease lost while AI selection rejected the account does not make the // run retryable: every host repeats that rejection until its owner acts. const ownedAiSelectionRejection = isOwnedAiConnectionSelectionRejection( @@ -1699,6 +1701,7 @@ export function createHeartbeatRunCompletion(db: Db, dependencies: HeartbeatRunC : null) ?? recordedResponsibleUserDenialCode ?? nonRetryablePreflightCode ?? + (sandboxDiskFull ? NATIVE_SANDBOX_DISK_FULL : null) ?? "setup_failed"; const failureCause = GENERIC_RUN_FAILURE_CODES.has(setupFailureErrorCode) ? thrownFailureCause : null; // Bounded kind and reason only: a workspace provider's own text never crosses into Core. diff --git a/server/src/services/native-runtime/native-sandbox-disk-full.test.ts b/server/src/services/native-runtime/native-sandbox-disk-full.test.ts index 14e5acdcbe1..0999c91c73c 100644 --- a/server/src/services/native-runtime/native-sandbox-disk-full.test.ts +++ b/server/src/services/native-runtime/native-sandbox-disk-full.test.ts @@ -1,7 +1,8 @@ import { describe, expect, it } from "vitest"; import { NativeProviderTerminalFailure, NativeSessionProtocolIntegrityError, SANDBOX_DISK_FULL_FAILURE_CODE } from "../../vendor/paperclip-runner/index.js"; import { nativeSessionFailureDisposition, nativeSessionFailureSourceCode } from "./native-session-executor.js"; -import { NATIVE_SANDBOX_DISK_FULL } from "./native-sandbox-disk-full.js"; +import { JsonRpcCallError, PLUGIN_RPC_ERROR_CODES } from "@paperclipai/plugin-sdk"; +import { isSandboxProviderDiskFullError, NATIVE_SANDBOX_DISK_FULL } from "./native-sandbox-disk-full.js"; import { NativeSessionDiagnostics } from "./native-session-diagnostics.js"; const turnLostOnRestore = () => new NativeProviderTerminalFailure("provider_turn_lost_on_restore", true); @@ -69,3 +70,31 @@ describe("a native run that ends because its sandbox disk filled", () => { expect(NATIVE_SANDBOX_DISK_FULL).toBe(SANDBOX_DISK_FULL_FAILURE_CODE); }); }); + +describe("a run setup that the sandbox provider refused because the sandbox disk is full", () => { + const daytonaRefusal = () => new JsonRpcCallError({ code: PLUGIN_RPC_ERROR_CODES.WORKER_ERROR, + message: "internal server error: failed to create session config directory: " + + "mkdir /home/daytona/.daytona/sessions/paperclip-78f6ce53: no space left on device" }); + + it("names the full disk from the provider plugin's refusal, also when it is wrapped", () => { + expect(isSandboxProviderDiskFullError(daytonaRefusal())).toBe(true); + expect(isSandboxProviderDiskFullError(new Error("Reconnect failed", { cause: daytonaRefusal() }))).toBe(true); + expect(isSandboxProviderDiskFullError(new AggregateError([new Error("other"), daytonaRefusal()], "setup failed"))).toBe(true); + }); + + it("names the full disk from the runner's named failure", () => { + const launch = Object.assign(new Error("sandbox_disk_full: the sandbox disk is full, so the runner cannot be started"), + { code: SANDBOX_DISK_FULL_FAILURE_CODE }); + expect(isSandboxProviderDiskFullError(new Error("setup failed", { cause: launch }))).toBe(true); + }); + + it("keeps a full disk on the Paperclip host and other plugin errors as they are", () => { + const hostDisk = Object.assign(new Error("ENOSPC: no space left on device, write"), { code: "ENOSPC" }); + expect(isSandboxProviderDiskFullError(hostDisk)).toBe(false); + expect(isSandboxProviderDiskFullError(new JsonRpcCallError({ code: PLUGIN_RPC_ERROR_CODES.WORKER_ERROR, + message: "unauthorized: authentication failed: Bearer token validation error" }))).toBe(false); + expect(isSandboxProviderDiskFullError(new JsonRpcCallError({ code: PLUGIN_RPC_ERROR_CODES.TIMEOUT, + message: "no space left on device" }))).toBe(false); + expect(isSandboxProviderDiskFullError(null)).toBe(false); + }); +}); 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 2ca342e055e..4dd676d932f 100644 --- a/server/src/services/native-runtime/native-sandbox-disk-full.ts +++ b/server/src/services/native-runtime/native-sandbox-disk-full.ts @@ -1,3 +1,4 @@ +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"; @@ -46,6 +47,21 @@ function diskFullCause(error: unknown, depth = 0): boolean { || (Array.isArray(value.errors) && value.errors.slice(0, 3).some(item => diskFullCause(item, depth + 1))); } +function sandboxProviderDiskFullCause(error: unknown, depth = 0): boolean { + if (!error || typeof error !== "object" || depth > 5) return false; + if (isSandboxDiskFullFailure(error)) return true; + if (error instanceof JsonRpcCallError && error.code === PLUGIN_RPC_ERROR_CODES.WORKER_ERROR + && isNativeSandboxDiskFullReport(error.message)) return true; + const value = error as { cause?: unknown; errors?: unknown; message?: unknown }; + if (typeof value.message === "string" && NAMED_DISK_FULL_FAILURE.test(value.message)) return true; + return sandboxProviderDiskFullCause(value.cause, depth + 1) + || (Array.isArray(value.errors) && value.errors.slice(0, 3).some(item => sandboxProviderDiskFullCause(item, depth + 1))); +} + +export function isSandboxProviderDiskFullError(error: unknown): boolean { + return sandboxProviderDiskFullCause(error); +} + export function nativeSandboxDiskFullSourceCode( code: T, error: unknown, diff --git a/server/src/services/recovery/provider-failure-classification.test.ts b/server/src/services/recovery/provider-failure-classification.test.ts index d072b3d93a5..e5bbc75b273 100644 --- a/server/src/services/recovery/provider-failure-classification.test.ts +++ b/server/src/services/recovery/provider-failure-classification.test.ts @@ -232,4 +232,10 @@ describe("classifyAdapterFailureForRecovery", () => { expect(classifyAdapterFailureForRecovery(run)).toEqual({ kind: "configuration_incomplete" }); expect(classifyContinuationFailure(run as never)).toMatchObject({ kind: "non_retryable", maxAttempts: 0 }); }); + it("does not continue a run that filled its sandbox disk", () => { + const run = { errorCode: "sandbox_disk_full", + error: "internal server error: failed to create session config directory: mkdir /home/daytona/.daytona/sessions/x: no space left on device", + resultJson: null }; + expect(classifyContinuationFailure(run as never)).toMatchObject({ kind: "non_retryable", maxAttempts: 0 }); + }); }); diff --git a/server/src/services/recovery/service.ts b/server/src/services/recovery/service.ts index ffdabb24fe3..7a92f5e196d 100644 --- a/server/src/services/recovery/service.ts +++ b/server/src/services/recovery/service.ts @@ -17,6 +17,7 @@ import { REUSABLE_SANDBOX_RESUME_FAILED_CODE } from "../reusable-sandbox-resume- import { PLUGIN_WORKER_UNAVAILABLE_CODE } from "../plugin-worker-unavailable-error.js"; import { ENVIRONMENT_PROVIDER_UNAVAILABLE_CODE } from "../environment-provider-unavailable-error.js"; import { RUNNER_REVISION_MISMATCH_CODE } from "../runner-revision-mismatch.js"; +import { NATIVE_SANDBOX_DISK_FULL } from "../native-runtime/native-sandbox-disk-full.js"; import { recoveryRunContextColumn, recoveryRunVersionColumn } from "./run-context-read.js"; import { recoveryRunResultColumn } from "./run-result-read.js"; import { readLegacyDispositionSource } from "./legacy-disposition-read.js"; @@ -618,6 +619,7 @@ const NON_RETRYABLE_CONTINUATION_ERROR_CODES = new Set([ "project_access_denied", "native_provider_model_rejected", "provider_tool_definition_invalid", + NATIVE_SANDBOX_DISK_FULL, "adapter_engine_unavailable", "agent_not_invokable", "agent_not_found",