{"record":{"id":"d4d671919c56e9aa","repo":"Yeachan-Heo/oh-my-codex","slug":"failed-to-persist-hud-authority-rate-limit-state","errorCode":null,"errorMessage":"failed to persist HUD authority rate-limit state","messagePattern":"failed to persist HUD authority rate-limit state","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/hud/authority.ts","lineNumber":429,"sourceCode":"      next_allowed_at: diagnosticState?.next_allowed_at,\n      skip_count: (diagnosticState?.skip_count ?? 0) + 1,\n      last_status: 'locked',\n      last_reason: 'spawn_lock_active',\n      last_error: diagnosticState?.last_error,\n    });\n    await writeAuthorityState(authorityOwnerPath, lockedState);\n    return;\n  }\n\n  await deps.onLockAcquired?.();\n\n  let lockedState: HudAuthorityState | null;\n  try {\n    lockedState = await readAuthorityState(authorityStatePath);\n  } catch (error) {\n    const diagnosticWritten = await writeInvalidStateDiagnostic(authorityStatePath, authorityOwnerPath, cwd, nowMs, minIntervalMs, jitterMs, error);\n    await releaseAuthorityLock(lock);\n    if (!diagnosticWritten) throw new Error('failed to persist HUD authority rate-limit state');\n    return;\n  }\n  const lockedNextAllowedMs = parseIsoMs(lockedState?.next_allowed_at);\n  if (lockedState && lockedNextAllowedMs !== null && nowMs < lockedNextAllowedMs) {\n    await writeRateLimitSkipState(\n      authorityStatePath,\n      authorityOwnerPath,\n      cwd,\n      nowMs,\n      minIntervalMs,\n      jitterMs,\n      lockedState,\n      'rate_limited_after_lock',\n    );\n    await releaseAuthorityLock(lock);\n    return;\n  }\n","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/Yeachan-Heo/oh-my-codex/blob/3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2/src/hud/authority.ts#L411-L447","documentation":"While holding the authority lock, the HUD authority tick re-read the state file and it failed validation; the attempted invalid-state diagnostic write failed as well, so after releasing the lock the tick throws this error. It indicates both a corrupt state file and an inability to persist diagnostics under the lock.","triggerScenarios":"Inside runHudAuthorityTick after acquiring the lock: readAuthorityState throws, writeInvalidStateDiagnostic returns false (unwritable path, EACCES, ENOSPC, missing directory), lock is released, and this error is thrown.","commonSituations":"Concurrent instances writing incompatible state schemas, permission drift on the state directory, disk full, or a crash mid-write leaving a truncated state file combined with restricted diagnostic paths.","solutions":["Repair or delete the corrupt authority state file","Fix write permissions on the state/diagnostic directory","Ensure sufficient disk space","Prevent concurrent runs with mismatched versions from sharing state"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// before ticking: validate state and writability\nconst raw = JSON.parse(fs.readFileSync(authorityStatePath,'utf8'));\nfs.accessSync(dirname(authorityStatePath), fs.constants.W_OK);","typeGuard":null,"tryCatchPattern":"catch (e) { if ((e as Error).message === 'failed to persist HUD authority rate-limit state') { /* remove corrupt state, fix perms, retry tick */ } }","preventionTips":["Prevent concurrent multi-version writers","Keep state directory writable","Heal corrupt state files at startup"],"tags":["hud","authority","lock","diagnostic","corrupt-state"],"backgroundTag":"state-file-corruption","analyzedSha":"3ad79a8a6fe6e95fdbb8c00e40716fffe4011ce2","analyzedAt":"2026-08-27T22:18:39.783Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}