JuliusBrussee/caveman · error · Error

${where} representative trace names a variant that is not th

Error message

${where} representative trace names a variant that is not that arm's variant

What it means

Every representative trace declares the arm it was selected from and the variant it ran; the validator resolves trace.arm in the arm-to-variant map and requires trace.variant_id to equal that arm's variant id (validate-continuous-improvement.mjs:159-161). A trace naming another variant — or an arm role that is not baseline/alternative, which makes the lookup miss — fails here.

Source

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

    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) {
      if (count > 3) throw new Error(`${where} arm ${arm} carries ${count} representative traces, more than three`);
    }

    const slice = item.causal_slice;
    const sliceVariant = variantsByID.get(slice.variant_id);
    if (!sliceVariant) throw new Error(`${where} causal slice references a workflow variant that is not in this report`);
    if (sliceVariant.id !== armVariants.get("baseline").id) throw new Error(`${where} causal slice is not taken from the baseline arm's variant`);
    const sliceNodes = new Set(sliceVariant.nodes.map((node) => node.id));
    if (slice.manifestation_node_id !== "" && !sliceNodes.has(slice.manifestation_node_id)) {
      throw new Error(`${where} manifestation node ${slice.manifestation_node_id} is not a node of variant ${sliceVariant.id}`);
    }
    if (item.diagnosis.manifestation.node_id !== slice.manifestation_node_id) {

View on GitHub (pinned to 766dce6b13)

Solutions

  1. Set trace.variant_id to the named arm's current variant_id.
  2. Fix trace.arm to be exactly "baseline" or "alternative".
  3. If the arm's variant changed, re-select traces from units that actually ran the new variant, then re-run the validator.

Example fix

// before — baseline arm's variant is wf-build-01
{ "arm": "baseline", "variant_id": "wf-build-02", "analysis_unit_id": "unit-901" }
// after
{ "arm": "baseline", "variant_id": "wf-build-01", "analysis_unit_id": "unit-901" }
Defensive patterns

Strategy: validation

Validate before calling

const traceVariantDrift = (report) =>
  report.cases.flatMap((c) => {
    const armVariant = new Map(c.cohort.arms.map((a) => [a.role, a.variant_id]));
    return c.representative_traces
      .filter((t) => armVariant.get(t.arm) !== t.variant_id)
      .map((t) => `${c.id}:${t.analysis_unit_id}`);
  });

Try / catch

try {
  execFileSync(process.execPath, [VALIDATOR, reportPath, spansPath]);
} catch (err) {
  if (/not that arm's variant/.test(err.message)) {
    failCI(`trace/arm variant mismatch — align variant_id with the arm: ${err.message}`);
  } else throw err;
}

Prevention

When it happens

Trigger: A trace was copied from the other arm without updating variant_id; trace.arm is misspelled ('base', 'alt') so armVariants.get(trace.arm) returns undefined; an arm's variant_id was changed after the traces were written.

Common situations: Duplicating a trace entry to pad a fixture; editing cohort arms in a refactor while leaving traces untouched; generator emitting traces from a variant snapshot taken before arms were finalized.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18). Data as JSON: /api/errors/b4ee4fa07b661e5d. Report an issue: GitHub.