{"record":{"id":"26a9036018da99be","repo":"JuliusBrussee/caveman","slug":"at-appears-twice-in-the-dataset","errorCode":null,"errorMessage":"${at} appears twice in the dataset","messagePattern":"(.+?) appears twice in the dataset","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":259,"sourceCode":"    }\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\"],\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.","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L241-L277","documentation":"Dataset case ids must be unique within the report's dataset. The validator tracks ids in a Set as it iterates dataset.cases and throws this error the moment it encounters an entry whose id was already seen, because duplicated ids would make replay results and references ambiguous.","triggerScenarios":"Running the validator on a report where two or more entries in dataset.cases share the same entry.id — detected when datasetCaseIDs.has(entry.id) is true on the second occurrence.","commonSituations":"Concatenating generated-case batches without deduplication; a generator emitting the same id for a recorded case and its perturbed variant; copy-pasting dataset entries while editing.","solutions":["Rename the duplicate entry's id so every dataset case id is unique.","If the entries are true duplicates, delete one of them.","Make the case generator namespace ids (e.g. include the perturbation or batch index) to prevent collisions."],"exampleFix":"// before\n[{ \"id\": \"case-1\", ... }, { \"id\": \"case-1\", ... }]\n// after\n[{ \"id\": \"case-1\", ... }, { \"id\": \"case-1-perturbed\", ... }]","handlingStrategy":"validation","validationCode":"const seen = new Set();\nfor (const c of dataset.cases) {\n  if (seen.has(c.id)) throw new Error(`dataset case ${c.id} duplicated`);\n  seen.add(c.id);\n}","typeGuard":null,"tryCatchPattern":"try { validateReport(report); } catch (err) { if (String(err.message).includes('appears twice in the dataset')) { /* dedupe or rename dataset case ids */ } else throw err; }","preventionTips":["Namespace generated case ids with perturbation/batch info.","Deduplicate before appending generated batches to the dataset.","Keep case id generation in one utility."],"tags":["validation","duplicate-id","dataset"],"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"}