Skip to content

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

@Patrick-81

Description

@Patrick-81

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions