{"record":{"id":"cbe40c62738d862c","repo":"JuliusBrussee/caveman","slug":"schema-failed-to-compile-schema-id","errorCode":null,"errorMessage":"schema failed to compile: ${schema.$id}","messagePattern":"schema failed to compile: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/shared/contracts/scripts/validate-schemas.mjs","lineNumber":32,"sourceCode":"}\n\nconst schemas = [];\nfor (const file of files) {\n  const schema = JSON.parse(await readFile(path.join(schemaRoot, file), \"utf8\"));\n  if (schema.$schema !== \"https://json-schema.org/draft/2020-12/schema\") {\n    throw new Error(`${file}: unsupported or missing $schema`);\n  }\n  if (typeof schema.$id !== \"string\" || schema.$id.length === 0) {\n    throw new Error(`${file}: missing $id`);\n  }\n  schemas.push(schema);\n}\n\nconst ajv = new Ajv2020({ allErrors: true, strict: true });\najv.addSchema(schemas);\nfor (const schema of schemas) {\n  const validate = ajv.getSchema(schema.$id);\n  if (!validate) throw new Error(`schema failed to compile: ${schema.$id}`);\n}\n\nconst agentFixtureRoot = path.join(packageRoot, \"fixtures\", \"agent\");\nconst fixtureFiles = (await readdir(agentFixtureRoot))\n  .filter((name) => name.endsWith(\".json\"))\n  .sort();\n\nif (fixtureFiles.length !== 2) {\n  throw new Error(`expected exactly 2 agent conformance fixtures, found ${fixtureFiles.length}`);\n}\n\nconst fixtures = await Promise.all(\n  fixtureFiles.map(async (file) => JSON.parse(await readFile(path.join(agentFixtureRoot, file), \"utf8\"))),\n);\nconst validateAdapterConformance = ajv.getSchema(\n  \"https://caveman.so/schemas/adapter-conformance.schema.json\",\n);\nif (!validateAdapterConformance) {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/shared/contracts/scripts/validate-schemas.mjs#L14-L50","documentation":"After adding all schemas, the script verifies that each $id resolves to a compiled validation function via ajv.getSchema. Ajv compiles lazily and in strict mode can silently skip/defer broken schemas; if the $id is missing from the compiled set, the script throws with the schema's $id. This catches strict-mode compile rejections or registration mismatches.","triggerScenarios":"Running scripts/validate-schemas.mjs when a schema referenced by $id fails AJv strict-mode compilation (e.g. unsupported keywords like $recursiveAnchor misuse, unknown formats without strict:false, invalid $ref targets) so ajv.getSchema($id) returns undefined.","commonSituations":"A schema uses a non-standard keyword or an unregistered format string and strict mode rejects it; a schema $refs another schema by an $id that doesn't match exactly (case, trailing slash); duplicate $ids causing registration to drop a schema.","solutions":["Temporarily call ajv.compile or inspect Ajv's emitted warnings to see the strict-mode error for that $id","Fix the schema's unsupported keyword, $ref target, or unknown format that blocks compilation","Align $ref targets with exact $id strings of the other registered schemas","As a last resort add a registered format or strict:false only with justification — prefer fixing the schema"],"exampleFix":"// before\n{ \"$id\": \"https://caveman.so/schemas/span.schema.json\", \"properties\": { \"startedAt\": { \"type\": \"string\", \"format\": \"date-time-x\" } } }\n// after\n{ \"$id\": \"https://caveman.so/schemas/span.schema.json\", \"properties\": { \"startedAt\": { \"type\": \"string\", \"format\": \"date-time\" } } }","handlingStrategy":"try-catch","validationCode":"try { ajv.addSchema(schemas); } catch (e) { console.error('Ajv compile failure:', e.message); process.exitCode = 1; }\n// or proactively:\nfor (const s of schemas) ajv.compile(s); // throws with the strict-mode reason","typeGuard":null,"tryCatchPattern":"try { for (const s of schemas) if (!ajv.getSchema(s.$id)) throw new Error(`schema failed to compile: ${s.$id}`); } catch (e) { console.error('Strict-mode compile rejected a schema:', e.message); process.exitCode = 1; }","preventionTips":["Avoid unknown keywords and unregistered format strings in schemas","Keep $ref targets exactly equal to other schemas' $id strings","Run ajv.compile on schemas locally before committing","Upgrade Ajv deliberately and read its strict-mode changelog"],"tags":["ajv","json-schema","compilation"],"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"}