Skip to content

fix(state): prefer pysqlite3 for session search FTS#61175

Open
martinramos002-bot wants to merge 1 commit into
NousResearch:mainfrom
martinramos002-bot:fix/session-search-pysqlite3-fts
Open

fix(state): prefer pysqlite3 for session search FTS#61175
martinramos002-bot wants to merge 1 commit into
NousResearch:mainfrom
martinramos002-bot:fix/session-search-pysqlite3-fts

Conversation

@martinramos002-bot

@martinramos002-bot martinramos002-bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • prefers pysqlite3-binary on Linux/x86_64, where upstream publishes wheels, so session-search FTS5/trigram support is present even if the distro stdlib SQLite lacks it
  • keeps a stdlib SQLite fallback for platforms/installations without pysqlite3
  • broadens SQLite OperationalError handling to cover either backend
  • keeps uv.lock in sync and avoids forcing source builds on Linux/arm64

Test plan

  • uv lock --check
  • python -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.

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 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-binary to improve SQLite feature availability for session-search FTS.
  • In hermes_state.py, attempt to import and use pysqlite3 as the sqlite3 backend (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.

Comment thread hermes_state.py
Comment on lines +29 to +52
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,)
Comment thread hermes_state.py
Comment on lines +401 to +405
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.
@martinramos002-bot martinramos002-bot force-pushed the fix/session-search-pysqlite3-fts branch from ca00412 to d8a6a1e Compare July 8, 2026 23:27
@alt-glitch alt-glitch added type/feature New feature or request comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have labels Jul 8, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: #41033 (the canonical open fix, which adds a modern-sqlite pyproject extra + a SQLite-capability startup warning + opt-out env var), #47068 (pure sys.modules swap subset), #41030 (the issue). This PR takes a competing approach — auto-preferring pysqlite3-binary on Linux/x86_64 with a stdlib fallback — rather than an opt-in extra. Flagging for a maintainer to pick the canonical direction.

@martinramos002-bot martinramos002-bot force-pushed the fix/session-search-pysqlite3-fts branch 3 times, most recently from c8ae7d3 to 49c05ba Compare July 9, 2026 12:14

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

@martinramos002-bot martinramos002-bot force-pushed the fix/session-search-pysqlite3-fts branch from 49c05ba to 4fedd7c Compare July 9, 2026 14:20
@martinramos002-bot martinramos002-bot force-pushed the fix/session-search-pysqlite3-fts branch from 4fedd7c to c218f31 Compare July 9, 2026 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants