{"record":{"id":"2e1c5465b432e9e2","repo":"gastownhall/beads","slug":"node-q-adding-dep-to-q-w","errorCode":null,"errorMessage":"node %q: adding dep to %q: %w","messagePattern":"node %q: adding dep to %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/graph_apply.go","lineNumber":1077,"sourceCode":"\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 {\n\t\t\t\t\t\treturn fmt.Errorf(\"node %q: %w\", node.Key, err)\n\t\t\t\t\t}\n\t\t\t\t\tif err := tx.AddDependency(ctx, d, actor); err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"node %q: adding dep to %q: %w\", node.Key, dep.Target, err)\n\t\t\t\t\t}\n\t\t\t\t\tif graphApplySchedulingDependencyType(d.Type) {\n\t\t\t\t\t\tnewSchedulingEdges = append(newSchedulingEdges, [2]string{d.IssueID, d.DependsOnID})\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif cyclePath, err := tx.CycleThroughEdges(ctx, newSchedulingEdges); err != nil {\n\t\t\treturn fmt.Errorf(\"final graph cycle check: %w\", err)\n\t\t} else if cyclePath != \"\" {\n\t\t\treturn fmt.Errorf(\"graph dependency cycle would be created: %s\", cyclePath)\n\t\t}\n\n\t\t// Apply deferred assignees.\n\t\tfor i, assignee := range pendingAssignees {\n\t\t\tupdates := map[string]interface{}{\n\t\t\t\t\"assignee\": assignee,\n\t\t\t}","sourceCodeStart":1059,"sourceCodeEnd":1095,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/graph_apply.go#L1059-L1095","documentation":"This wraps a storage failure from tx.AddDependency while inserting an inline node dependency (the dep already constructed successfully). The apply transaction is rolled back and the node key plus dependency target are included to help locate the offending relation.","triggerScenarios":"node.Deps entry passes NewGraphNodeDependency but tx.AddDependency(ctx, d, actor) errors — e.g. target issue missing in storage, constraint violation, duplicate dependency, or backend failure mid-transaction.","commonSituations":"Concurrent deletion of the target issue between validation and insert, re-applying a partially applied plan causing duplicates, or Dolt storage errors.","solutions":["Check the wrapped underlying error for the specific storage cause","Confirm the target issue exists right before applying (bd show <target>)","Avoid concurrent writers to the same database during graph apply","Deduplicate deps in the plan to prevent duplicate-dependency rejections"],"exampleFix":"// before: two agents applying overlapping plans concurrently\nbd graph apply plan.json & bd graph apply plan.json\n// after: serialize applies\nbd graph apply plan.json && bd graph apply plan2.json","handlingStrategy":"try-catch","validationCode":"for _, n := range plan.Nodes {\n  for _, d := range n.Deps {\n    if !issueExists(keyToID[d.Target]) { return fmt.Errorf(\"target %s missing\", d.Target) }\n  }\n}","typeGuard":"func depsPersistable(n Node, db DB, keyToID map[string]string) bool {\n  return len(n.Deps) == 0 || every(n.Deps, func(d Dep) bool { return db.HasIssue(keyToID[d.Target]) })\n}","tryCatchPattern":"if err := bd.GraphApply(ctx, plan); err != nil {\n  if strings.Contains(err.Error(), \"adding dep to\") {\n    // apply is atomic; retry once storage is healthy\n    return retryGraphApply(ctx, plan)\n  }\n  return err\n}","preventionTips":["Serialize graph applies; avoid parallel agents writing the same DB","Re-verify target issues exist immediately before applying","Retry idempotently — failed applies roll back the whole transaction"],"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"}