Skip to content

Commit 43e1544

Browse files
committed
fix: handle dangling tool results when history is cleared due to size limits
1 parent 3981b1c commit 43e1544

File tree

1 file changed

+12
-0
lines changed
  • server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb

1 file changed

+12
-0
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,18 @@ export class ChatDatabase {
439439
// Make sure max characters ≤ remaining Character Budget
440440
allMessages = this.trimMessagesToMaxLength(allMessages, remainingCharacterBudget)
441441

442+
// Edge case: If the history is empty and the next message contains tool results, then we have to just abandon them.
443+
if (
444+
allMessages.length === 0 &&
445+
newUserMessage.userInputMessage?.userInputMessageContext?.toolResults?.length &&
446+
newUserMessage.userInputMessage?.userInputMessageContext?.toolResults?.length > 0
447+
) {
448+
this.#features.logging.warn('History overflow: abandoning dangling toolResults.')
449+
newUserMessage.userInputMessage.userInputMessageContext.toolResults = []
450+
newUserMessage.userInputMessage.content =
451+
'The conversation context was too large and has been cleared; please continue.'
452+
}
453+
442454
const clientType = this.#features.lsp.getClientInitializeParams()?.clientInfo?.name || 'unknown'
443455

444456
tabData.conversations = [

0 commit comments

Comments
 (0)