Skip to content

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

Closed

Description

@cabras-co

Bug Description

On a SQLite-only install, basic-memory mcp imports asyncpg at startup, so the server dies whenever the asyncpg native extension can't be loaded. On Windows 11 with Smart App Control enabled this happens: SAC blocks the unsigned asyncpg\pgproto\pgproto.cp314-win_amd64.pyd, and the MCP server exits before answering initialize (MCP clients only see "Connection closed").

The import chain is unconditional:

basic_memory/mcp/server.py:15
 -> basic_memory/api/... -> basic_memory/deps/services.py:35
 -> basic_memory/services/search_service.py:31
 -> basic_memory/repository/search_refresh_race.py:21
      from asyncpg.exceptions import DeadlockDetectedError, UniqueViolationError
 -> asyncpg/__init__.py -> asyncpg/protocol/__init__.py:11  (native extension)

search_refresh_race.py itself says the race "never" happens on SQLite, so SQLite users pay for a Postgres driver import they can't use.

Steps To Reproduce

  1. Windows 11 with Smart App Control On, basic-memory 1.0.0 installed with uv tool install, SQLite backend (default).
  2. Run basic-memory mcp (or connect from Claude Code).
  3. SAC blocks pgproto.cp314-win_amd64.pyd (CodeIntegrity event 3077, Windows Security toast "Part of this app has been blocked").

Expected Behavior

The SQLite path starts without importing asyncpg, as it would without the race helper.

Actual Behavior

ImportError: DLL load failed while importing pgproto: An Application Control policy has blocked this file.

The process exits with code 1. On the same machine SAC also blocked sqlalchemy\util\_collections_cy.cp314-win_amd64.pyd, but SQLAlchemy 2.1 ships pure-Python fallbacks for those, so asyncpg is the only hard blocker on the SQLite path.

Environment

  • OS: Windows 11 25H2 (build 26200), Smart App Control On
  • Python version: 3.14.6 (PSF-signed)
  • Basic Memory version: 1.0.0
  • Installation method: uv tool install
  • Client: Claude Code (stdio MCP)

Possible Solution

Import asyncpg lazily in lost_search_refresh_race, or guard it:

try:
    from asyncpg.exceptions import DeadlockDetectedError, UniqueViolationError
except ImportError:  # SQLite-only installs, or a blocked native extension
    DeadlockDetectedError = UniqueViolationError = None

and return None early when they're unavailable. Optionally, keep asyncpg as an extra (basic-memory[postgres]) so SQLite users don't install a native Postgres driver at all.

Workaround for affected users today: turning Smart App Control off.

Activity

  1. added
    bug
    on Nov 12, 2026
  2. added a commit that references this issue on Nov 13, 2026
    b1e96b6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions