TUI now generates a UUID session_id on mount and on chat clear

This commit is contained in:
Yiorgis Gozadinos 2026-02-10 14:21:22 +02:00
parent aaa9b6a32f
commit a7b79c433d
No known key found for this signature in database
3 changed files with 29 additions and 6 deletions

View file

@ -1,6 +1,10 @@
# Changelog
## [Unreleased]
### Fixed
- **TUI session context not updating**: The Chat TUI now generates a UUID `session_id` on mount and on chat clear, fixing background summarization which requires a non-empty `session_id`.
## [0.29.1] - 2026-02-10
### Fixed

View file

@ -156,6 +156,7 @@ class ChatApp(App):
# Create agent and session state
self.agent = create_chat_agent(self.config)
self.session_state = ChatSessionState(
session_id=str(uuid.uuid4()),
initial_context=self._initial_context,
document_filter=self._document_filter,
)
@ -328,6 +329,7 @@ class ChatApp(App):
# Reset context lock and session state (reset to CLI value)
self._context_locked = False
self.session_state = ChatSessionState(
session_id=str(uuid.uuid4()),
initial_context=self._initial_context,
document_filter=self._document_filter,
)

View file

@ -245,9 +245,25 @@ async def test_chat_history_thinking_indicator(temp_db_path: Path):
assert len(list(thinking)) == 0
@pytest.mark.asyncio
async def test_chat_app_generates_session_id(temp_db_path: Path):
"""Test that ChatApp generates a UUID session_id on mount."""
from haiku.rag.chat.app import ChatApp
mock_client = AsyncMock()
mock_client.__aenter__ = AsyncMock(return_value=mock_client)
mock_client.__aexit__ = AsyncMock(return_value=None)
with patch("haiku.rag.chat.app.HaikuRAG", return_value=mock_client):
app = ChatApp(temp_db_path, read_only=True)
async with app.run_test():
assert app.session_state.session_id != ""
@pytest.mark.asyncio
async def test_clear_chat_resets_session(temp_db_path: Path):
"""Test that clearing chat resets the session state."""
"""Test that clearing chat resets the session state with a new session_id."""
from haiku.rag.chat.app import ChatApp
from haiku.rag.chat.widgets.chat_history import ChatHistory
@ -266,9 +282,9 @@ async def test_clear_chat_resets_session(temp_db_path: Path):
await chat_history.add_message("assistant", "Hi there")
assert len(chat_history.messages) == 2
# Mutate session state to simulate an active session
assert app.session_state is not None
app.session_state.session_id = "active-session-123"
# Record the original session_id
original_session_id = app.session_state.session_id
assert original_session_id != ""
# Clear chat via action (available through command palette)
await app.action_clear_chat()
@ -277,9 +293,10 @@ async def test_clear_chat_resets_session(temp_db_path: Path):
# Verify messages cleared
assert len(chat_history.messages) == 0
# Verify session state reset
# Verify session state reset with a new session_id
assert app.session_state is not None
assert app.session_state.session_id == ""
assert app.session_state.session_id != ""
assert app.session_state.session_id != original_session_id
assert app.session_state.qa_history == []
assert app.session_state.citations == []