{{ message }}
fix(core): retry sqlite statements on lock timeout - #47567
Open
woodsonl wants to merge 1 commit into
Open
Conversation
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.
Contributor
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Issue for this PR
Closes #47566
Type of change
What does this PR do?
When multiple opencode processes share one database, statements that can't grab the SQLite write lock within
busy_timeoutfail withdatabase 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 holdingBEGIN IMMEDIATE, setsbusy_timeout = 0on the client, then updates through the effect client while the lock is held and releases it 100ms later. Asserts the update lands. Fails ondev(lock error propagates), passes here.core and opencode package suites pass (
OPENCODE_CLIENT=cli);bun turbo typecheckclean; lint unchanged from dev steady state (one pre-existing octal-escape error in session-ui, same count on base).Checklist