dagger/dagger · error
load canonical scratch directory: %w
Error message
load canonical scratch directory: %w
What it means
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.
Source
Thrown at core/directory.go:335
lazy, err := decodePersistedDirectoryLazy(ctx, dag, persisted.LazyKind, persisted.LazyJSON)
if err != nil {
return nil, err
}
dir.Lazy = lazy
return dir, nil
default:
return nil, fmt.Errorf("decode persisted directory payload: unsupported form %q", persisted.Form)
}
}
func (*Directory) DecodePersistedObject(ctx context.Context, dag *dagql.Server, resultID uint64, _ *dagql.ResultCall, payload json.RawMessage) (dagql.Typed, error) {
return decodePersistedDirectoryWithSnapshotRole(ctx, dag, resultID, payload, "snapshot")
}
func loadCanonicalScratchDirectory(ctx context.Context) (string, bkcache.ImmutableRef, error) {
query, err := CurrentQuery(ctx)
if err != nil {
return "", nil, fmt.Errorf("load canonical scratch directory: %w", err)
}
scratchSnapshot, err := query.SnapshotManager().Scratch(ctx)
if err != nil {
return "", nil, err
}
return "/", scratchSnapshot, nil
}
type DirectoryWithDirectoryLazy struct {
LazyState
Parent dagql.ObjectResult[*Directory]
DestDir string
Source dagql.ObjectResult[*Directory]
Filter CopyFilter
Owner string
Permissions *int
}
View on GitHub (pinned to 82ba2681db)
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
Example fix
// before result, err := dir.WithFile(ctx, ...) // background ctx, no query // after ctx = query.WithQuery(ctx, query) // or call within a resolved dagql field result, err := dir.WithFile(ctx, ...)
Defensive patterns
Strategy: validation
Validate before calling
// verify the context carries the query before calling core APIs
if CurrentQuery(ctx) == nil-or-errors {
// install: ctx = query.WithQuery(ctx, q)
} Try / catch
err := runDirOp(ctx)
var cqErr *queryMissingError
if errors.As(err, &cqErr) {
ctx = query.WithQuery(ctx, q)
err = runDirOp(ctx)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- decode persisted directory payload: missing lazy kind
- %s: unexpected result %T
- failed to load module source dependencies: %w
- unexpected context type for arg %s
- failed to evaluate changeset diff selector: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/e70e3391d8173a9e.
Report an issue: GitHub.