Skip to content

opencode crashes on startup when SQLite database is corrupted #37821

Closed as not planned

Description

@leecoder

Bug

When the local SQLite database file becomes corrupted, opencode crashes on startup with:

SQLiteError: database disk image is malformed

or:

SQLiteError: file is not a database

This can happen due to power loss, disk issues, or incomplete writes to the WAL file.

Expected Behavior

opencode should detect corruption, backup the corrupted files, and recreate a fresh database so the user can continue working without manual intervention.

Steps to Reproduce

  1. Corrupt the database file at ~/.local/share/opencode/opencode.db (e.g. write garbage to internal pages while keeping the SQLite header intact)
  2. Run opencode
  3. Observe crash

Environment

  • OS: macOS
  • opencode: latest dev branch

Activity

  1. github-actions commented on Jul 20, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. B67687 commented on Aug 3, 2026

    @B67687
    Contributor

    Confirmed on our side (opencode v1.18.11, Linux, 2026-08-02)

    Same crash: opencode aborted natively (SIGABRT, 'core dumped') at startup, silently — no log line, no journal, no apport entry. Every dying instance stopped right after the boot line 'booting location services' (session-list/storage init, where a pathological DB/WAL gets read).

    Root cause chain on our machine:

    1. Shared SQLite store (WAL mode) grew to 5.45GB main + 5.48GB WAL because a runaway agent loop wrote unbounded into it (silent retry loop, ~94% CPU, 2h).
    2. New instances opened that DB → native abort at 'booting location services', intermittently, depending on DB state at launch.

    This is storage-layer corruption/bloat, not app logic — which is exactly why it was silent: the native abort happens below the JS layer.

    What fixed it for us

    • PRAGMA wal_checkpoint(TRUNCATE) + VACUUM (reclaimed ~1.7GB freelist, page_count 1,330,391 → compacted) + killed the runaway writer. DB 3.6GB, integrity ok, WAL 4KB, boot clean.

    Request

    A startup recovery path would have prevented the crash entirely: on open of a pathological/oversized DB, checkpoint or rebuild-in-place instead of native abort. #37822 (auto-recover) covers the right direction — hope it ships soon. Happy to attach core data or reproduce on request.

  3. github-actions commented on Oct 3, 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