Hmbown/CodeWhale · error · Error
Unsupported observation version.
Error message
Unsupported observation version.
What it means
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.
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
Example fix
// before
{"version":"1","id":"o1",...}
// after
{"version":1,"id":"o1",...} Defensive patterns
Strategy: validation
Validate before calling
if (rec.version !== 1) throw new Error(`observation version ${rec.version} unsupported; expected 1`); Type guard
const isV1Observation = (r: {version?: unknown}): r is {version: 1} => r.version === 1; Try / catch
try { validateObservation(rec); } catch (e) { if (e.message === 'Unsupported observation version.') { rec.version = 1; retry or upgrade lib; } throw e; } Prevention
- 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
When it happens
Trigger: Feeding an observation object (via validateObservation or validateBundle/normalizedEvent) whose `version` is 0, 2, a string "1", or missing.
Common situations: 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.
Related errors
- receipt schema_version changed
- Automation run schema v
- Automation schema v is newer than supported v
- Checkpoint schema v is newer than supported v
- Codewhale stream-json contained an unknown event type
AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15).
Data as JSON: /api/errors/1ebe760b5682212b.
Report an issue: GitHub.
Appendix: source
Thrown at pet/src/core/evidence.ts:86
};
const num = (v:unknown,field:string,min=0):number => {
if(typeof v!=='number'||!Number.isFinite(v)||v<min||Math.abs(v)>Number.MAX_SAFE_INTEGER)throw new Error(`Invalid ${field}.`);return v;
};
const optionalText = (o:Record<string,unknown>,key:string):string|undefined => o[key]===undefined?undefined:text(o[key],key);
const strings = (v:unknown,field:string,allowEmpty=false):string[]=>{
if(!Array.isArray(v)||(!allowEmpty&&!v.length)||v.length>256)throw new Error(`Invalid ${field}.`);
const out=v.map(x=>text(x,field));if(new Set(out).size!==out.length)throw new Error(`Duplicate ${field}.`);return out;
};
const boolean = (v:unknown,field:string):boolean=>{if(typeof v!=='boolean')throw new Error(`Invalid ${field}.`);return v;};
const optionalNumber=(o:Record<string,unknown>,key:string)=>o[key]===undefined?undefined:num(o[key],key);
function onlyKeys(o:Record<string,unknown>,keys:string[],label:string):void{
for(const k of Object.keys(o))if(!keys.includes(k))throw new Error(`Unknown ${label} field: ${k}.`);
}
/** All unrecognized fields are rejected, never secretly retained in metadata-only evidence. */
export function validateObservation(input:unknown):Observation {
const o=object(input,'observation');
onlyKeys(o,['version','id','runId','operationId','sourceId','epoch','sequence','time','receivedAt','subject','stage','surface','action','effect','status','target','actionDigest','authority','correlation','facts'],'observation');
if(o.version!==1)throw new Error('Unsupported observation version.');
const t=object(o.time,'time'),s=object(o.subject,'subject');
onlyKeys(t,['wallMs','clockId','monotonicMs','taskMs','uncertaintyMs'],'time');onlyKeys(s,['agentId','sandboxId','isolationGroup'],'subject');
const seq=num(o.sequence,'sequence',1);if(!Number.isSafeInteger(seq))throw new Error('sequence must be an integer.');
const facts=object(o.facts??{},'facts'),safeFacts:Observation['facts']={};
if(Object.keys(facts).length>48)throw new Error('Too many observation facts.');
for(const [k,v] of Object.entries(facts)){
text(k,'fact key',80);if(['__proto__','prototype','constructor'].includes(k))throw new Error('Unsafe fact key.');
if(typeof v==='string')safeFacts[k]=text(v,'fact value',512);
else if(typeof v==='number')safeFacts[k]=num(v,'fact value',-Number.MAX_SAFE_INTEGER);
else if(v===null||typeof v==='boolean')safeFacts[k]=v;
else throw new Error('Facts must be scalar metadata, not content objects.');
}
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')};}
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')};}
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')};}
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,
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'),
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};View on GitHub (pinned to 433685b202)