{"record":{"id":"a0b59dd65606dbce","repo":"gastownhall/beads","slug":"applygraph-node-q-adding-dep-to-q-w","errorCode":null,"errorMessage":"applyGraph: node %q: adding dep to %q: %w","messagePattern":"applyGraph: node %q: adding dep to %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/issue.go","lineNumber":1283,"sourceCode":"\t\t\t}\n\t\t\tif types.IsSchedulingEdge(depType) {\n\t\t\t\tnewSchedulingEdges = append(newSchedulingEdges, [2]string{fromID, toID})\n\t\t\t}\n\t\t}\n\n\t\t// Per-node inline deps in stable order for this phase, resolved by the\n\t\t// same shared builder as the embedded executeGraphApply (cmd/bd/graph_apply.go).\n\t\tfor _, node := range plan.Nodes {\n\t\t\tfor _, nd := range node.Deps {\n\t\t\t\tdep, err := types.NewGraphNodeDependency(keyToID[node.Key], nd.Type, nd.Target, keyToID)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: node %q: %w\", node.Key, err)\n\t\t\t\t}\n\t\t\t\tif (dep.Type == types.DepParentChild) != parentPhase {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tif err := u.depRepo.Insert(ctx, dep, actor, DepInsertOpts{UseWispsTable: useWisp}); err != nil {\n\t\t\t\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: node %q: adding dep to %q: %w\", node.Key, nd.Target, err)\n\t\t\t\t}\n\t\t\t\tif types.IsSchedulingEdge(dep.Type) {\n\t\t\t\t\tnewSchedulingEdges = append(newSchedulingEdges, [2]string{dep.IssueID, dep.DependsOnID})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif cyclePath, err := u.depRepo.CycleThroughEdges(ctx, newSchedulingEdges); err != nil {\n\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: final cycle check: %w\", err)\n\t} else if cyclePath != \"\" {\n\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: dependency cycle would be created: %s\", cyclePath)\n\t}\n\n\t// Pass 5 — apply deferred assignees.\n\tfor i, assignee := range pendingAssignees {\n\t\tif assignee == \"\" {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":1265,"sourceCodeEnd":1301,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/issue.go#L1265-L1301","documentation":"The same inline node dependency as 3151 was constructed successfully but depRepo.Insert failed when persisting it, wrapped with both the node key and the dependency target. The cause lives in the wrapped error: constraint violation, missing endpoint, or storage failure. This is the persistence-stage counterpart of the construction error at issue.go:1277.","triggerScenarios":"Inserting a node's dependency after construction fails: endpoint issues not in the expected table (wisp vs regular mismatch), duplicate dependency already present, or a database-level error from depRepo.Insert.","commonSituations":"Re-applying plans that double-insert deps; applying a plan where dep targets live in the wisps table but UseWispsTable is false (or vice versa); transient Dolt/network errors mid-apply; foreign-key style violations when the target issue was deleted between phases.","solutions":["Inspect the wrapped error for the storage-level cause.","Confirm both endpoints of the dep are in the same table (matching UseWispsTable).","Make the plan idempotent — skip or upsert deps that already exist.","Re-run apply after fixing any missing/deleted target issues."],"exampleFix":"// before: re-running a plan that already inserted the dep causes duplicate insert\nbd graph apply plan.yaml   # second run fails on same edge\n// after: remove already-applied deps from the plan or use an idempotent apply\nbd graph apply plan.yaml --skip-existing-deps","handlingStrategy":"validation","validationCode":"// Pre-check for duplicates before apply\nseen := map[string]bool{}\nfor _, n := range plan.Nodes {\n    for _, d := range n.Deps {\n        k := n.Key + \"->\" + d.Target + \":\" + d.Type\n        if seen[k] { return fmt.Errorf(\"duplicate dep %s\", k) }\n        seen[k] = true\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := bd.GraphApply(ctx, plan); err != nil {\n    var insertErr *depInsertError\n    if errors.As(err, &insertErr) {\n        log.Printf(\"dep %s -> %s not inserted: %v\", insertErr.Node, insertErr.Target, errors.Unwrap(insertErr))\n    }\n    return err\n}","preventionTips":["Deduplicate node deps before applying","Match UseWispsTable to the actual table of both endpoints","Check for pre-existing identical deps in the DB"],"tags":["go","storage","dependency-graph"],"backgroundTag":"graph-edge-insert-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}