From 8769b55c51fd0934e82ac0dbf5ea23ea238d8be4 Mon Sep 17 00:00:00 2001 From: Otto Date: Sat, 31 Jan 2026 08:56:12 +0000 Subject: [PATCH] fix: use MAX_RETRIES constant and invalidate cache before reload Addresses CodeRabbit review feedback: - Use shared MAX_RETRIES constant instead of hardcoded value - Invalidate session cache before reloading to ensure fresh data --- .../backend/backend/api/features/chat/service.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/autogpt_platform/backend/backend/api/features/chat/service.py b/autogpt_platform/backend/backend/api/features/chat/service.py index d05e5f77f2..79f4dd3afc 100644 --- a/autogpt_platform/backend/backend/api/features/chat/service.py +++ b/autogpt_platform/backend/backend/api/features/chat/service.py @@ -1887,7 +1887,7 @@ async def _generate_llm_continuation( Includes retry logic with exponential backoff for transient API errors. """ retry_count = 0 - max_retries = 3 + max_retries = MAX_RETRIES last_error: Exception | None = None while retry_count <= max_retries: @@ -1945,7 +1945,9 @@ async def _generate_llm_continuation( assistant_content = response.choices[0].message.content # Reload session from DB to avoid race condition with user messages - # that may have been sent while we were generating the LLM response + # that may have been sent while we were generating the LLM response. + # Invalidate cache first to ensure we get fresh data from the database. + await invalidate_session_cache(session_id) fresh_session = await get_chat_session(session_id, user_id) if not fresh_session: logger.error(