Repository navigation
fix(desktop): keep drafts storage out of the CLI database - #64203
Conversation
There was a problem hiding this comment.
Looks good. On the base, a drafts.sqlite symlinked to a CLI-like opencode.db ends up with blob, document, state and plugin written into the CLI database. With this change the file is moved aside to drafts.sqlite.cli-<ts>, the desktop gets a fresh database, and the CLI database keeps exactly its original tables and migration rows. bun test src/main/storage passes (62 tests). The typecheck script doesn't run on the installed Bun 1.4.2 ("Script not found"), but tsc -b in packages/desktop passes. I didn't launch the Electron app.
Public API is unchanged. Everything touched is internal to the desktop main process. On disk, a drafts.sqlite that holds CLI tables is now renamed and replaced with a fresh file.
No blocking concerns. No desktop migration creates a session table, so the check can't misfire on a real drafts database. A WAL file left behind after the rename is harmless, because SQLite discards a WAL next to an empty database file.
Related: #63913
Issue for this PR
Part of #63913 (the desktop half). The core
20261025123711_blobmigration still needs its own fix.Type of change
What does this PR do?
When
drafts.sqliteis a symlink to (or a copy of) the CLI'sopencode.db, the desktop ran its own migrations against the CLI database. Both apps define ablobtable and both keep their migration list in a table calledmigration, so they can't share one file:blob(id, data)anddocumentinto the CLI database, so the coreblobmigration fails withtable blob already existsdrafts.sqlitewhenmigrationis empty, and here it holds the CLI's rows, so20260906234153_draftsfails the same way and the app quits on startChanges:
migrateDatabasethrows before writing anything when the file has asessionorsession_v2table. That covers the early window snapshot read, which already falls back to empty state on errorsopenDatabaserenames thatdrafts.sqlitetodrafts.sqlite.cli-<timestamp>and opens a fresh one. Renaming only moves the directory entry, so a symlink's target (the CLI database) isn't touchedThe few drafts the old desktop wrote into the CLI database stay there and aren't carried over.
No flag, it's a fix.
How did you verify your code works?
database.test.tsthat runs once with a symlink and once with a copy: it sets up a CLI-like database, runs the window snapshot read andopenDatabase, then checks the desktop got its own tables and the CLI database still has exactly its original tables and migration rows. The symlink case is skipped on WindowsmigrateDatabase, desktop tables land in the CLI database; without the rename,openDatabasethrowsbun test src/main/storage(62 pass),bun typecheck,bun run checkScreenshots / recordings
Not a UI change.
Checklist
Added by the opencode bot (AI-generated).
Related: #63913