{"record":{"id":"9ebb625ec0553079","repo":"dagger/dagger","slug":"container-directory-lazy-missing-mounted-director","errorCode":null,"errorMessage":"container directory lazy: missing mounted directory source for %s","messagePattern":"container directory lazy: missing mounted directory source for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/container.go","lineNumber":3288,"sourceCode":"\t\t\tif err := srv.Select(ctx, lazy.Parent, &rootfs, dagql.Selector{Field: \"rootfs\"}); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tif subpath == \"\" || subpath == \".\" || subpath == \"/\" {\n\t\t\t\tresolved = rootfs\n\t\t\t} else {\n\t\t\t\tif err := srv.Select(ctx, rootfs, &resolved, dagql.Selector{\n\t\t\t\t\tField: \"directory\",\n\t\t\t\t\tArgs: []dagql.NamedInput{\n\t\t\t\t\t\t{Name: \"path\", Value: dagql.String(subpath)},\n\t\t\t\t\t},\n\t\t\t\t}); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t}\n\t\tcase mnt.DirectorySource != nil:\n\t\t\tmountedDir, ok := mnt.DirectorySource.Peek()\n\t\t\tif !ok || mountedDir == nil {\n\t\t\t\treturn fmt.Errorf(\"container directory lazy: missing mounted directory source for %s\", mnt.Target)\n\t\t\t}\n\t\t\tif subpath == \"\" || subpath == \".\" {\n\t\t\t\tdetached, err := cloneDetachedDirectoryForContainerResult(ctx, mountedDir)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tdir.Platform = detached.Platform\n\t\t\t\tdir.Services = slices.Clone(detached.Services)\n\t\t\t\tif dirPath, ok := detached.Dir.Peek(); ok {\n\t\t\t\t\tdir.Dir.setValue(dirPath)\n\t\t\t\t}\n\t\t\t\tif snapshot, ok := detached.Snapshot.Peek(); ok && snapshot != nil {\n\t\t\t\t\tdir.Snapshot.setValue(snapshot)\n\t\t\t\t}\n\t\t\t\tdir.Lazy = nil\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tmountedDirPath, ok := mountedDir.Dir.Peek()","sourceCodeStart":3270,"sourceCodeEnd":3306,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/container.go#L3270-L3306","documentation":"While lazily materializing a directory view of a container mount, Dagger inspects each mount record. For a mount whose source is a Directory result (DirectorySource), it peeks the already-computed directory value; if the value is absent or nil at evaluation time the mount cannot be materialized and this error names the mount target path. It indicates the mounted directory was never evaluated or its result was lost (e.g. cache miss/corruption) before the container state was consumed.","triggerScenarios":"Using container.directory(target) or listing files on a lazy container where a withMountedDirectory(target, dir) mount's Directory result cannot be Peeked when the lazy state is evaluated — typically after persisted-state replay where the directory was never forced.","commonSituations":"Module caching replaying a container built with mounted directories across engine restarts; passing a lazily-built directory that errored upstream; engine cache eviction/corruption dropping the mounted dir result.","solutions":["Force evaluation of the mounted directory before building the container (e.g. call dir.entries() or export it) so its result is concrete","Re-run in a fresh session to rebuild the DAG without persisted lazy state","Restart/prune the engine cache to remove stale persisted results","Check for upstream errors on the source directory (a failed dir computation can leave the source nil)"],"exampleFix":"// before\nctr := client.Container().From(\"alpine\").WithMountedDirectory(\"/work\", lazilyBuiltDir)\nout := ctr.Directory(\"/work/out\")\n// after\nif _, err := lazilyBuiltDir.Contents(ctx); err != nil { return err } // force evaluation first\nctr := client.Container().From(\"alpine\").WithMountedDirectory(\"/work\", lazilyBuiltDir)","handlingStrategy":"validation","validationCode":"// Ensure the mounted source directory is fully evaluated before mounting\nif _, err := srcDir.Contents(ctx); err != nil { return err }\nctr := client.Container().From(\"alpine\").WithMountedDirectory(\"/work\", srcDir)","typeGuard":null,"tryCatchPattern":"d, err := ctr.Directory(ctx, \"/work/out\")\nif err != nil && strings.Contains(err.Error(), \"missing mounted directory source\") {\n\t// re-evaluate the source directory, rebuild container, retry\n}","preventionTips":["Force-evaluate source directories (entries/contents/export) before withMountedDirectory","Don't chain .directory() reads off containers built from cache-restored IDs","Check upstream directory operations for errors before mounting them","Keep engine cache healthy; prune after upgrades"],"tags":["lazy-evaluation","mount","directory","cache"],"backgroundTag":"missing-mounted-directory-source","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}