{"record":{"id":"80a151b9ca78b00f","repo":"JuliusBrussee/caveman","slug":"where-names-an-opportunity-that-is-not-in-this","errorCode":null,"errorMessage":"${where} names an opportunity that is not in this report","messagePattern":"(.+?) names an opportunity that is not in this report","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":229,"sourceCode":"    }\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`);\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;","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L211-L247","documentation":"Every improvement case must investigate an opportunity that exists in the same report. The validator looks up item.opportunity_id in report.opportunities and throws when no opportunity with that id is present, because a case tied to a nonexistent opportunity cannot be traced back to the comparison it is supposed to study.","triggerScenarios":"Running the validator on a report where a case's opportunity_id does not match any opportunity.id in report.opportunities (typo, deleted opportunity, or opportunity from a different report).","commonSituations":"Regenerating opportunities (ids are usually derived) after cases were already written; referencing an opportunity from a prior report run; hand-editing opportunity ids.","solutions":["Correct item.opportunity_id to the id of an opportunity present in this report.","If the opportunity was removed, delete or re-parent the case to an existing opportunity.","Regenerate the cases in the same pass as the opportunities so ids stay in sync."],"exampleFix":"// before\n{ \"id\": \"case-1\", \"opportunity_id\": \"opp-stale\" }\n// after\n{ \"id\": \"case-1\", \"opportunity_id\": \"opp-2026-09-20-a\" }","handlingStrategy":"validation","validationCode":"const oppIds = new Set(report.opportunities.map(o => o.id));\nfor (const item of report.cases) {\n  if (!oppIds.has(item.opportunity_id)) throw new Error(`case ${item.id} references missing opportunity ${item.opportunity_id}`);\n}","typeGuard":null,"tryCatchPattern":"try { validateReport(report); } catch (err) { if (String(err.message).includes('names an opportunity that is not in this report')) { /* re-link or delete the case */ } else throw err; }","preventionTips":["Always generate cases from the opportunities of the same report run.","Never hand-edit opportunity ids.","Re-run case derivation after regenerating opportunities."],"tags":["validation","reference-not-found","report"],"backgroundTag":"entity-not-found","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"}