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",