{"record":{"id":"e950076f4d729e01","repo":"JuliusBrussee/caveman","slug":"where-hard-chain-edge-edge-from-edge-to","errorCode":null,"errorMessage":"${where} hard chain edge ${edge.from}->${edge.to} names a node outside variant ${sliceVariant.id}","messagePattern":"(.+?) hard chain edge (.+?)->(.+?) names a node outside variant (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":192,"sourceCode":"    if (sliceVariant.id !== armVariants.get(\"baseline\").id) throw new Error(`${where} causal slice is not taken from the baseline arm's variant`);\n    const sliceNodes = new Set(sliceVariant.nodes.map((node) => node.id));\n    if (slice.manifestation_node_id !== \"\" && !sliceNodes.has(slice.manifestation_node_id)) {\n      throw new Error(`${where} manifestation node ${slice.manifestation_node_id} is not a node of variant ${sliceVariant.id}`);\n    }\n    if (item.diagnosis.manifestation.node_id !== slice.manifestation_node_id) {\n      throw new Error(`${where} diagnosis manifestation node disagrees with its causal slice`);\n    }\n    for (const nodeID of slice.node_chain) {\n      if (!sliceNodes.has(nodeID)) throw new Error(`${where} causal slice node ${nodeID} is not a node of variant ${sliceVariant.id}`);\n    }\n    if (slice.manifestation_node_id !== \"\" && !slice.node_chain.includes(slice.manifestation_node_id)) {\n      throw new Error(`${where} causal slice omits its own manifestation node`);\n    }\n    const provenDependency = (edge) => edge.strength === \"hard\" && (edge.type === \"data\" || edge.type === \"control\") && edge.evidence_refs.length > 0;\n    const variantEdges = new Map(sliceVariant.edges.map((edge) => [`${edge.from}\u0000${edge.to}\u0000${edge.type}`, edge]));\n    for (const edge of slice.hard_edges) {\n      if (!provenDependency(edge)) throw new Error(`${where} hard chain carries an unproven edge ${edge.from}->${edge.to}`);\n      if (!sliceNodes.has(edge.from) || !sliceNodes.has(edge.to)) throw new Error(`${where} hard chain edge ${edge.from}->${edge.to} names a node outside variant ${sliceVariant.id}`);\n      if (!slice.node_chain.includes(edge.from) || !slice.node_chain.includes(edge.to)) {\n        throw new Error(`${where} hard chain edge ${edge.from}->${edge.to} is outside the slice's node chain`);\n      }\n      const source = variantEdges.get(`${edge.from}\u0000${edge.to}\u0000${edge.type}`);\n      if (!source || source.strength !== \"hard\") throw new Error(`${where} hard chain edge ${edge.from}->${edge.to} is not a hard edge of variant ${sliceVariant.id}`);\n    }\n    for (const edge of slice.unproven_adjacencies) {\n      // The whole point of the separate list: nothing in it may read as proven.\n      if (provenDependency(edge)) throw new Error(`${where} unproven adjacency ${edge.from}->${edge.to} is in fact a proven hard dependency`);\n      if (slice.hard_edges.some((hard) => hard.from === edge.from && hard.to === edge.to && hard.type === edge.type)) {\n        throw new Error(`${where} adjacency ${edge.from}->${edge.to} appears in both the hard chain and the unproven list`);\n      }\n    }\n    const upstream = new Set(item.diagnosis.root_cause_hypothesis.upstream_node_ids);\n    for (const nodeID of upstream) {\n      if (!slice.node_chain.includes(nodeID) || nodeID === slice.manifestation_node_id) {\n        throw new Error(`${where} diagnosis upstream node ${nodeID} is not an upstream node of its causal slice`);\n      }","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L174-L210","documentation":"Both endpoints of every hard-chain edge must be nodes of the slice's variant. The validator checks `sliceNodes.has(edge.from) && sliceNodes.has(edge.to)` and throws if either endpoint references a node outside the variant graph.","triggerScenarios":"A hard edge in `slice.hard_edges` has a `from` or `to` id not present among `sliceVariant.nodes`.","commonSituations":"Cross-variant edge copied into the slice; node ids from a shared/sub-workflow not inlined into this variant; stale ids after graph refactor.","solutions":["Remove the cross-variant edge from hard_edges","Inline the sub-workflow's nodes into the variant or remap the edge to in-variant node ids","Regenerate the slice from the current variant graph"],"exampleFix":"// before\nhard_edges: [{from:'shared_init',to:'node_2',type:'data',strength:'hard',evidence_refs:['e1']}]\n// after\nhard_edges: [{from:'node_1',to:'node_2',type:'data',strength:'hard',evidence_refs:['e1']}]","handlingStrategy":"validation","validationCode":"const nodeIds = new Set(variant.nodes.map(n => n.id));\nconst bad = slice.hard_edges.filter(e => !nodeIds.has(e.from) || !nodeIds.has(e.to));\nif (bad.length) throw new Error(`edges naming nodes outside variant: ${bad.map(e => e.from + '->' + e.to)}`);","typeGuard":"const edgesInVariant = (slice, variant) => { const ids = new Set(variant.nodes.map(n => n.id)); return slice.hard_edges.every(e => ids.has(e.from) && ids.has(e.to)); };","tryCatchPattern":"try { validateCase(item); } catch (e) { if (String(e.message).includes('names a node outside variant')) inlineSubworkflowNodes(item); else throw e; }","preventionTips":["Inline sub-workflows into the variant before extracting slices","Remap external node ids when composing variants","Lint edges against the variant node set in CI"],"tags":["validation","graph-reference"],"backgroundTag":"entity-not-found","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}