{"record":{"id":"2a9fd36cf65f06e3","repo":"gastownhall/beads","slug":"failed-to-create-dependency-s-s-v","errorCode":null,"errorMessage":"Failed to create dependency %s -> %s: %v","messagePattern":"Failed to create dependency (.+?) -> (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/tracker/engine.go","lineNumber":1352,"sourceCode":"\t\t}\n\t\ttoIssue, err := resolveIssue(ctx, dep.ToExternalID)\n\t\tif err != nil {\n\t\t\te.warn(\"Failed to resolve dependency target %s: %v\", dep.ToExternalID, err)\n\t\t\terrCount++\n\t\t\tcontinue\n\t\t}\n\n\t\tif fromIssue == nil || toIssue == nil {\n\t\t\tcontinue // Not found (no error) — expected if issue wasn't imported\n\t\t}\n\n\t\td := &types.Dependency{\n\t\t\tIssueID:     fromIssue.ID,\n\t\t\tDependsOnID: toIssue.ID,\n\t\t\tType:        types.DependencyType(dep.Type),\n\t\t}\n\t\tif err := e.Store.AddDependency(ctx, d, e.Actor); err != nil {\n\t\t\te.warn(\"Failed to create dependency %s -> %s: %v\", fromIssue.ID, toIssue.ID, err)\n\t\t\terrCount++\n\t\t}\n\t}\n\treturn errCount\n}\n\nfunc (e *Engine) previewDependencies(ctx context.Context, deps []DependencyInfo, dryRunIssues []*types.Issue) int {\n\tif len(deps) == 0 {\n\t\treturn 0\n\t}\n\n\tresolveIssue, err := e.dependencyIssueResolver(ctx, dryRunIssues)\n\tif err != nil {\n\t\te.warn(\"Failed to build dependency resolver: %v\", err)\n\t\treturn len(deps)\n\t}\n\n\twouldCreate := 0","sourceCodeStart":1334,"sourceCodeEnd":1370,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/tracker/engine.go#L1334-L1370","documentation":"Both endpoints of the dependency resolved to local issues, but AddDependency failed when inserting the dependency edge into the store. The dependency is skipped and counted as failed; remaining dependencies are still processed. Common causes are uniqueness constraints (dependency already exists), foreign-key violations, or storage transaction errors.","triggerScenarios":"e.Store.AddDependency(ctx, d, e.Actor) returns an error — duplicate dependency edge (unique constraint), referenced issue deleted concurrently, invalid dependency type value, or storage lock/transaction failure.","commonSituations":"Tracker contains duplicate dependency links and the store enforces uniqueness; one endpoint was deleted by another process between resolution and insert; invalid dependency type string from the tracker not in bd's allowed set; DB lock during pull.","solutions":["Check the wrapped error: 'unique constraint' means the dependency already exists — safe to ignore; 'foreign key' means an endpoint vanished — re-run pull.","Re-run `bd pull` to retry failed edges; AddDependency is idempotent for existing edges.","Normalize the tracker's dependency type strings to bd's supported types (blocks/related/blocks, etc.).","Avoid concurrent bd processes writing during pull.","If a constraint error persists, inspect and dedupe existing dependencies via `bd dep list`/storage queries."],"exampleFix":"// before: tracker emits custom type \"is-blocked-by\"\nType: types.DependencyType(dep.Type) // \"is-blocked-by\" → insert error\n// after: normalize in the tracker adapter's dependency mapper\nswitch dep.Type { case \"is-blocked-by\": return \"blocks\" (with endpoints swapped) }","handlingStrategy":"try-catch","validationCode":"// skip known-duplicate edges before import\nfor _, dep := range deps {\n    dup, _ := store.HasDependency(ctx, fromLocal(dep), toLocal(dep))\n    if dup { log.Printf(\"edge exists, skipping: %v -> %v\", dep.FromExternalID, dep.ToExternalID) }\n}","typeGuard":null,"tryCatchPattern":"// classify the failure: duplicates are safe, transient errors retry\nstats, err := engine.Sync(ctx, opts)\nif stats != nil && stats.FailedDeps > 0 {\n    if isUniqueViolation(err) {\n        log.Println(\"duplicate dependency edges — safe to ignore\")\n    } else if isTransient(err) {\n        time.Sleep(backoff)\n        engine.Sync(ctx, opts)\n    }\n}","preventionTips":["Normalize tracker dependency types to bd's supported set in the adapter","Deduplicate links in the tracker before first import","Avoid concurrent deletion of issues during pull","Re-run pull after fixes — edge creation is idempotent"],"tags":["sync","dependencies","storage","constraint"],"backgroundTag":"dependency-create-constraint","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}