JuliusBrussee/caveman · error · Error

cohort arms are not baseline then alternative

Error message

${where} cohort arms are not baseline then alternative

What it means

Every cohort must expose exactly two arms in a fixed order: the first with role "baseline" and the second with role "alternative". The validator joins the arm roles with commas and compares against the literal string "baseline,alternative". Any other ordering, extra arms, missing arms, or wrong role names triggers this error.

Solutions

  1. Reorder/renames cohort.arms so the first arm has role "baseline" and the second has role "alternative".
  2. Remove extra arms or add the missing second arm so exactly two arms exist.
  3. Regenerate the fixture using the tooling that emits the canonical baseline-then-alternative layout.

Example fix

// before
arms: [{ role: "alternative", ... }, { role: "baseline", ... }]

// after
arms: [{ role: "baseline", ... }, { role: "alternative", ... }]
Defensive patterns

Strategy: validation

Validate before calling

for (const c of report.cases) {
  const roles = c.cohort.arms.map((a) => a.role);
  if (roles.join(',') !== 'baseline,alternative') {
    throw new Error(`case ${c.id}: arms must be exactly [baseline, alternative], got [${roles.join(', ')}]`);
  }
}

Type guard

function isBaselineAlternativeArms(arms) {
  return Array.isArray(arms) && arms.length === 2 &&
    arms[0]?.role === 'baseline' && arms[1]?.role === 'alternative';
}

Try / catch

try {
  validateReport(report);
} catch (err) {
  if (String(err.message).includes('arms are not baseline then alternative')) {
    console.error('Normalize arm order/roles to [baseline, alternative]:', err.message);
  } else throw err;
}

Prevention

When it happens

Trigger: A report fixture case where `cohort.arms` has roles in any arrangement other than exactly ["baseline","alternative"] — e.g. arms reversed, roles misspelled ("control"/"treatment"), only one arm, or three arms.

Common situations: Authoring fixtures with different role vocabulary; programmatically building arms with nondeterministic key order; refactoring the schema to support multi-arm experiments without updating fixtures.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

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

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

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

View on GitHub (pinned to 3ee70a1026)