AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend/copilot-bot): keep copilot session alive as long as the thread auto-replies (#13322)
Bently9ed959b949fc
diff --git a/autogpt_platform/backend/backend/copilot/bot/config.py b/autogpt_platform/backend/backend/copilot/bot/config.pyindex cff751cb52..2a0b03dfab 100644--- a/autogpt_platform/backend/backend/copilot/bot/config.py+++ b/autogpt_platform/backend/backend/copilot/bot/config.py@@ -1,4 +1,12 @@"""Platform-agnostic bot config."""-# Cache TTL for AutoPilot session IDs (per channel/thread)-SESSION_TTL = 86400 # 24 hours+# Cache TTL for AutoPilot session IDs (per channel/thread).+#+# Must be >= the thread auto-reply subscription TTL (``threads.+# THREAD_SUBSCRIPTION_TTL``, 7 days). If it's shorter, the bot keeps+# auto-replying in a thread after the session cache has expired and silently+# starts a *fresh* copilot session that has lost the whole conversation — it+# then acts on stale cross-session memory instead of the actual thread, which is+# dangerous. Each turn refreshes this TTL, so an active conversation never loses+# context within the subscription window.+SESSION_TTL = 7 * 86400 # 7 days — matches the thread subscription windowdiff --git a/autogpt_platform/backend/backend/copilot/bot/sessions_test.py b/autogpt_platform/backend/backend/copilot/bot/sessions_test.pyindex 3ded808943..0214d337da 100644--- a/autogpt_platform/backend/backend/copilot/bot/sessions_test.py+++ b/autogpt_platform/backend/backend/copilot/bot/sessions_test.py@@ -4,7 +4,16 @@ from unittest.mock import AsyncMock, MagicMock, patchimport pytest-from backend.copilot.bot import sessions+from backend.copilot.bot import sessions, threads+from backend.copilot.bot.config import SESSION_TTL+++def test_session_ttl_outlives_thread_subscription():+ # If the session cache expires before the thread stops auto-replying, a+ # follow-up message silently starts a fresh copilot session and loses the+ # whole conversation. The session must live at least as long as the bot+ # keeps replying in the thread.+ assert SESSION_TTL >= threads.THREAD_SUBSCRIPTION_TTLdef test_session_cache_key_format():