{"record":{"id":"cfde9f22cfafa705","repo":"JuliusBrussee/caveman","slug":"where-cohort-arms-armvariants-get-baseline","errorCode":null,"errorMessage":"${where} cohort arms (${armVariants.get(\"baseline\").id}/${armVariants.get(\"alternative\").id}) are not the variants opportunity ${source.id} named","messagePattern":"(.+?) cohort arms \\((.+?)/(.+?)\\) are not the variants opportunity (.+?) named","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":231,"sourceCode":"    // A case that proposes nothing must carry nothing: no operator, no eval\n    // pack, no replay. Anything else would present an abstention as a proposal.\n    if (item.status === \"diagnosis_only\") {\n      if (item.change_set.operator_id !== \"\" || item.eval_pack.id !== \"\" || item.replay.status !== \"not_run\") {\n        throw new Error(`${where} is diagnosis-only but carries a change set, eval pack or replay`);\n      }\n      continue;\n    }\n    if (item.change_set.case_id !== item.id || item.eval_pack.case_id !== item.id) {\n      throw new Error(`${where} change set or eval pack is bound to another case`);\n    }\n\n    // The case must investigate the pair its own opportunity named. A cohort\n    // built from a differently-derived pair would describe one comparison and\n    // measure another.\n    const source = report.opportunities.find((opportunity) => opportunity.id === item.opportunity_id);\n    if (!source) throw new Error(`${where} names an opportunity that is not in this report`);\n    if (armVariants.get(\"baseline\").id !== source.current_variant_id || armVariants.get(\"alternative\").id !== source.alternative_variant_id) {\n      throw new Error(`${where} cohort arms (${armVariants.get(\"baseline\").id}/${armVariants.get(\"alternative\").id}) are not the variants opportunity ${source.id} named`);\n    }\n\n    // Every required grader is one the recorded interpreter actually computes.\n    // `json_schema` is deliberately absent: over a typed interpreter result it\n    // could only assert that a hash is non-empty, which is a grader that cannot\n    // fail and therefore inflates how much a replay was checked.\n    const knownGraders = new Set([\"exact_match\", \"tool_order\", \"tool_count\", \"guard_respected\"]);\n    for (const grader of item.eval_pack.graders) {\n      if (!knownGraders.has(grader)) throw new Error(`${where} requires grader ${grader}, which the recorded interpreter does not compute`);\n    }\n\n    // Every dataset case — recorded or generated — must name a real analysis\n    // unit of this case's own task family, and its generator and perturbation\n    // must agree. A generated case whose source unit cannot be resolved would be\n    // invented evidence wearing an adversarial label.\n    const dataset = item.eval_pack.dataset;\n    const generatorPerturbation = new Map([\n      [\"recorded_case.v1\", \"none\"],","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L213-L249","documentation":"A case's cohort arms must be exactly the variant pair its source opportunity names: the \"baseline\" arm must be source.current_variant_id and the \"alternative\" arm must be source.alternative_variant_id. This error means the cohort was built from a different variant pair, so the case would describe one comparison but measure another.","triggerScenarios":"Running the validator on a report where armVariants.get(\"baseline\").id !== source.current_variant_id or armVariants.get(\"alternative\").id !== source.alternative_variant_id for the case's resolved opportunity.","commonSituations":"Cohort derivation using stale or differently-derived variant ids after the opportunity was regenerated; swapping baseline/alternative; building the cohort from a hard-coded variant pair.","solutions":["Rebuild the cohort so its baseline arm is source.current_variant_id and its alternative arm is source.alternative_variant_id.","If the intended pair differs, update the opportunity itself to name the pair the cohort actually uses.","Derive cohort arms programmatically from the opportunity record instead of hard-coding variant ids."],"exampleFix":"// before\narms: { baseline: \"variant-old\", alternative: \"variant-b\" } // opportunity names variant-a\n// after\narms: { baseline: source.current_variant_id, alternative: source.alternative_variant_id }","handlingStrategy":"validation","validationCode":"const source = report.opportunities.find(o => o.id === item.opportunity_id);\nif (armVariants.get('baseline').id !== source.current_variant_id || armVariants.get('alternative').id !== source.alternative_variant_id) {\n  throw new Error(`cohort arms mismatch for opportunity ${source.id}`);\n}","typeGuard":null,"tryCatchPattern":"try { validateReport(report); } catch (err) { if (String(err.message).includes('are not the variants opportunity')) { /* rebuild cohort from source opportunity */ } else throw err; }","preventionTips":["Derive cohort arms directly from the opportunity record.","Never hard-code variant ids in cohort builders.","Regenerate cohorts whenever opportunities are regenerated."],"tags":["validation","cohort","variant-mismatch"],"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"}