{"record":{"id":"73c38ef34b6172f9","repo":"Yeachan-Heo/oh-my-codex","slug":"authority-state-cooldown-ms-must-be-a-non-negative","errorCode":null,"errorMessage":"authority state cooldown_ms must be a non-negative number","messagePattern":"authority state cooldown_ms must be a non-negative number","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/hud/authority.ts","lineNumber":154,"sourceCode":"\nfunction isAuthorityStatus(value: unknown): value is HudAuthorityState['last_status'] {\n  return value === 'spawned' || value === 'skipped' || value === 'failed' || value === 'locked';\n}\n\nfunction validateAuthorityState(value: unknown): HudAuthorityState {\n  if (typeof value !== 'object' || value === null) {\n    throw new Error('authority state must be an object');\n  }\n  const state = value as Partial<HudAuthorityState>;\n  if (state.owner !== 'hud') throw new Error('authority state owner must be hud');\n  if (typeof state.pid !== 'number' || !Number.isInteger(state.pid) || state.pid <= 0) {\n    throw new Error('authority state pid must be a positive integer');\n  }\n  if (typeof state.cwd !== 'string' || !state.cwd) throw new Error('authority state cwd must be a non-empty string');\n  if (parseIsoMs(state.heartbeat_at) === null) throw new Error('authority state heartbeat_at must be a valid ISO timestamp');\n  if (parseIsoMs(state.next_allowed_at) === null) throw new Error('authority state next_allowed_at must be a valid ISO timestamp');\n  if (typeof state.cooldown_ms !== 'number' || !Number.isFinite(state.cooldown_ms) || state.cooldown_ms < 0) {\n    throw new Error('authority state cooldown_ms must be a non-negative number');\n  }\n  if (typeof state.jitter_ms !== 'number' || !Number.isFinite(state.jitter_ms) || state.jitter_ms < 0) {\n    throw new Error('authority state jitter_ms must be a non-negative number');\n  }\n  if (typeof state.skip_count !== 'number' || !Number.isInteger(state.skip_count) || state.skip_count < 0) {\n    throw new Error('authority state skip_count must be a non-negative integer');\n  }\n  if (!isAuthorityStatus(state.last_status)) throw new Error('authority state last_status is invalid');\n  if (typeof state.last_reason !== 'string' || !state.last_reason) {\n    throw new Error('authority state last_reason must be a non-empty string');\n  }\n  return state as HudAuthorityState;\n}\n\nasync function readAuthorityState(path: string): Promise<HudAuthorityState | null> {\n  try {\n    return validateAuthorityState(JSON.parse(await readFile(path, 'utf-8')));\n  } catch (error) {","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/hud/authority.ts#L136-L172","documentation":"This error is thrown by validateAuthorityState in the HUD authority module when the persisted authority state file contains a cooldown_ms field that is not a finite non-negative number. The validator runs on every read of the authority state, so any corruption or hand-editing of the state file surfaces here. It protects the rate-limiting cooldown computation from NaN/negative values.","triggerScenarios":"readAuthorityState parses the authority state JSON and its cooldown_ms is a string, NaN, Infinity, a negative number, or missing/mis-typed after manual editing or a partially written file. Called from runHudAuthorityTick during tick processing.","commonSituations":"Hand-edited .omx state files, state written by an older version with a different schema, disk corruption or truncated JSON writes, or external tooling writing the state file with stringified numbers.","solutions":["Inspect the authority state JSON file and fix cooldown_ms to a non-negative finite number (e.g. 0)","Delete the authority state file so it is recreated with defaults","Ensure only one version of the tool writes the state file (no version mixing)","Check for concurrent writers racing on the state file"],"exampleFix":"// before: state file contains \"cooldown_ms\": \"1000\"\n// after: state file contains \"cooldown_ms\": 1000","handlingStrategy":"validation","validationCode":"const s = JSON.parse(fs.readFileSync(authorityStatePath,'utf8'));\nif (typeof s.cooldown_ms !== 'number' || !Number.isFinite(s.cooldown_ms) || s.cooldown_ms < 0) {\n  // repair or reset state before running the tick\n}","typeGuard":"function isValidAuthorityState(s: any): s is { cooldown_ms: number } {\n  return typeof s?.cooldown_ms === 'number' && Number.isFinite(s.cooldown_ms) && s.cooldown_ms >= 0;\n}","tryCatchPattern":"catch (e) { if ((e as Error).message.includes('cooldown_ms')) { /* reset state file and retry once */ } else throw e; }","preventionTips":["Never hand-edit authority state files","Run one tool version against a given state directory","Back up state before upgrades"],"tags":["hud","authority-state","validation","rate-limit"],"backgroundTag":"state-file-schema-validation-failed","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}