{"record":{"id":"f88da5c4ea54c855","repo":"JuliusBrussee/caveman","slug":"where-references-workflow-variant-variantid-that-is-not-in","errorCode":null,"errorMessage":"${where} references workflow variant ${variantID} that is not in this report","messagePattern":"(.+?) references 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":116,"sourceCode":"    if (Math.abs(relationship.probability_a_given_b - expectedAGivenB) > 1e-9) {\n      throw new Error(`${where} probability_a_given_b ${relationship.probability_a_given_b} != ${expectedAGivenB}`);\n    }\n  }\n  relationshipCount += report.relationships.length;\n\n  // A motif is a structural count over variants this report carries, so every\n  // part of it must be re-derivable from those variants.\n  const variantsByID = new Map(report.workflow_variants.map((variant) => [variant.id, variant]));\n  const familyIDs = new Set(report.task_families.map((family) => family.id));\n  for (const motif of report.motifs) {\n    const where = `report fixture ${reportPaths[index]}: motif ${motif.id}`;\n    if (!familyIDs.has(motif.task_family_id)) throw new Error(`${where} references a task family that is not in this report`);\n    if (motif.support_variant_count !== motif.variant_ids.length) throw new Error(`${where} support variant count disagrees with its variant ids`);\n    let runs = 0;\n    let weighted = 0;\n    for (const variantID of motif.variant_ids) {\n      const variant = variantsByID.get(variantID);\n      if (!variant) throw new Error(`${where} references workflow variant ${variantID} that is not in this report`);\n      if (variant.task_family_id !== motif.task_family_id) throw new Error(`${where} supporting variant ${variantID} belongs to another task family`);\n      if (!contiguouslyContains(variant.signature, motif.operations)) {\n        throw new Error(`${where} operations are not a contiguous subsequence of variant ${variantID}'s signature`);\n      }\n      runs += variant.eligible_runs;\n      weighted += (motif.operations.length / variant.signature.length) * variant.eligible_runs;\n    }\n    if (motif.support_run_count !== runs) throw new Error(`${where} support run count ${motif.support_run_count} != ${runs}`);\n    const expectedShare = runs > 0 ? weighted / runs : 0;\n    if (Math.abs(motif.structural_cost_share - expectedShare) > 1e-6) {\n      throw new Error(`${where} structural_cost_share ${motif.structural_cost_share} != ${expectedShare}`);\n    }\n  }\n  motifCount += report.motifs.length;\n\n  // The causal investigation of every case: the cohort's arms, the traces it\n  // selected from them, and the backward hard-dependency slice.\n  const unitsByID = new Map(report.analysis_units.map((unit) => [unit.id, unit]));","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L98-L134","documentation":"Each variant id listed in a motif's variant_ids must exist in the same report's workflow_variants. The validator builds a map of variant ids and throws when a motif references a variant the report does not carry, enforcing intra-report referential integrity.","triggerScenarios":"A motif lists a variantID absent from report.workflow_variants — a typo, a variant deleted from the report, or a motif copied from another report fixture.","commonSituations":"Pruning variants during report regeneration while motifs still reference them; renaming variant ids; cross-report fixture copy-paste.","solutions":["Remove or correct the stale variantID in the motif's variant_ids.","Regenerate the report so motifs and variants stay in sync.","Re-add the missing workflow variant if it should be present."],"exampleFix":"// before\n{ \"variant_ids\": [\"v1\", \"v-deleted\"] }\n// after\n{ \"variant_ids\": [\"v1\"] }","handlingStrategy":"validation","validationCode":"const variantIDs = new Set(report.workflow_variants.map(v => v.id));\nfor (const m of report.motifs) for (const id of m.variant_ids) if (!variantIDs.has(id)) throw new Error(`motif ${m.id}: unknown variant ${id}`);","typeGuard":"const allVariantsExist = (motif, report) => motif.variant_ids.every(id => report.workflow_variants.some(v => v.id === id));","tryCatchPattern":"try { validateContinuousImprovement(report); } catch (e) { if (String(e.message).includes('not in this report')) { console.error('Remove stale variant ids or regenerate the report'); } else throw e; }","preventionTips":["Regenerate motifs whenever workflow_variants change","Avoid renaming or deleting variant ids without updating dependent motifs","Cross-check motifs only against their own report fixture"],"tags":["fixture","reference-integrity","validation"],"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"}