{"record":{"id":"afc17403c42455ff","repo":"gastownhall/beads","slug":"applygraph-edge-d-references-undefined-to-key-q","errorCode":null,"errorMessage":"applyGraph: edge %d references undefined to_key %q","messagePattern":"applyGraph: edge (.+?) references undefined to_key %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/issue.go","lineNumber":1183,"sourceCode":"\tparentDepPairs := graphParentDepPairs(plan.Nodes, keyToID)\n\tnewSchedulingEdges := make([][2]string, 0, len(plan.Nodes)+len(plan.Edges))\n\tif err := u.validatePlannedBlockingPaths(ctx, plan, keyToID, parentDepPairs); err != nil {\n\t\treturn GraphApplyResult{}, err\n\t}\n\tif err := u.validatePlannedBlockingCycles(ctx, plan, keyToID); err != nil {\n\t\treturn GraphApplyResult{}, err\n\t}\n\t// Preserve failure-before-write for explicit edges that conflict directly\n\t// with an implicit node parent relationship. Parent-first mutation below is\n\t// for transitive hierarchy visibility, not for deferring structural errors.\n\tfor i, edge := range plan.Edges {\n\t\tfromID := resolveEdgeRef(edge.FromKey, edge.FromID, keyToID)\n\t\tif fromID == \"\" {\n\t\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: edge %d references undefined from_key %q\", i, edge.FromKey)\n\t\t}\n\t\ttoID := resolveEdgeRef(edge.ToKey, edge.ToID, keyToID)\n\t\tif toID == \"\" {\n\t\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: edge %d references undefined to_key %q\", i, edge.ToKey)\n\t\t}\n\t\tdepType := edge.Type\n\t\tif depType == \"\" {\n\t\t\tdepType = types.DepBlocks\n\t\t}\n\t\tif parentDepPairs[depPairKey(fromID, toID)] && depType != types.DepParentChild {\n\t\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: edge %d %s->%s duplicates a parent-child relationship with dependency type %q\", i, fromID, toID, depType)\n\t\t}\n\t\tif parentDepPairs[depPairKey(toID, fromID)] && cycleRelevantDepType(depType) {\n\t\t\treturn GraphApplyResult{}, fmt.Errorf(\"applyGraph: edge %d %s->%s creates a blocking reverse of a parent-child relationship\", i, fromID, toID)\n\t\t}\n\t}\n\n\t// Pass 3 — insert node parent-child deps now that all IDs are known. These\n\t// must be visible before any blocking edge in the same plan so the storage\n\t// hierarchy guard evaluates existing + planned ancestry.\n\tfor _, node := range plan.Nodes {\n\t\tparentID := node.ParentID","sourceCodeStart":1165,"sourceCodeEnd":1201,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/issue.go#L1165-L1201","documentation":"Same fail-fast validation as the from_key check, but applied to the edge's to-side: applyGraph resolves Edges[i].ToKey/ToID against keyToID and aborts the entire graph apply if the dependency target does not exist, preserving failure-before-write semantics.","triggerScenarios":"applyGraph plan contains an edge whose ToKey (with no valid ToID) names an issue absent from the DB and from the plan's own nodes.","commonSituations":"Referencing a blocker that was closed-and-deleted; typo in the dependency target key; plan split across two applies where the target was expected in the other half; key from a different project prefix.","solutions":["Create the target issue (in the plan or beforehand) so ToKey resolves","Check the target key with bd show; fix typos","Use edge.ToID when the UUID is known","Sync first if the target lives on another machine/remote"],"exampleFix":"// before\nGraphEdge{FromKey: \"bd-1\", ToKey: \"bd-blocked-by-missing\"}\n// after\nGraphEdge{FromKey: \"bd-1\", ToKey: \"bd-2\"} // ensure bd-2 exists or is a node in the same plan","handlingStrategy":"validation","validationCode":"for _, e := range plan.Edges {\n    if _, ok := keyToID[e.ToKey]; !ok && e.ToID == \"\" {\n        return fmt.Errorf(\"edge to_key %q not found; create it or add a node\", e.ToKey)\n    }\n}","typeGuard":"func edgeToResolved(e GraphEdge, keyToID map[string]string) bool {\n    _, ok := keyToID[e.ToKey]\n    return ok || e.ToID != \"\"\n}","tryCatchPattern":null,"preventionTips":["Validate every edge target exists before applyGraph","Keep plan construction and application against the same DB snapshot","Guard against deleted targets by re-reading keys just before apply","Use consistent issue-key prefixes across environments"],"tags":["graph-apply","validation","storage"],"backgroundTag":"undefined-issue-reference","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}