Skip to content

fix(repair): wait out transient SQLite contention - #2015

Merged
igorls merged 1 commit into
developfrom
agent/fix-sqlite-integrity-contention
Jul 14, 2026
Merged

fix(repair): wait out transient SQLite contention#2015
igorls merged 1 commit into
developfrom
agent/fix-sqlite-integrity-contention

Conversation

@igorls

@igorls igorls commented Jul 14, 2026

Copy link
Copy Markdown
Member

What changed

  • Give sqlite_integrity_errors() an explicit 15-second SQLite busy timeout.
  • Add a deterministic regression test that verifies the connection contract without a multi-second sleep.

Why

PRAGMA quick_check previously inherited Python's five-second default timeout. A healthy palace with a longer-running batch writer could therefore return database is locked, which callers interpreted as SQLite corruption. Contention should get a bounded grace period; actual quick_check findings 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 passed
  • uv run ruff check mempalace/repair.py tests/test_repair.py
  • uv run ruff format --check mempalace/repair.py tests/test_repair.py
  • Real SQLite smoke on this Mac: held BEGIN EXCLUSIVE from 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.

@igorls
igorls marked this pull request as ready for review July 14, 2026 22:31
@igorls
igorls requested a review from milla-jovovich as a code owner July 14, 2026 22:31
Copilot AI review requested due to automatic review settings July 14, 2026 22:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.0 and pass it via sqlite3.connect(..., timeout=...) for the PRAGMA quick_check connection.
  • Add a regression test that monkeypatches sqlite3.connect to assert the uri=True + timeout=... connection arguments and the executed PRAGMA 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.

@igorls
igorls merged commit 4c8ef8e into develop Jul 14, 2026
9 checks passed
@igorls
igorls deleted the agent/fix-sqlite-integrity-contention branch July 14, 2026 23:25
@igorls igorls mentioned this pull request Jul 14, 2026
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.

2 participants