Merge remote-tracking branch 'origin/test/sweep-retained-restore-source' into measure/remote-warm-2

* origin/test/sweep-retained-restore-source:
  test(restart-chaos): grade a stopped retain-on-failure restore source as retained
This commit is contained in:
Dotta committed 2026-11-08 11:59:59 -06:00
commit c5a172a183
2 files changed
+22 -3

No files matched your search

+11
View File
@@ -126,6 +126,17 @@ describe("Daytona R6 reconciliation", () => {
expect(result.orphanSandboxes.map(leak => leak.sandboxId)).toEqual(["r2", "e1"]); expect(result.orphanSandboxes.map(leak => leak.sandboxId)).toEqual(["r2", "e1"]);
}); });
it("keeps a stopped restore source (retain_on_failure) as retained, but not a running one or one with no lease", () => {
const result = reconcileSandboxes(
[{ id: "s1", state: "stopped" }, { id: "s2", state: "started" }, { id: "s3", state: "stopped" }],
[{ id: "f1", status: "released", leasePolicy: "retain_on_failure", providerLeaseId: "s1" },
{ id: "f2", status: "released", leasePolicy: "retain_on_failure", providerLeaseId: "s2" }],
);
expect(result.retainedLeases.map(lease => lease.leaseId)).toEqual(["f1"]);
// Running, or left behind by a deleted environment (no lease): still leaks.
expect(result.orphanSandboxes.map(leak => leak.sandboxId)).toEqual(["s2", "s3"]);
});
it("judges a reused sandbox by its current lease row, whatever the listing order", () => { it("judges a reused sandbox by its current lease row, whatever the listing order", () => {
const rows = [{ id: "old", status: "expired", leasePolicy: "reuse_by_environment", providerLeaseId: "r1" }, const rows = [{ id: "old", status: "expired", leasePolicy: "reuse_by_environment", providerLeaseId: "r1" },
{ id: "new", status: "released", leasePolicy: "reuse_by_environment", providerLeaseId: "r1" }]; { id: "new", status: "released", leasePolicy: "reuse_by_environment", providerLeaseId: "r1" }];
+11 -3
View File
@@ -43,16 +43,24 @@ export interface DaytonaSweepResult {
orphanSandboxes: SandboxLeak[]; orphanSandboxes: SandboxLeak[];
/** Leases still `active` or `pending_cleanup` with every task at rest. */ /** Leases still `active` or `pending_cleanup` with every task at rest. */
heldLeases: LeaseLeak[]; heldLeases: LeaseLeak[];
/** Leases kept on purpose (`retained`, or a released reusable lease whose sandbox is stopped for reuse), reported but not a leak. */ /** Leases kept on purpose (`retained`, a released reusable lease whose sandbox is stopped for reuse, or a released retain-on-failure restore source whose sandbox is stopped), reported but not a leak. */
retainedLeases: LeaseLeak[]; retainedLeases: LeaseLeak[];
/** Archived sandboxes behind a released lease: expected and reported; Daytona deletes them. */ /** Archived sandboxes behind a released lease: expected and reported; Daytona deletes them. */
archivedSandboxes: string[]; archivedSandboxes: string[];
error: string | null; error: string | null;
} }
/** A stopped sandbox behind a released reuse_by_environment lease: a later run on the same workspace resumes it. */ /**
* A stopped sandbox Paperclip keeps on purpose behind a released lease:
* - `reuse_by_environment`: a later run on the same workspace resumes it;
* - `retain_on_failure`: a failed run's workspace copy kept for file recovery
* (restore recovery owns it; environment deletion destroys it).
* Only a stopped one counts: a running sandbox, or one with no lease (for
* example after its environment was deleted), is still a leak.
*/
function keptForReuse(lease: LeaseRow, sandbox: DaytonaSandboxRow): boolean { function keptForReuse(lease: LeaseRow, sandbox: DaytonaSandboxRow): boolean {
return lease.status === "released" && lease.leasePolicy === "reuse_by_environment" return lease.status === "released"
&& (lease.leasePolicy === "reuse_by_environment" || lease.leasePolicy === "retain_on_failure")
&& String(sandbox.state ?? "").toLowerCase() === "stopped"; && String(sandbox.state ?? "").toLowerCase() === "stopped";
} }