Skip to content

Commit 3e378da

Browse files
authored
feat(featureDev): handle iteration limit errors during planning / code generation #4559
Problem We want to handle iteration limit errors for plan generation and code generation for featureDev; currently the user experience is impacted as proper prompts in chat are not surfaced, instead Retry is prompted incorrectly. Solution Added handling of iteration limit errors during both planning phase and code generation phase, to show specific prompts in planning and code generation phase. This will unblock customers in case of limit errors.
1 parent ed5bebd commit 3e378da

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Amazon Q Feature Dev: Fix followups after hitting iteration limit"
4+
}

packages/core/src/amazonqFeatureDev/client/featureDev.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import * as FeatureDevProxyClient from './featuredevproxyclient'
1313
import apiConfig = require('./codewhispererruntime-2022-11-11.json')
1414
import { featureName } from '../constants'
1515
import { CodeReference } from '../../amazonq/webview/ui/connector'
16-
import { ApiError, ContentLengthError, UnknownApiError } from '../errors'
16+
import {
17+
ApiError,
18+
CodeIterationLimitError,
19+
ContentLengthError,
20+
PlanIterationLimitError,
21+
UnknownApiError,
22+
} from '../errors'
1723
import { ToolkitError, isAwsError, isCodeWhispererStreamingServiceException } from '../../shared/errors'
1824
import { getCodewhispererConfig } from '../../codewhisperer/client/codewhisperer'
1925
import { LLMResponseType } from '../types'
@@ -168,6 +174,13 @@ export class FeatureDevClient {
168174
e.$metadata.requestId ?? 'unknown'
169175
}`
170176
)
177+
if (
178+
(e.name === 'ThrottlingException' &&
179+
e.message.includes('limit for number of iterations on an implementation plan')) ||
180+
e.name === 'ServiceQuotaExceededException'
181+
) {
182+
throw new PlanIterationLimitError()
183+
}
171184
throw new ApiError(
172185
e.message,
173186
'GeneratePlan',
@@ -206,6 +219,14 @@ export class FeatureDevClient {
206219
(e as any).requestId
207220
}`
208221
)
222+
if (
223+
isAwsError(e) &&
224+
((e.code === 'ThrottlingException' &&
225+
e.message.includes('limit for number of iterations on a code generation')) ||
226+
e.code === 'ServiceQuotaExceededException')
227+
) {
228+
throw new CodeIterationLimitError()
229+
}
209230
throw new ToolkitError((e as Error).message, { code: 'StartCodeGenerationFailed' })
210231
}
211232
}

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ import { EventEmitter } from 'vscode'
1111
import { telemetry } from '../../../shared/telemetry/telemetry'
1212
import { createSingleFileDialog } from '../../../shared/ui/common/openDialog'
1313
import { featureDevScheme } from '../../constants'
14-
import { ContentLengthError, SelectedFolderNotInWorkspaceFolderError, createUserFacingErrorMessage } from '../../errors'
14+
import {
15+
CodeIterationLimitError,
16+
ContentLengthError,
17+
PlanIterationLimitError,
18+
SelectedFolderNotInWorkspaceFolderError,
19+
createUserFacingErrorMessage,
20+
} from '../../errors'
1521
import { defaultRetryLimit } from '../../limits'
1622
import { Session } from '../../session/session'
1723
import { featureName } from '../../constants'
@@ -236,6 +242,38 @@ export class FeatureDevController {
236242
},
237243
],
238244
})
245+
} else if (err instanceof PlanIterationLimitError) {
246+
this.messenger.sendErrorMessage(err.message, message.tabID, this.retriesRemaining(session))
247+
this.messenger.sendAnswer({
248+
type: 'system-prompt',
249+
tabID: message.tabID,
250+
followUps: [
251+
{
252+
pillText: 'Discuss a new plan',
253+
type: FollowUpTypes.NewTask,
254+
status: 'info',
255+
},
256+
{
257+
pillText: 'Generate code',
258+
type: FollowUpTypes.GenerateCode,
259+
status: 'info',
260+
},
261+
],
262+
})
263+
} else if (err instanceof CodeIterationLimitError) {
264+
this.messenger.sendErrorMessage(err.message, message.tabID, this.retriesRemaining(session))
265+
this.messenger.sendAnswer({
266+
type: 'system-prompt',
267+
tabID: message.tabID,
268+
followUps: [
269+
{
270+
pillText: 'Insert code',
271+
type: FollowUpTypes.InsertCode,
272+
icon: 'ok' as MynahIcons,
273+
status: 'success',
274+
},
275+
],
276+
})
239277
} else {
240278
const errorMessage = createUserFacingErrorMessage(
241279
`${featureName} request failed: ${err.cause?.message ?? err.message}`

packages/core/src/amazonqFeatureDev/errors.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ export class ContentLengthError extends ToolkitError {
7676
}
7777
}
7878

79+
export class PlanIterationLimitError extends ToolkitError {
80+
constructor() {
81+
super(
82+
'You have reached the free tier limit for number of iterations on an implementation plan. Please proceed to generating code or start to discuss a new plan.',
83+
{ code: 'PlanIterationLimitError' }
84+
)
85+
}
86+
}
87+
88+
export class CodeIterationLimitError extends ToolkitError {
89+
constructor() {
90+
super(
91+
'You have reached the free tier limit for number of iterations on a code generation. Please proceed to accept the code or start a new conversation.',
92+
{ code: 'CodeIterationLimitError' }
93+
)
94+
}
95+
}
96+
7997
export class UnknownApiError extends ToolkitError {
8098
constructor(message: string, api: string) {
8199
super(message, { code: `${api}-Unknown` })

0 commit comments

Comments
 (0)