fix(core): retry sqlite statements on lock timeout by woodsonl · Pull Request #47567 · anomalyco/opencode · GitHub
Skip to content

fix(core): retry sqlite statements on lock timeout - #47567

Open
woodsonl wants to merge 1 commit into
anomalyco:devfrom
woodsonl:db-lock-retry
Open

fix(core): retry sqlite statements on lock timeout#47567
woodsonl wants to merge 1 commit into
anomalyco:devfrom
woodsonl:db-lock-retry

Conversation

@woodsonl

@woodsonl woodsonl commented Sep 6, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #47566

Type of change

  • Bug fix

What does this PR do?

When multiple opencode processes share one database, statements that can't grab the SQLite write lock within busy_timeout fail with database is locked. Callers treat that as fatal (Effect.orDie), so a competing process's write kills an unrelated prompt.

The statement is fine — it just needs the lock. This PR retries statements whose failure is classified as LockTimeoutError (SQLITE_BUSY/SQLITE_LOCKED) with jittered exponential backoff (50ms → 250ms cap, 30s total), in both the bun and node sqlite drivers. The async sleep between attempts yields the thread so the other process's write can finish.

How did you verify your code works?

packages/core/test/sqlite-lock-retry.test.ts: opens a second connection holding BEGIN IMMEDIATE, sets busy_timeout = 0 on the client, then updates through the effect client while the lock is held and releases it 100ms later. Asserts the update lands. Fails on dev (lock error propagates), passes here.

core and opencode package suites pass (OPENCODE_CLIENT=cli); bun turbo typecheck clean; lint unchanged from dev steady state (one pre-existing octal-escape error in session-ui, same count on base).

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Statements failing with SQLITE_BUSY under concurrent processes now retry
with jittered exponential backoff (up to 30s) instead of surfacing
LockTimeoutError, which killed prompts and message updates when multiple
opencode processes shared one database.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Sep 6, 2026
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

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.

Concurrent opencode processes on one database fail prompts with "Failed to execute statement" (SQLITE_BUSY)

1 participant