gastownhall/beads · error
failed to create dependency: %w
Error message
failed to create dependency: %w
What it means
Wraps a failure from tx.AddDependency while persisting a cooked formula's dependency edges (DepBlocks/DepWaitsFor etc.) inside the single atomic transaction that creates issues, labels, and deps. When any single dependency insert fails the whole cook --persist transaction rolls back, leaving no partial subgraph. The wrapped cause carries the storage-level reason (duplicate edge, missing target issue, type not allowed, driver error).
Source
Thrown at cmd/bd/cook.go:926
return fmt.Errorf("checking custom types: %w", err)
}
// Create all issues
if err := tx.CreateIssues(ctx, issues, actor); err != nil {
return fmt.Errorf("failed to create issues: %w", err)
}
// Add labels
for _, l := range labels {
if err := tx.AddLabel(ctx, l.issueID, l.label, actor); err != nil {
return fmt.Errorf("failed to add label %s to %s: %w", l.label, l.issueID, err)
}
}
// Add dependencies
for _, dep := range deps {
if err := tx.AddDependency(ctx, dep, actor); err != nil {
return fmt.Errorf("failed to create dependency: %w", err)
}
}
return nil
})
if err != nil {
return nil, err
}
return &cookFormulaResult{
ProtoID: protoID,
Created: len(issues),
}, nil
}
// collectDependencies collects blocking dependencies from depends_on, needs, and waits_for fields.
// This is the shared implementation used by both DB-persisted and in-memory subgraph cooking.View on GitHub (pinned to 71377f2769)
Solutions
- Read the wrapped cause: if it's a duplicate/unknown-target dependency, fix the formula's depends_on/needs/waits_for so each edge references an existing step ID and isn't redundant with waits_for
- Validate the formula (bd mol / formula lint) before persisting so step IDs and dependency references resolve
- Re-run the command — the transaction rolled back cleanly, so no cleanup is needed; retry after fixing the formula
- If the cause is a driver/storage error, check database connectivity and Dolt health before retrying
Example fix
# before (formula.yaml) depends_on: [build, build] # duplicate edge # after depends_on: [build]
Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate the formula before persisting
for _, step := range f.Steps {
for _, depID := range append(append([]string{}, step.DependsOn...), step.Needs...) {
if _, ok := idMapping[depID]; !ok {
return fmt.Errorf("step %q references unknown dependency %q", step.ID, depID)
}
}
} Try / catch
if err := persistCookFormula(ctx, s, f); err != nil {
var cause error
errors.As(err, &cause) // inspect wrapped storage error
return fmt.Errorf("cook persist rolled back, formula unchanged: %w", err)
} Prevention
- Lint formulas so every depends_on/needs/waits_for references an existing step ID
- Avoid redundant edges where waits_for spawner equals a depends_on target (GH#3783)
- Use registered issue types or rely on automatic flattening to task before insert
- Treat cook --persist as atomic: a failed run needs no manual cleanup, just fix and rerun
When it happens
Trigger: Running `bd cook <formula> --persist` (via persistCookFormula) where a step's depends_on/needs/waits_for produces an AddDependency call that storage rejects — e.g. the target issue was not among the created issues, a duplicate edge on the same (source,target) pair, or a driver-level constraint failure.
Common situations: A formula YAML whose waits_for spawner overlaps depends_on in a way the dedupe logic (GH#3783) doesn't cover; a custom/registered step type that maps to an issue ID missing from idMapping; Dolt driver errors or constraint violations during the transaction.
Related errors
- delete %s: %w
- failed to link digest to root: %w
- ErrTransaction
- db: DependencySQLRepository.Insert: dep must not be nil
- db: DependencySQLRepository.Insert: IssueID must not be empt
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/11d9968fdf5384d5.
Report an issue: GitHub.