{"record":{"id":"6352c87b6fb4c31e","repo":"dagger/dagger","slug":"ensure-lease-for-snapshot-diff","errorCode":null,"errorMessage":"ensure lease for snapshot diff","messagePattern":"ensure lease for snapshot diff","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/snapshots/manager.go","lineNumber":508,"sourceCode":"\t}\n\n\tid := identity.NewID()\n\tsnapshotID := id\n\n\tvar diffs []Diff\n\tif upper == nil || lower.SnapshotID() != upper.SnapshotID() {\n\t\tdiff := Diff{\n\t\t\tLower:      lower.SnapshotID(),\n\t\t\tComparison: fsdiff.CompareContentOnMetadataMatch,\n\t\t}\n\t\tif upper != nil {\n\t\t\tdiff.Upper = upper.SnapshotID()\n\t\t}\n\t\tdiffs = append(diffs, diff)\n\t}\n\tctx, err := EnsureLease(ctx)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"ensure lease for snapshot diff\")\n\t}\n\tif err := cm.Snapshotter.Merge(ctx, snapshotID, diffs); err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to apply snapshot diff\")\n\t}\n\n\tcm.mu.Lock()\n\tdefer cm.mu.Unlock()\n\n\tmd := cm.ensureMetadata(id)\n\trec := &cacheRecord{\n\t\tmutable: false,\n\t\tcm:      cm,\n\t\tmd:      md,\n\t}\n\n\topts = append(opts, withSnapshotID(snapshotID))\n\tif err := initializeMetadata(rec.md, opts...); err != nil {\n\t\treturn nil, err","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/engine/snapshots/manager.go#L490-L526","documentation":"ApplySnapshotDiff wraps EnsureLease failures with this message. EnsureLease attaches (or creates) the lease context needed so the snapshots referenced by the diff are not garbage-collected while Merge runs. If lease acquisition fails (lease manager error, backend unavailable), the whole diff application is aborted before any merge occurs.","triggerScenarios":"ApplySnapshotDiff(ctx, lower, upper) is called and EnsureLease(ctx) fails — typically when the lease manager cannot create/attach a lease for the context (backend error, cancelled context, lease manager not wired).","commonSituations":"Calling ApplySnapshotDiff with an already-cancelled context; lease manager misconfigured or its storage unavailable; concurrent engine shutdown racing lease creation.","solutions":["Inspect the wrapped error: if it's a context error, retry with a fresh, live context.","Verify the lease manager is properly initialized in the engine setup.","Avoid cancelling the context while diff/merge operations are in flight.","Check engine logs for lease-manager backend failures (often signals broader store problems)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if err := ctx.Err(); err != nil { return err } // context must be live before ApplySnapshotDiff","typeGuard":null,"tryCatchPattern":"ir, err := cm.ApplySnapshotDiff(ctx, lower, upper)\nif err != nil && strings.Contains(err.Error(), \"ensure lease for snapshot diff\") {\n\t// lease acquisition failed: retry with fresh context, log lease-manager state\n}","preventionTips":["Keep contexts alive for the duration of diff/merge operations.","Ensure the lease manager is initialized before any ref operations.","Avoid cancelling upstream work while merges are in flight.","Watch engine logs for lease manager failures."],"tags":["lease","snapshots","context"],"backgroundTag":"lease-acquisition-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}