Skip to content

fix(state): quote dotted terms in FTS5 queries - #4246

Closed
lumethegreat wants to merge 1 commit into
NousResearch:mainfrom
lumethegreat:fix/session-search-dot-queries
Closed

fix(state): quote dotted terms in FTS5 queries#4246
lumethegreat wants to merge 1 commit into
NousResearch:mainfrom
lumethegreat:fix/session-search-dot-queries

Conversation

@lumethegreat

Copy link
Copy Markdown

What changed

FTS5 session search queries containing dots (e.g. P2.2, simulate.p2.test.ts) can hit query parse edge cases that yield empty results (or an OperationalError that gets handled as no matches) unless the term is quoted.

This PR extends SessionDB._sanitize_fts5_query() to automatically wrap dotted tokens in double quotes, similar to the existing mitigation for hyphenated terms.

Why

Users naturally search for version-like strings (P2.2) and file-like strings (simulate.p2.test.ts). Without quoting, these queries can be interpreted in ways that prevent matching, leading to misleading “no results” behavior in session_search.

How it works

  • Detect tokens that contain one or more dots (and only word-ish characters / hyphens around them)
  • Rewrite them into quoted phrases:
    • P2.2"P2.2"
    • simulate.p2.test.ts"simulate.p2.test.ts"

Tests

  • Added regression tests ensuring:
    • dotted queries do not crash and still return matches
    • dotted tokens are quoted by _sanitize_fts5_query

Command:

  • pytest -q tests/test_hermes_state.py -k dotted

Files changed

  • hermes_state.py
  • tests/test_hermes_state.py

FTS5 queries containing dots (e.g. P2.2, simulate.p2.test.ts) can trigger query parse edge cases that yield OperationalError or empty results unless quoted. Extend _sanitize_fts5_query to wrap dotted tokens in double quotes (similar to hyphenated terms) and add regression tests.
@teknium1

teknium1 commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Merged via PR #4549. Your commit was cherry-picked onto current main with your authorship preserved in git log. During salvage, I merged the dotted-term and hyphenated-term regex steps into a single pass to fix a double-quoting bug for terms containing both dots and hyphens (e.g. my-app.config.ts). Thanks for the contribution!

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.

2 participants