Skip to content

fix(gateway): trust SQLite codes for FTS recovery - #108318

Open
ehz0ah wants to merge 1 commit into
NousResearch:mainfrom
ehz0ah:fix-gateway-fts-provenance
Open

ehz0ah wants to merge 1 commit into
NousResearch:mainfrom
ehz0ah:fix-gateway-fts-provenance

Conversation

@ehz0ah

@ehz0ah ehz0ah commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Uses SQLite result codes as the authoritative signal when gateway transcript writes decide whether to rebuild FTS and retry. The existing substring check treated any exception text containing messages_fts as FTS corruption, including constraint failures that should not trigger recovery.

Explicit missing-table recovery remains supported for the three Hermes FTS tables because SQLite reports those trigger failures as SQLITE_ERROR. The missing-table match is exact and accepts the schema-qualified main.messages_fts form emitted by real triggers without accepting lookalike table names.

Related Issue

Refs #108130
Related to #97940

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Classify exceptions with live SQLite result codes through the shared corruption classifier.
  • Preserve recovery for exact missing base, trigram, and CJK FTS tables.
  • Accept real schema-qualified trigger errors.
  • Reject lookalike table names and contradictory constraint result codes.

How to Test

  1. Run HERMES_PYTHON=/path/to/python scripts/run_tests.sh tests/gateway/test_session.py -q.
  2. Confirm 65 tests pass.
  3. Run ruff check gateway/session_transcript.py tests/gateway/test_session.py.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior or N/A

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery area/sessions Session lifecycle, resume, persistence, history sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state P3 Low — cosmetic, nice to have labels Sep 11, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/sessions Session lifecycle, resume, persistence, history comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants