dagger/dagger · error

attach workspace mounts

Error message

attach workspace mounts: %w

What it means

This error wraps a failure that occurred while re-attaching a Workspace's mounts result during dependency-result attachment (AttachDependencyResults in core/workspace.go:893). Dagger re-attaches stored dagql results to the current query context when a cached object is reused; if the underlying attach call fails (e.g. the cached result is no longer valid in this context), the error is wrapped with this message. It indicates the Workspace could not have its mounts directory re-linked to the executing query.

Solutions

  1. Inspect the wrapped inner error (%w) to find the root cause of the attach failure.
  2. Re-create the Workspace in the current session instead of reusing a cross-session/cached result.
  3. Retry the query with a fresh dagql client so results are attached in their original context.
  4. If reproducible after an engine upgrade, clear the query cache or pin the engine version.

Example fix

// before: reusing workspace from old session
ws := oldClient.Workspace(...)
dir := newClient.Workspace(...).Mounts()
// after: build workspace in the current client
ws := newClient.Workspace(...)
dir := ws.Mounts()
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: validate before use
if ws == nil || ws.Mounts() == nil {
    return fmt.Errorf("workspace has no mounts to attach")
}

Type guard

func isValidMounts(r dagql.AnyResult) bool {
    _, ok := r.(dagql.ObjectResult[*core.Directory])
    return ok
}

Try / catch

ws, err := client.Workspace(ctx, ...)
if err != nil {
    var wrapErr *fmt.WrapError
    if errors.As(err, &wrapErr) && strings.Contains(err.Error(), "attach workspace mounts") {
        // rebuild workspace in current session instead of retrying
        ws = client.NewWorkspace(ctx)
    }
    return err
}

Prevention

When it happens

Trigger: Calling any Workspace API (e.g. Query.workspace, Workspace.directory/mounts accessors) when the workspace's mounts field holds a dagql result whose AttachDependencyResults attach call returns an error — typically a cache/context mismatch when a workspace result is replayed in a different query scope.

Common situations: Using a Workspace obtained from a different session or cached response; replaying saved DAG results across queries; engine upgrades that invalidate cached result metadata.

Related errors


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

Appendix: source

Thrown at core/workspace.go:893

		if !ok {
			return nil, fmt.Errorf("attach workspace rootfs: unexpected result %T", attached)
		}
		ws.rootfs = typed
		deps = append(deps, typed)
	}

	if ws.source != nil {
		sourceDeps, err := attachWorkspaceSource(attach, ws.source)
		if err != nil {
			return nil, err
		}
		deps = append(deps, sourceDeps...)
	}

	if ws.mounts.Self() != nil {
		attached, err := attach(ws.mounts)
		if err != nil {
			return nil, fmt.Errorf("attach workspace mounts: %w", err)
		}
		typed, ok := attached.(dagql.ObjectResult[*Directory])
		if !ok {
			return nil, fmt.Errorf("attach workspace mounts: unexpected result %T", attached)
		}
		ws.mounts = typed
		deps = append(deps, typed)
	}

	return deps, nil
}

func attachWorkspaceSource(
	attach func(dagql.AnyResult) (dagql.AnyResult, error),
	src WorkspaceSource,
) ([]dagql.AnyResult, error) {
	switch src := src.(type) {
	case nil, *WorkspaceSourceClientLocal, *WorkspaceSourceRootlessLocal:

View on GitHub (pinned to 82ba2681db)