Skip to content

Commit 6cb4dcb

Browse files
committed
fix(amazonq): Don't delete history on exception; Don't include history for requests to Mynah
1 parent 16aa876 commit 6cb4dcb

File tree

2 files changed

+6
-34
lines changed

2 files changed

+6
-34
lines changed

packages/core/src/codewhispererChat/controllers/chat/controller.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,9 +1120,6 @@ export class ChatController {
11201120

11211121
this.messenger.sendErrorMessage(errorMessage, tabID, requestID, statusCode)
11221122
getLogger().error(`error: ${errorMessage} tabID: ${tabID} requestID: ${requestID}`)
1123-
1124-
this.sessionStorage.deleteSession(tabID)
1125-
this.chatHistoryDb.clearTab(tabID)
11261123
}
11271124

11281125
private async processContextMenuCommand(command: EditorContextCommand) {
@@ -1299,6 +1296,7 @@ export class ChatController {
12991296
this.processException(e, message.tabID)
13001297
}
13011298
}
1299+
13021300
private sessionCleanUp(session: ChatSession) {
13031301
// Create a fresh token for this new conversation
13041302
session.createNewTokenSource()
@@ -1581,9 +1579,10 @@ export class ChatController {
15811579
if (currentMessage) {
15821580
this.chatHistoryDb.fixHistory(tabID, currentMessage)
15831581
}
1584-
request.conversationState.history = this.chatHistoryDb
1585-
.getMessages(tabID)
1586-
.map((chat) => messageToChatMessage(chat))
1582+
// Do not include chatHistory for requests going to Mynah
1583+
request.conversationState.history = request.conversationState.currentMessage?.userInputMessage?.userIntent
1584+
? []
1585+
: this.chatHistoryDb.getMessages(tabID).map((chat) => messageToChatMessage(chat))
15871586
request.conversationState.conversationId = session.sessionIdentifier
15881587

15891588
triggerPayload.documentReferences = this.mergeRelevantTextDocuments(triggerPayload.relevantTextDocuments)

packages/core/src/shared/db/chatDb/chatDb.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,34 +170,6 @@ export class Database {
170170
}
171171
}
172172

173-
// Removes the most recent message(s) from the chat history for a given tab
174-
clearRecentHistory(tabId: string): void {
175-
if (this.initialized) {
176-
const historyId = this.historyIdMapping.get(tabId)
177-
this.logger.info(`Clearing recent history: tabId=${tabId}, historyId=${historyId || 'undefined'}`)
178-
if (historyId) {
179-
const tabCollection = this.db.getCollection<Tab>(TabCollection)
180-
const tabData = tabCollection.findOne({ historyId })
181-
if (tabData) {
182-
const activeConversation = tabData.conversations[0]
183-
const allMessages = this.getMessages(tabId)
184-
const lastMessage = allMessages[allMessages.length - 1]
185-
this.logger.debug(`Last message type: ${lastMessage.type}`)
186-
187-
if (lastMessage.type === ('prompt' as ChatItemType)) {
188-
allMessages.pop()
189-
this.logger.info(`Removed last user message`)
190-
} else {
191-
allMessages.splice(-2)
192-
this.logger.info(`Removed last assistant message and user message`)
193-
}
194-
activeConversation.messages = allMessages
195-
tabCollection.update(tabData)
196-
}
197-
}
198-
}
199-
}
200-
201173
updateTabOpenState(tabId: string, isOpen: boolean) {
202174
if (this.initialized) {
203175
const tabCollection = this.db.getCollection<Tab>(TabCollection)
@@ -388,6 +360,7 @@ export class Database {
388360
this.handleToolUses(allMessages, newUserMessage)
389361

390362
activeConversation.messages = allMessages
363+
tabData.updatedAt = new Date()
391364
tabCollection.update(tabData)
392365
this.logger.info(`Updated tab data in collection`)
393366
}

0 commit comments

Comments
 (0)