{"record":{"id":"8377b348a7f288dc","repo":"Hmbown/CodeWhale","slug":"invalid-version-1-pet-bucket-native","errorCode":null,"errorMessage":"Invalid version 1 pet bucket.","messagePattern":"Invalid version 1 pet bucket\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pet/ios/Resources/pet-native.js","lineNumber":1111,"sourceCode":"exports.encodePetJSONL = encodePetJSONL;\nexports.encodePetTSV = encodePetTSV;\nconst model_js_1 = require(\"./model.js\");\nconst signal_js_1 = require(\"./signal.js\");\nconst pet_sim_js_1 = require(\"./pet-sim.js\");\n/** One projection for imports, demos and recorded live snapshots. Times are ms.\n * These are aesthetic encodings of measured events, never model confidence. */\nexports.PET_BIN_MS = 400;\nfunction validatePetBucket(value) {\n    (0, pet_sim_js_1.validatePetState)(value);\n    const b = value;\n    if (!b || typeof b !== 'object' || b.version !== 1 || !Number.isSafeInteger(b.sequence) || b.sequence < 0 || b.sequence > pet_sim_js_1.PET_MAX_SECONDS * 2.5\n        || b.simTimeMs !== b.sequence * exports.PET_BIN_MS || b.durationMs !== exports.PET_BIN_MS\n        || !model_js_1.CATEGORIES.includes(b.channel) || typeof b.waiting !== 'boolean'\n        || !Array.isArray(b.agentIds) || b.agentIds.length > 250_000 || b.agentIds.some(id => typeof id !== 'string' || !id || id.length > 4096)\n        || !Number.isSafeInteger(b.errors) || b.errors < 0 || b.errors > 250_000\n        || !Array.isArray(b.onsets) || b.onsets.length !== 13 || b.onsets.some(n => !Number.isSafeInteger(n) || n < 0 || n > 250_000)\n        || !Array.isArray(b.activeMs) || b.activeMs.length !== 13 || b.activeMs.some(n => !Number.isFinite(n) || n < 0 || n > 100_000_000))\n        throw new Error('Invalid version 1 pet bucket.');\n}\nfunction decodePetJSONL(text) {\n    if (text.length > 64 * 1024 * 1024)\n        throw new Error('Pet tape exceeds 64 MiB.');\n    const rows = text.split(/\\r?\\n/).filter(line => line.trim()).map(line => JSON.parse(line));\n    if (rows.length > 216_000)\n        throw new Error('Pet tape exceeds 24 hours.');\n    return rows.map((row, i) => { validatePetBucket(row); if (row.sequence !== i)\n        throw new Error('Non-contiguous pet tape.'); return row; });\n}\n/** A live file must advance before its contents count as a new observation.\n * Existing bytes, duplicate samples and a restarted sequence establish a\n * baseline; they never replay an old onset or human request. Drivers supply a\n * bounded tail and reset this cursor after suspension or a new attachment. */\nclass PetLiveTape {\n    sequence;\n    reset() { this.sequence = undefined; }\n    readTail(text) {","sourceCodeStart":1093,"sourceCodeEnd":1129,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/433685b2024e7bc4c99e1e2e326bcad39b4d9d65/pet/ios/Resources/pet-native.js#L1093-L1129","documentation":"Each row of a version-1 pet tape (JSONL) must pass validatePetBucket: exact simTimeMs/durationMs derived from the sequence and PET_BIN_MS, a known channel category, boolean waiting, bounded agentIds and error counts, and exactly-13-length onsets/activeMs arrays with values in range. A bucket failing any of these checks throws this error, so malformed telemetry rows never enter the renderer.","triggerScenarios":"Calling decodePetJSONL on a file where any row violates the v1 bucket schema: simTimeMs !== sequence*PET_BIN_MS, durationMs !== PET_BIN_MS, unknown channel, agentIds >250k or entries not strings/empty/>4096 chars, errors outside 0-250000, or onsets/activeMs arrays not exactly 13 long or containing out-of-range numbers.","commonSituations":"Producing the JSONL with a different bin duration than PET_BIN_MS; adding a 14th channel upstream while the tape validator still expects 13; log collector concatenating or rewriting rows; a producer bug writing durations in a different unit (seconds vs ms).","solutions":["Fix the tape producer so simTimeMs = sequence * PET_BIN_MS and durationMs = PET_BIN_MS for every row.","Ensure every bucket's onsets and activeMs arrays have exactly 13 entries matching CHANNELS.","Validate agentIds are non-empty strings <=4096 chars and drop oversized collections.","Regenerate the tape from the same pet-native.js version that will decode it."],"exampleFix":"// before\nrows.push({ sequence: i, simTimeMs: i * 1000, durationMs: 1000, channel: 'unknown', waiting: false, agentIds: [], errors: 0, onsets: new Array(13).fill(0), activeMs: new Array(13).fill(0) })\n// after\nrows.push({ sequence: i, simTimeMs: i * PET_BIN_MS, durationMs: PET_BIN_MS, channel: CATEGORIES[0], waiting: false, agentIds: [], errors: 0, onsets: new Array(13).fill(0), activeMs: new Array(13).fill(0) })","handlingStrategy":"validation","validationCode":"function looksLikeV1Bucket(b, CATEGORIES, PET_BIN_MS) {\n  const safeInt = (n, hi) => Number.isSafeInteger(n) && n >= 0 && n <= hi;\n  return !!b && b.simTimeMs === b.sequence * PET_BIN_MS && b.durationMs === PET_BIN_MS\n    && CATEGORIES.includes(b.channel) && typeof b.waiting === 'boolean'\n    && Array.isArray(b.agentIds) && b.agentIds.length <= 250000 && b.agentIds.every(id => typeof id === 'string' && id && id.length <= 4096)\n    && safeInt(b.errors, 250000) && Array.isArray(b.onsets) && b.onsets.length === 13 && b.onsets.every(n => safeInt(n, 250000))\n    && Array.isArray(b.activeMs) && b.activeMs.length === 13 && b.activeMs.every(n => Number.isFinite(n) && n >= 0 && n <= 100000000);\n}","typeGuard":"const isV1Bucket = (b) => typeof b === 'object' && b !== null && typeof b.sequence === 'number' && Array.isArray(b.onsets) && b.onsets.length === 13;","tryCatchPattern":"try { rows = decodePetJSONL(text); }\ncatch (e) { if (/Invalid version 1 pet bucket/.test(e.message)) { reportBadTape(e); rows = []; } else throw e; }","preventionTips":["Generate tapes with the same pet-native.js constants (PET_BIN_MS, CHANNELS) used to decode them.","Add a producer-side unit test asserting validatePetBucket passes on real output.","Never concatenate tapes from producers with different bin durations or channel counts.","Validate each row at write time."],"tags":["validation","jsonl","telemetry","schema"],"backgroundTag":"schema-validation-failed","analyzedSha":"433685b2024e7bc4c99e1e2e326bcad39b4d9d65","analyzedAt":"2026-09-15T12:24:24.634Z","contentChangedAt":"2026-09-15T12:24:24.634Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}