{"record":{"id":"b9b40658891720ee","repo":"JuliusBrussee/caveman","slug":"where-support-variant-count-disagrees-with-its-variant-ids","errorCode":null,"errorMessage":"${where} support variant count disagrees with its variant ids","messagePattern":"(.+?) support variant count disagrees with its variant ids","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":111,"sourceCode":"    const expectedBGivenA = relationship.shared_unit_count / relationship.theme_a_unit_count;\n    const expectedAGivenB = relationship.shared_unit_count / relationship.theme_b_unit_count;\n    if (Math.abs(relationship.probability_b_given_a - expectedBGivenA) > 1e-9) {\n      throw new Error(`${where} probability_b_given_a ${relationship.probability_b_given_a} != ${expectedBGivenA}`);\n    }\n    if (Math.abs(relationship.probability_a_given_b - expectedAGivenB) > 1e-9) {\n      throw new Error(`${where} probability_a_given_b ${relationship.probability_a_given_b} != ${expectedAGivenB}`);\n    }\n  }\n  relationshipCount += report.relationships.length;\n\n  // A motif is a structural count over variants this report carries, so every\n  // part of it must be re-derivable from those variants.\n  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  }","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L93-L129","documentation":"support_variant_count is a redundant count that must equal the length of the motif's variant_ids array. The validator throws when they disagree, keeping every motif's structural counts re-derivable from its listed variants.","triggerScenarios":"A motif entry where motif.support_variant_count !== motif.variant_ids.length, e.g. after adding/removing variant ids without updating the count.","commonSituations":"Appending a variant id during fixture updates; filtering variants from a motif after regeneration; hand-editing one field and forgetting the other.","solutions":["Set support_variant_count to variant_ids.length.","Re-run the report generator so counts and id lists are recomputed together.","If the variant list is wrong, re-derive which variants support the motif and fix the list."],"exampleFix":"// before\n{ \"support_variant_count\": 2, \"variant_ids\": [\"v1\", \"v2\", \"v3\"] }\n// after\n{ \"support_variant_count\": 3, \"variant_ids\": [\"v1\", \"v2\", \"v3\"] }","handlingStrategy":"validation","validationCode":"for (const m of report.motifs) if (m.support_variant_count !== m.variant_ids.length) throw new Error(`motif ${m.id}: support_variant_count != variant_ids.length`);","typeGuard":"const motifCountsConsistent = (motif) => motif.support_variant_count === motif.variant_ids.length;","tryCatchPattern":"try { validateContinuousImprovement(report); } catch (e) { if (String(e.message).includes('support variant count disagrees')) { console.error('Set support_variant_count = variant_ids.length'); } else throw e; }","preventionTips":["Compute support_variant_count as variant_ids.length at write time","Treat redundant count fields as derived data — never edit independently","Run the validator on fixtures in CI"],"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"}