Skip to content

auth.json corruption causes startup crash (sub-cause of #27530) #29628

Closed as not planned

Description

@Tushar49

Summary

opencode crashes on startup when auth.json is in a corrupted state (whitespace-only, truncated, or otherwise unparseable JSON). The crash is fatal -- the user cannot launch opencode at all until they manually delete or restore the file.

This is a sub-cause of umbrella issue #27530, which tracks multiple distinct startup-failure modes (provider-API 5xx, #-in-instructions parser crash, SSL/config failures). This issue narrows the scope to only the corrupted-auth.json case so it can be addressed independently.

Reproduction

  1. Open ~/.local/share/opencode/auth.json (Linux/Mac) or %LOCALAPPDATA%\opencode\auth.json (Windows)
  2. Replace the contents with whitespace, an empty string, or invalid JSON like { (simulating an interrupted write or disk-full event)
  3. Launch opencode
  4. Expected: opencode treats the corrupted file as if no auth exists, prompts the user to log in fresh, continues startup.
  5. Actual: opencode throws an unhandled JSON parse exception during auth initialization, exits with a stack trace.

Why this happens

Interrupted writes to auth.json (Ctrl+C during save, sudden shutdown, disk-full, antivirus quarantine) leave the file in a partially-written state. The current auth loader calls JSON.parse() on the raw contents without a try/catch + recovery path, so any malformed content crashes the whole process.

Proposed fix

Treat corrupted auth.json as logically equivalent to a missing/empty auth.json -- i.e. proceed with no cached credentials and let the user re-authenticate. PR #29562 implements this: wraps the load in a try/catch that, on parse failure, logs a warning and returns an empty auth object.

Linked PR

PR #29562 (this issue's fix): #29562

Related

Part of umbrella issue #27530 (which also tracks 3 other unrelated startup-failure modes still open for separate fixes).

Activity

  1. github-actions commented on Jul 27, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions