hermes-control-interface icon indicating copy to clipboard operation
hermes-control-interface copied to clipboard

[BUG] TUI Gateway Spawns New Slash Worker on Every Message Without Session Persistence

Open Patrick-81 opened this issue 6 months ago • 2 comments

The TUI gateway (tui_gateway/server.py) creates a new slash_worker subprocess for every incoming message, destroying the previous agent session and losing all context. This causes the TUI to behave like a fresh conversation on each interaction, breaking the user experience. Root Cause

In tui_gateway/server.py, the message handling flow: This happens on every single message, not just on explicit /new or /reset commands.

Evidence

Copy 20260528_152431_2407f0 ← session 120260528_155307_656940 ← session 220260528_155638_4303b7 ← session 3 (3 instances running simultaneously!)20260528_155745_942523 ← session 4 All slash_workers use the same model (Qwen3.5-9B-DeepSeek-V4-Flash-MTP-Q5_K_M.gguf) but with different session keys, confirming they're independent processes without shared state.

Impact

Context loss: Every message is treated as a new conversation Memory waste: Multiple slash_worker instances running simultaneously User experience broken: No persistent chat history in the TUI Resource waste: Unnecessary process spawning and session reinitialization Maintain a single slash_worker instance per WebSocket connection Pass the session context to the worker via shared memory or process arguments Only restart the worker on explicit /new or /reset commands Instead of fully reinitializing the agent, preserve the session context Only reset the agent's internal state (not the slash_worker) Ensure the worker reuses the same session key Store the slash_worker PID and session key in a persistent store (SQLite/Redis) On connection, check if a worker is already running for this session Reuse existing worker if found, spawn new one only if not tui_gateway/server.py - main message handler tui_gateway/slash_worker.py - worker process management agent/AIAgent.py - session initialization

Receives a message via WebSocket Calls _reset_session_agent() → completely reinitializes the AIAgent (new session, no history) Calls _restart_slash_worker() → spawns a fresh subprocess with a new session key The previous slash_worker is orphaned and eventually killed by the OS

Option 1: Reuse existing slash_worker (preferred) Option 2: Fix _reset_session_agent()

Option 3: Add session persistence layer

Minimal Fix

Add a check in _reset_session_agent() to preserve the slash_worker instance: pythonCopy

Instead of:self.slash_worker = Noneself._reset_session_agent()

Do:if self.slash_worker and self.slash_worker.is_alive(): self.slash_worker.session_key = new_session_key # Reuse existing workerelse: self._restart_slash_worker()

Priority

P0 - This is a critical UX bug that prevents the TUI from functioning as intended.

Environment:

  • OS: Ubuntu 24.04.4 LTS
  • Node.js version: v22.22.0
  • Browser: chromium
  • Hermes version: v0.14.0 (2026.5.16)
  • HCI version: 3.5.0

Patrick-81 avatar May 28 '26 16:05 Patrick-81

Same for me:

[WS] chat.start received profile="default" session_id="a6c0ac90" [TUI:default] session.resume(a6c0ac90) [TUI:default] session.resume FAILED (session not found), creating new session [WS] chat.start received profile="default" session_id="07718427" [TUI:default] session.resume(07718427) [TUI:default] session.resume FAILED (session not found), creating new session [WS] chat.start received profile="default" session_id="844ac7b4" [TUI:default] session.resume(844ac7b4) [TUI:default] session.resume FAILED (session not found), creating new session

MattXcz avatar May 29 '26 08:05 MattXcz

Fixed in 1419564 and deployed.

FIX #68 — TUI Session Persistence:

Root cause: HCI frontend sent chat.start on every message, triggering session.resume → new slash_worker each time.

Fix (HCI-only, no Hermes Agent core changes):

  • New chat.send path: sends prompt.submit directly without session.resume
  • First message → chat.start (session init)
  • Subsequent messages → chat.send (reuse existing session, zero overhead)

Files: bridge, server WS handler, ws-client, main.js.

xaspx avatar Jun 01 '26 04:06 xaspx