From 6b1320f9e0ce4d3c663648ce66d01d7cc113ee0a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 24 Feb 2026 07:03:15 +0000 Subject: [PATCH] Support unlimited message history when max_messages_per_user is 0 Co-Authored-By: Claude Opus 4.6 --- meshai/history.py | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/meshai/history.py b/meshai/history.py index 0d0dddd..9cdea10 100644 --- a/meshai/history.py +++ b/meshai/history.py @@ -110,16 +110,27 @@ class ConversationHistory: cutoff_time = time.time() - self.config.conversation_timeout async with self._lock: - cursor = await self._db.execute( - """ - SELECT role, content, timestamp - FROM conversations - WHERE user_id = ? AND timestamp > ? - ORDER BY timestamp ASC - LIMIT ? - """, - (user_id, cutoff_time, self.config.max_messages_per_user * 2), - ) + if self.config.max_messages_per_user > 0: + cursor = await self._db.execute( + """ + SELECT role, content, timestamp + FROM conversations + WHERE user_id = ? AND timestamp > ? + ORDER BY timestamp ASC + LIMIT ? + """, + (user_id, cutoff_time, self.config.max_messages_per_user * 2), + ) + else: + cursor = await self._db.execute( + """ + SELECT role, content, timestamp + FROM conversations + WHERE user_id = ? AND timestamp > ? + ORDER BY timestamp ASC + """, + (user_id, cutoff_time), + ) rows = await cursor.fetchall() @@ -161,6 +172,9 @@ class ConversationHistory: async def _prune_history(self, user_id: str) -> None: """Remove old messages beyond the limit for a user.""" + if self.config.max_messages_per_user <= 0: + return # No limit + # Get count of messages for user cursor = await self._db.execute( "SELECT COUNT(*) FROM conversations WHERE user_id = ?",