{"record":{"id":"e7403df084ef5711","repo":"JuliusBrussee/caveman","slug":"at-names-source-unit-entry-source-unit-id-th","errorCode":null,"errorMessage":"${at} names source unit ${entry.source_unit_id} that is not an analysis unit of this report","messagePattern":"(.+?) names source unit (.+?) that is not an analysis unit of this report","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":261,"sourceCode":"    // 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\"],\n      [\"boundary_guard_threshold.v1\", \"guard_threshold_boundary\"],\n      [\"adversarial_misleading_tool_output.v1\", \"misleading_tool_output\"],\n      [\"adversarial_stale_input.v1\", \"stale_input\"],\n    ]);\n    const roleCounts = { target_failure: 0, prior_success: 0, boundary: 0, adversarial: 0 };\n    const recordedSources = new Set();\n    const datasetCaseIDs = new Set();\n    for (const entry of dataset.cases) {\n      const at = `${where} dataset case ${entry.id}`;\n      if (datasetCaseIDs.has(entry.id)) throw new Error(`${at} appears twice in the dataset`);\n      datasetCaseIDs.add(entry.id);\n      if (!unitsByID.has(entry.source_unit_id)) throw new Error(`${at} names source unit ${entry.source_unit_id} that is not an analysis unit of this report`);\n      if (!familyUnits.has(entry.source_unit_id)) throw new Error(`${at} names source unit ${entry.source_unit_id} that is not a member of task family ${family.id}`);\n      if (generatorPerturbation.get(entry.generator) !== entry.perturbation) {\n        throw new Error(`${at} generator ${entry.generator} disagrees with perturbation ${entry.perturbation}`);\n      }\n      if (entry.perturbation === \"none\" && entry.id !== entry.source_unit_id) {\n        throw new Error(`${at} replays a recorded flow but is not identified by its source unit`);\n      }\n      if (entry.perturbation !== \"none\" && entry.id !== `${entry.generator}:${entry.source_unit_id}`) {\n        throw new Error(`${at} is a generated case whose id does not name its generator and source unit`);\n      }\n      roleCounts[entry.role] += 1;\n      if (entry.role === \"target_failure\" || entry.role === \"prior_success\") recordedSources.add(entry.source_unit_id);\n    }\n    for (const entry of dataset.cases) {\n      // Leakage: a generated case must not perturb a unit the manifest already\n      // replays unperturbed.\n      if (entry.perturbation !== \"none\" && recordedSources.has(entry.source_unit_id)) {\n        throw new Error(`${where} generated case ${entry.id} perturbs a unit the dataset already replays unperturbed`);","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L243-L279","documentation":"Thrown when a dataset case's source_unit_id is not in unitsByID, the map of all analysis units of this report. Every dataset case — recorded or generated — must be derived from a real analysis unit of the report; an unresolvable source unit would be invented evidence wearing an adversarial label.","triggerScenarios":"Typing a wrong unit id; generating dataset cases from a unit list that is out of sync with report.analysis_units; removing an analysis unit from the report while dataset cases still cite it.","commonSituations":"Regenerating analysis units under new ids (e.g., hashing or renumbering) without regenerating eval packs; cross-report case reuse.","solutions":["Correct source_unit_id to an id present in the report's analysis units (and in the case's own task family — the next check enforces family membership).","If the unit no longer exists, delete the dataset case that cites it.","Regenerate the dataset from the same unit snapshot the report embeds."],"exampleFix":"// before\nentry.source_unit_id = \"unit-77\"   // not in report.analysis_units\n\n// after\nentry.source_unit_id = \"unit-07\"","handlingStrategy":"validation","validationCode":"const units = new Set(report.analysis_units.map((u) => u.id));\nconst resolvable = dataset.cases.every((c) => units.has(c.source_unit_id));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Snapshot the report's analysis-unit ids and validate dataset sources against that snapshot before composition.","Regenerate eval packs whenever analysis-unit ids change."],"tags":["validation","dataset","referential-integrity"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}