From 5b29ff5a16e4a62d048a1860e67307d773eb1d2e Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Fri, 17 Apr 2026 18:44:37 +0700 Subject: [PATCH] fix(backend): invalidate cache on failed write in append_message_if Mirror the failure-path invalidation already in append_and_save_message. Without this, a failed cache write leaves stale session data in Redis, which later predicate checks could act on and produce duplicate messages. --- autogpt_platform/backend/backend/copilot/model.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autogpt_platform/backend/backend/copilot/model.py b/autogpt_platform/backend/backend/copilot/model.py index 436630c90e..9b82682bca 100644 --- a/autogpt_platform/backend/backend/copilot/model.py +++ b/autogpt_platform/backend/backend/copilot/model.py @@ -757,6 +757,9 @@ async def append_message_if( await cache_chat_session(session) except Exception as e: logger.warning(f"Cache write failed for session {session_id}: {e}") + # Invalidate the stale entry so future reads fall back to DB, + # preventing a predicate check from acting on stale state. + await invalidate_session_cache(session_id) return session