Repository navigation
Description
What is the issue?
What happened
When a Directory is taken from a container whose exec deleted a directory
and recreated it (e.g. a package manager replacing a package directory), and
that Directory is then used engine-side β Container.WithDirectory,
Directory.Glob, etc. β files that were deleted from subdirectories of the
recreated directory reappear with their old content.
The same Directory is correct when read through a mounted view
(WithMountedDirectory, terminal, host export), which makes the
corruption easy to miss: everything you eyeball looks right, while the copied
tree is wrong.
Root cause analysis (AI)
util/layercopy/source_linux.go walks the source snapshot's overlay layer
directories directly instead of reading a mounted view.
readOverlayDir
merges the layers per directory: for each layer it checks
isOpaqueDir(layerDir) on that directory and stops descending to lower
layers when it is opaque. Whiteout entries in the listing are honored via
isWhiteout.
The bug: opacity is only consulted for the directory currently being listed.
When the walk recurses into a subdirectory, readOverlayDir(child) starts a
fresh merge across all layers with no knowledge that an ancestor was
opaque in an upper layer.
In overlayfs, a directory that is deleted and recreated gets
trusted.overlay.opaque on itself only β subdirectories created inside it
carry no marker of their own, because the kernel applies opacity to the whole
subtree. The walker doesn't:
- listing the recreated dir
a/: upper layer is opaque β upper entries only.
x.txtand any dropped subdir are absent β correctly gone. β - recursing into
a/b/: upperb/has no own opaque marker β the walker
falls through to the lower layer'sa/b/and unions the oldy.txt
back in. β
realPath
has the same ancestor-blindness for single-file resolution: it walks layers
top-down per path, honoring a whiteout of the file itself but not an opaque
ancestor, so it also resolves to lower-layer content that should be hidden.
The code is unchanged on main at the time of writing.
Impact
Silent data corruption, discovered in production: our CI upgrades WordPress
plugins inside a container (the WP upgrader replaces plugin directories),
grafts the upgraded tree into a toolbox container and commits with git. Since
the v0.20 β v0.21 engine upgrade, every upgrade commit silently re-added
files that upstream releases had removed β including files removed by a
security release. Six weeks of CMS-upgrade commits across multiple
repositories were affected before a plugin's own version self-check exposed
it. export to the host is unaffected, so local inspection showed a correct
tree while the engine-side copy did not.
Environment
- Reproduced on: dagger v0.21.7 and v0.21.8 (CLI + engine, linux/amd64,
rootful engine container, overlayfs) - Not reproducible on v0.20.8 (pre-layercopy)
Workaround
Use a kernel-resolved view instead of the layer walker:
WithMountedDirectoryinstead ofWithDirectorywhere the tree is only
needed inside execs, or- round-trip the directory through a tarball created from a mounted view.
Dagger version
v0.21.8 (image://registry.dagger.io/engine:v0.21.8) linux/amd64
Steps to reproduce
Reproduction (v0.21.8)
mkdir -p mini/a/b
echo old > mini/a/x.txt
echo old > mini/a/b/y.txt
# View inside the container that did the delete+recreate: correct.
dagger -c 'container | from alpine:3.20 | with-directory /data mini | with-exec sh,-c,"rm -rf /data/a && mkdir -p /data/a/b && echo new > /data/a/b/new.txt" | with-exec sh,-c,"find /data -type f" | stdout'
# /data/a/b/new.txt
# Same directory grafted into a fresh container: y.txt is resurrected.
dagger -c 'container | from alpine:3.20 | with-directory /graft $(container | from alpine:3.20 | with-directory /data mini | with-exec sh,-c,"rm -rf /data/a && mkdir -p /data/a/b && echo new > /data/a/b/new.txt" | directory /data) | with-exec sh,-c,"find /graft -type f" | stdout'
# /graft/a/b/new.txt
# /graft/a/b/y.txt <-- deleted before the recreate, back with old contentNote the asymmetry: a/x.txt (direct child of the recreated dir) stays
deleted; a/b/y.txt (one level deeper) is resurrected. That asymmetry is the
fingerprint of the root cause below.
Log output
No response
Activity
sipsma commentedon Aug 5, 2026
Thanks for finding and reporting it! Fix is in progress, will link the PR for it soon
sipsma commentedon Aug 6, 2026
fix here #13848
jeffreyzant commentedon Aug 6, 2026
Thanks man! That's some quick issue handling :)