From a8ba96ff4aa6cd3390d13aec5613becb6ffda13c Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sun, 14 Sep 2025 18:47:26 -0700 Subject: [PATCH] fix: allows truncation for empty conversation, for when automatic truncation is tried after failed request (#6200) --- src/core/context/context-management/ContextManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/context/context-management/ContextManager.ts b/src/core/context/context-management/ContextManager.ts index 5e41b12c..6a523e0b 100644 --- a/src/core/context/context-management/ContextManager.ts +++ b/src/core/context/context-management/ContextManager.ts @@ -291,7 +291,7 @@ export class ContextManager { // Make sure that the last message being removed is a assistant message, so the next message after the initial user-assistant pair is an assistant message. This preserves the user-assistant-user-assistant structure. // NOTE: anthropic format messages are always user-assistant-user-assistant, while openai format messages can have multiple user messages in a row (we use anthropic format throughout cline) - if (apiMessages[rangeEndIndex].role !== "assistant") { + if (apiMessages[rangeEndIndex] && apiMessages[rangeEndIndex].role !== "assistant") { rangeEndIndex -= 1 }