From d3659c8ca0625dee76b2136531398e6a981a8647 Mon Sep 17 00:00:00 2001 From: Tenzin Jampa <60624133+ten-jampa@users.noreply.github.com> Date: Sat, 21 Mar 2026 19:04:53 -0400 Subject: [PATCH] fix(gateway): /title command fails when session doesn't exist in SQLite yet (#2379) The /title command would fail with 'Session not found in database.' when used as the first command in a new session. This happened because: 1. Gateway creates session in session_store (in-memory) 2. But SQLite _session_db only gets sessions when agent flushes messages 3. set_session_title() does UPDATE which fails if row doesn't exist Now we check if session exists in SQLite and create it if needed before attempting to set the title. Fixes: Session not found in database. error on /title in new chats --- gateway/run.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gateway/run.py b/gateway/run.py index 9b5ccf67f..d9da48357 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -3677,6 +3677,20 @@ class GatewayRunner: if not self._session_db: return "Session database not available." + # Ensure session exists in SQLite DB (it may only exist in session_store + # if this is the first command in a new session) + existing_title = self._session_db.get_session_title(session_id) + if existing_title is None: + # Session doesn't exist in DB yet — create it + try: + self._session_db.create_session( + session_id=session_id, + source=source.platform.value if source.platform else "unknown", + user_id=source.user_id, + ) + except Exception: + pass # Session might already exist, ignore errors + title_arg = event.get_command_args().strip() if title_arg: # Sanitize the title before setting