Skip to content

fix(search): quote underscored terms in FTS5 query sanitization - #16915

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-738e2ba4
Apr 28, 2026
Merged

fix(search): quote underscored terms in FTS5 query sanitization#16915
teknium1 merged 2 commits into
mainfrom
hermes/hermes-738e2ba4

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvages #16827 from @crayfish-ai onto current main.

Summary

FTS5 search now returns results for underscored terms like sp_new, which previously got tokenized as sp AND new and produced zero hits even when content matched.

Changes

  • hermes_state.py: Step 5 regex [.-][._-] in _sanitize_fts5_query (one-pass, avoids double-quoting).
  • tests/test_hermes_state.py: 8 new cases covering simple/multi/mixed underscores, already-quoted passthrough, and hyphen+dot regression.
  • scripts/release.py: AUTHOR_MAP entry for @crayfish-ai.

Validation

  • Reproduced bug on main: search_messages('sp_new') against messages containing sp_new1 → 0 results.
  • After fix: same query → 2 results.
  • scripts/run_tests.sh tests/test_hermes_state.py -k sanitize_fts5 → 5/5 passing.

Closes #16827. Credit to @crayfish-ai.

crayfish-ai and others added 2 commits April 28, 2026 01:27
FTS5 default tokenizer splits 'sp_new1' into tokens 'sp' and 'new1'.
Without quoting, a search for 'sp_new' becomes an AND query
('sp AND new') that fails to match rows indexed as 'sp_new1'.

Fix: add underscore to the character class in Step 5 regex
([.-] -> [._-]) so underscored terms are wrapped in double quotes.

Also adds test_sanitize_fts5_quotes_underscored_terms.
@teknium1
teknium1 merged commit 7d884f8 into main Apr 28, 2026
10 of 11 checks passed
@teknium1
teknium1 deleted the hermes/hermes-738e2ba4 branch April 28, 2026 08:31
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels Apr 28, 2026
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 P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants