{"record":{"id":"825e18f0f8b59185","repo":"paperclipai/paperclip","slug":"failed-to-stop-daytona-sandbox-during-lease-releas","errorCode":null,"errorMessage":"Failed to stop Daytona sandbox during lease release: ${formatErrorMessage(error)}. Attempting delete instead.","messagePattern":"Failed to stop Daytona sandbox during lease release: (.+?)\\. Attempting delete instead\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/plugins/sandbox-providers/daytona/src/plugin.ts","lineNumber":2243,"sourceCode":"      if (!sandbox) return;\n\n      evictSandboxHandle(scope);\n      await sandboxHandleActivityGates.waitForIdle(scope);\n      await teardownSession(sandbox, scope);\n      // Close every duplex channel on this lease before the stop or the delete,\n      // so no channel outlives the sandbox and no stored channel id survives.\n      await closeDaytonaDuplexChannelsForLease(params.providerLeaseId);\n\n      if (config.reuseLease) {\n        if (sandbox.state !== \"stopped\") {\n          try {\n            await sandbox.stop(toTimeoutSeconds(config.timeoutMs));\n          } catch (error) {\n            console.warn(\n              `Failed to stop Daytona sandbox during lease release: ${formatErrorMessage(error)}. Attempting delete instead.`,\n            );\n            await sandbox.delete(toTimeoutSeconds(config.timeoutMs)).catch((deleteError) => {\n              console.warn(\n                `Failed to delete Daytona sandbox after stop failure: ${formatErrorMessage(deleteError)}`,\n              );\n            });\n          }\n        }\n        return;\n      }\n\n      if (config.archiveOnRelease) {\n        try {\n          if (sandbox.state !== \"stopped\") {\n            await sandbox.stop(toTimeoutSeconds(config.timeoutMs));\n          }\n          await sandbox.setAutoDeleteInterval(ARCHIVE_ON_RELEASE_AUTO_DELETE_MINUTES);\n          await sandbox.archive();\n          return;\n        } catch (error) {\n          console.warn(","sourceCodeStart":2225,"sourceCodeEnd":2261,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/packages/plugins/sandbox-providers/daytona/src/plugin.ts#L2225-L2261","documentation":"During Daytona sandbox lease release with reuseLease=true, the plugin calls sandbox.stop() to preserve the sandbox for reuse. If stop() throws (API error, timeout, sandbox already gone server-side), it logs this warning and falls back to sandbox.delete() so the sandbox does not leak; if delete also fails, a follow-up warning fires and the sandbox may be orphaned.","triggerScenarios":"reuseLease=true, sandbox state is not 'stopped', and sandbox.stop(toTimeoutSeconds(config.timeoutMs)) rejects — Daytona API 5xx/timeout, sandbox expired or already deleted remotely, or network interruption between paperclip and Daytona.","commonSituations":"Daytona cloud incident or rate limiting; timeoutMs too small for the sandbox to shut down; sandbox expired server-side while the lease still references it; stale local state after Daytona workspace events.","solutions":["Check the sandbox's real state in the Daytona dashboard; if the follow-up delete warning also fired, delete the orphan manually.","Increase the plugin's timeoutMs so stop/delete have room to complete.","Check Daytona service status and API credentials if failures repeat.","If sandbox reuse is not required, set reuseLease=false so release deletes directly and stop is never the dependent step."],"exampleFix":"// before (daytona sandbox provider config)\n{ \"reuseLease\": true, \"timeoutMs\": 5000 }\n\n// after\n{ \"reuseLease\": true, \"timeoutMs\": 30000 }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await lease.release();\n} catch (err) {\n  // Stop-failure already fell back to delete inside the plugin; verify the sandbox\n  // is actually gone before treating the release as clean.\n  const stillExists = await daytonaClient.sandboxExists(lease.sandboxId);\n  if (stillExists) {\n    await janitor.queueManualDelete(lease.sandboxId); // reconcile later\n  }\n}","preventionTips":["Watch for the follow-up 'Failed to delete Daytona sandbox after stop failure' warn — that pair means a true orphan.","Run a periodic reconciliation job comparing Daytona sandboxes against active leases.","Size timeoutMs above the p99 sandbox stop/delete latency.","Prefer reuseLease=false unless reuse is a measured requirement — it removes stop() from the release path."],"tags":["daytona","sandbox","lease-release","stop-failed","timeout"],"backgroundTag":"sandbox-teardown-failure","analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}