Skip to content

fix(core): stop SQLite startup importing asyncpg - #2108

Merged
phernandez merged 1 commit into
mainfrom
fix/2103-asyncpg-sqlite-startup
Nov 13, 2026
Merged

phernandez merged 1 commit into
mainfrom
fix/2103-asyncpg-sqlite-startup

Conversation

@phernandez

Copy link
Copy Markdown
Member

Fixes #2103.

Problem

search_refresh_race.py imported asyncpg.exceptions at module load. The search service and the accepted-note write runner import it, so every install loaded the Postgres driver at startup, including SQLite-only installs. On Windows 11 with Smart App Control on, Windows blocks asyncpg's unsigned native extension, and bm mcp exits before it answers initialize.

Change

lost_search_refresh_race now matches the driver error by its Postgres SQLSTATE (40P01 deadlock, 23505 unique violation) and constraint name instead of by asyncpg's exception classes. The module no longer imports asyncpg. After this change, importing basic_memory.cli.main and basic_memory.mcp.server leaves asyncpg out of sys.modules.

Tests

  • New test_sqlite_startup_never_imports_the_postgres_driver imports the CLI and MCP server in a fresh interpreter and checks that asyncpg was not loaded. It fails on main.
  • The existing classifier tests, which build real asyncpg errors, still pass.
  • tests/services/test_search_refresh_concurrency.py passes against Postgres; it produces the real deadlock and primary-key races.
  • just typecheck passes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CMYVL1rjJwNnrvxniz1dDD

lost_search_refresh_race matched asyncpg's exception classes, so importing
it loaded the Postgres driver on every install. On Windows with Smart App
Control the native extension is blocked and bm mcp exits before initialize.
Match on the SQLSTATE and constraint name on the driver error instead.

Fixes #2103

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01CMYVL1rjJwNnrvxniz1dDD
Signed-off-by: phernandez <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T21:11:36.274315Z ac4aed7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@phernandez
phernandez merged commit b1e96b6 into main Nov 13, 2026
51 checks passed
@phernandez
phernandez deleted the fix/2103-asyncpg-sqlite-startup branch November 13, 2026 01:11
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.

[BUG] SQLite-only startup imports asyncpg unconditionally; MCP server dies when Windows Smart App Control blocks its native extension

1 participant