{"record":{"id":"73b9f50e1f76d15d","repo":"JuliusBrussee/caveman","slug":"where-causal-slice-references-a-workflow-varian","errorCode":null,"errorMessage":"${where} causal slice references a workflow variant that is not in this report","messagePattern":"(.+?) causal slice references a workflow variant that is not in this report","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":173,"sourceCode":"      throw new Error(`${where} cohort arms (${comparedUnits}) plus exclusions (${excluded}) do not account for its ${item.cohort.family_unit_count} family units`);\n    }\n\n    const selectedPerArm = new Map();\n    for (const trace of item.representative_traces) {\n      const variant = armVariants.get(trace.arm);\n      if (!variant || variant.id !== trace.variant_id) throw new Error(`${where} representative trace names a variant that is not that arm's variant`);\n      if (!unitsByID.has(trace.analysis_unit_id)) throw new Error(`${where} representative trace ${trace.analysis_unit_id} is not an analysis unit of this report`);\n      if (!familyUnits.has(trace.analysis_unit_id)) throw new Error(`${where} representative trace ${trace.analysis_unit_id} is not a member of the cohort's task family`);\n      if (!variant.analysis_unit_ids.includes(trace.analysis_unit_id)) throw new Error(`${where} representative trace ${trace.analysis_unit_id} did not run that arm's workflow variant`);\n      selectedPerArm.set(trace.arm, (selectedPerArm.get(trace.arm) ?? 0) + 1);\n    }\n    for (const [arm, count] of selectedPerArm) {\n      if (count > 3) throw new Error(`${where} arm ${arm} carries ${count} representative traces, more than three`);\n    }\n\n    const slice = item.causal_slice;\n    const sliceVariant = variantsByID.get(slice.variant_id);\n    if (!sliceVariant) throw new Error(`${where} causal slice references a workflow variant that is not in this report`);\n    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}`);","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L155-L191","documentation":"Every case's causal_slice must reference a workflow variant that exists in the report's variant registry (`variantsByID`). If `slice.variant_id` does not resolve, the slice cannot be checked against any variant's nodes/edges, so validation fails fast with this error.","triggerScenarios":"`item.causal_slice.variant_id` is not a key of the report's workflow-variants map when running the validator.","commonSituations":"Typo in variant_id; slice copied from another report; variant deleted from the report after the slice was authored.","solutions":["Correct slice.variant_id to match a variant id present in the report","Add the referenced workflow variant to the report","Regenerate the causal slice from a variant that ships in this report"],"exampleFix":"// before\ncausal_slice: { variant_id: 'variant-old-refactor', ... }\n// after\ncausal_slice: { variant_id: 'variant-baseline-v2', ... }","handlingStrategy":"validation","validationCode":"if (!report.workflow_variants.some(v => v.id === slice.variant_id)) throw new Error('slice variant missing from report');","typeGuard":"const sliceVariantExists = (slice, variants) => variants.some(v => v.id === slice.variant_id);","tryCatchPattern":"try { validateCase(item); } catch (e) { if (String(e.message).includes('not in this report')) remapSliceVariant(item); else throw e; }","preventionTips":["Generate slices only from variants registered in the same report","Keep variant ids stable across report revisions","Cross-check slice.variant_id against the report before writing fixtures"],"tags":["validation","reference-integrity"],"backgroundTag":"record-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"}