Skip to content

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

Closed

Description

@shariqriazz

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.

Activity

  1. neriousy commented on Oct 20, 2026

    @neriousy
    Member

    The desktop shutdown flush handling has been fixed in v2: late or empty draft flushes are ignored, and shutdown listeners are removed before the database closes. Please update the desktop app. If you still see this on v2, please open a new issue with the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions