fix(state): prefer pysqlite3 for session search FTS#61175
fix(state): prefer pysqlite3 for session search FTS#61175martinramos002-bot wants to merge 1 commit into
Conversation
b8ba3d3 to
ca00412
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves Hermes’ session search reliability on Linux by preferring pysqlite3-binary (when available) to ensure FTS5 + trigram support even when the distro-provided stdlib sqlite3 is built without those extensions, while keeping a stdlib fallback.
Changes:
- Add a Linux-only dependency on
pysqlite3-binaryto improve SQLite feature availability for session-search FTS. - In
hermes_state.py, attempt to import and usepysqlite3as thesqlite3backend (with stdlib fallback) and broaden OperationalError handling to cover both backends. - Add a TypeError compatibility fallback in WAL setup to avoid failing initialization when cross-backend cursor/connection types are incompatible (notably under certain test shims).
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pyproject.toml | Adds a Linux-only pysqlite3-binary dependency to improve SQLite extension availability for session search. |
| hermes_state.py | Switches SQLite backend preference to pysqlite3 when available and broadens error handling around WAL/FTS initialization paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try: | ||
| import pysqlite3 as sqlite3 # type: ignore[import-not-found] | ||
| # Some already-imported modules (notably tests) may hold a reference to the | ||
| # stdlib sqlite3 module object. Mirror the DB-API symbols we rely on so new | ||
| # connections/cursor subclasses in those modules use the same C extension | ||
| # type family as Hermes itself. | ||
| for _name in ( | ||
| "connect", | ||
| "Connection", | ||
| "Cursor", | ||
| "Row", | ||
| "Error", | ||
| "DatabaseError", | ||
| "OperationalError", | ||
| "IntegrityError", | ||
| "ProgrammingError", | ||
| ): | ||
| if hasattr(sqlite3, _name): | ||
| setattr(_stdlib_sqlite3, _name, getattr(sqlite3, _name)) | ||
| sys.modules["sqlite3"] = sqlite3 | ||
| _SQLITE_OPERATIONAL_ERRORS = (sqlite3.OperationalError, _stdlib_sqlite3.OperationalError) | ||
| except ModuleNotFoundError: # pragma: no cover - depends on local Python build | ||
| sqlite3 = _stdlib_sqlite3 | ||
| _SQLITE_OPERATIONAL_ERRORS = (sqlite3.OperationalError,) |
| except TypeError as exc: | ||
| # pysqlite3 can be active in production while tests deliberately | ||
| # monkeypatch stdlib-sqlite connection subclasses. Those cross-module | ||
| # C extension types are not always interchangeable; skip WAL rather | ||
| # than failing SessionDB initialization in that compatibility shim. |
ca00412 to
d8a6a1e
Compare
Related: #41033 (the canonical open fix, which adds a |
c8ae7d3 to
49c05ba
Compare
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Comment (prior automated review noted)
This PR has a prior automated COMMENT review. No new issues found.
Looks Good
- Prefers pysqlite3 for session search FTS — appropriate performance/portability fix
- No security concerns
49c05ba to
4fedd7c
Compare
4fedd7c to
c218f31
Compare
Summary
pysqlite3-binaryon Linux/x86_64, where upstream publishes wheels, so session-search FTS5/trigram support is present even if the distro stdlib SQLite lacks itpysqlite3uv.lockin sync and avoids forcing source builds on Linux/arm64Test plan
uv lock --checkpython -m pytest tests/test_hermes_state.py -q -o addopts=''The diff contains only generic dependency/backend handling and synthetic tests from the existing suite.