{"record":{"id":"abf6e90e8bc2513c","repo":"paperclipai/paperclip","slug":"failed-to-record-pending-sandbox-cleanup-lease","errorCode":null,"errorMessage":"Failed to record pending sandbox cleanup lease","messagePattern":"Failed to record pending sandbox cleanup lease","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/environments.ts","lineNumber":1632,"sourceCode":"      const row = await db.transaction(async (tx) => {\n        // Lock the environment row so a concurrent delete cannot commit between\n        // this read and the insert. An absent row means a delete already removed\n        // the environment, so record the orphan with a null reference.\n        const environmentRows = await tx\n          .select({ id: environments.id })\n          .from(environments)\n          .where(eq(environments.id, input.environmentId))\n          .for(\"update\");\n        const environmentIdForRow = environmentRows[0]?.id ?? null;\n        return tx\n          .insert(environmentLeases)\n          .values({\n            companyId: input.companyId,\n            environmentId: environmentIdForRow,\n            executionWorkspaceId: input.executionWorkspaceId ?? null,\n            issueId: input.issueId ?? null,\n            heartbeatRunId: input.heartbeatRunId ?? null,\n            status: \"pending_cleanup\" as const,\n            leasePolicy: \"ephemeral\",\n            provider: input.provider ?? null,\n            providerLeaseId: input.providerLeaseId ?? null,\n            acquiredAt: now,\n            lastUsedAt: now,\n            expiresAt: null,\n            releasedAt: now,\n            failureReason: input.failureReason,\n            cleanupStatus: \"failed\",\n            metadata: input.metadata ?? null,\n            createdAt: now,\n            updatedAt: now,\n          })\n          .returning()\n          .then((rows) => rows[0] ?? null);\n      });\n      if (!row) {\n        throw new Error(\"Failed to record pending sandbox cleanup lease\");","sourceCodeStart":1614,"sourceCodeEnd":1650,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/server/src/services/environments.ts#L1614-L1650","documentation":"Generic guard when recording a failed/cleanup lease: the INSERT of a pending_cleanup lease row returned no result. The failure record for a sandbox that needs cleanup could not be persisted, so the service surfaces it instead of losing the cleanup obligation.","triggerScenarios":"Thrown at server/src/services/environments.ts:1496 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check database health and logs for the lease insert failure, then retry; ensure cleanup state is recorded manually if needed."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}