Skip to content

Commit 644dedd

Browse files
committed
fix(amazonqFeatureDev): include currentCodeGenerationId to track reference for stop code generation
1 parent 709c0c5 commit 644dedd

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,8 @@ export class FeatureDevController {
349349
await session.send(message)
350350
const filePaths = session.state.filePaths ?? []
351351
const deletedFiles = session.state.deletedFiles ?? []
352-
353352
// Only add the follow up accept/deny buttons when the tab hasn't been closed/request hasn't been cancelled
354353
if (session?.state?.tokenSource?.token.isCancellationRequested) {
355-
session?.state.tokenSource?.dispose()
356-
if (session?.state?.tokenSource) {
357-
session.state.tokenSource = undefined
358-
}
359354
return
360355
}
361356

@@ -416,6 +411,14 @@ export class FeatureDevController {
416411
this.messenger.sendUpdatePlaceholder(tabID, i18n('AWS.amazonq.featureDev.pillText.selectOption'))
417412
} finally {
418413
// Finish processing the event
414+
415+
if (session?.state?.tokenSource?.token.isCancellationRequested) {
416+
session?.state.tokenSource?.dispose()
417+
if (session?.state?.tokenSource) {
418+
session.state.tokenSource = undefined
419+
}
420+
return
421+
}
419422
this.messenger.sendAsyncEventProgress(tabID, false, undefined)
420423

421424
// Lock the chat input until they explicitly click one of the follow ups

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export class Session {
8989
...this.getSessionStateConfig(),
9090
conversationId: this.conversationId,
9191
uploadId: '',
92+
currentCodeGenerationId: undefined,
9293
},
9394
[],
9495
[],
@@ -109,7 +110,6 @@ export class Session {
109110
workspaceFolders: this.config.workspaceFolders,
110111
proxyClient: this.proxyClient,
111112
conversationId: this.conversationId,
112-
currentCodeGenerationId: this.currentCodeGenerationId as string,
113113
}
114114
}
115115

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ abstract class CodeGenBase {
126126
public phase: SessionStatePhase = DevPhase.CODEGEN
127127
public readonly conversationId: string
128128
public readonly uploadId: string
129-
public readonly currentCodeGenerationId?: string
129+
public currentCodeGenerationId?: string
130130

131131
constructor(
132132
protected config: SessionStateConfig,
@@ -274,6 +274,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
274274

275275
action.tokenSource?.token.onCancellationRequested(() => {
276276
this.isCancellationRequested = true
277+
if (action.tokenSource) this.tokenSource = action.tokenSource
277278
action.tokenSource?.dispose()
278279
action.tokenSource = undefined
279280
})
@@ -285,9 +286,12 @@ export class CodeGenState extends CodeGenBase implements SessionState {
285286
this.config.conversationId,
286287
this.config.uploadId,
287288
action.msg,
288-
this.config.currentCodeGenerationId
289+
this.currentCodeGenerationId
289290
)
290291

292+
this.currentCodeGenerationId = codeGenerationId
293+
this.config.currentCodeGenerationId = codeGenerationId
294+
291295
if (!this.isCancellationRequested) {
292296
action.messenger.sendAnswer({
293297
message: i18n('AWS.amazonq.featureDev.pillText.generatingCode'),
@@ -325,7 +329,8 @@ export class CodeGenState extends CodeGenBase implements SessionState {
325329
this.currentIteration + 1,
326330
this.codeGenerationRemainingIterationCount,
327331
this.codeGenerationTotalIterationCount,
328-
this.tokenSource
332+
this.tokenSource,
333+
this.currentCodeGenerationId
329334
)
330335
return {
331336
nextState,
@@ -428,7 +433,6 @@ export class MockCodeGenState implements SessionState {
428433
export class PrepareCodeGenState implements SessionState {
429434
public readonly phase = DevPhase.CODEGEN
430435
public uploadId: string
431-
public currentCodeGenerationId?: string
432436
public conversationId: string
433437
public tokenSource: vscode.CancellationTokenSource
434438
constructor(
@@ -440,11 +444,12 @@ export class PrepareCodeGenState implements SessionState {
440444
private currentIteration: number,
441445
public codeGenerationRemainingIterationCount?: number,
442446
public codeGenerationTotalIterationCount?: number,
443-
public superTokenSource?: vscode.CancellationTokenSource
447+
public superTokenSource?: vscode.CancellationTokenSource,
448+
public currentCodeGenerationId?: string
444449
) {
445450
this.tokenSource = superTokenSource || new vscode.CancellationTokenSource()
446451
this.uploadId = config.uploadId
447-
this.currentCodeGenerationId = config.currentCodeGenerationId
452+
this.currentCodeGenerationId = currentCodeGenerationId
448453
this.conversationId = config.conversationId
449454
}
450455

@@ -496,7 +501,7 @@ export class PrepareCodeGenState implements SessionState {
496501
this.uploadId = uploadId
497502
}
498503
const nextState = new CodeGenState(
499-
{ ...this.config, uploadId: this.uploadId, currentCodeGenerationId: this.config.currentCodeGenerationId },
504+
{ ...this.config, uploadId: this.uploadId, currentCodeGenerationId: this.currentCodeGenerationId },
500505
this.filePaths,
501506
this.deletedFiles,
502507
this.references,

packages/core/src/amazonqFeatureDev/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export type Interaction = {
2121
export interface SessionStateInteraction {
2222
nextState: SessionState | Omit<SessionState, 'uploadId'> | undefined
2323
interaction: Interaction
24+
currentCodeGenerationId?: string
2425
}
2526

2627
export enum DevPhase {
@@ -60,7 +61,7 @@ export interface SessionState {
6061
readonly references?: CodeReference[]
6162
readonly phase?: SessionStatePhase
6263
readonly uploadId: string
63-
readonly currentCodeGenerationId?: string
64+
currentCodeGenerationId?: string
6465
tokenSource?: CancellationTokenSource
6566
readonly tabID: string
6667
interact(action: SessionStateAction): Promise<SessionStateInteraction>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const mockSessionStateAction = (msg?: string): SessionStateAction => {
3030
}
3131
}
3232

33-
let mockGeneratePlan: sinon.SinonStub
3433
let mockGetCodeGeneration: sinon.SinonStub
3534
let mockExportResultArchive: sinon.SinonStub
3635
let mockCreateUploadUrl: sinon.SinonStub
@@ -49,7 +48,6 @@ const mockSessionStateConfig = ({
4948
proxyClient: {
5049
createConversation: () => sinon.stub(),
5150
createUploadUrl: () => mockCreateUploadUrl(),
52-
generatePlan: () => mockGeneratePlan(),
5351
startCodeGeneration: () => sinon.stub(),
5452
getCodeGeneration: () => mockGetCodeGeneration(),
5553
exportResultArchive: () => mockExportResultArchive(),

0 commit comments

Comments
 (0)