{"record":{"id":"b710720d51fcfe74","repo":"JuliusBrussee/caveman","slug":"where-cohort-arm-arm-role-uses-a-variant-of","errorCode":null,"errorMessage":"${where} cohort arm ${arm.role} uses a variant of another task family","messagePattern":"(.+?) cohort arm (.+?) uses a variant of another task family","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":149,"sourceCode":"\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    }\n    for (const [arm, count] of selectedPerArm) {","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L131-L167","documentation":"After resolving an arm's variant, the validator checks that the variant's `task_family_id` equals the family the cohort already resolved to (`family.id`). An arm whose variant belongs to a different task family would compare workflows outside the cohort's population, so the validator rejects it. This keeps every arm's variant within the same task family as the cohort.","triggerScenarios":"Running the validator when `variant.task_family_id !== family.id` for one of the cohort's arms — i.e. the arm references a valid variant, but that variant is registered under another task family than `cohort.task_family_id`.","commonSituations":"Copying an arm (e.g. a baseline variant) between cohorts of different families; a variant being reassigned to a new family while old cases still reference it; assembling a report from pieces of other reports.","solutions":["Change the arm's variant_id to a variant whose task_family_id matches the cohort's task family.","Correct the referenced variant's task_family_id in the report if it was misassigned.","Regenerate the fixture from the pipeline so variants and cohorts are derived from the same family definitions."],"exampleFix":"// before\n// cohort.task_family_id: \"family-summarize\"\narms: [{ role: \"alternative\", variant_id: \"variant-extract-v1\", ... }] // variant-extract-v1.task_family_id: \"family-extract\"\n\n// after\narms: [{ role: \"alternative\", variant_id: \"variant-summarize-v2\", ... }] // same family as the cohort","handlingStrategy":"validation","validationCode":"const variants = new Map(report.workflow_variants.map((v) => [v.id, v]));\nconst families = new Map(report.task_families.map((f) => [f.id, f]));\nfor (const c of report.cases) {\n  const fam = families.get(c.cohort.task_family_id);\n  for (const arm of c.cohort.arms) {\n    const v = variants.get(arm.variant_id);\n    if (fam && v && v.task_family_id !== fam.id) {\n      throw new Error(`case ${c.id}: arm ${arm.role} variant belongs to ${v.task_family_id}, cohort expects ${fam.id}`);\n    }\n  }\n}","typeGuard":"function variantBelongsToFamily(variant, familyId) {\n  return variant != null && variant.task_family_id === familyId;\n}","tryCatchPattern":"try {\n  validateReport(report);\n} catch (err) {\n  if (String(err.message).includes('uses a variant of another task family')) {\n    console.error('Cross-family variant reference; reassign the variant or pick a same-family variant:', err.message);\n  } else throw err;\n}","preventionTips":["When reassigning a variant to a new family, update or regenerate all cohorts referencing it.","Build comparisons only from variants listed under the family's own variants, never by copying arms across cohorts.","Filter candidate variants by task_family_id programmatically when assembling fixtures.","Add a pre-commit script that recomputes variant-to-family mappings and diffs them against fixtures."],"tags":["fixture-validation","cross-reference","task-family"],"backgroundTag":"schema-validation-failed","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"}