Skip to content

fix(tui): degrade gracefully when state.db init fails#14135

Merged
OutThisLife merged 1 commit into
NousResearch:mainfrom
helix4u:fix/tui-state-db-optional
Apr 23, 2026
Merged

fix(tui): degrade gracefully when state.db init fails#14135
OutThisLife merged 1 commit into
NousResearch:mainfrom
helix4u:fix/tui-state-db-optional

Conversation

@helix4u

@helix4u helix4u commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Prevents hermes --tui from hard-failing when state.db cannot be opened during TUI startup. The TUI gateway was the odd path out: classic CLI and gateway already treat SessionDB() init failure as non-fatal, but TUI let the exception bubble out of _get_db() and surface as agent init failed: locking protocol.

This change makes the TUI gateway degrade gracefully when SessionDB() init fails, lets chat continue without state-backed session indexing, and returns explicit state.db unavailable RPC errors only for TUI features that actually require the database.

Related Issue

Fixes #

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

  • make tui_gateway.server._get_db() catch SessionDB() init failures and return None instead of aborting TUI startup
  • skip create_session(...) during TUI session bootstrap when state.db is unavailable
  • return clear state.db unavailable: ... RPC errors for DB-backed TUI methods like session list, resume, title, branch, and insights
  • add regression tests covering broken SessionDB() init, successful session.create without state.db, and clean TUI errors for DB-backed commands

How to Test

  1. Reproduce a failing SessionDB() init in the TUI path so _get_db() cannot open state.db.
  2. Run hermes --tui and confirm the session still comes up instead of showing agent init failed: locking protocol.
  3. Confirm DB-backed TUI features like /resume or session listing now fail with a clear state.db unavailable: ... message instead of killing the TUI session.
  4. Run scripts/run_tests.sh tests/test_tui_gateway_server.py tests/tui_gateway/test_protocol.py -n 4.

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: Ubuntu / WSL2-style TUI path analysis

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

Screenshots / Logs

TUI currently surfaced raw startup failures like:

agent init failed: locking protocol

after SessionDB() initialization failed in tui_gateway/server.py.

Targeted coverage for this change passed:

source venv/bin/activate && scripts/run_tests.sh tests/test_tui_gateway_server.py tests/tui_gateway/test_protocol.py -n 4

Repo-wide hermetic coverage was also run:

source venv/bin/activate && scripts/run_tests.sh -n 4

That full run is currently red on this checkout with 55 failing tests and 14443 passing tests. The failures observed in that run were spread across unrelated areas including gateway approval flows, DingTalk, Discord bot filtering, MiniMax, Anthropic/Codex response paths, backup, browser/camofox, Tirith, write-deny, and zombie cleanup.

@helix4u helix4u marked this pull request as ready for review April 22, 2026 20:01
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/tui Terminal UI (ui-tui/ + tui_gateway/) labels Apr 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #13029 (SQLite FTS5 missing breaks session store) and #10972 (graceful FTS5 degradation). This PR extends graceful degradation to the TUI gateway path specifically.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #13029 and #10972.

@OutThisLife OutThisLife self-requested a review April 23, 2026 01:05
@OutThisLife OutThisLife merged commit e47537e into NousResearch:main Apr 23, 2026
6 of 7 checks passed
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
…ptional

fix(tui): degrade gracefully when state.db init fails
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
…ptional

fix(tui): degrade gracefully when state.db init fails
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…ptional

fix(tui): degrade gracefully when state.db init fails
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…ptional

fix(tui): degrade gracefully when state.db init fails
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…ptional

fix(tui): degrade gracefully when state.db init fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/tui Terminal UI (ui-tui/ + tui_gateway/) 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