fix(state): survive broken trigram fts index#30082
Draft
0-CYBERDYNE-SYSTEMS-0 wants to merge 1 commit into
Draft
fix(state): survive broken trigram fts index#300820-CYBERDYNE-SYSTEMS-0 wants to merge 1 commit into
0-CYBERDYNE-SYSTEMS-0 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes a
state.dbfailure mode where a broken optionalmessages_fts_trigramFTS5 virtual table can preventSessionDBfrom initializing, even though the canonicalsessionsandmessagestables are intact.This matters because the gateway now relies on
state.dbas canonical transcript storage. If SessionDB init fails, the agent can appear to have no conversation history despite ordinary transcript rows still being present.The approach is intentionally narrow:
sqlite3.DatabaseError, not onlyOperationalError;messages;append_message()create a missing session row defensively so gateway flush races do not drop messages.This is related to #27770, but not a duplicate: #27770 makes trigram FTS optional for size/configuration. This PR handles the corrupt-vtable constructor failure path that prevents
state.dbfrom opening.Related Issue
Fixes #
Refs #27770
Type of Change
Changes Made
hermes_state.pyappend_message()insert a missingsessionsrow with sourceunknownbefore inserting the message.tests/test_hermes_state.pyHow to Test
state.dbwhereSELECT * FROM messages_fts_trigram LIMIT 0raisesvtable constructor failed: messages_fts_trigram; SessionDB should still open and ordinary writes should still work.Local verification:
python -m py_compile hermes_state.py tests/test_hermes_state.pypassed.python -m pytest tests/test_hermes_state.py -qpassed:218 passed in 1.45s.integrity ok,sessions 446,messages 27893, and a new message write succeeded with trigram search disabled for the connection.scripts/run_tests.shwas attempted. It completed with unrelated environment/live-system failures in this macOS sandbox:24354 passed, 333 failed; failures were in socket binding, live-system guard, systemd/platform, OAuth/env tests, and unrelated web provider expectations.Checklist
Code
fix(state): survive broken trigram fts index)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — N/Acli-config.yaml.exampleif I added/changed config keys — N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — N/AScreenshots / Logs