Skip to content

fix(upload): read the session store when no codev process has it open - #378

Merged
quickbeard merged 1 commit into
mainfrom
fix/session-db-readonly
Sep 25, 2026
Merged

quickbeard merged 1 commit into
mainfrom
fix/session-db-readonly

Conversation

@quickbeard

Copy link
Copy Markdown
Owner

Summary

Found while testing #377. opencode.db runs in WAL mode, and @codev/upload's Bun session reader opened it read-only. A read-only connection can't create the -wal/-shm side files that a WAL read needs:

  • While any CoDev process has the store open, the side files exist and the read works. That covers most launch-time pushes, which race a running TUI or server.
  • After the last process closes cleanly the side files are deleted, and Bun's SQLite fails the first query with SQLITE_CANTOPEN. readAllSessions / readAllSessionStats then throw, the exporter logs "session store read failed", and the user sees "No sessions found". That hits codev upload, codev upload --logs and codev debug stats whenever nothing else is running.

Reproduced on a copy of a real 52-session store with the side files removed: before the fix SQLITE_CANTOPEN; after it, 52 sessions for both stats and log export.

Fix (packages/codev-upload/src/sqlite.bun.ts, fork-only, so no DIVERGENCES.md row):

  • Open read-only as before and probe with a cheap schema read.
  • Only on SQLITE_CANTOPEN, reopen with { readwrite: true, create: false } so SQLite recreates the side files the way any reader of a WAL database does. The reader still only runs SELECTs, and a missing store is never created.
  • node:sqlite (the desktop sidecar's driver) already handles this case, verified under Node 24. Its code is unchanged, and the parity test now covers it.

Test plan

  • bun test in packages/codev-upload (60 tests). New:
    • the Bun driver reads a checkpointed WAL store with no side files (fails without the fix);
    • the Bun driver never creates a missing store;
    • the Node parity test also runs against the WAL fixture under real Node.
  • bun typecheck in packages/codev-upload
  • A copy of a real session store in the failing state: SQLITE_CANTOPEN before, 52 sessions after

🤖 Generated with Claude Code

opencode.db runs in WAL mode. The Bun session reader opened it read-only,
and a read-only connection cannot create the -wal/-shm side files a WAL
read needs. While a codev process holds the store they exist; after the
last one closes cleanly they are gone, and Bun's SQLite fails the first
query with SQLITE_CANTOPEN — so `codev upload`, `codev upload --logs`,
or a stats push with nothing else running found no sessions.

The Bun driver now probes the read-only connection and, only on
SQLITE_CANTOPEN, reopens read-write without create so SQLite recreates
the side files as any WAL reader does; the reader still only runs
SELECTs, and a missing store is never created. node:sqlite (the desktop
sidecar's driver) already handles this case; the parity test now covers
it for both drivers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@quickbeard
quickbeard merged commit 6f4a8e6 into main Sep 25, 2026
0 of 5 checks passed
@quickbeard
quickbeard deleted the fix/session-db-readonly branch September 25, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant