fix: inject SessionDB into AIAgent for WebUI sessions (enables session_search) - #356
DelightRun wants to merge 1 commit into
Conversation
session_search tool requires a SessionDB instance passed via the session_db parameter. The CLI and gateway paths already do this, but the WebUI streaming path was missing it, causing every session_search call to return 'Session database not available'. Initialize SessionDB before creating the AIAgent and pass it through. Failure is non-fatal — a warning is printed and session_search gracefully degrades.
Review: fix — inject SessionDB into AIAgent for WebUI sessionsThanks for this! Clean, minimal fix that closes an important capability gap. What the fix does
Code reviewThe change is correct and well-structured: _session_db = None
try:
from hermes_state import SessionDB
_session_db = SessionDB()
except Exception as _db_err:
print(f"[webui] WARNING: SessionDB init failed — session_search will be unavailable: {_db_err}", flush=True)
Minor noteThe warning uses logger.warning("SessionDB init failed — session_search will be unavailable: %s", _db_err)Not a blocker for this PR, just worth noting for consistency. Summary
Looks good to merge. |
…n_search) (#356) - api/streaming.py: initialize SessionDB() before AIAgent construction and pass session_db= kwarg so session_search works in WebUI sessions - tests/test_sprint42.py: 7 new tests covering SessionDB injection, try/except guard, WARNING log, ordering, and AST lock-safety check - CHANGELOG.md: v0.50.13 entry; 822 tests total (up from 815)
…on_search (#356) * fix: inject SessionDB into AIAgent for WebUI sessions session_search tool requires a SessionDB instance passed via the session_db parameter. The CLI and gateway paths already do this, but the WebUI streaming path was missing it, causing every session_search call to return 'Session database not available'. Initialize SessionDB before creating the AIAgent and pass it through. Failure is non-fatal — a warning is printed and session_search gracefully degrades. * fix: inject SessionDB into AIAgent for WebUI sessions (enables session_search) (#356) - api/streaming.py: initialize SessionDB() before AIAgent construction and pass session_db= kwarg so session_search works in WebUI sessions - tests/test_sprint42.py: 7 new tests covering SessionDB injection, try/except guard, WARNING log, ordering, and AST lock-safety check - CHANGELOG.md: v0.50.13 entry; 822 tests total (up from 815) --------- Co-authored-by: 王昌旭 <wangchangxu@xiaohongshu.com> Co-authored-by: Nathan Esquenazi <nesquena@gmail.com>
|
Closed in favor of #359 which merged this fix with added tests (test_sprint42.py) and CHANGELOG entry. 822 tests pass on master. |
…on_search (nesquena#356) * fix: inject SessionDB into AIAgent for WebUI sessions session_search tool requires a SessionDB instance passed via the session_db parameter. The CLI and gateway paths already do this, but the WebUI streaming path was missing it, causing every session_search call to return 'Session database not available'. Initialize SessionDB before creating the AIAgent and pass it through. Failure is non-fatal — a warning is printed and session_search gracefully degrades. * fix: inject SessionDB into AIAgent for WebUI sessions (enables session_search) (nesquena#356) - api/streaming.py: initialize SessionDB() before AIAgent construction and pass session_db= kwarg so session_search works in WebUI sessions - tests/test_sprint42.py: 7 new tests covering SessionDB injection, try/except guard, WARNING log, ordering, and AST lock-safety check - CHANGELOG.md: v0.50.13 entry; 822 tests total (up from 815) --------- Co-authored-by: 王昌旭 <wangchangxu@xiaohongshu.com> Co-authored-by: Nathan Esquenazi <nesquena@gmail.com>
…on_search (nesquena#356) * fix: inject SessionDB into AIAgent for WebUI sessions session_search tool requires a SessionDB instance passed via the session_db parameter. The CLI and gateway paths already do this, but the WebUI streaming path was missing it, causing every session_search call to return 'Session database not available'. Initialize SessionDB before creating the AIAgent and pass it through. Failure is non-fatal — a warning is printed and session_search gracefully degrades. * fix: inject SessionDB into AIAgent for WebUI sessions (enables session_search) (nesquena#356) - api/streaming.py: initialize SessionDB() before AIAgent construction and pass session_db= kwarg so session_search works in WebUI sessions - tests/test_sprint42.py: 7 new tests covering SessionDB injection, try/except guard, WARNING log, ordering, and AST lock-safety check - CHANGELOG.md: v0.50.13 entry; 822 tests total (up from 815) --------- Co-authored-by: 王昌旭 <wangchangxu@xiaohongshu.com> Co-authored-by: Nathan Esquenazi <nesquena@gmail.com>
Problem
The session_search tool always returns "Session database not available" when used from WebUI sessions. This means the agent cannot recall past conversations or search session history — a capability that works fine in CLI and gateway modes.
Root Cause
The session_search tool requires a SessionDB instance passed via the session_db parameter on AIAgent.init(). Both the CLI path (cli.py) and gateway path (gateway/run.py) already initialize and inject SessionDB, but the WebUI streaming path (api/streaming.py) was missing this step.
The agent's _invoke_tool() method checks self._session_db — when it's None, it short-circuits with the error message without ever touching the database.
Fix
Two changes in api/streaming.py:
Testing
Verified manually: after the fix, session_search successfully returns recent sessions with metadata (session_id, title, source, timestamps, preview) from the existing state.db (59 sessions, 2309 messages).