{"record":{"id":"175ad5de37b4ca17","repo":"JuliusBrussee/caveman","slug":"where-cohort-arm-arm-role-references-a-workf","errorCode":null,"errorMessage":"${where} cohort arm ${arm.role} references a workflow variant that is not in this report","messagePattern":"(.+?) cohort arm (.+?) 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":148,"sourceCode":"  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]));\n  const familiesByID = new Map(report.task_families.map((family) => [family.id, family]));\n  for (const item of report.cases) {\n    const where = `report fixture ${reportPaths[index]}: case ${item.id}`;\n    const family = familiesByID.get(item.cohort.task_family_id);\n    if (!family) throw new Error(`${where} cohort references a task family that is not in this report`);\n    const familyUnits = new Set(family.analysis_unit_ids);\n    if (item.cohort.family_unit_count !== familyUnits.size) throw new Error(`${where} cohort family unit count disagrees with the task family`);\n    const roles = item.cohort.arms.map((arm) => arm.role);\n    if (roles.join(\",\") !== \"baseline,alternative\") throw new Error(`${where} cohort arms are not baseline then alternative`);\n    const armVariants = new Map();\n    let comparedUnits = 0;\n    for (const arm of item.cohort.arms) {\n      const variant = variantsByID.get(arm.variant_id);\n      if (!variant) throw new Error(`${where} cohort arm ${arm.role} references a workflow variant that is not in this report`);\n      if (variant.task_family_id !== family.id) throw new Error(`${where} cohort arm ${arm.role} uses a variant of another task family`);\n      armVariants.set(arm.role, variant);\n      comparedUnits += arm.unit_count;\n    }\n    const excluded = item.cohort.excluded_units.reduce((total, exclusion) => total + exclusion.unit_count, 0);\n    if (comparedUnits + excluded !== item.cohort.family_unit_count) {\n      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    }","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L130-L166","documentation":"For each cohort arm, the validator looks up `arm.variant_id` in the report's workflow-variant index (`variantsByID`, built from the report's workflow variants). If the id is absent, the arm points at a variant the report does not contain, and this error is thrown. It enforces that both arms of a comparison reference variants declared in the same report.","triggerScenarios":"Running the validator when a case's `cohort.arms[i].variant_id` matches no variant id in the report — typo'd variant id, variant deleted from the report, or an arm copied from a different report.","commonSituations":"Hand-editing fixture ids; regenerating the variant list without updating cohort arms; renaming a variant while cases still use the old id.","solutions":["Fix `arm.variant_id` on the named arm to an id present in the report's workflow variants.","Add the missing workflow variant entry to the report if the variant is legitimate.","Regenerate the fixture so variants and cohort arms are emitted together."],"exampleFix":"// before\narms: [{ role: \"baseline\", variant_id: \"variant-prompt-v2\", ... }]\n\n// after\narms: [{ role: \"baseline\", variant_id: \"variant-prompt-v1\", ... }] // id that exists in report workflow_variants","handlingStrategy":"validation","validationCode":"const variantIds = new Set(report.workflow_variants.map((v) => v.id));\nfor (const c of report.cases) {\n  for (const arm of c.cohort.arms) {\n    if (!variantIds.has(arm.variant_id)) {\n      throw new Error(`case ${c.id}: arm ${arm.role} variant_id ${arm.variant_id} not in report`);\n    }\n  }\n}","typeGuard":"function hasVariant(report, id) {\n  return typeof id === 'string' && report.workflow_variants.some((v) => v.id === id);\n}","tryCatchPattern":"try {\n  validateReport(report);\n} catch (err) {\n  if (String(err.message).includes('references a workflow variant that is not in this report')) {\n    console.error('Dangling variant_id in cohort arm:', err.message);\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["Rename variant ids with a global search-and-replace across all fixture files, not just the variant list.","Derive arm variant_ids from the report's variant registry rather than typing them by hand.","Run the validator in CI so deleted variants surface the same day they are removed.","Keep one fixture per pipeline run so variants and arms never diverge."],"tags":["fixture-validation","referential-integrity","workflow-variant"],"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"}