Skip to content

fix(engine): lease parent layer content for tarball export#13307

Merged
sipsma merged 1 commit into
dagger:mainfrom
sipsma:missing-content
Jun 2, 2026
Merged

fix(engine): lease parent layer content for tarball export#13307
sipsma merged 1 commit into
dagger:mainfrom
sipsma:missing-content

Conversation

@sipsma
Copy link
Copy Markdown
Contributor

@sipsma sipsma commented Jun 2, 2026

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:

  • creates a container and exports it once as a zstd tarball
  • closes the producing session
  • pins the container in a new session
  • creates additional cache pressure
  • prunes aggressively
  • verifies the pinned filesystem is still readable
  • 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$'

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>
@sipsma sipsma added this to the v0.21.4 milestone Jun 2, 2026
@grouville grouville self-requested a review June 2, 2026 18:16
@sipsma sipsma merged commit 41a7910 into dagger:main Jun 2, 2026
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants