JuliusBrussee/caveman · error · Error

cohort arm references a workflow variant that is not in…

Error message

${where} cohort arm ${arm.role} references a workflow variant that is not in this report

What it means

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.

Solutions

  1. Fix `arm.variant_id` on the named arm to an id present in the report's workflow variants.
  2. Add the missing workflow variant entry to the report if the variant is legitimate.
  3. Regenerate the fixture so variants and cohort arms are emitted together.

Example fix

// before
arms: [{ role: "baseline", variant_id: "variant-prompt-v2", ... }]

// after
arms: [{ role: "baseline", variant_id: "variant-prompt-v1", ... }] // id that exists in report workflow_variants
Defensive patterns

Strategy: validation

Validate before calling

const variantIds = new Set(report.workflow_variants.map((v) => v.id));
for (const c of report.cases) {
  for (const arm of c.cohort.arms) {
    if (!variantIds.has(arm.variant_id)) {
      throw new Error(`case ${c.id}: arm ${arm.role} variant_id ${arm.variant_id} not in report`);
    }
  }
}

Type guard

function hasVariant(report, id) {
  return typeof id === 'string' && report.workflow_variants.some((v) => v.id === id);
}

Try / catch

try {
  validateReport(report);
} catch (err) {
  if (String(err.message).includes('references a workflow variant that is not in this report')) {
    console.error('Dangling variant_id in cohort arm:', err.message);
    process.exitCode = 1;
  } else throw err;
}

Prevention

When it happens

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

Common situations: Hand-editing fixture ids; regenerating the variant list without updating cohort arms; renaming a variant while cases still use the old id.

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/175ad5de37b4ca17. Report an issue: GitHub.

Appendix: source

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

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

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

View on GitHub (pinned to 3ee70a1026)