Skip to content

fix: incorrect history when user aborts in-progress toolUse #1542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
TabType,
updateOrCreateConversation,
} from './util'
import * as crypto from 'crypto'

Check warning on line 20 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "crypto"

Check warning on line 20 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "crypto"
import * as path from 'path'

Check warning on line 21 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "path"

Check warning on line 21 in server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/chatDb.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "path"
import { Features } from '@aws/language-server-runtimes/server-interface/server'
import { ConversationItemGroup } from '@aws/language-server-runtimes/protocol'
import { ChatMessage, ToolResultStatus } from '@amzn/codewhisperer-streaming'
Expand Down Expand Up @@ -375,7 +375,10 @@

formatChatHistoryMessage(message: Message): Message {
if (message.type === ('prompt' as ChatItemType)) {
const hasToolResults = message.userInputMessageContext?.toolResults
let hasToolResults = false
if (message.userInputMessageContext?.toolResults) {
hasToolResults = message.userInputMessageContext?.toolResults.length > 0
}
return {
...message,
userInputMessageContext: {
Expand Down Expand Up @@ -589,6 +592,13 @@

// Make sure the last stored message is from the assistant (type === 'answer'), else drop
if (messages.length > 0 && messages[messages.length - 1].type === ('prompt' as ChatItemType)) {
// When user aborts some in-progress tooluse event, we should still send the previous toolResult back
if (messages[messages.length - 1].userInputMessageContext?.toolResults) {
if (newUserMessage.userInputMessage?.userInputMessageContext) {
newUserMessage.userInputMessage.userInputMessageContext.toolResults =
messages[messages.length - 1].userInputMessageContext?.toolResults
}
}
messages.pop()
this.#features.logging.debug('Dropped trailing user message')
}
Expand Down Expand Up @@ -686,10 +696,10 @@

getModelId(): string | undefined {
const settings = this.getSettings()
return settings?.modelId
return settings?.modelId === '' ? undefined : settings?.modelId
}

setModelId(modelId: string | undefined): void {
this.updateSettings({ modelId })
this.updateSettings({ modelId: modelId === '' ? undefined : modelId })
}
}
Loading