{"record":{"id":"f24b86b815ef93d0","repo":"JuliusBrussee/caveman","slug":"where-supporting-variant-variantid-belongs-t","errorCode":null,"errorMessage":"${where} supporting variant ${variantID} belongs to another task family","messagePattern":"(.+?) supporting variant (.+?) belongs to another task family","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":117,"sourceCode":"      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  }\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]));","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L99-L135","documentation":"A motif's supporting variants must all belong to the motif's own task family. The validator compares variant.task_family_id with motif.task_family_id and throws when they differ, so family-scoped structural metrics stay coherent.","triggerScenarios":"A motif lists a variantID whose workflow variant entry has a different task_family_id than the motif's task_family_id.","commonSituations":"Motif mining that grouped across family boundaries; a variant reassigned to a different family after motif generation; motif task_family_id corrected without re-filtering its variants.","solutions":["Remove the cross-family variant from the motif's variant_ids (and fix support_variant_count).","Re-derive the motif only from variants whose task_family_id matches the motif's.","Fix the motif's task_family_id if it was recorded incorrectly."],"exampleFix":"// before\n{ \"task_family_id\": \"fa\", \"variant_ids\": [\"v-fa\", \"v-fb\"] }\n// after\n{ \"task_family_id\": \"fa\", \"variant_ids\": [\"v-fa\"] }","handlingStrategy":"validation","validationCode":"for (const m of report.motifs) {\n  const byId = new Map(report.workflow_variants.map(v => [v.id, v]));\n  for (const id of m.variant_ids) if (byId.get(id)?.task_family_id !== m.task_family_id) throw new Error(`motif ${m.id}: variant ${id} is cross-family`);\n}","typeGuard":"const motifVariantsSameFamily = (motif, report) => motif.variant_ids.every(id => report.workflow_variants.find(v => v.id === id)?.task_family_id === motif.task_family_id);","tryCatchPattern":"try { validateContinuousImprovement(report); } catch (e) { if (String(e.message).includes('belongs to another task family')) { console.error('Drop the cross-family variant or fix the motif family id'); } else throw e; }","preventionTips":["Filter supporting variants by task_family_id during motif mining","Re-derive motifs after reassigning variants between families","Validate family coherence as part of the fixture generator"],"tags":["fixture","reference-integrity","validation"],"backgroundTag":"incompatible-source-type","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"}