dagger/dagger · error
attach workspace git ref source: %w
Error message
attach workspace git ref source: %w
What it means
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.
Source
Thrown at core/workspace.go:933
return nil, nil
}
attached, err := attach(src.Root)
if err != nil {
return nil, fmt.Errorf("attach workspace directory source: %w", err)
}
root, ok := attached.(dagql.ObjectResult[*Directory])
if !ok {
return nil, fmt.Errorf("attach workspace directory source: unexpected result %T", attached)
}
src.Root = root
return []dagql.AnyResult{root}, nil
case *WorkspaceSourceGitRef:
if src.Ref.Self() == nil {
return nil, nil
}
attached, err := attach(src.Ref)
if err != nil {
return nil, fmt.Errorf("attach workspace git ref source: %w", err)
}
switch ref := attached.(type) {
case dagql.Result[*GitRef]:
src.Ref = ref
return []dagql.AnyResult{ref}, nil
case dagql.ObjectResult[*GitRef]:
src.Ref = ref.Result
return []dagql.AnyResult{ref}, nil
default:
return nil, fmt.Errorf("attach workspace git ref source: unexpected result %T", attached)
}
case *WorkspaceSourceOverlay:
var deps []dagql.AnyResult
baseDeps, err := attachWorkspaceSource(attach, src.Base)
if err != nil {
return nil, err
}
deps = append(deps, baseDeps...)View on GitHub (pinned to 82ba2681db)
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.
Example fix
// before: stale git ref id
gitRef := GitRefFromID(savedID)
// after: resolve fresh in the current client
gitRef := client.Git("https://...").Ref("main") Defensive patterns
Strategy: validation
Validate before calling
// confirm the git ref is resolvable before building the workspace
ref, err := client.Git(repoURL).Ref(branch).ID(ctx)
if err != nil {
return fmt.Errorf("git ref not resolvable in this session: %w", err)
} Type guard
func hasValidGitRef(src *core.WorkspaceSourceGitRef) bool {
return src != nil && src.Ref.Self() != nil
} Try / catch
ws, err := buildGitWorkspace(ctx, repo, branch)
if err != nil {
if strings.Contains(err.Error(), "attach workspace git ref source") {
// re-resolve the git ref freshly
ws = client.Workspace(client.Git(repo).Ref(branch))
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Replaying workspaces built from git sources in a new session; expired or evicted cached git ref results; engine restart between result creation and reuse.
Related errors
- attach workspace git workspace: %w
- read workspace root: %w
- failed to add vcs generated file: %w
- workspace directory %q: create rootless directory: %w
- seed overlay delta root: %w
AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05).
Data as JSON: /api/errors/346b8248e98fcd3c.
Report an issue: GitHub.