{"record":{"id":"1ebe760b5682212b","repo":"Hmbown/CodeWhale","slug":"unsupported-observation-version","errorCode":null,"errorMessage":"Unsupported observation version.","messagePattern":"Unsupported observation version\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/src/core/evidence.ts","lineNumber":86,"sourceCode":"};\nconst num = (v:unknown,field:string,min=0):number => {\n  if(typeof v!=='number'||!Number.isFinite(v)||v<min||Math.abs(v)>Number.MAX_SAFE_INTEGER)throw new Error(`Invalid ${field}.`);return v;\n};\nconst optionalText = (o:Record<string,unknown>,key:string):string|undefined => o[key]===undefined?undefined:text(o[key],key);\nconst strings = (v:unknown,field:string,allowEmpty=false):string[]=>{\n  if(!Array.isArray(v)||(!allowEmpty&&!v.length)||v.length>256)throw new Error(`Invalid ${field}.`);\n  const out=v.map(x=>text(x,field));if(new Set(out).size!==out.length)throw new Error(`Duplicate ${field}.`);return out;\n};\nconst boolean = (v:unknown,field:string):boolean=>{if(typeof v!=='boolean')throw new Error(`Invalid ${field}.`);return v;};\nconst optionalNumber=(o:Record<string,unknown>,key:string)=>o[key]===undefined?undefined:num(o[key],key);\nfunction onlyKeys(o:Record<string,unknown>,keys:string[],label:string):void{\n  for(const k of Object.keys(o))if(!keys.includes(k))throw new Error(`Unknown ${label} field: ${k}.`);\n}\n/** All unrecognized fields are rejected, never secretly retained in metadata-only evidence. */\nexport function validateObservation(input:unknown):Observation {\n  const o=object(input,'observation');\n  onlyKeys(o,['version','id','runId','operationId','sourceId','epoch','sequence','time','receivedAt','subject','stage','surface','action','effect','status','target','actionDigest','authority','correlation','facts'],'observation');\n  if(o.version!==1)throw new Error('Unsupported observation version.');\n  const t=object(o.time,'time'),s=object(o.subject,'subject');\n  onlyKeys(t,['wallMs','clockId','monotonicMs','taskMs','uncertaintyMs'],'time');onlyKeys(s,['agentId','sandboxId','isolationGroup'],'subject');\n  const seq=num(o.sequence,'sequence',1);if(!Number.isSafeInteger(seq))throw new Error('sequence must be an integer.');\n  const facts=object(o.facts??{},'facts'),safeFacts:Observation['facts']={};\n  if(Object.keys(facts).length>48)throw new Error('Too many observation facts.');\n  for(const [k,v] of Object.entries(facts)){\n    text(k,'fact key',80);if(['__proto__','prototype','constructor'].includes(k))throw new Error('Unsafe fact key.');\n    if(typeof v==='string')safeFacts[k]=text(v,'fact value',512);\n    else if(typeof v==='number')safeFacts[k]=num(v,'fact value',-Number.MAX_SAFE_INTEGER);\n    else if(v===null||typeof v==='boolean')safeFacts[k]=v;\n    else throw new Error('Facts must be scalar metadata, not content objects.');\n  }\n  let target:Observation['target'];if(o.target!==undefined){const a=object(o.target,'target');onlyKeys(a,['id','kind','version','boundary'],'target');target={id:text(a.id,'target.id'),kind:text(a.kind,'target.kind',64),version:optionalText(a,'version'),boundary:a.boundary===undefined?undefined:enumValue(a.boundary,['local','external','unknown'] as const,'boundary')};}\n  let authority:Observation['authority'];if(o.authority!==undefined){const a=object(o.authority,'authority');onlyKeys(a,['grantId','claimed'],'authority');authority={grantId:optionalText(a,'grantId'),claimed:a.claimed===undefined?undefined:boolean(a.claimed,'claimed')};}\n  let correlation:Observation['correlation'];if(o.correlation!==undefined){const a=object(o.correlation,'correlation');onlyKeys(a,['sessionId','requestId','parentOperationId','messageId'],'correlation');correlation={sessionId:optionalText(a,'sessionId'),requestId:optionalText(a,'requestId'),parentOperationId:optionalText(a,'parentOperationId'),messageId:optionalText(a,'messageId')};}\n  return {version:1,id:text(o.id,'id'),runId:text(o.runId,'runId'),operationId:optionalText(o,'operationId'),sourceId:text(o.sourceId,'sourceId'),epoch:text(o.epoch,'epoch'),sequence:seq,\n    time:{wallMs:num(t.wallMs,'wallMs'),clockId:optionalText(t,'clockId'),monotonicMs:optionalNumber(t,'monotonicMs'),taskMs:optionalNumber(t,'taskMs'),uncertaintyMs:optionalNumber(t,'uncertaintyMs')},receivedAt:optionalNumber(o,'receivedAt'),\n    subject:{agentId:text(s.agentId,'agentId'),sandboxId:optionalText(s,'sandboxId'),isolationGroup:optionalText(s,'isolationGroup')},stage:enumValue(o.stage,STAGES,'stage'),surface:enumValue(o.surface,SURFACES,'surface'),action:text(o.action,'action',128),effect:enumValue(o.effect,EFFECTS,'effect'),status:enumValue(o.status,['started','completed','error','unknown'],'status'),target,actionDigest:optionalText(o,'actionDigest'),authority,correlation,facts:safeFacts};","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/src/core/evidence.ts#L68-L104","documentation":"validateObservation only accepts observation records with `version === 1`; any other version value throws `Unsupported observation version.` This lets the library evolve its schema while refusing records it cannot safely interpret instead of guessing field meanings.","triggerScenarios":"Feeding an observation object (via validateObservation or validateBundle/normalizedEvent) whose `version` is 0, 2, a string \"1\", or missing.","commonSituations":"Producer was upgraded to a newer record format before the validator; a record constructed by hand forgot the version field; version serialized as string by a non-JSON producer.","solutions":["Set `version: 1` (number) on the observation","Upgrade this library to a version that supports the record's version","Check what produced the record — an emitter on a newer schema must be aligned with the validator"],"exampleFix":"// before\n{\"version\":\"1\",\"id\":\"o1\",...}\n// after\n{\"version\":1,\"id\":\"o1\",...}","handlingStrategy":"validation","validationCode":"if (rec.version !== 1) throw new Error(`observation version ${rec.version} unsupported; expected 1`);","typeGuard":"const isV1Observation = (r: {version?: unknown}): r is {version: 1} => r.version === 1;","tryCatchPattern":"try { validateObservation(rec); } catch (e) { if (e.message === 'Unsupported observation version.') { rec.version = 1; retry or upgrade lib; } throw e; }","preventionTips":["Pin producer and validator to the same schema version","Emit version as a JSON number, never a string","Check the library changelog when bumping versions"],"tags":["validation","versioning","schema"],"backgroundTag":"unsupported-config-value","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T16:17:23.217Z"}