{"record":{"id":"e7674ecaea7bd63a","repo":"JuliusBrussee/caveman","slug":"where-representative-trace-trace-analysis-uni-e7674e","errorCode":null,"errorMessage":"${where} representative trace ${trace.analysis_unit_id} did not run that arm's workflow variant","messagePattern":"(.+?) representative trace (.+?) did not run that arm's workflow variant","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":164,"sourceCode":"    for (const arm of item.cohort.arms) {\n      const variant = variantsByID.get(arm.variant_id);\n      if (!variant) throw new Error(`${where} cohort arm ${arm.role} references a workflow variant that is not in this report`);\n      if (variant.task_family_id !== family.id) throw new Error(`${where} cohort arm ${arm.role} uses a variant of another task family`);\n      armVariants.set(arm.role, variant);\n      comparedUnits += arm.unit_count;\n    }\n    const excluded = item.cohort.excluded_units.reduce((total, exclusion) => total + exclusion.unit_count, 0);\n    if (comparedUnits + excluded !== item.cohort.family_unit_count) {\n      throw new Error(`${where} cohort arms (${comparedUnits}) plus exclusions (${excluded}) do not account for its ${item.cohort.family_unit_count} family units`);\n    }\n\n    const selectedPerArm = new Map();\n    for (const trace of item.representative_traces) {\n      const variant = armVariants.get(trace.arm);\n      if (!variant || variant.id !== trace.variant_id) throw new Error(`${where} representative trace names a variant that is not that arm's variant`);\n      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`);\n      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`);\n      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`);\n      selectedPerArm.set(trace.arm, (selectedPerArm.get(trace.arm) ?? 0) + 1);\n    }\n    for (const [arm, count] of selectedPerArm) {\n      if (count > 3) throw new Error(`${where} arm ${arm} carries ${count} representative traces, more than three`);\n    }\n\n    const slice = item.causal_slice;\n    const sliceVariant = variantsByID.get(slice.variant_id);\n    if (!sliceVariant) throw new Error(`${where} causal slice references a workflow variant that is not in this report`);\n    if (sliceVariant.id !== armVariants.get(\"baseline\").id) throw new Error(`${where} causal slice is not taken from the baseline arm's variant`);\n    const sliceNodes = new Set(sliceVariant.nodes.map((node) => node.id));\n    if (slice.manifestation_node_id !== \"\" && !sliceNodes.has(slice.manifestation_node_id)) {\n      throw new Error(`${where} manifestation node ${slice.manifestation_node_id} is not a node of variant ${sliceVariant.id}`);\n    }\n    if (item.diagnosis.manifestation.node_id !== slice.manifestation_node_id) {\n      throw new Error(`${where} diagnosis manifestation node disagrees with its causal slice`);\n    }\n    for (const nodeID of slice.node_chain) {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L146-L182","documentation":"The validator rejects a representative trace whose analysis_unit_id is not listed in the arm variant's analysis_unit_ids. Even if the unit exists and belongs to the family, the trace claims a run of that arm's workflow variant on that unit; the variant's recorded unit list is the source of truth for which units actually ran it.","triggerScenarios":"A trace pairs an analysis unit with an arm whose variant did not execute on that unit (unit id missing from variant.analysis_unit_ids) — e.g. after swapping the arm's variant_id, regenerating variants with different unit assignments, or hand-picking trace units that were excluded from that variant's runs.","commonSituations":"Pointing an arm at a rebuilt variant whose analysis_unit_ids no longer includes the previously traced units; copying traces between cases with different variant assignments; a generator that assigns units to variants but selects representative traces from the whole family.","solutions":["Choose representative trace units that appear in variant.analysis_unit_ids for that arm, or update the variant's analysis_unit_ids to include the traced unit if it truly ran","Regenerate representative traces from the variants' own analysis_unit_ids lists","Check whether the arm's variant_id was swapped and restore the variant that produced the traced runs"],"exampleFix":"// before\n\"representative_traces\": [{ \"arm\": \"alternative\", \"variant_id\": \"v-alt\", \"analysis_unit_id\": \"unit-42\" }]\n// v-alt.analysis_unit_ids = [\"unit-7\",\"unit-8\",\"unit-9\"]\n// after\n\"representative_traces\": [{ \"arm\": \"alternative\", \"variant_id\": \"v-alt\", \"analysis_unit_id\": \"unit-8\" }]","handlingStrategy":"validation","validationCode":"const variantsByID = new Map(report.workflow_variants.map((v) => [v.id, v]));\nfor (const item of report.cases) {\n  const armVariants = new Map(item.cohort.arms.map((a) => [a.role, variantsByID.get(a.variant_id)]));\n  for (const t of item.representative_traces) {\n    const v = armVariants.get(t.arm);\n    if (v && !v.analysis_unit_ids.includes(t.analysis_unit_id)) {\n      throw new Error(`unit ${t.analysis_unit_id} did not run variant ${v.id}`);\n    }\n  }\n}","typeGuard":"function unitRanVariant(unitId, variant) {\n  return variant !== undefined && variant.analysis_unit_ids.includes(unitId);\n}","tryCatchPattern":"try {\n  validateReport(report);\n} catch (err) {\n  if (err.message.includes(\"did not run that arm's workflow variant\")) {\n    console.error('Trace unit not in arm variant analysis_unit_ids; reselect traces.');\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["Select representative traces only from variant.analysis_unit_ids, never from the family at large","After swapping an arm's variant, re-derive traces from the new variant's unit list","Run the validator locally before committing fixture edits"],"tags":["validation","fixtures","consistency"],"backgroundTag":"schema-validation-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}