{"record":{"id":"1ad4376138218e77","repo":"gastownhall/beads","slug":"adding-edge-s-s-w","errorCode":null,"errorMessage":"adding edge %s->%s: %w","messagePattern":"adding edge (.+?)->(.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/graph_apply.go","lineNumber":1055,"sourceCode":"\t\t\t\tdepType := graphApplyDependencyType(edge.Type)\n\t\t\t\tif (depType == types.DepParentChild) != parentPhase {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif parentDepPairs[graphApplyDepPairKey(fromID, toID)] {\n\t\t\t\t\tif depType == types.DepParentChild {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\treturn fmt.Errorf(\"edge %d %s->%s duplicates a parent-child relationship with dependency type %q\", i, fromID, toID, depType)\n\t\t\t\t}\n\t\t\t\tif parentDepPairs[graphApplyDepPairKey(toID, fromID)] && graphApplyCycleRelevantDependencyType(depType) {\n\t\t\t\t\treturn fmt.Errorf(\"edge %d %s->%s creates a blocking reverse of a parent-child relationship\", i, fromID, toID)\n\t\t\t\t}\n\t\t\t\tdep, err := types.NewGraphEdgeDependency(fromID, toID, depType, edge.Gate, edge.SpawnerKey, edge.SpawnerID, edge.ThreadID, keyToID)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"edge %s->%s: %w\", fromID, toID, err)\n\t\t\t\t}\n\t\t\t\tif err := tx.AddDependencyWithOptions(ctx, dep, actor, storage.DependencyAddOptions{}); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"adding edge %s->%s: %w\", fromID, toID, err)\n\t\t\t\t}\n\t\t\t\tif graphApplySchedulingDependencyType(depType) {\n\t\t\t\t\tnewSchedulingEdges = append(newSchedulingEdges, [2]string{fromID, toID})\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Add per-node inline dependencies in stable order for this phase.\n\t\t\tfor i, node := range plan.Nodes {\n\t\t\t\tfor _, dep := range node.Deps {\n\t\t\t\t\tdepType := types.DependencyType(dep.Type)\n\t\t\t\t\tif depType == \"\" {\n\t\t\t\t\t\tdepType = types.DepBlocks\n\t\t\t\t\t}\n\t\t\t\t\tif (depType == types.DepParentChild) != parentPhase {\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\td, err := types.NewGraphNodeDependency(issues[i].ID, depType, dep.Target, keyToID)\n\t\t\t\t\tif err != nil {","sourceCodeStart":1037,"sourceCodeEnd":1073,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/graph_apply.go#L1037-L1073","documentation":"This wraps a failure from tx.AddDependencyWithOptions when persisting a graph edge dependency inside the apply transaction. The edge constructed successfully but the storage layer refused the insert — commonly a foreign-key violation (endpoint issue missing in the DB), a duplicate dependency, or a backend error — aborting the whole graph apply.","triggerScenarios":"tx.AddDependencyWithOptions(ctx, dep, actor, storage.DependencyAddOptions{}) returns an error after NewGraphEdgeDependency succeeded, e.g. fromID/toID exists in keyToID but the corresponding row is missing in storage, or a uniqueness/constraint violation.","commonSituations":"Concurrent modifications racing with the apply (issue deleted between planning and apply), database constraint conflicts from a partially-applied earlier attempt, or storage connectivity problems.","solutions":["Check the wrapped error for the storage-level cause (foreign key, duplicate, connection)","Re-run bd graph apply after confirming both endpoint issues exist (bd show)","Deduplicate the plan so the same edge isn't inserted twice","Verify database health (bd doctor) and retry on a clean connection"],"exampleFix":"// before: applying a stale plan after the target issue was deleted\nbd graph apply plan.json\n// after: regenerate the plan and ensure targets exist\nbd show task-2 && bd graph apply plan.json","handlingStrategy":"try-catch","validationCode":"for _, e := range plan.Edges {\n  if !issueExists(resolve(e.From)) || !issueExists(resolve(e.To)) {\n    return fmt.Errorf(\"edge endpoint missing in db\")\n  }\n}","typeGuard":"func depInsertable(e Edge, keyToID map[string]string, db DB) bool {\n  return db.HasIssue(keyToID[e.FromKey]) && db.HasIssue(keyToID[e.ToKey])\n}","tryCatchPattern":"if err := bd.GraphApply(ctx, plan); err != nil {\n  if strings.Contains(err.Error(), \"adding edge\") {\n    // transaction rolled back; safe to retry after fixing storage\n    return retryGraphApply(ctx, plan)\n  }\n  return err\n}","preventionTips":["Don't run concurrent writers against the same beads database","Regenerate plans after any issue deletions","Run bd doctor to verify storage health before large applies"],"tags":["beads","graph-apply","dependency","storage"],"backgroundTag":"dependency-insert-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}