{"record":{"id":"346b8248e98fcd3c","repo":"dagger/dagger","slug":"attach-workspace-git-ref-source-w","errorCode":null,"errorMessage":"attach workspace git ref source: %w","messagePattern":"attach workspace git ref source: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/workspace.go","lineNumber":933,"sourceCode":"\t\t\treturn nil, nil\n\t\t}\n\t\tattached, err := attach(src.Root)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"attach workspace directory source: %w\", err)\n\t\t}\n\t\troot, ok := attached.(dagql.ObjectResult[*Directory])\n\t\tif !ok {\n\t\t\treturn nil, fmt.Errorf(\"attach workspace directory source: unexpected result %T\", attached)\n\t\t}\n\t\tsrc.Root = root\n\t\treturn []dagql.AnyResult{root}, nil\n\tcase *WorkspaceSourceGitRef:\n\t\tif src.Ref.Self() == nil {\n\t\t\treturn nil, nil\n\t\t}\n\t\tattached, err := attach(src.Ref)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"attach workspace git ref source: %w\", err)\n\t\t}\n\t\tswitch ref := attached.(type) {\n\t\tcase dagql.Result[*GitRef]:\n\t\t\tsrc.Ref = ref\n\t\t\treturn []dagql.AnyResult{ref}, nil\n\t\tcase dagql.ObjectResult[*GitRef]:\n\t\t\tsrc.Ref = ref.Result\n\t\t\treturn []dagql.AnyResult{ref}, nil\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"attach workspace git ref source: unexpected result %T\", attached)\n\t\t}\n\tcase *WorkspaceSourceOverlay:\n\t\tvar deps []dagql.AnyResult\n\t\tbaseDeps, err := attachWorkspaceSource(attach, src.Base)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tdeps = append(deps, baseDeps...)","sourceCodeStart":915,"sourceCodeEnd":951,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/workspace.go#L915-L951","documentation":"This error wraps a failure from the attach call while re-attaching a WorkspaceSourceGitRef's Ref result (core/workspace.go:933). When a workspace's source is a git ref, the stored GitRef result must be re-attached to the current query context; an attach failure is surfaced with this message.","triggerScenarios":"Using a Workspace sourced from a git ref (WorkspaceSourceGitRef with non-nil Ref) where the attach call for src.Ref errors during dependency attachment — e.g. cached git ref result reused across query scopes.","commonSituations":"Replaying workspaces built from git sources in a new session; expired or evicted cached git ref results; engine restart between result creation and reuse.","solutions":["Inspect the wrapped inner error to find the attach failure root cause.","Re-create the workspace git source in the current session (re-run the git query).","Retry with a fresh client so the GitRef result attaches in-context.","Verify the git ref/repo is still reachable if the inner error points to git resolution."],"exampleFix":"// before: stale git ref id\ngitRef := GitRefFromID(savedID)\n// after: resolve fresh in the current client\ngitRef := client.Git(\"https://...\").Ref(\"main\")","handlingStrategy":"validation","validationCode":"// confirm the git ref is resolvable before building the workspace\nref, err := client.Git(repoURL).Ref(branch).ID(ctx)\nif err != nil {\n    return fmt.Errorf(\"git ref not resolvable in this session: %w\", err)\n}","typeGuard":"func hasValidGitRef(src *core.WorkspaceSourceGitRef) bool {\n    return src != nil && src.Ref.Self() != nil\n}","tryCatchPattern":"ws, err := buildGitWorkspace(ctx, repo, branch)\nif err != nil {\n    if strings.Contains(err.Error(), \"attach workspace git ref source\") {\n        // re-resolve the git ref freshly\n        ws = client.Workspace(client.Git(repo).Ref(branch))\n    }\n    return err\n}","preventionTips":["Resolve git refs in the same session that consumes the workspace.","Check repo/branch reachability before constructing the workspace.","Do not persist GitRef IDs across engine restarts.","Unwrap the inner error to distinguish attach failures from git errors."],"tags":["dagger","workspace","git","dagql"],"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-12T12:17:11.808Z"}