Skip to content

Commit 086bd04

Browse files
committed
fix(amazonqFeatureDev): create a new token to stop and iterate in the same session
1 parent 13dcfde commit 086bd04

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export class FeatureDevController {
415415
if (session?.state?.tokenSource?.token.isCancellationRequested) {
416416
session?.state.tokenSource?.dispose()
417417
if (session?.state?.tokenSource) {
418-
session.state.tokenSource = undefined
418+
session.state.tokenSource = new vscode.CancellationTokenSource()
419419
}
420420
getLogger().debug('Request cancelled, skipping further processing')
421421
} else {
@@ -712,7 +712,9 @@ export class FeatureDevController {
712712
})
713713
this.workOnNewTask(message)
714714
const session = await this.sessionStorage.getSession(message.tabID)
715-
session.state?.tokenSource?.cancel()
715+
if (session.state?.tokenSource) {
716+
session.state?.tokenSource?.cancel()
717+
}
716718
}
717719

718720
private async tabOpened(message: any) {

packages/core/src/amazonqFeatureDev/session/session.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { ReferenceLogViewProvider } from '../../codewhisperer/service/referenceL
2626
import { AuthUtil } from '../../codewhisperer/util/authUtil'
2727
import { getLogger } from '../../shared'
2828
import { logWithConversationId } from '../userFacingText'
29-
3029
export class Session {
3130
private _state?: SessionState | Omit<SessionState, 'uploadId'>
3231
private task: string = ''
@@ -136,7 +135,7 @@ export class Session {
136135

137136
if (resp.nextState) {
138137
// Cancel the request before moving to a new state
139-
this.state?.tokenSource?.cancel()
138+
if (!this.state?.tokenSource?.token.isCancellationRequested) this.state?.tokenSource?.cancel()
140139

141140
// Move to the next state
142141
this._state = resp.nextState

packages/core/src/amazonqFeatureDev/session/sessionState.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import { collectFiles, getWorkspaceFoldersByPrefixes } from '../../shared/utilit
3939
import { i18n } from '../../shared/i18n-helper'
4040
import { Messenger } from '../controllers/chat/messenger/messenger'
4141

42+
const EMPTY_CODEGEN_ID = 'EMPTY_CURRENT_CODE_GENERATION_ID'
43+
4244
export class ConversationNotStartedState implements Omit<SessionState, 'uploadId'> {
4345
public tokenSource: vscode.CancellationTokenSource
4446
public readonly phase = DevPhase.INIT
@@ -128,7 +130,7 @@ abstract class CodeGenBase {
128130
this.isCancellationRequested = false
129131
this.conversationId = config.conversationId
130132
this.uploadId = config.uploadId
131-
this.currentCodeGenerationId = config.currentCodeGenerationId
133+
this.currentCodeGenerationId = config.currentCodeGenerationId || EMPTY_CODEGEN_ID
132134
}
133135

134136
async generateCode({
@@ -152,8 +154,7 @@ abstract class CodeGenBase {
152154
}> {
153155
for (
154156
let pollingIteration = 0;
155-
pollingIteration < this.pollCount &&
156-
(!this.isCancellationRequested || !this.tokenSource.token.isCancellationRequested);
157+
pollingIteration < this.pollCount && !this.isCancellationRequested;
157158
++pollingIteration
158159
) {
159160
const codegenResult = await this.config.proxyClient.getCodeGeneration(this.conversationId, codeGenerationId)
@@ -267,8 +268,6 @@ export class CodeGenState extends CodeGenBase implements SessionState {
267268
action.tokenSource?.token.onCancellationRequested(() => {
268269
this.isCancellationRequested = true
269270
if (action.tokenSource) this.tokenSource = action.tokenSource
270-
action.tokenSource?.dispose()
271-
action.tokenSource = undefined
272271
})
273272

274273
action.telemetry.setGenerateCodeIteration(this.currentIteration)
@@ -282,9 +281,6 @@ export class CodeGenState extends CodeGenBase implements SessionState {
282281
this.currentCodeGenerationId
283282
)
284283

285-
this.currentCodeGenerationId = codeGenerationId
286-
this.config.currentCodeGenerationId = codeGenerationId
287-
288284
if (!this.isCancellationRequested) {
289285
action.messenger.sendAnswer({
290286
message: i18n('AWS.amazonq.featureDev.pillText.generatingCode'),
@@ -305,6 +301,11 @@ export class CodeGenState extends CodeGenBase implements SessionState {
305301
workspaceFolders: this.config.workspaceFolders,
306302
})
307303

304+
if (codeGeneration && !this.isCancellationRequested) {
305+
this.config.currentCodeGenerationId = codeGenerationId
306+
this.currentCodeGenerationId = codeGenerationId
307+
}
308+
308309
this.filePaths = codeGeneration.newFiles
309310
this.deletedFiles = codeGeneration.deletedFiles
310311
this.references = codeGeneration.references
@@ -470,7 +471,11 @@ export class PrepareCodeGenState implements SessionState {
470471
span
471472
)
472473
const uploadId = randomUUID()
473-
const { uploadUrl, kmsKeyArn } = await this.config.proxyClient.createUploadUrl(
474+
const {
475+
uploadUrl,
476+
uploadId: returnedUploadId,
477+
kmsKeyArn,
478+
} = await this.config.proxyClient.createUploadUrl(
474479
this.config.conversationId,
475480
zipFileChecksum,
476481
zipFileBuffer.length,

0 commit comments

Comments
 (0)