{"record":{"id":"0c9ddeaf47e13bba","repo":"JuliusBrussee/caveman","slug":"where-guard-respected-grader-perturbed-mis","errorCode":null,"errorMessage":"${where} guard_respected grader ${perturbed ? \"missing for\" : \"declared without\"} perturbed dataset cases","messagePattern":"(.+?) guard_respected grader (.+?) perturbed dataset cases","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-continuous-improvement.mjs","lineNumber":320,"sourceCode":"    const expectedPriors = Math.min(2, dataset.prior_success_cases.length);\n    if (roleCounts.target_failure !== expectedTargets) throw new Error(`${where} dataset carries ${roleCounts.target_failure} target-failure cases, want ${expectedTargets}`);\n    if (roleCounts.prior_success !== expectedPriors) throw new Error(`${where} dataset carries ${roleCounts.prior_success} prior-success cases, want ${expectedPriors}`);\n    if (roleCounts.boundary > 1) throw new Error(`${where} dataset carries ${roleCounts.boundary} boundary cases, want at most one`);\n    if (roleCounts.adversarial > (confidenceGuard ? 2 : 1)) throw new Error(`${where} dataset carries ${roleCounts.adversarial} adversarial cases`);\n    if (roleCounts.boundary !== dataset.boundary_cases.length) throw new Error(`${where} boundary case list disagrees with the composed dataset`);\n    if (roleCounts.adversarial !== dataset.generated_cases.length) throw new Error(`${where} generated case list disagrees with the composed dataset`);\n    const composed = roleCounts.target_failure + roleCounts.prior_success + roleCounts.boundary + roleCounts.adversarial;\n    if (composed !== dataset.cases.length) throw new Error(`${where} dataset roles (${composed}) do not account for its ${dataset.cases.length} cases`);\n    if (dataset.replay_case_ids.length !== datasetCaseIDs.size) throw new Error(`${where} replay manifest carries ${dataset.replay_case_ids.length} ids for ${datasetCaseIDs.size} dataset cases`);\n    for (const datasetCaseID of dataset.replay_case_ids) {\n      if (!datasetCaseIDs.has(datasetCaseID)) throw new Error(`${where} replay manifest case ${datasetCaseID} is not a composed dataset case`);\n    }\n\n    // The guard grader exists exactly when there is a perturbed case to catch a\n    // candidate on; a required grader with no case behind it is decoration.\n    const perturbed = dataset.cases.some((entry) => entry.perturbation !== \"none\");\n    if (perturbed !== item.eval_pack.graders.includes(\"guard_respected\")) {\n      throw new Error(`${where} guard_respected grader ${perturbed ? \"missing for\" : \"declared without\"} perturbed dataset cases`);\n    }\n    for (const proof of item.replay.trial_proofs) {\n      if (!datasetCaseIDs.has(proof.dataset_case_id)) throw new Error(`${where} replay trial ${proof.id} replays a case outside the composed dataset`);\n      for (const arm of [proof.baseline, proof.candidate]) {\n        const graders = arm.grader_results.map((grader) => grader.grader).sort();\n        const required = [...item.eval_pack.graders].sort();\n        if (graders.join(\",\") !== required.join(\",\")) {\n          throw new Error(`${where} replay trial ${proof.id} graded ${graders.join(\",\")}, want exactly ${required.join(\",\")}`);\n        }\n      }\n    }\n  }\n}\nif (!Array.isArray(spans) || spans.length === 0) throw new Error(\"canonical span fixture is empty\");\nfor (const [index, span] of spans.entries()) {\n  if (!validateSpan(span)) throw new Error(`canonical span ${index}: ${ajv.errorsText(validateSpan.errors)}`);\n}\nif (relationshipCount === 0) throw new Error(\"no theme relationship reached the shared-analysis-unit threshold in any fixture\");","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-continuous-improvement.mjs#L302-L338","documentation":"The guard_respected grader must exist exactly when the composed dataset contains at least one case with a perturbation other than \"none\": the grader is the mechanism that catches candidates breaking under perturbation, so declaring it without perturbed cases is decoration, and omitting it with perturbed cases leaves them unguarded. The validator throws on either side of the mismatch.","triggerScenarios":"validate-continuous-improvement.mjs computes perturbed = dataset.cases.some(c => c.perturbation !== \"none\") and it differs from item.eval_pack.graders.includes(\"guard_respected\").","commonSituations":"Adding a perturbed case but forgetting to add guard_respected to eval_pack.graders; removing all perturbations while the grader list still declares it; an editor stripping perturbation values to \"none\".","solutions":["If cases are perturbed, add \"guard_respected\" to item.eval_pack.graders.","If no case is perturbed, remove \"guard_respected\" from eval_pack.graders.","Adjust perturbation fields on dataset.cases to match the intended guard configuration.","Regenerate the eval pack and dataset together so the grader set is derived from the cases."],"exampleFix":"// before: perturbed case added, graders lack guard_respected\n// after:\nitem.eval_pack.graders.push(\"guard_respected\");","handlingStrategy":"validation","validationCode":"const perturbed = dataset.cases.some((c) => c.perturbation !== \"none\");\nconst declared = item.eval_pack.graders.includes(\"guard_respected\");\nif (perturbed !== declared) throw new Error(\"guard_respected grader / perturbed cases mismatch\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat guard_respected and perturbed cases as one unit — change them together.","Derive the grader list from dataset contents in your generator.","Add this exact invariant to fixture unit tests."],"tags":["fixture-validation","eval-pack","grader-coupling"],"backgroundTag":"internal-invariant-violation","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"}