Skip to content

fix(state): honor boolean operators in trigram-off LIKE fallback + fail-closed drops - #114

Merged
exiao merged 2 commits into
live-configfrom
fix/cjk-like-boolean-and-lock-hardening
Jul 15, 2026
Merged

fix(state): honor boolean operators in trigram-off LIKE fallback + fail-closed drops#114
exiao merged 2 commits into
live-configfrom
fix/cjk-like-boolean-and-lock-hardening

Conversation

@exiao

@exiao exiao commented Jul 15, 2026

Copy link
Copy Markdown
Owner

What

Salvages the two genuine improvements from #111 onto the already-merged sessions.fts_trigram gate (#110). #100/#110/#113 merged in the sweep; #110 shipped the same "drop the trigram FTS index to shrink state.db" feature #111 proposed, but under the config key sessions.fts_trigram instead of #111's sessions.trigram_fts. Rather than land a second knob + duplicate implementation, #111 is closed as superseded and its two non-duplicate fixes are ported here against the merged key.

Fixes

  1. CJK/substring LIKE fallback honors boolean operators. When trigram is gated off, the LIKE fallback is the only CJK/substring search path. The old fallback OR-joined every non-operator token, so A NOT B returned rows containing B and A AND B returned rows matching only A. It now walks tokens left-to-right honoring AND (intersection) and NOT (AND NOT, exclusion), with COALESCE(col,'') so a NULL tool column under the AND NOT branch yields FALSE instead of NULL (which would silently drop every row).

  2. _drop_trigram_schema fails closed. The trigger + table drops now run inside one BEGIN IMMEDIATE transaction, so a database is locked during startup contention (gateway + cron) propagates instead of being swallowed and leaving a stale trigram trigger pointing at a missing table. On a SQLite build missing the trigram tokenizer (the DROP TABLE raises no such tokenizer: trigram), the triggers are re-dropped in a standalone committed step so message INSERTs degrade to the base FTS/LIKE path instead of crashing on the unusable vtable.

Tests

Red-before/green-after regressions in tests/test_hermes_state.py:

  • test_trigram_off_like_fallback_honors_boolean_operators (AND/OR/NOT)
  • test_drop_trigram_schema_propagates_locked_drop (lock fails closed)
  • test_drop_trigram_schema_drops_triggers_when_tokenizer_missing

Full tests/test_hermes_state.py suite: 352 passed. ruff clean.

…il-closed drops

Salvages the two genuine improvements from #111 onto the merged
sessions.fts_trigram gate (#110), which shipped the same trigram-disable
feature under a different config key. #111 is superseded and closed.

1. CJK/substring LIKE fallback now preserves query boolean structure: it
   walks tokens left-to-right honoring AND (intersection) and NOT
   (exclusion) instead of OR-joining every term. Once trigram is disabled
   this fallback is the only CJK path, so "A NOT B" no longer returns rows
   with B and "A AND B" no longer returns rows matching only A. COALESCE
   guards the AND NOT branch against NULL tool columns dropping every row.

2. _drop_trigram_schema now fails closed: the trigger + table drops run in
   one BEGIN IMMEDIATE transaction so a "database is locked" propagates
   instead of leaving a stale trigger pointing at a missing table. On a
   build missing the trigram tokenizer (DROP TABLE raises), the triggers are
   re-dropped in a standalone committed step so message INSERTs degrade to
   the base FTS/LIKE path instead of crashing on the unusable vtable.

Regression tests: red-before/green-after for the boolean fallback and the
locked-drop propagation; tokenizer-missing trigger cleanup.
@exiao

exiao commented Jul 15, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@claude

claude Bot commented Jul 15, 2026

Copy link
Copy Markdown

Claude encountered an error after 2s —— View job


I'll analyze this and get back to you.

@gemini-code-assist gemini-code-assist Bot 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

This pull request updates the SQLite trigram schema teardown to execute transactionally, preventing partial drops during concurrent lock contention, and adds a fallback path to drop triggers standalone if the trigram tokenizer is missing. Additionally, the fallback LIKE search is refactored to preserve the query's boolean structure (AND, OR, NOT) and handle NULL columns correctly. The review feedback suggests propagating lock errors during the standalone trigger drop to avoid starting up in a state that crashes on subsequent writes, and correctly handling combined OR NOT operators to prevent them from being parsed as AND NOT.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread hermes_state.py
Comment thread hermes_state.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8fb266ad39

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread hermes_state.py Outdated
…upport OR NOT

Addresses codex review on #114: (1) the tokenizer-missing trigger-drop
recovery now propagates a lock instead of swallowing it (a swallowed lock
left stale triggers crashing INSERTs); (2) the LIKE-fallback boolean parser
now keeps the OR connector on 'A OR NOT B' instead of collapsing it to
'A AND NOT B'. Adds regressions for both.
@exiao

exiao commented Jul 15, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 9b504ec357

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@exiao
exiao merged commit db08c27 into live-config Jul 15, 2026
38 of 40 checks passed
@exiao
exiao deleted the fix/cjk-like-boolean-and-lock-hardening branch July 15, 2026 03:48
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.

1 participant