stablyai/orca · error · Error
Codex auth.json is corrupt or not valid JSON
Error message
Codex auth.json is corrupt or not valid JSON
What it means
Thrown by loadOAuthCredentials when auth.json inside a managed home fails JSON.parse. The raw SyntaxError is deliberately swallowed and replaced with this generic message so malformed credential bytes are never echoed into logs or error UI. The file is still expected to be Orca-owned (assertManagedHomePath runs first).
Source
Thrown at src/main/codex-accounts/service.ts:1843
}
private loadOAuthCredentials(
managedHomePath: string,
expectedAccountId: string
): CodexOAuthCredentials {
const authFilePath = join(
this.assertManagedHomePath(managedHomePath, expectedAccountId),
'auth.json'
)
const authFileContents = readFileSync(authFilePath, 'utf-8')
let parsed: Record<string, unknown>
try {
parsed = JSON.parse(authFileContents) as Record<string, unknown>
} catch {
// Why: a raw SyntaxError echoes credential bytes into logs/error UI; a
// corrupt auth.json must fail loudly but without them (same sanitization
// intent as the system-default identity path, which degrades instead).
throw new Error('Codex auth.json is corrupt or not valid JSON')
}
return this.extractOAuthCredentials(parsed)
}
private extractOAuthCredentials(raw: Record<string, unknown>): CodexOAuthCredentials {
// Why: API-key-based auth files have no OAuth tokens or JWT identity
// claims. Returning nulls causes the caller to fail with a clear
// "could not resolve the account email" error rather than crashing
// on missing nested token fields.
if (typeof raw.OPENAI_API_KEY === 'string' && raw.OPENAI_API_KEY.trim() !== '') {
return {
idToken: null,
accountId: null
}
}
const tokens = this.readRecordClaim(raw, 'tokens')
return {View on GitHub (pinned to 1136503c6a)
Solutions
- Re-run the Codex login flow for the account so auth.json is regenerated cleanly.
- If you have a known-good backup of auth.json, restore it (preserving the Orca-owned home/marker) and retry.
- Ensure no other process (editor, sync agent) writes to the managed home concurrently during login.
Example fix
// before: auth.json is corrupt -> login identity load fails await svc.readIdentityFromHome(homePath, acctId) // throws 'Codex auth.json is corrupt or not valid JSON' // after: re-login to regenerate auth.json await svc.runCodexLogin(account, credentials)
Defensive patterns
Strategy: try-catch
Validate before calling
import { readFileSync } from 'node:fs'
function isAuthJsonParsable(homePath: string): boolean {
try {
JSON.parse(readFileSync(`${homePath}/auth.json`, 'utf-8'))
return true
} catch {
return false
}
}
if (!isAuthJsonParsable(homePath)) {
// re-run codex login to regenerate auth.json
} Type guard
function isCorruptAuthJsonError(error: unknown): boolean {
return error instanceof Error && error.message === 'Codex auth.json is corrupt or not valid JSON'
} Try / catch
try {
await svc.readIdentityFromHome(homePath, acctId)
} catch (error) {
if (isCorruptAuthJsonError(error)) {
// credentials are unrecoverable from this file; re-login
await svc.runCodexLogin(account, credentials)
} else {
throw error
}
} Prevention
- Do not open or edit auth.json in a text editor; treat it as binary.
- Ensure login writes are atomic and no other process writes the file concurrently.
- Use backup tools that deliver complete files, not partial deltas.
When it happens
Trigger: loadOAuthCredentials(managedHomePath, expectedAccountId) where readFileSync(<home>/auth.json) succeeds but JSON.parse(contents) throws — truncated file, BOM/garbage, hand-edited invalid JSON, or another process mid-write.
Common situations: Concurrent write to auth.json truncated it; a text editor saved it with invalid syntax; a sync/backup tool delivered a partial file; encoding conversion corrupted it; a previous login was interrupted mid-write.
Related errors
- Managed Codex home is missing Orca ownership marker.
- Managed WSL Codex home ownership marker does not match its a
- Refusing to patch unexpected node-pty console-list agent sou
- ${commandLabel} ${args.join(' ')} ok=false: ${JSON.stringify
- Failed to load ${path.basename(jsonPath)}: ${error.message}
AI-assisted analysis of stablyai/orca@1136503c6a (2026-08-12).
Data as JSON: /api/errors/9991f618eb452361.
Report an issue: GitHub.