{"record":{"id":"08165dadc5446e82","repo":"JuliusBrussee/caveman","slug":"unknown-adapter-failure-must-preserve-original-bytes","errorCode":null,"errorMessage":"unknown adapter failure must preserve original bytes","messagePattern":"unknown adapter failure must preserve original bytes","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-schemas.mjs","lineNumber":82,"sourceCode":"\nfor (const key of [\n  \"normalized_context_digest\",\n  \"plan_sha256\",\n  \"ordered_transform_ids\",\n  \"provider_visible_digest\",\n  \"recovery_handles\",\n  \"accounting_method\",\n  \"failure_fallback\",\n]) {\n  if (JSON.stringify(claude[key]) !== JSON.stringify(pi[key])) {\n    throw new Error(`agent conformance mismatch: ${key}`);\n  }\n}\nif (claude.build_sha256 === pi.build_sha256) {\n  throw new Error(\"adapter-specific build_sha256 values must differ\");\n}\nif (claude.failure_fallback !== \"original\") {\n  throw new Error(\"unknown adapter failure must preserve original bytes\");\n}\n\nconst middleware = JSON.parse(await readFile(path.join(packageRoot, \"..\", \"..\", \"sdk\", \"parity\", \"middleware.fixtures.json\"), \"utf8\"));\nfor (const [field, schemaName] of Object.entries({ capabilities: \"capabilities\", request: \"optimize\", plan: \"plan\", page: \"page\" })) {\n  const validate = ajv.getSchema(`https://caveman.so/schemas/middleware-${schemaName}.schema.json`);\n  if (!validate?.(middleware[field])) throw new Error(`middleware ${field}: ${ajv.errorsText(validate?.errors)}`);\n}\n\nconsole.log(\n  `validated ${files.length} JSON schemas and ${fixtureFiles.length} static agent contract fixtures (not executable parity)`,\n);\n","sourceCodeStart":64,"sourceCodeEnd":94,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-schemas.mjs#L64-L94","documentation":"The validator enforces that both adapter fixtures declare failure_fallback === \"original\", throwing this error otherwise. This encodes the repo's byte-safety/honesty rule: when an adapter hits an unknown failure it must fall back to emitting the original, untransformed bytes rather than dropping or substituting output. It guards against a fixture (or contract change) that opts an adapter into a lossy or fail-closed-on-output fallback.","triggerScenarios":"Running the contracts validation script when failure_fallback in a fixture is changed to any other string (e.g. \"passthrough\", \"fail_closed\", \"last_known_good\", \"\"); a refactor renames the enum value in fixtures or schemas without updating the validator; a new fixture is authored with a missing/alternative fallback value that still passes adapter-conformance.schema.json because its enum is looser than this hardcoded check.","commonSituations":"Editing the failure-handling policy for an adapter and updating fixtures to match; a bulk enum rename across schemas/fixtures that missed this literal \"original\" comparison; onboarding a new adapter whose fallback design differs and needs the validator (and contract) updated deliberately.","solutions":["Set failure_fallback back to \"original\" in both packages/shared/contracts/fixtures/agent/*.json files.","If the fallback semantics intentionally changed, update the literal in validate-schemas.mjs (line 81), the adapter-conformance schema enum, and both fixtures together in one coordinated change.","Confirm the adapter implementations actually preserve original bytes on unknown failure before encoding any new fallback value.","Re-run the validation script to confirm all checks pass."],"exampleFix":"// before (claude-conformance.json)\n\"failure_fallback\": \"last_known_good\"\n\n// after\n\"failure_fallback\": \"original\"","handlingStrategy":"validation","validationCode":"const [a, b] = fixtures;\nif (a.failure_fallback !== \"original\" || b.failure_fallback !== \"original\") {\n  throw new Error(\"failure_fallback must be 'original' in both fixtures (byte-safety rule)\");\n}","typeGuard":"function preservesOriginalBytes(fixture) {\n  return fixture?.failure_fallback === \"original\";\n}","tryCatchPattern":"try {\n  await runValidationScript();\n} catch (err) {\n  if (err.message === \"unknown adapter failure must preserve original bytes\") {\n    console.error(\"failure_fallback drifted from 'original'; restore it or coordinate a deliberate contract change.\");\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Treat failure_fallback as a frozen contract value; never change it without updating validator, schema, and both fixtures together.","Keep adapter implementations byte-safe on unknown failures so 'original' remains true.","Add a CI check that greps fixtures for failure_fallback before schema validation runs."],"tags":["build","fixtures","byte-safety","fail-open"],"backgroundTag":"invalid-enum-value","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"}