{"record":{"id":"29ada2ac044e9452","repo":"Yeachan-Heo/oh-my-codex","slug":"failed-to-persist-hud-authority-invalid-state-diag","errorCode":null,"errorMessage":"failed to persist HUD authority invalid-state diagnostic","messagePattern":"failed to persist HUD authority invalid-state diagnostic","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/hud/authority.ts","lineNumber":385,"sourceCode":"  const random = deps.random ?? Math.random;\n  const jitterMs = jitterMaxMs > 0 ? Math.floor(random() * (jitterMaxMs + 1)) : 0;\n  const mergedEnv = { ...process.env, ...options.env };\n  const watcherScript = resolveHudWatcherScript(packageRoot, 'notify-fallback-watcher.js', cwd, mergedEnv);\n  const notifyScript = resolveHudWatcherScript(packageRoot, 'notify-hook.js', cwd, mergedEnv);\n  const authorityStateDir = join(cwd, '.omx', 'state');\n  const authorityOwnerPath = join(authorityStateDir, 'notify-fallback-authority-owner.json');\n  const authorityStatePath = join(authorityStateDir, 'notify-fallback-authority-state.json');\n  const authorityLockPath = join(authorityStateDir, 'notify-fallback-authority.lock');\n  const runProcess = deps.runProcess ?? defaultRunProcess;\n\n  await mkdir(authorityStateDir, { recursive: true }).catch(() => {});\n\n  let previousState: HudAuthorityState | null;\n  try {\n    previousState = await readAuthorityState(authorityStatePath);\n  } catch (error) {\n    if (!(await writeInvalidStateDiagnostic(authorityStatePath, authorityOwnerPath, cwd, nowMs, minIntervalMs, jitterMs, error))) {\n      throw new Error('failed to persist HUD authority invalid-state diagnostic');\n    }\n    return;\n  }\n  const previousNextAllowedMs = parseIsoMs(previousState?.next_allowed_at);\n  if (previousState && previousNextAllowedMs !== null && nowMs < previousNextAllowedMs) {\n    await writeRateLimitSkipState(\n      authorityStatePath,\n      authorityOwnerPath,\n      cwd,\n      nowMs,\n      minIntervalMs,\n      jitterMs,\n      previousState,\n      'rate_limited',\n    );\n    return;\n  }\n","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/hud/authority.ts#L367-L403","documentation":"During a HUD authority tick, the previously persisted authority state failed validation, and the library attempted to write an invalid-state diagnostic but that write also failed. This is a compound failure: corrupt input state plus an unwritable diagnostic path. The tick aborts so the failure is visible rather than silently ignored.","triggerScenarios":"runHudAuthorityTick calls readAuthorityState which throws (invalid state), then writeInvalidStateDiagnostic returns false because the diagnostic file path is unwritable (permissions, read-only FS, missing parent dir), so the wrapper error is thrown.","commonSituations":"State directory owned by another user, read-only mount or sandboxed filesystem, disk full, or a stray lock/permission change after a crash. Often follows an initial state corruption event.","solutions":["Check permissions/ownership of the .omx state directory and fix with chown/chmod","Free disk space or remount the filesystem read-write","Delete or fix the corrupt authority state file that triggered the diagnostic","Verify no other process holds an exclusive lock on the diagnostic path"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"import fs from 'node:fs';\nfs.accessSync(dirname(diagnosticPath), fs.constants.W_OK); // preflight writability","typeGuard":null,"tryCatchPattern":"catch (e) { if ((e as Error).message === 'failed to persist HUD authority invalid-state diagnostic') { /* log state path, check perms/disk, surface to operator */ } }","preventionTips":["Ensure state dirs are writable by the running user","Monitor disk space","Alert on any authority-state validation failure so the diagnostic write path stays exercised"],"tags":["hud","authority","diagnostic","filesystem","permissions"],"backgroundTag":"state-file-unwritable","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}