Skip to content

fix(layercopy): preserve source visibility bounds - #13848

Merged
sipsma merged 4 commits into
dagger:mainfrom
sipsma:dagger-issue-13844-lead-aa1e1ba2
Aug 6, 2026
Merged

sipsma merged 4 commits into
dagger:mainfrom
sipsma:dagger-issue-13844-lead-aa1e1ba2

Conversation

@sipsma

@sipsma sipsma commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

When an exec deletes and recreates a directory, copying that container Directory with Container.withDirectory or Directory.withDirectory can restore files that only exist below the deleted directory in older snapshot layers.

The mounted and exported views are correct because the kernel overlay mount already applies ancestor opacity and whiteouts. The bug is in layercopy's engine-side reconstruction: child directory walks could scan below the visibility bound established by an ancestor.

This change:

  • carries the lowest visible overlay layer through recursive traversal and initializes it from ancestors of a selected copy root;
  • treats opaque directories, whiteouts, and other non-directory entries as lower-layer visibility bounds, using Lstat so physical source-layer symlinks are not followed;
  • caches cumulative ancestor bounds per Copier and mounted source, avoiding repeated layer scans for wildcard copy roots.

The cache does not change traversal results. In a local synthetic 500-match, 20-layer benchmark, it reduced repeated-copy time from roughly 0.5–0.6 seconds to 25–30 milliseconds, allocations from about 1.12 million to 132 thousand, and allocated bytes from about 99 MB to 7.7 MB per operation.

Validation

  • go test -count=1 ./util/layercopy
  • focused non-directory, symlink, cache-scope, and cumulative-bound layercopy tests
  • go vet ./util/layercopy
  • Darwin and Windows layercopy cross-compilation
  • dagger api call engine-dev test --pkg ./core/integration --run='Test(Directory|Container)/TestWithDirectory(OpaqueSourceAncestor|WhiteoutSourceAncestor|Union)?$' (14 passed using the source-built development engine)

The new integration regressions verify that mounted/exported views exclude deleted files and that engine-side copies now produce the same contents. Before the fix, those controls passed while the engine-side copy assertions failed for both opaque-directory and separate-layer whiteout cases.

Fixes #13844

sipsma added 4 commits August 6, 2026 02:12
Carry the lowest visible overlay layer through recursive source walks so opaque directories and non-directory entries continue hiding lower-layer descendants. Initialize the bound from ancestors of a selected source subtree.

Signed-off-by: Erik Sipsma <[email protected]>
Stop source traversal before reading non-directory overlay entries so symlink targets cannot contribute contents that the kernel overlay view hides.

Signed-off-by: Erik Sipsma <[email protected]>
Reuse cumulative ancestor visibility floors across copies from the same mounted overlay source. This avoids rescanning shared ancestor paths for every wildcard match while keeping cache state scoped to one Copier.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma force-pushed the dagger-issue-13844-lead-aa1e1ba2 branch from cbb8424 to c195598 Compare August 6, 2026 02:15
@grouville
grouville self-requested a review August 6, 2026 05:50
@sipsma
sipsma merged commit 5e9d3b4 into dagger:main Aug 6, 2026
88 checks passed
marcosnils pushed a commit to marcosnils/dagger that referenced this pull request Aug 24, 2026
(cherry picked from commit 5e9d3b4)

Signed-off-by: Marcos Lilljedahl <[email protected]>
marcosnils pushed a commit to marcosnils/dagger that referenced this pull request Aug 24, 2026
(cherry picked from commit 5e9d3b4)

Signed-off-by: Marcos Lilljedahl <[email protected]>
marcosnils pushed a commit to marcosnils/dagger that referenced this pull request Aug 25, 2026
(cherry picked from commit 5e9d3b4)

Signed-off-by: Marcos Lilljedahl <[email protected]>
marcosnils pushed a commit that referenced this pull request Aug 25, 2026
(cherry picked from commit 5e9d3b4)

Signed-off-by: Marcos Lilljedahl <[email protected]>
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
dagger 0.21.9

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## v0.21.9 - 2026-08-25

### Added
- Added SSHFS-backed volumes, allowing remote filesystems to be mounted into containers without copying their contents into Dagger's content store by @sipsma in dagger/dagger#13462

### Fixed
- `Container.withDirectory` and `Directory.withDirectory` no longer restore by @sipsma in dagger/dagger#13848 \
  deleted nested files after execs remove and recreate an ancestor
  directory.
- Engine client enumeration no longer blocks behind another session's by @sipsma in dagger/dagger#13542 \
  initialization or teardown, preventing Cloud keeper heartbeats from stalling
  and live engines from being suspended.
- Session teardown now runs in the background after the main client disconnects, by @sipsma in dagger/dagger#13681 \
  preventing shutdown responses from timing out while the engine releases
  session-owned cache results.
- The engine now bounds retained DAGQL cache metadata independently of disk by @sipsma in dagger/dagger#13846 \
  usage by pruning cold persisted results when the structural estimate exceeds
  its configured limit. This may mitigate metadata growth at scale while
  preserving active and engine-lifetime cache roots.
- Registry protocol probes no longer appear as scary errors in progress output by @vito in dagger/dagger#13410 \
  when image pulls or publishes succeed, while genuine registry failures remain
  visible.
- Registry authentication no longer invalidates downstream container cache reuse across sessions when applied before or after `Container.from` by @sipsma in dagger/dagger#13901

### What to do next?
- Read the [documentation](https://docs.dagger.io)
- Join our [Discord server](https://discord.gg/dagger-io)
- Follow us on [Twitter](https://twitter.com/dagger_io)

</pre>
  <p>View the full release notes at <a href="https://github.com/dagger/dagger/releases/tag/v0.21.9">https://github.com/dagger/dagger/releases/tag/v0.21.9</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!17786
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.

🐞 WithDirectory from a container with delete+recreate exec history resurrects deleted files (layercopy ignores ancestor opaque dirs)

2 participants