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.
This commit is contained in:
Zamil Majdy
2026-04-17 18:44:37 +07:00
parent a31297cf8a
commit 5b29ff5a16

View File

@@ -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