paperclipai/paperclip · error

Failed to record pending sandbox cleanup lease

Error message

Failed to record pending sandbox cleanup lease

What it means

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.

Solutions

  1. Check database health and logs for the lease insert failure, then retry; ensure cleanup state is recorded manually if needed.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at server/src/services/environments.ts:1496 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of paperclipai/paperclip@3f1d897a7c (2026-08-18). Data as JSON: /api/errors/abf6e90e8bc2513c. Report an issue: GitHub.

Appendix: source

Thrown at server/src/services/environments.ts:1700

      const row = await db.transaction(async (tx) => {
        // Lock the environment row so a concurrent delete cannot commit between
        // this read and the insert. An absent row means a delete already removed
        // the environment, so record the orphan with a null reference.
        const environmentRows = await tx
          .select({ id: environments.id })
          .from(environments)
          .where(eq(environments.id, input.environmentId))
          .for("update");
        const environmentIdForRow = environmentRows[0]?.id ?? null;
        return tx
          .insert(environmentLeases)
          .values({
            companyId: input.companyId,
            environmentId: environmentIdForRow,
            executionWorkspaceId: input.executionWorkspaceId ?? null,
            issueId: input.issueId ?? null,
            heartbeatRunId: input.heartbeatRunId ?? null,
            status: "pending_cleanup" as const,
            leasePolicy: "ephemeral",
            provider: input.provider ?? null,
            providerLeaseId: input.providerLeaseId ?? null,
            acquiredAt: now,
            lastUsedAt: now,
            expiresAt: null,
            releasedAt: now,
            failureReason: input.failureReason,
            cleanupStatus: "failed",
            metadata: input.metadata ?? null,
            createdAt: now,
            updatedAt: now,
          })
          .returning()
          .then((rows) => rows[0] ?? null);
      });
      if (!row) {
        throw new Error("Failed to record pending sandbox cleanup lease");

View on GitHub (pinned to 3f1d897a7c)