{"record":{"id":"e70e3391d8173a9e","repo":"dagger/dagger","slug":"load-canonical-scratch-directory-w","errorCode":null,"errorMessage":"load canonical scratch directory: %w","messagePattern":"load canonical scratch directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/directory.go","lineNumber":335,"sourceCode":"\t\tlazy, err := decodePersistedDirectoryLazy(ctx, dag, persisted.LazyKind, persisted.LazyJSON)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tdir.Lazy = lazy\n\t\treturn dir, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"decode persisted directory payload: unsupported form %q\", persisted.Form)\n\t}\n}\n\nfunc (*Directory) DecodePersistedObject(ctx context.Context, dag *dagql.Server, resultID uint64, _ *dagql.ResultCall, payload json.RawMessage) (dagql.Typed, error) {\n\treturn decodePersistedDirectoryWithSnapshotRole(ctx, dag, resultID, payload, \"snapshot\")\n}\n\nfunc loadCanonicalScratchDirectory(ctx context.Context) (string, bkcache.ImmutableRef, error) {\n\tquery, err := CurrentQuery(ctx)\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"load canonical scratch directory: %w\", err)\n\t}\n\tscratchSnapshot, err := query.SnapshotManager().Scratch(ctx)\n\tif err != nil {\n\t\treturn \"\", nil, err\n\t}\n\treturn \"/\", scratchSnapshot, nil\n}\n\ntype DirectoryWithDirectoryLazy struct {\n\tLazyState\n\tParent      dagql.ObjectResult[*Directory]\n\tDestDir     string\n\tSource      dagql.ObjectResult[*Directory]\n\tFilter      CopyFilter\n\tOwner       string\n\tPermissions *int\n}\n","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/directory.go#L317-L353","documentation":"Wraps a failure to obtain the current Query from the context while loading the canonical scratch (empty) directory. CurrentQuery requires the caller to run inside a Dagger engine request with the query stored in ctx; without it, no SnapshotManager is reachable to create the scratch root. This is an infrastructure/context wiring error, not a content error.","triggerScenarios":"loadCanonicalScratchDirectory is invoked (via ensureRootFS, WithFile, WithSymlink, applyPatchFileResult, Diff) with a context that lacks the CurrentQuery value — e.g. calling core APIs outside a dagql-resolved request, using a background context, or context value dropped when spawning goroutines.","commonSituations":"Custom embeddings of the Dagger core that call Directory methods outside query resolution; tests that construct *Directory directly without CurrentQuery(ctx) setup; goroutines spawned without propagating the engine context.","solutions":["Ensure the code runs within a dagql-resolved call where CurrentQuery(ctx) returns the active *Query","Propagate the engine context (context.WithValue with the query key) into any goroutines or helpers","In tests, install a Query in the context before calling Directory APIs"],"exampleFix":"// before\nresult, err := dir.WithFile(ctx, ...) // background ctx, no query\n// after\nctx = query.WithQuery(ctx, query) // or call within a resolved dagql field\nresult, err := dir.WithFile(ctx, ...)","handlingStrategy":"validation","validationCode":"// verify the context carries the query before calling core APIs\nif CurrentQuery(ctx) == nil-or-errors {\n    // install: ctx = query.WithQuery(ctx, q)\n}","typeGuard":null,"tryCatchPattern":"err := runDirOp(ctx)\nvar cqErr *queryMissingError\nif errors.As(err, &cqErr) {\n    ctx = query.WithQuery(ctx, q)\n    err = runDirOp(ctx)\n}","preventionTips":["Always invoke Directory methods inside dagql field resolution","Propagate the engine context into goroutines (never context.Background())","In tests, install a Query in ctx before exercising core APIs"],"tags":["context","internal-state","directory","scratch"],"backgroundTag":"missing-context-value","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}