anomalyco / anomalyco/opencode

desktop (beta): DrizzleError "Failed to run the query 'begin'" uncaught exception on every app quit

Open
#44,239 0 comments 0 reactions 1 assignee View on GitHub

@Brendonovich is already working on this.

Since Aug 22, 2026.

2.0
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

  1. Launch OpenCode Beta (0.0.0-beta-17927) on macOS.
  2. Use it normally for any amount of time.
  3. Quit the app (Cmd+Q or closing the window).
  4. 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_check pass on both drafts.sqlite and the shared service DB (~/.local/share/opencode/opencode.db) — no corruption.
  • Only one app instance runs (no SingletonLock conflicts); lsof shows 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 (flush handler) that fires during app shutdown, so the transaction races connection teardown.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.