{"record":{"id":"1f9592df67ddf0e1","repo":"dagger/dagger","slug":"attach-workspace-mounts-w","errorCode":null,"errorMessage":"attach workspace mounts: %w","messagePattern":"attach workspace mounts: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/workspace.go","lineNumber":893,"sourceCode":"\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"attach workspace rootfs: unexpected result %T\", attached)\n\t\t}\n\t\tws.rootfs = typed\n\t\tdeps = append(deps, typed)\n\t}\n\n\tif ws.source != nil {\n\t\tsourceDeps, err := attachWorkspaceSource(attach, ws.source)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tdeps = append(deps, sourceDeps...)\n\t}\n\n\tif ws.mounts.Self() != nil {\n\t\tattached, err := attach(ws.mounts)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"attach workspace mounts: %w\", err)\n\t\t}\n\t\ttyped, ok := attached.(dagql.ObjectResult[*Directory])\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"attach workspace mounts: unexpected result %T\", attached)\n\t\t}\n\t\tws.mounts = typed\n\t\tdeps = append(deps, typed)\n\t}\n\n\treturn deps, nil\n}\n\nfunc attachWorkspaceSource(\n\tattach func(dagql.AnyResult) (dagql.AnyResult, error),\n\tsrc WorkspaceSource,\n) ([]dagql.AnyResult, error) {\n\tswitch src := src.(type) {\n\tcase nil, *WorkspaceSourceClientLocal, *WorkspaceSourceRootlessLocal:","sourceCodeStart":875,"sourceCodeEnd":911,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/workspace.go#L875-L911","documentation":"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.","triggerScenarios":"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.","commonSituations":"Using a Workspace obtained from a different session or cached response; replaying saved DAG results across queries; engine upgrades that invalidate cached result metadata.","solutions":["Inspect the wrapped inner error (%w) to find the root cause of the attach failure.","Re-create the Workspace in the current session instead of reusing a cross-session/cached result.","Retry the query with a fresh dagql client so results are attached in their original context.","If reproducible after an engine upgrade, clear the query cache or pin the engine version."],"exampleFix":"// before: reusing workspace from old session\nws := oldClient.Workspace(...)\ndir := newClient.Workspace(...).Mounts()\n// after: build workspace in the current client\nws := newClient.Workspace(...)\ndir := ws.Mounts()","handlingStrategy":"try-catch","validationCode":"// Go: validate before use\nif ws == nil || ws.Mounts() == nil {\n    return fmt.Errorf(\"workspace has no mounts to attach\")\n}","typeGuard":"func isValidMounts(r dagql.AnyResult) bool {\n    _, ok := r.(dagql.ObjectResult[*core.Directory])\n    return ok\n}","tryCatchPattern":"ws, err := client.Workspace(ctx, ...)\nif err != nil {\n    var wrapErr *fmt.WrapError\n    if errors.As(err, &wrapErr) && strings.Contains(err.Error(), \"attach workspace mounts\") {\n        // rebuild workspace in current session instead of retrying\n        ws = client.NewWorkspace(ctx)\n    }\n    return err\n}","preventionTips":["Always create Workspace objects in the same client/session where they are consumed.","Do not serialize and replay dagql results across sessions.","Pin the Dagger engine version to avoid cache invalidation surprises.","Check errors.Is/errors.As on the wrapped inner error to route recovery."],"tags":["dagger","workspace","dagql","result-attachment"],"backgroundTag":"dagql-result-attach-failed","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"}