From 20c7d7e6b76fdee6588971b3b7d2f95cd3b64479 Mon Sep 17 00:00:00 2001 From: Lukas Parsons Date: Tue, 7 Jul 2026 22:12:22 -0400 Subject: [PATCH] fix: unconditional lazy hydration in get_session MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Drop the message_count > 0 guard — if it's 0 in the DB (stale metadata, race condition, failed persist), the session stays empty and the model gets no conversation history. The UI history endpoint has its own DB fallback, so messages display correctly but never reach the LLM. Now hydrate from DB whenever history is empty, regardless of message_count. Trade-off: one extra DB query for genuinely empty sessions (rare). --- core/session_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/session_manager.py b/core/session_manager.py index 491fbc07..3b82282e 100644 --- a/core/session_manager.py +++ b/core/session_manager.py @@ -382,7 +382,7 @@ class SessionManager: else: cached = self.sessions[session_id] # Lazy hydrate: metadata-only entries get their messages on first read. - if not cached.history and getattr(cached, "message_count", 0) > 0: + if not cached.history: self._load_session_from_db(session_id) # Keep model/endpoint metadata fresh. Endpoint deletion can clear the