JuliusBrussee/caveman · error · Error

names an opportunity that is not in this report

Error message

${where} names an opportunity that is not in this report

What it means

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.

Solutions

  1. Correct item.opportunity_id to the id of an opportunity present in this report.
  2. If the opportunity was removed, delete or re-parent the case to an existing opportunity.
  3. Regenerate the cases in the same pass as the opportunities so ids stay in sync.

Example fix

// before
{ "id": "case-1", "opportunity_id": "opp-stale" }
// after
{ "id": "case-1", "opportunity_id": "opp-2026-09-20-a" }
Defensive patterns

Strategy: validation

Validate before calling

const oppIds = new Set(report.opportunities.map(o => o.id));
for (const item of report.cases) {
  if (!oppIds.has(item.opportunity_id)) throw new Error(`case ${item.id} references missing opportunity ${item.opportunity_id}`);
}

Try / catch

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; }

Prevention

When it happens

Trigger: 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).

Common situations: Regenerating opportunities (ids are usually derived) after cases were already written; referencing an opportunity from a prior report run; hand-editing opportunity ids.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/80a151b9ca78b00f. Report an issue: GitHub.

Appendix: source

Thrown at packages/shared/contracts/scripts/validate-continuous-improvement.mjs:229

    }

    // A case that proposes nothing must carry nothing: no operator, no eval
    // pack, no replay. Anything else would present an abstention as a proposal.
    if (item.status === "diagnosis_only") {
      if (item.change_set.operator_id !== "" || item.eval_pack.id !== "" || item.replay.status !== "not_run") {
        throw new Error(`${where} is diagnosis-only but carries a change set, eval pack or replay`);
      }
      continue;
    }
    if (item.change_set.case_id !== item.id || item.eval_pack.case_id !== item.id) {
      throw new Error(`${where} change set or eval pack is bound to another case`);
    }

    // The case must investigate the pair its own opportunity named. A cohort
    // built from a differently-derived pair would describe one comparison and
    // measure another.
    const source = report.opportunities.find((opportunity) => opportunity.id === item.opportunity_id);
    if (!source) throw new Error(`${where} names an opportunity that is not in this report`);
    if (armVariants.get("baseline").id !== source.current_variant_id || armVariants.get("alternative").id !== source.alternative_variant_id) {
      throw new Error(`${where} cohort arms (${armVariants.get("baseline").id}/${armVariants.get("alternative").id}) are not the variants opportunity ${source.id} named`);
    }

    // Every required grader is one the recorded interpreter actually computes.
    // `json_schema` is deliberately absent: over a typed interpreter result it
    // could only assert that a hash is non-empty, which is a grader that cannot
    // fail and therefore inflates how much a replay was checked.
    const knownGraders = new Set(["exact_match", "tool_order", "tool_count", "guard_respected"]);
    for (const grader of item.eval_pack.graders) {
      if (!knownGraders.has(grader)) throw new Error(`${where} requires grader ${grader}, which the recorded interpreter does not compute`);
    }

    // Every dataset case — recorded or generated — must name a real analysis
    // unit of this case's own task family, and its generator and perturbation
    // must agree. A generated case whose source unit cannot be resolved would be
    // invented evidence wearing an adversarial label.
    const dataset = item.eval_pack.dataset;

View on GitHub (pinned to 3ee70a1026)