anomalyco / anomalyco/opencode
desktop (beta): DrizzleError "Failed to run the query 'begin'" uncaught exception on every app quit
@Brendonovich is already working on this.
Since Aug 22, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Summary
Every time the OpenCode Beta desktop app is quit, an "Uncaught Exception" dialog appears with a DrizzleError: Failed to run the query 'begin' from the main process's draft-flush routine. It appears to be a shutdown ordering race: the final drafts flush runs a transaction while/after the SQLite connection is being torn down. No data loss observed; the error is cosmetic but appears on every quit.
Environment
- opencode version: 0.0.0-beta-17927 (OpenCode Beta desktop app)
- OS: macOS 26.0 (Darwin 25.6.0, arm64, Apple M3 Max)
- Terminal: Unavailable (not applicable — Electron desktop app)
- Shell: /bin/zsh
- Install/channel: beta
- Active plugins: one user-global CLI plugin configured (
factory-droid-oauth.ts); the failing code path is in the desktop app's own main process (out/main/index.js), not a plugin
Reproduction
- Launch OpenCode Beta (0.0.0-beta-17927) on macOS.
- Use it normally for any amount of time.
- Quit the app (Cmd+Q or closing the window).
- An "Uncaught Exception" dialog appears.
Reproduces consistently on every quit across multiple launches.
Expected Behavior
The app quits cleanly without an uncaught exception dialog; the final drafts flush either completes before teardown or is skipped/handled during shutdown.
Actual Behavior
On quit, the main process throws:
Uncaught Exception:
DrizzleError: Failed to run the query 'begin'
at NodeSQLiteSession.run (file:///Applications/OpenCode%20Beta.app/Contents/Resources/app.asar/node_modules/drizzle-orm/sqlite-core/session.js:121:10)
at NodeSQLiteSession.transaction (file:///Applications/OpenCode%20Beta.app/Contents/Resources/app.asar/node_modules/drizzle-orm/node-sqlite/session.js:29:8)
at NodeSQLiteDatabase.transaction (file:///Applications/OpenCode%20Beta.app/Contents/Resources/app.asar/node_modules/drizzle-orm/sqlite-core/db.js:343:23)
at Object.flush (file:///Applications/OpenCode%20Beta.app/Contents/Resources/app.asar/out/main/index.js:4600:6)
at EventEmitter.flush (file:///Applications/OpenCode%20Beta.app/Contents/Resources/app.asar/out/main/index.js:4643:37)
at EventEmitter.emit (node:events:521:24)
Additional Context
- The failing database is the app's local drafts store (
~/Library/Application Support/ai.opencode.desktop.beta/drafts.sqlite). PRAGMA integrity_check/quick_checkpass on bothdrafts.sqliteand the shared service DB (~/.local/share/opencode/opencode.db) — no corruption.- Only one app instance runs (no SingletonLock conflicts);
lsofshows a single writer. - Deleting
drafts.sqlite*while the app is closed did not help; the dialog returns on the next quit. - The flush is triggered via an EventEmitter (
flushhandler) that fires during app shutdown, so the transaction races connection teardown.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.