{"record":{"id":"abc72b516d1cf4fa","repo":"JuliusBrussee/caveman","slug":"where-cohort-references-a-task-family-that-is-n","errorCode":null,"errorMessage":"${where} cohort references a task family that is not in this report","messagePattern":"(.+?) cohort references a task family that is not in this report","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":139,"sourceCode":"      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]));\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","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L121-L157","documentation":"The continuous-improvement report validator builds an index of every task family in `report.task_families` and then checks each case's `cohort.task_family_id` against it. If a case's cohort points at a task_family_id that has no matching entry in the report's task_families list, validation aborts with this error. It enforces referential integrity inside a report fixture: cohorts can only be defined over families the same report declares.","triggerScenarios":"Running validate-continuous-improvement.mjs against a report fixture where `report.cases[i].cohort.task_family_id` does not match any `report.task_families[j].id` (typo'd ID, family removed from the list but cases still reference it, or cases copied from another report).","commonSituations":"Hand-editing fixture JSON and renaming a family id; regenerating task_families without regenerating cases; merging reports so cases reference families that were dropped; copy-pasting a case between report files.","solutions":["Open the fixture report, find the case whose id is in the error message, and correct `cohort.task_family_id` to an id present in `task_families`.","If the family is legitimately missing, add the corresponding entry to `report.task_families` with a matching `id` and `analysis_unit_ids`.","Regenerate the report fixture from the pipeline so all cross-references are produced together instead of hand-editing."],"exampleFix":"// before\ncases: [{ id: \"case-1\", cohort: { task_family_id: \"family-summarize\", ... } }]\ntask_families: [{ id: \"family-summarization\", ... }]\n\n// after\ntask_families: [{ id: \"family-summarize\", ... }] // or fix cohort.task_family_id to \"family-summarization\"","handlingStrategy":"validation","validationCode":"const familyIds = new Set(report.task_families.map((f) => f.id));\nfor (const c of report.cases) {\n  if (!familyIds.has(c.cohort.task_family_id)) {\n    throw new Error(`case ${c.id}: task_family_id ${c.cohort.task_family_id} missing from task_families`);\n  }\n}","typeGuard":"function hasFamily(report, id) {\n  return typeof id === 'string' && report.task_families.some((f) => f.id === id);\n}","tryCatchPattern":"try {\n  validateReport(report);\n} catch (err) {\n  if (String(err.message).includes('cohort references a task family')) {\n    console.error('Fixture referential integrity broken:', err.message);\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["Generate cohort and task_families sections from the same pipeline run; never hand-edit ids independently.","Keep a shared constants file or ID registry for family ids referenced by fixtures.","Run the validator in CI on every fixture change to catch dangling references immediately.","Add a lint script that cross-checks all *_id references against their parent collections."],"tags":["fixture-validation","referential-integrity","task-family"],"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"}