fix(engine): lease parent layer content for tarball export#13307
Merged
Conversation
Dagger owner leases only retained the snapshot directly attached to a persisted result, along with content digests already recorded for that one snapshot. Image export walks the full snapshot parent chain, and imported base image layer blobs plus generated compression variants are recorded against the individual layer snapshots in that chain. After the producing session ended, prune could therefore reclaim parent layer content that was still needed by a retained container result. This showed up as intermittent Container.asTarball(forcedCompression: Zstd) failures during engine builds: the retained container filesystem could still be read, but export could no longer find a local layer blob or compression variant. When attaching an owner lease, walk the snapshot parent chain and attach each snapshot and its known content digests to the same containerd lease. Also register the owner lease against each chain snapshot so content recorded later, such as zstd variants, is backfilled to the lease. Add an integration repro that pins a container across sessions, creates zstd tarball content, prunes aggressively, verifies the filesystem remains readable, then exports the pinned container as a zstd tarball again. Validated with: - go test ./engine/snapshots - dagger --progress=plain call engine-dev test --pkg ./core/integration --run='^TestLocalCache/TestLocalCachePruneDoesNotDropZstdTarballLayerContent$' Signed-off-by: Erik Sipsma <erik@sipsma.dev>
grouville
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Container image tarball export can fail after cache pruning when the export needs layer content that is no longer retained by an owner lease. The observed failure was intermittent during engine builds, especially through
Container.asTarball(forcedCompression: Zstd), with errors like a missing local content blob or a content digest not found while ensuring the requested compression type.Root Cause
Dagger owner leases only retained the snapshot directly attached to a persisted result, plus content digests already recorded for that direct snapshot. Image export walks the full snapshot parent chain, while imported image blobs and generated compression variants are recorded against the individual layer snapshots in that chain. That left parent layer content eligible for prune even when a descendant container result remained retained and usable.
The filesystem snapshot could still be read after prune, but export could fail because the layer blob or zstd compression variant needed to construct the tarball had been reclaimed.
Fix
When attaching an owner lease, walk the snapshot parent chain and attach each snapshot plus its known content digests to the same containerd lease. Also register the owner lease against each snapshot in the chain, so content recorded later for any ancestor snapshot, including zstd compression variants, is backfilled to the active owner lease.
This keeps tarball-export layer content retained for the same lifetime as the retained container result without changing stale-lease cleanup semantics.
Validation
Added an integration repro that:
Validated with:
go test ./engine/snapshotsdagger --progress=plain call engine-dev test --pkg ./core/integration --run='^TestLocalCache/TestLocalCachePruneDoesNotDropZstdTarballLayerContent$'