{"record":{"id":"2510172331237de1","repo":"JuliusBrussee/caveman","slug":"where-representative-trace-trace-analysis-uni-251017","errorCode":null,"errorMessage":"${where} representative trace ${trace.analysis_unit_id} is not a member of the cohort's task family","messagePattern":"(.+?) representative trace (.+?) is not a member of the cohort's task family","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":163,"sourceCode":"    let comparedUnits = 0;\n    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    }","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L145-L181","documentation":"Stronger than a plain existence check: the trace's unit must also be a member of the cohort's task family, i.e. appear in that family's analysis_unit_ids (validate-continuous-improvement.mjs:163). A trace from a unit of another family cannot speak to this cohort's comparison even though it is a valid analysis unit of the report.","triggerScenarios":"The trace reuses a unit from a sibling family (unit-doc-3 while the cohort's family is family-codegen); the unit was moved between families; family.analysis_unit_ids was edited without re-selecting traces.","commonSituations":"Multi-family fixtures where unit ids look interchangeable; reorganizing family membership during a refactor; copy-pasting a trace entry from a case about a different task family.","solutions":["Choose a trace whose analysis_unit_id is listed in the cohort family's analysis_unit_ids.","If the unit's membership was mislabeled, fix family.analysis_unit_ids — then re-check errors 603 and 611 for the same family.","Re-run the validator."],"exampleFix":"// before — cohort family is family-codegen, but the unit belongs to family-doc\n{ \"arm\": \"baseline\", \"variant_id\": \"wf-build-01\", \"analysis_unit_id\": \"unit-doc-3\" }\n// after\n{ \"arm\": \"baseline\", \"variant_id\": \"wf-build-01\", \"analysis_unit_id\": \"unit-code-1\" }","handlingStrategy":"validation","validationCode":"const foreignFamilyTraces = (report) => {\n  const byID = new Map(report.task_families.map((f) => [f.id, f]));\n  return report.cases.flatMap((c) => {\n    const units = new Set(byID.get(c.cohort.task_family_id)?.analysis_unit_ids ?? []);\n    return c.representative_traces\n      .filter((t) => !units.has(t.analysis_unit_id)).map((t) => `${c.id}:${t.analysis_unit_id}`);\n  });\n};","typeGuard":null,"tryCatchPattern":"try {\n  execFileSync(process.execPath, [VALIDATOR, reportPath, spansPath]);\n} catch (err) {\n  if (/not a member of the cohort's task family/.test(err.message)) {\n    failCI(`trace unit belongs to another family: ${err.message}`);\n  } else throw err;\n}","preventionTips":["Select traces only from the cohort family's analysis_unit_ids.","After editing family membership, re-run trace selection.","Prefix unit ids with the family (unit-code-*) so cross-family traces are obvious."],"tags":["fixtures","cross-validation","representative-trace","task-family","membership"],"backgroundTag":"membership-violation","analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}