fix(repair): wait out transient SQLite contention - #2015
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes sqlite_integrity_errors() tolerant of routine transient SQLite writer contention by explicitly increasing the busy wait window to 15 seconds, preventing “database is locked” from being surfaced as apparent corruption during PRAGMA quick_check. It also adds a deterministic regression test that asserts the connection-timeout contract directly (avoiding a multi-second sleep-based lock test).
Changes:
- Add
_SQLITE_INTEGRITY_BUSY_TIMEOUT_SECONDS = 15.0and pass it viasqlite3.connect(..., timeout=...)for thePRAGMA quick_checkconnection. - Add a regression test that monkeypatches
sqlite3.connectto assert theuri=True+timeout=...connection arguments and the executedPRAGMA quick_check.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| mempalace/repair.py | Adds a bounded (15s) SQLite busy timeout to the quick_check connection used by sqlite_integrity_errors(). |
| tests/test_repair.py | Adds a deterministic regression test asserting the new connection contract without introducing a real-time sleep. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merged
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.
What changed
sqlite_integrity_errors()an explicit 15-second SQLite busy timeout.Why
PRAGMA quick_checkpreviously inherited Python's five-second default timeout. A healthy palace with a longer-running batch writer could therefore returndatabase is locked, which callers interpreted as SQLite corruption. Contention should get a bounded grace period; actualquick_checkfindings still fail exactly as before.This is the clean replacement for the core fix in #1932. It deliberately excludes that branch's unrelated L1 and CLI commits and its seven-second test.
Local validation
uv run pytest tests/test_repair.py -q— 92 passeduv run ruff check mempalace/repair.py tests/test_repair.pyuv run ruff format --check mempalace/repair.py tests/test_repair.pyBEGIN EXCLUSIVEfrom a peer connection for ~0.35s;sqlite_integrity_errors()waited and returned clean after the writer released.Supersedes the intended repair-only portion of #1932.