{"record":{"id":"681906fa727565ef","repo":"JuliusBrussee/caveman","slug":"where-support-run-count-motif-support-run-cou","errorCode":null,"errorMessage":"${where} support run count ${motif.support_run_count} != ${runs}","messagePattern":"(.+?) support run count (.+?) != (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":124,"sourceCode":"  const variantsByID = new Map(report.workflow_variants.map((variant) => [variant.id, variant]));\n  const familyIDs = new Set(report.task_families.map((family) => family.id));\n  for (const motif of report.motifs) {\n    const where = `report fixture ${reportPaths[index]}: motif ${motif.id}`;\n    if (!familyIDs.has(motif.task_family_id)) throw new Error(`${where} references a task family that is not in this report`);\n    if (motif.support_variant_count !== motif.variant_ids.length) throw new Error(`${where} support variant count disagrees with its variant ids`);\n    let runs = 0;\n    let weighted = 0;\n    for (const variantID of motif.variant_ids) {\n      const variant = variantsByID.get(variantID);\n      if (!variant) throw new Error(`${where} references workflow variant ${variantID} that is not in this report`);\n      if (variant.task_family_id !== motif.task_family_id) throw new Error(`${where} supporting variant ${variantID} belongs to another task family`);\n      if (!contiguouslyContains(variant.signature, motif.operations)) {\n        throw new Error(`${where} operations are not a contiguous subsequence of variant ${variantID}'s signature`);\n      }\n      runs += variant.eligible_runs;\n      weighted += (motif.operations.length / variant.signature.length) * variant.eligible_runs;\n    }\n    if (motif.support_run_count !== runs) throw new Error(`${where} support run count ${motif.support_run_count} != ${runs}`);\n    const expectedShare = runs > 0 ? weighted / runs : 0;\n    if (Math.abs(motif.structural_cost_share - expectedShare) > 1e-6) {\n      throw new Error(`${where} structural_cost_share ${motif.structural_cost_share} != ${expectedShare}`);\n    }\n  }\n  motifCount += report.motifs.length;\n\n  // The causal investigation of every case: the cohort's arms, the traces it\n  // selected from them, and the backward hard-dependency slice.\n  const unitsByID = new Map(report.analysis_units.map((unit) => [unit.id, unit]));\n  const familiesByID = new Map(report.task_families.map((family) => [family.id, family]));\n  for (const item of report.cases) {\n    const where = `report fixture ${reportPaths[index]}: case ${item.id}`;\n    const family = familiesByID.get(item.cohort.task_family_id);\n    if (!family) throw new Error(`${where} cohort references a task family that is not in this report`);\n    const familyUnits = new Set(family.analysis_unit_ids);\n    if (item.cohort.family_unit_count !== familyUnits.size) throw new Error(`${where} cohort family unit count disagrees with the task family`);\n    const roles = item.cohort.arms.map((arm) => arm.role);","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L106-L142","documentation":"support_run_count must equal the sum of eligible_runs over the motif's supporting variants. The validator accumulates runs during iteration and throws when the stored count diverges, ensuring the motif's run totals are re-derivable from the report's variants.","triggerScenarios":"motif.support_run_count !== sum(variant.eligible_runs for variantID in motif.variant_ids) — typically after editing variant eligible_runs or the motif's variant list without recomputing the total.","commonSituations":"Updating variant run counts during report regeneration; adding/removing supporting variants without recomputing; hand-rounded or stale totals in fixtures.","solutions":["Set support_run_count to the sum of eligible_runs across variant_ids.","Regenerate the report so support_run_count is recomputed from variants.","Fix eligible_runs values if the variant counts are the stale fields."],"exampleFix":"// before\nvariants eligible_runs 10 + 15, motif.support_run_count = 20\n// after\nmotif.support_run_count = 25","handlingStrategy":"validation","validationCode":"const runs = motif.variant_ids.reduce((n, id) => n + report.workflow_variants.find(v => v.id === id).eligible_runs, 0);\nif (motif.support_run_count !== runs) throw new Error(`motif ${motif.id}: support_run_count must be ${runs}`);","typeGuard":"const runCountConsistent = (motif, report) => motif.support_run_count === motif.variant_ids.reduce((n, id) => n + (report.workflow_variants.find(v => v.id === id)?.eligible_runs ?? 0), 0);","tryCatchPattern":"try { validateContinuousImprovement(report); } catch (e) { if (String(e.message).includes('support run count')) { console.error('Recompute support_run_count from variant eligible_runs'); } else throw e; }","preventionTips":["Sum eligible_runs programmatically when writing support_run_count","Recompute all motif aggregates whenever variant run counts change","Keep aggregates derived, never hand-maintained"],"tags":["fixture","count-mismatch","validation"],"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"}