fix(core): degrade gracefully when sqlite-vec cannot load on init#774
Conversation
When the underlying CPython lacks sqlite extension support (the python.org macOS installer is the well-known case — its sqlite3 module ships without enable_load_extension), basic-memory crashed with AttributeError during init_search_index → _ensure_vector_tables → _ensure_sqlite_vec_loaded, triggered by `await driver_connection.enable_load_extension(True)`. That crash happens early in MCP startup, before the handshake with the client completes — so Claude Desktop sees "Server transport closed unexpectedly" and gives up permanently until manually restarted (#711). Two-part fix: 1. _ensure_sqlite_vec_loaded now checks for enable_load_extension before calling it and raises a typed SemanticDependenciesMissingError with a clear cause/remediation message instead of letting the AttributeError surface. 2. init_search_index catches that error, logs a warning, and flips the repository to semantic-disabled. Keyword search still works; downstream semantic call sites already short-circuit on _semantic_enabled. The user gets a degraded but functional MCP server instead of a hung handshake. Closes #711 Signed-off-by: phernandez <paul@basicmachines.co>
|
Claude finished @phernandez's task in 1m 52s —— View job PR Review:
|
Summary
init_search_index → _ensure_vector_tables → _ensure_sqlite_vec_loaded.Server transport closed unexpectedlyand stops trying. The reporter ([BUG] Fatal crash on startup when python.org Python 3.12 is present alongside Homebrew on macOS #711) had to manually clean up to recover.Change
Two-part fix in
src/basic_memory/repository/sqlite_search_repository.py:_ensure_sqlite_vec_loaded— proactively checkhasattr(driver_connection, "enable_load_extension")and raiseSemanticDependenciesMissingErrorwith a clear cause + remediation instead of letting theAttributeErrorbubble up.init_search_index— wrap the_ensure_vector_tables()call intry/except SemanticDependenciesMissingError, log a warning, and flipself._semantic_enabled = False. Keyword search still works; downstream semantic call sites already short-circuit on_semantic_enabled.The user now gets a degraded but functional MCP server instead of a hung handshake.
Test plan
tests/repository/test_search_repository.py::test_init_search_index_degrades_when_extension_loading_unavailable— patches_ensure_vector_tablesto raise, asserts init returns and_semantic_enabledisFalse.tests/repository/test_search_repository.py::test_ensure_sqlite_vec_loaded_raises_typed_error_without_extension_support— supplies a stub driver connection with noenable_load_extensionattribute, asserts the typed error fires.uv run pytest tests/repository/test_search_repository.py tests/services/test_search_service.py tests/services/test_semantic_search.py --no-cov— 106 passed.Out of scope
Closes #711
🤖 Generated with Claude Code