GeezerVison is showing github.com — fix: preserve withChanges parent layers by dagger-codex[bot] · Pull Request #13342 · dagger/dagger
Conversation
dagger-codex
Bot
commented
Jun 5, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
Fixes Directory.withChanges flattening published image layers.
WithChanges used to build a diff snapshot and merge it with the current rootfs. That merge produced a committed snapshot without preserving the pulled image's parent chain, so publishing the result could collapse the base image history into one layer.
This now applies the changeset into a mutable child snapshot derived from the current rootfs, then commits that child as the new changes layer.
Changes
- Compute changeset paths before mutating snapshots.
- Delete removed paths first, then copy added/modified content from the diff snapshot into the mutable child with
layercopy.
- Recreate added empty directories after the copy so empty dirs and type replacements are preserved.
- Avoid
SnapshotManager.Merge in WithChanges, matching the layer-preserving shape used by WithDirectory.
- Teach
layercopy to mark overlay replacement directories opaque when a directory replaces a non-directory, preventing lower-layer children from reappearing.
- Split the layercopy directory helper so the new replacement handling stays under the lint complexity threshold.
Tests
- Adds
TestPublishWithChangesPreservesBaseLayers to prove publishing a withChanges result retains the base image layer digest prefix and adds a changes layer.
- Expands
TestChangeset/TestWithChanges for type replacements, symlink retargeting/replacement/removal, dangling symlinks, and lower-layer resurrection coverage.
- Adds
TestDirectory/TestWithDirectory coverage for the overlay opaque-dir replacement case.
- Adds layercopy unit coverage for mkdir/copy replacement over overlay lower and hidden upper paths, including opaque-dir marking.
Verification
go test ./util/layercopy -count=1
go run github.com/fzipp/gocyclo/cmd/[email protected] -over 30 util/layercopy/dest_linux.go
git diff --check origin/main...HEAD
- Previously run before the latest rebase:
dagger --progress=plain call engine-dev test --pkg ./core/integration --run='TestChangeset|TestDirectory/TestWithDirectory'
- Previously run before the latest rebase:
dagger --progress=plain call engine-dev test --pkg ./core/integration --run='TestContainer/TestPublishWithChangesPreservesBaseLayers'
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
dagger-codex
Bot
changed the title
test: reproduce withChanges layer flattening
fix: preserve withChanges parent layers
Jun 8, 2026
Apply changesets in a mutable child snapshot instead of merging the target rootfs with the diff snapshot. This keeps published images from flattening the pulled image layer chain.
Run removals before copying changed content so type replacements such as directory-to-file work correctly, and create empty added directories through layercopy so file-to-empty-directory replacements handle overlay whiteouts.
Signed-off-by: Solomon Hykes <[email protected]>
Mark upper directories opaque when layercopy replaces a non-directory on an overlay destination. This preserves lower-layer hiding semantics for file-to-directory replacement and avoids stale merged-view checks while copying children into the new directory.
Add layercopy, withChanges, and withDirectory coverage for the hidden lower-directory case.
Signed-off-by: Solomon Hykes <[email protected]>
Uh oh!
There was an error while loading. Please reload this page.
marcosnils
pushed a commit
that referenced
this pull request
Jun 9, 2026
* test: reproduce withChanges layer flattening
Signed-off-by: Solomon Hykes <[email protected]>
* fix: preserve withChanges parent layers
Apply changesets in a mutable child snapshot instead of merging the target rootfs with the diff snapshot. This keeps published images from flattening the pulled image layer chain.
Run removals before copying changed content so type replacements such as directory-to-file work correctly, and create empty added directories through layercopy so file-to-empty-directory replacements handle overlay whiteouts.
Signed-off-by: Solomon Hykes <[email protected]>
* fix: mark overlay replacement dirs opaque
Mark upper directories opaque when layercopy replaces a non-directory on an overlay destination. This preserves lower-layer hiding semantics for file-to-directory replacement and avoids stale merged-view checks while copying children into the new directory.
Add layercopy, withChanges, and withDirectory coverage for the hidden lower-directory case.
Signed-off-by: Solomon Hykes <[email protected]>
* refactor: split layercopy directory creation
Signed-off-by: Solomon Hykes <[email protected]>
* test: make git depth test deterministic
Signed-off-by: Solomon Hykes <[email protected]>
---------
Signed-off-by: Solomon Hykes <[email protected]>
Co-authored-by: Solomon Hykes <[email protected]>
sipsma
pushed a commit
that referenced
this pull request
Aug 3, 2026
* test: reproduce withChanges snapshot poisoning
Applying an empty changeset with Directory.withChanges stores the parent's
snapshot ref instance on the derived directory. When the derived cache entry
is later collected (session close plus cache prune), its OnRelease releases
the shared handle, and the parent's still-cached snapshot becomes unusable:
every later mount, from any session, fails with "invalid immutable ref"
until the engine restarts. Reproduce with two sessions against a nested
engine: one keeps the parent entry alive while the other applies an empty
changeset and disconnects, then a prune loop re-mounts the parent.
Signed-off-by: Alex Suraci <[email protected]>
* fix: reopen snapshot ref for no-op withChanges
Directory.withChanges with an empty changeset returned the parent's snapshot
ref instance as the derived directory's snapshot. Every cached Directory
owns its handle and releases it when its cache entry is collected, so the
shared instance let a collected withChanges result invalidate the parent's
still-cached snapshot engine-wide (introduced in #13342). Reopen the
snapshot by ID instead, matching how subdirectory and diff derive their
handles.
Signed-off-by: Alex Suraci <[email protected]>
---------
Signed-off-by: Alex Suraci <[email protected]>
vito
added a commit
that referenced
this pull request
Aug 4, 2026
* test: reproduce withChanges snapshot poisoning
Applying an empty changeset with Directory.withChanges stores the parent's
snapshot ref instance on the derived directory. When the derived cache entry
is later collected (session close plus cache prune), its OnRelease releases
the shared handle, and the parent's still-cached snapshot becomes unusable:
every later mount, from any session, fails with "invalid immutable ref"
until the engine restarts. Reproduce with two sessions against a nested
engine: one keeps the parent entry alive while the other applies an empty
changeset and disconnects, then a prune loop re-mounts the parent.
Signed-off-by: Alex Suraci <[email protected]>
* fix: reopen snapshot ref for no-op withChanges
Directory.withChanges with an empty changeset returned the parent's snapshot
ref instance as the derived directory's snapshot. Every cached Directory
owns its handle and releases it when its cache entry is collected, so the
shared instance let a collected withChanges result invalidate the parent's
still-cached snapshot engine-wide (introduced in #13342). Reopen the
snapshot by ID instead, matching how subdirectory and diff derive their
handles.
Signed-off-by: Alex Suraci <[email protected]>
---------
Signed-off-by: Alex Suraci <[email protected]>
marcosnils
pushed a commit
to marcosnils/dagger
that referenced
this pull request
Aug 24, 2026
* test: reproduce withChanges snapshot poisoning
Applying an empty changeset with Directory.withChanges stores the parent's
snapshot ref instance on the derived directory. When the derived cache entry
is later collected (session close plus cache prune), its OnRelease releases
the shared handle, and the parent's still-cached snapshot becomes unusable:
every later mount, from any session, fails with "invalid immutable ref"
until the engine restarts. Reproduce with two sessions against a nested
engine: one keeps the parent entry alive while the other applies an empty
changeset and disconnects, then a prune loop re-mounts the parent.
Signed-off-by: Alex Suraci <[email protected]>
* fix: reopen snapshot ref for no-op withChanges
Directory.withChanges with an empty changeset returned the parent's snapshot
ref instance as the derived directory's snapshot. Every cached Directory
owns its handle and releases it when its cache entry is collected, so the
shared instance let a collected withChanges result invalidate the parent's
still-cached snapshot engine-wide (introduced in dagger#13342). Reopen the
snapshot by ID instead, matching how subdirectory and diff derive their
handles.
Signed-off-by: Alex Suraci <[email protected]>
---------
Signed-off-by: Alex Suraci <[email protected]>
(cherry picked from commit b1c2c81)
marcosnils
pushed a commit
to marcosnils/dagger
that referenced
this pull request
Aug 24, 2026
* test: reproduce withChanges snapshot poisoning
Applying an empty changeset with Directory.withChanges stores the parent's
snapshot ref instance on the derived directory. When the derived cache entry
is later collected (session close plus cache prune), its OnRelease releases
the shared handle, and the parent's still-cached snapshot becomes unusable:
every later mount, from any session, fails with "invalid immutable ref"
until the engine restarts. Reproduce with two sessions against a nested
engine: one keeps the parent entry alive while the other applies an empty
changeset and disconnects, then a prune loop re-mounts the parent.
Signed-off-by: Alex Suraci <[email protected]>
* fix: reopen snapshot ref for no-op withChanges
Directory.withChanges with an empty changeset returned the parent's snapshot
ref instance as the derived directory's snapshot. Every cached Directory
owns its handle and releases it when its cache entry is collected, so the
shared instance let a collected withChanges result invalidate the parent's
still-cached snapshot engine-wide (introduced in dagger#13342). Reopen the
snapshot by ID instead, matching how subdirectory and diff derive their
handles.
Signed-off-by: Alex Suraci <[email protected]>
---------
Signed-off-by: Alex Suraci <[email protected]>
(cherry picked from commit b1c2c81)
marcosnils
pushed a commit
to marcosnils/dagger
that referenced
this pull request
Aug 25, 2026
* test: reproduce withChanges snapshot poisoning
Applying an empty changeset with Directory.withChanges stores the parent's
snapshot ref instance on the derived directory. When the derived cache entry
is later collected (session close plus cache prune), its OnRelease releases
the shared handle, and the parent's still-cached snapshot becomes unusable:
every later mount, from any session, fails with "invalid immutable ref"
until the engine restarts. Reproduce with two sessions against a nested
engine: one keeps the parent entry alive while the other applies an empty
changeset and disconnects, then a prune loop re-mounts the parent.
Signed-off-by: Alex Suraci <[email protected]>
* fix: reopen snapshot ref for no-op withChanges
Directory.withChanges with an empty changeset returned the parent's snapshot
ref instance as the derived directory's snapshot. Every cached Directory
owns its handle and releases it when its cache entry is collected, so the
shared instance let a collected withChanges result invalidate the parent's
still-cached snapshot engine-wide (introduced in dagger#13342). Reopen the
snapshot by ID instead, matching how subdirectory and diff derive their
handles.
Signed-off-by: Alex Suraci <[email protected]>
---------
Signed-off-by: Alex Suraci <[email protected]>
(cherry picked from commit b1c2c81)
marcosnils
pushed a commit
that referenced
this pull request
Aug 25, 2026
* test: reproduce withChanges snapshot poisoning
Applying an empty changeset with Directory.withChanges stores the parent's
snapshot ref instance on the derived directory. When the derived cache entry
is later collected (session close plus cache prune), its OnRelease releases
the shared handle, and the parent's still-cached snapshot becomes unusable:
every later mount, from any session, fails with "invalid immutable ref"
until the engine restarts. Reproduce with two sessions against a nested
engine: one keeps the parent entry alive while the other applies an empty
changeset and disconnects, then a prune loop re-mounts the parent.
Signed-off-by: Alex Suraci <[email protected]>
* fix: reopen snapshot ref for no-op withChanges
Directory.withChanges with an empty changeset returned the parent's snapshot
ref instance as the derived directory's snapshot. Every cached Directory
owns its handle and releases it when its cache entry is collected, so the
shared instance let a collected withChanges result invalidate the parent's
still-cached snapshot engine-wide (introduced in #13342). Reopen the
snapshot by ID instead, matching how subdirectory and diff derive their
handles.
Signed-off-by: Alex Suraci <[email protected]>
---------
Signed-off-by: Alex Suraci <[email protected]>
(cherry picked from commit b1c2c81)
Reviewers
sipsma
sipsma approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|