dagger/dagger · error

failed to get ref for source directory: %w

Error message

failed to get ref for source directory: %w

What it means

Error 'failed to get ref for source directory: %w' (core/service.go:1465) wraps errors from source.Self().Snapshot.GetOrEval in runAndSnapshotChanges. Snapshot.GetOrEval resolves the directory to an underlying ImmutableRef (a content-addressed snapshot); failure means the directory's contents could not be resolved to a stored layer/ref in the engine.

Source

Thrown at core/service.go:1465

	running.workspaceMu.Lock()
	defer running.workspaceMu.Unlock()

	cache, err := dagql.EngineCache(ctx)
	if err != nil {
		return res, false, err
	}
	if err := cache.Evaluate(ctx, source); err != nil {
		return res, false, fmt.Errorf("failed to evaluate source directory: %w", err)
	}

	query, err := CurrentQuery(ctx)
	if err != nil {
		return res, false, err
	}

	ref, err := source.Self().Snapshot.GetOrEval(ctx, source.Result)
	if err != nil {
		return res, false, fmt.Errorf("failed to get ref for source directory: %w", err)
	}
	sourceDirPath, err := source.Self().Dir.GetOrEval(ctx, source.Result)
	if err != nil {
		return res, false, fmt.Errorf("failed to get path for source directory: %w", err)
	}

	bk, err := query.Engine(ctx)
	if err != nil {
		return res, false, fmt.Errorf("failed to get engine client: %w", err)
	}

	mutableRef, err := query.SnapshotManager().New(ctx, ref,
		bkcache.WithRecordType(bkclient.UsageRecordTypeRegular),
		bkcache.WithDescription("mcp remount"))
	if err != nil {
		return res, false, fmt.Errorf("failed to create new ref for source directory: %w", err)
	}
	defer func() {

View on GitHub (pinned to 82ba2681db)

Solutions

  1. Read the wrapped %w error to identify the snapshot/ref failure
  2. Prune and retry: clean a corrupted engine cache (dagger engine prune / restart engine)
  3. Re-create the Directory from its source so the snapshot is regenerated
  4. Check content-store permissions/disk space on the engine host
Defensive patterns

Strategy: retry

Try / catch

// Go: retry once on snapshot resolution failure (possible transient cache issue)
res, _, err := runAndSnapshotChanges(ctx, running, target, src, fn)
if err != nil && strings.Contains(err.Error(), "failed to get ref for source directory") {
    return runAndSnapshotChanges(ctx, running, target, rebuildSrc(ctx), fn)
}

Prevention

When it happens

Trigger: Calling runAndSnapshotChanges where source.Self().Snapshot.GetOrEval fails — e.g. the directory ref points to data not present in the content store (garbage-collected), the snapshot backend errors, or evaluation of the underlying result fails.

Common situations: Content-store eviction or corrupted cache on the engine; a directory produced by a remote source that failed to import; running against a containerd/buildkit store with permission problems.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/fc1bfca9765b93af. Report an issue: GitHub.