Skip to content

Codex Chat falls back to the terminal when Codex's state_5.sqlite has no -wal/-shm (SQLITE_CANTOPEN) #2444

Closed

Description

@devswha

Problem

Codex's state_5.sqlite is a WAL-mode database. When no Codex process holds it open (the shared app-server daemon releases it after a while), the -wal and -shm files are gone. Ovis opens the store read-only (new Database(…/state_5.sqlite, { readonly: true, create: false }), server/codex.ts), and SQLite cannot open a WAL database read-only without a -shm file it may create: every query fails with SQLITE_CANTOPEN (errno 14). codexTranscriptPath swallows the error and finds no candidates, so Chat falls back to the terminal for every Codex pane until some Codex process opens the store again.

This is the class #1668 fixed for Agy's store.

Reproduction (test MacBook Air, macOS 27.0.1, Codex 0.163.0 TUI with the 0.166.0 app-server daemon, isolated herdr session)

  1. Run Codex in a herdr pane with its own CODEX_HOME, finish a turn, and leave it idle.
  2. Once the store is released:
    $ ls $CODEX_HOME/state_5*
    state_5.sqlite                      # no -wal, no -shm
    $ od -A d -t u1 -j 18 -N 2 $CODEX_HOME/state_5.sqlite
    0000018     2   2                   # WAL mode
    
  3. Read the pane's conversation from a freshly started Ovis: GET /api/pane/conversation?pane_id=… → {"source":"scrollback","turns":[]}. A direct open shows the cause:
    new Database(home + "/state_5.sqlite", { readonly: true, create: false }).query("PRAGMA journal_mode").get()
    → SQLiteError: unable to open database file  (SQLITE_CANTOPEN, errno 14)
    
    A running Ovis that already bound the pane keeps showing it, so this shows after a restart or for a pane not yet bound.
  4. Send any message in a Codex pane (the daemon reopens the store, -wal/-shm reappear): the same request now returns the pane's native conversation.

Seen on main (6c78047f, 0.4.21) and on the branches of #2443 and #2420.

Expected

Ovis reads Codex's store whether or not a Codex process holds it, never writing to it.

Suggested fix

Open the store so it needs no -wal/-shm of its own: SQLite's read-only immutable=1 URI when no -wal exists (nothing uncheckpointed to miss), or read a consistent copy. Never write to Codex's database.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions