JuliusBrussee/caveman · error · Error

cohort references a task family that is not in this report

Error message

${where} cohort references a task family that is not in this report

What it means

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.

Solutions

  1. 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`.
  2. If the family is legitimately missing, add the corresponding entry to `report.task_families` with a matching `id` and `analysis_unit_ids`.
  3. Regenerate the report fixture from the pipeline so all cross-references are produced together instead of hand-editing.

Example fix

// before
cases: [{ id: "case-1", cohort: { task_family_id: "family-summarize", ... } }]
task_families: [{ id: "family-summarization", ... }]

// after
task_families: [{ id: "family-summarize", ... }] // or fix cohort.task_family_id to "family-summarization"
Defensive patterns

Strategy: validation

Validate before calling

const familyIds = new Set(report.task_families.map((f) => f.id));
for (const c of report.cases) {
  if (!familyIds.has(c.cohort.task_family_id)) {
    throw new Error(`case ${c.id}: task_family_id ${c.cohort.task_family_id} missing from task_families`);
  }
}

Type guard

function hasFamily(report, id) {
  return typeof id === 'string' && report.task_families.some((f) => f.id === id);
}

Try / catch

try {
  validateReport(report);
} catch (err) {
  if (String(err.message).includes('cohort references a task family')) {
    console.error('Fixture referential integrity broken:', err.message);
    process.exitCode = 1;
  } else throw err;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/abc72b516d1cf4fa. Report an issue: GitHub.

Appendix: source

Thrown at packages/shared/contracts/scripts/validate-continuous-improvement.mjs:139

      runs += variant.eligible_runs;
      weighted += (motif.operations.length / variant.signature.length) * variant.eligible_runs;
    }
    if (motif.support_run_count !== runs) throw new Error(`${where} support run count ${motif.support_run_count} != ${runs}`);
    const expectedShare = runs > 0 ? weighted / runs : 0;
    if (Math.abs(motif.structural_cost_share - expectedShare) > 1e-6) {
      throw new Error(`${where} structural_cost_share ${motif.structural_cost_share} != ${expectedShare}`);
    }
  }
  motifCount += report.motifs.length;

  // The causal investigation of every case: the cohort's arms, the traces it
  // selected from them, and the backward hard-dependency slice.
  const unitsByID = new Map(report.analysis_units.map((unit) => [unit.id, unit]));
  const familiesByID = new Map(report.task_families.map((family) => [family.id, family]));
  for (const item of report.cases) {
    const where = `report fixture ${reportPaths[index]}: case ${item.id}`;
    const family = familiesByID.get(item.cohort.task_family_id);
    if (!family) throw new Error(`${where} cohort references a task family that is not in this report`);
    const familyUnits = new Set(family.analysis_unit_ids);
    if (item.cohort.family_unit_count !== familyUnits.size) throw new Error(`${where} cohort family unit count disagrees with the task family`);
    const roles = item.cohort.arms.map((arm) => arm.role);
    if (roles.join(",") !== "baseline,alternative") throw new Error(`${where} cohort arms are not baseline then alternative`);
    const armVariants = new Map();
    let comparedUnits = 0;
    for (const arm of item.cohort.arms) {
      const variant = variantsByID.get(arm.variant_id);
      if (!variant) throw new Error(`${where} cohort arm ${arm.role} references a workflow variant that is not in this report`);
      if (variant.task_family_id !== family.id) throw new Error(`${where} cohort arm ${arm.role} uses a variant of another task family`);
      armVariants.set(arm.role, variant);
      comparedUnits += arm.unit_count;
    }
    const excluded = item.cohort.excluded_units.reduce((total, exclusion) => total + exclusion.unit_count, 0);
    if (comparedUnits + excluded !== item.cohort.family_unit_count) {
      throw new Error(`${where} cohort arms (${comparedUnits}) plus exclusions (${excluded}) do not account for its ${item.cohort.family_unit_count} family units`);
    }

View on GitHub (pinned to 3ee70a1026)