JuliusBrussee/caveman · error · Error

cohort arm uses a variant of another task family

Error message

${where} cohort arm ${arm.role} uses a variant of another task family

What it means

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.

Solutions

  1. Change the arm's variant_id to a variant whose task_family_id matches the cohort's task family.
  2. Correct the referenced variant's task_family_id in the report if it was misassigned.
  3. Regenerate the fixture from the pipeline so variants and cohorts are derived from the same family definitions.

Example fix

// before
// cohort.task_family_id: "family-summarize"
arms: [{ role: "alternative", variant_id: "variant-extract-v1", ... }] // variant-extract-v1.task_family_id: "family-extract"

// after
arms: [{ role: "alternative", variant_id: "variant-summarize-v2", ... }] // same family as the cohort
Defensive patterns

Strategy: validation

Validate before calling

const variants = new Map(report.workflow_variants.map((v) => [v.id, v]));
const families = new Map(report.task_families.map((f) => [f.id, f]));
for (const c of report.cases) {
  const fam = families.get(c.cohort.task_family_id);
  for (const arm of c.cohort.arms) {
    const v = variants.get(arm.variant_id);
    if (fam && v && v.task_family_id !== fam.id) {
      throw new Error(`case ${c.id}: arm ${arm.role} variant belongs to ${v.task_family_id}, cohort expects ${fam.id}`);
    }
  }
}

Type guard

function variantBelongsToFamily(variant, familyId) {
  return variant != null && variant.task_family_id === familyId;
}

Try / catch

try {
  validateReport(report);
} catch (err) {
  if (String(err.message).includes('uses a variant of another task family')) {
    console.error('Cross-family variant reference; reassign the variant or pick a same-family variant:', err.message);
  } else throw err;
}

Prevention

When it happens

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

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

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

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

  // 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`);
    }

    const selectedPerArm = new Map();
    for (const trace of item.representative_traces) {
      const variant = armVariants.get(trace.arm);
      if (!variant || variant.id !== trace.variant_id) throw new Error(`${where} representative trace names a variant that is not that arm's variant`);
      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`);
      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`);
      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`);
      selectedPerArm.set(trace.arm, (selectedPerArm.get(trace.arm) ?? 0) + 1);
    }
    for (const [arm, count] of selectedPerArm) {

View on GitHub (pinned to 3ee70a1026)