{"record":{"id":"4f3ae50849c7ee56","repo":"paperclipai/paperclip","slug":"createos-command-cleanup-failed-process-termination-is","errorCode":null,"errorMessage":"CreateOS command cleanup failed; process termination is unconfirmed.","messagePattern":"CreateOS command cleanup failed; process termination is unconfirmed\\.","errorType":"exception","errorClass":"CreateosCleanupError","httpStatus":null,"severity":"error","filePath":"packages/plugins/sandbox-providers/createos/src/execute.ts","lineNumber":217,"sourceCode":"    if (signal.aborted && signal.reason?.name === \"TimeoutError\") {\n      output.finish();\n      return {\n        exitCode: null, timedOut: true, stdout: output.stdout, stderr: output.stderr,\n        metadata: { processId, outputTruncated: output.truncated },\n      };\n    }\n    if (signal.aborted) throw new Error(\"CreateOS command was cancelled.\");\n    throw error;\n  } finally {\n    const cleanupSignal = AbortSignal.timeout(client.config.timeoutMs);\n    // Do not hide a cleanup failure: the host must know containment is unproven.\n    try {\n      if (processId && !completed) {\n        try {\n          const termination = await client.json(`${base}/${processId}?grace_ms=1000`, \"DELETE\", undefined, cleanupSignal);\n          if (termination.tree_exited !== true) throw new Error(\"Process tree has not exited.\");\n        }\n        catch (error) { if (!(error instanceof CreateosApiError && error.status === 404)) throw new CreateosCleanupError(\"CreateOS command cleanup failed; process termination is unconfirmed.\"); }\n      }\n    } finally {\n      if (staged && stdinPath) {\n        // /files has no delete verb. /exec supplies a bounded, one-shot removal\n        // after the managed process finishes, without retaining another record.\n        await client.json(`/sandboxes/${id}/exec`, \"POST\", {\n          cmd: \"/bin/rm\", args: [\"-f\", \"--\", stdinPath],\n        }, cleanupSignal).catch(() => undefined);\n      }\n    }\n  }\n}\n","sourceCodeStart":199,"sourceCodeEnd":230,"githubUrl":"https://github.com/paperclipai/paperclip/blob/3f1d897a7c018d76563a21c6e39c3c9b03933622/packages/plugins/sandbox-providers/createos/src/execute.ts#L199-L230","documentation":"CreateosCleanupError thrown when post-run process termination fails for any reason other than a 404 (process already gone). The host must know that containment is unproven — the process may still be running in the sandbox. The 404 case is tolerated because a missing process means it already exited.","triggerScenarios":"DELETE /sandboxes/:id/processes/:pid fails with a network error, non-404 HTTP status, times out (cleanupSignal), or the inner 'Process tree has not exited.' error is raised — anything except CreateosApiError with status 404.","commonSituations":"Sandbox became unreachable after the run; cleanup AbortSignal.timeout(client.config.timeoutMs) fired during a slow termination; server returned 500 during termination; permission/lease state changed mid-cleanup.","solutions":["Destroy the lease entirely — treat it as poisoned, since termination is unconfirmed.","Increase client.config.timeoutMs if cleanup routinely exceeds the timeout.","Retry termination once before destroying the lease.","Check sandbox/lease status via API to confirm whether the process survived."],"exampleFix":"// before\ncatch (error) { if (!(error instanceof CreateosApiError && error.status === 404)) throw new CreateosCleanupError(\"...\"); }\n// after\ncatch (error) {\n  if (error instanceof CreateosApiError && error.status === 404) break; // already gone\n  await destroyLease(lease); // fail safe: reclaim the whole sandbox\n  throw new CreateosCleanupError(\"...\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isCreateosCleanupError(e) {\n  return e instanceof CreateosCleanupError;\n}","tryCatchPattern":"try {\n  return await execute(lease, cmd, { signal });\n} catch (e) {\n  if (isCreateosCleanupError(e)) {\n    await destroyLease(lease); // treat lease as poisoned\n  }\n  throw e;\n}","preventionTips":["Increase client timeoutMs if cleanup terminations routinely time out.","Destroy rather than reuse leases after cleanup failures.","Monitor for 5xx from the termination endpoint to catch server-side issues."],"tags":["sandbox","cleanup","timeout","containment"],"backgroundTag":"http-error-response","analyzedSha":"3f1d897a7c018d76563a21c6e39c3c9b03933622","analyzedAt":"2026-09-18T08:03:59.046Z","contentChangedAt":"2026-09-18T08:03:59.046Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}