Skip to content

fix(core): retry locked SQLite statements cooperatively - #42539

Open
cms19859230182-lang wants to merge 1 commit into
anomalyco:v2from
cms19859230182-lang:interrupt-latency
Open

fix(core): retry locked SQLite statements cooperatively#42539
cms19859230182-lang wants to merge 1 commit into
anomalyco:v2from
cms19859230182-lang:interrupt-latency

Conversation

@cms19859230182-lang

@cms19859230182-lang cms19859230182-lang commented Aug 14, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #42120

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Interrupted turns can take ~11s to settle because locked SQLite statements spin in the native busy handler (busy_timeout = 5000), freezing the event loop while the interrupted step waits for the shared transaction permit inside its settlement mask.

  • Statements that hit SQLITE_BUSY/LOCKED now fail fast and retry cooperatively in Sqlite.makeConnection (bounded ~1.6s, only LockTimeoutError, never re-runs a transaction).
  • busy_timeout is set to 0 (node driver timeout too), so waits happen in Effect fibers and the event loop stays schedulable.

How did you verify your code works?

  • New tests: a locked write retries and succeeds after the lock releases; an exhausted retry still reports LockTimeoutError; interrupted settlement queues behind an unrelated transaction (deterministic Deferred gates, no sleeps).
  • bun test test/session-runner.test.ts test/database-drizzle.test.ts from packages/core: 158 passed.
  • bun typecheck: passed.

Screenshots / recordings

Not a UI change.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@cms19859230182-lang

Copy link
Copy Markdown
Author

FYI: this PR links #42120 (Closes #42120 in the description, cross-referenced on the issue timeline). The needs:issue label looks like a stale cross-reference index — happy to fix if I am missing something.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant