Skip to content

Commit 6b12b54

Browse files
authored
fix: handle requestAborted errors silently (#1394)
1 parent 2e542ae commit 6b12b54

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {
5757
AmazonQServicePendingSigninError,
5858
} from '../../shared/amazonQServiceManager/errors'
5959
import { AgenticChatResultStream } from './agenticChatResultStream'
60+
import { AgenticChatError } from './errors'
6061

6162
describe('AgenticChatController', () => {
6263
const mockTabId = 'tab-1'
@@ -2224,10 +2225,12 @@ ${' '.repeat(8)}}
22242225
const cancellationError = new CancellationError('user')
22252226
const rejectionError = new ToolApprovalException()
22262227
const tokenSource = new CancellationTokenSource()
2228+
const requestAbortedError = new AgenticChatError('Request aborted', 'RequestAborted')
22272229

22282230
assert.ok(!chatController.isUserAction(nonUserAction))
22292231
assert.ok(chatController.isUserAction(cancellationError))
22302232
assert.ok(chatController.isUserAction(rejectionError))
2233+
assert.ok(chatController.isUserAction(requestAbortedError))
22312234

22322235
assert.ok(!chatController.isUserAction(nonUserAction, tokenSource.token))
22332236

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ import {
121121
responseTimeoutPartialMsg,
122122
} from './constants'
123123
import { URI } from 'vscode-uri'
124-
import { AgenticChatError, customerFacingErrorCodes, unactionableErrorCodes } from './errors'
124+
import { AgenticChatError, customerFacingErrorCodes, isRequestAbortedError, unactionableErrorCodes } from './errors'
125125
import { CommandCategory } from './tools/executeBash'
126126
import { UserWrittenCodeTracker } from '../../shared/userWrittenCodeTracker'
127127

@@ -1261,6 +1261,7 @@ export class AgenticChatController implements ChatHandlers {
12611261
return (
12621262
CancellationError.isUserCancelled(err) ||
12631263
err instanceof ToolApprovalException ||
1264+
isRequestAbortedError(err) ||
12641265
(token?.isCancellationRequested ?? false)
12651266
)
12661267
}

server/aws-lsp-codewhisperer/src/language-server/agenticChat/errors.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type AgenticChatErrorCode =
77
| 'InputTooLong' // too much context given to backend service.
88
| 'PromptCharacterLimit' // customer prompt exceeds
99
| 'ResponseProcessingTimeout' // response didn't finish streaming in the allowed time
10+
| 'RequestAborted' // request was aborted by the user
1011

1112
export const customerFacingErrorCodes: AgenticChatErrorCode[] = [
1213
'QModelResponse',
@@ -52,3 +53,16 @@ export function isInputTooLongError(error: unknown): boolean {
5253

5354
return false
5455
}
56+
57+
export function isRequestAbortedError(error: unknown): boolean {
58+
if (error instanceof AgenticChatError && error.code === 'RequestAborted') {
59+
return true
60+
}
61+
62+
if (error instanceof Error) {
63+
// This is fragile (breaks if the backend changes their error message wording)
64+
return error.message.includes('Request aborted')
65+
}
66+
67+
return false
68+
}

server/aws-lsp-codewhisperer/src/language-server/chat/chatSessionService.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
SendMessageCommandOutput,
1212
} from '../../shared/streamingClientService'
1313
import { ChatResult } from '@aws/language-server-runtimes/server-interface'
14-
import { AgenticChatError, isInputTooLongError, wrapErrorWithCode } from '../agenticChat/errors'
14+
import { AgenticChatError, isInputTooLongError, isRequestAbortedError, wrapErrorWithCode } from '../agenticChat/errors'
1515
import { AmazonQBaseServiceManager } from '../../shared/amazonQServiceManager/BaseAmazonQServiceManager'
1616

1717
export type ChatSessionServiceConfig = CodeWhispererStreamingClientConfig
@@ -151,11 +151,19 @@ export class ChatSessionService {
151151
try {
152152
return await client.generateAssistantResponse(request, this.#abortController)
153153
} catch (e) {
154+
if (isRequestAbortedError(e)) {
155+
const requestId =
156+
e instanceof CodeWhispererStreamingServiceException ? e.$metadata?.requestId : undefined
157+
throw new AgenticChatError(
158+
'Request aborted',
159+
'RequestAborted',
160+
e instanceof Error ? e : undefined,
161+
requestId
162+
)
163+
}
154164
if (isInputTooLongError(e)) {
155-
let requestId
156-
if (e instanceof CodeWhispererStreamingServiceException) {
157-
requestId = e.$metadata?.requestId
158-
}
165+
const requestId =
166+
e instanceof CodeWhispererStreamingServiceException ? e.$metadata?.requestId : undefined
159167
throw new AgenticChatError(
160168
'Too much context loaded. I have cleared the conversation history. Please retry your request with smaller input.',
161169
'InputTooLong',

0 commit comments

Comments
 (0)