{"record":{"id":"f7f8fb88e84cfb16","repo":"JuliusBrussee/caveman","slug":"where-change-set-or-eval-pack-is-bound-to-anoth","errorCode":null,"errorMessage":"${where} change set or eval pack is bound to another case","messagePattern":"(.+?) change set or eval pack is bound to another case","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":222,"sourceCode":"      }\n    }\n    const upstream = new Set(item.diagnosis.root_cause_hypothesis.upstream_node_ids);\n    for (const nodeID of upstream) {\n      if (!slice.node_chain.includes(nodeID) || nodeID === slice.manifestation_node_id) {\n        throw new Error(`${where} diagnosis upstream node ${nodeID} is not an upstream node of its causal slice`);\n      }\n    }\n\n    // 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`);","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L204-L240","documentation":"Each improvement case's change_set and eval_pack carry a case_id that must point back at the case itself (item.id). This error means one of them references a different case, so the proposal or evaluation would be attributed to the wrong investigation. The validator throws to keep every artifact bound to exactly one case.","triggerScenarios":"Running the validator on a report where change_set.case_id or eval_pack.case_id differs from item.id for any non-diagnosis_only case.","commonSituations":"Duplicating a case and editing its id but not the embedded change_set/eval_pack case_ids; copying an eval_pack from a sibling case; automated case cloning with incomplete field rewriting.","solutions":["Set change_set.case_id and eval_pack.case_id to the owning case's item.id.","If the artifacts intentionally belong to another case, move them to that case's record instead of embedding them here.","When cloning cases, rewrite all embedded *_case_id fields in the same step."],"exampleFix":"// before\n{ \"id\": \"case-7\", \"change_set\": { \"case_id\": \"case-6\" } }\n// after\n{ \"id\": \"case-7\", \"change_set\": { \"case_id\": \"case-7\" } }","handlingStrategy":"validation","validationCode":"for (const item of report.cases) {\n  if (item.status === 'diagnosis_only') continue;\n  if (item.change_set.case_id !== item.id || item.eval_pack.case_id !== item.id) throw new Error(`case ${item.id}: embedded case_id mismatch`);\n}","typeGuard":null,"tryCatchPattern":"try { validateReport(report); } catch (err) { if (String(err.message).includes('bound to another case')) { /* rewrite embedded case_id fields */ } else throw err; }","preventionTips":["Set embedded case_ids from item.id in a factory function, never by hand.","When cloning cases, run a rewrite pass over all *_case_id fields.","Keep case creation in one code path."],"tags":["validation","identifier-mismatch","contract"],"backgroundTag":"invalid-identifier","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"}