Skip to content

Commit

Permalink
fix(amazonqFeatureDev): require isCancellation to localize in the ins…
Browse files Browse the repository at this point in the history
…tance and abort the individual call
  • Loading branch information
tverney committed Sep 26, 2024
1 parent 132d260 commit 0588d8e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/core/src/amazonqFeatureDev/session/sessionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ abstract class CodeGenBase {
public readonly conversationId: string
public readonly uploadId: string
public currentCodeGenerationId?: string
public isCancellationRequested?: boolean

constructor(
protected config: SessionStateConfig,
Expand All @@ -137,14 +138,12 @@ abstract class CodeGenBase {
codeGenerationId,
telemetry: telemetry,
workspaceFolders,
isCancellationRequested,
}: {
messenger: Messenger
fs: VirtualFileSystem
codeGenerationId: string
telemetry: TelemetryHelper
workspaceFolders: CurrentWsFolders
isCancellationRequested?: boolean
}): Promise<{
newFiles: NewFileInfo[]
deletedFiles: DeletedFileInfo[]
Expand All @@ -154,7 +153,7 @@ abstract class CodeGenBase {
}> {
for (
let pollingIteration = 0;
pollingIteration < this.pollCount && !isCancellationRequested;
pollingIteration < this.pollCount && !this.isCancellationRequested;
++pollingIteration
) {
const codegenResult = await this.config.proxyClient.getCodeGeneration(this.conversationId, codeGenerationId)
Expand Down Expand Up @@ -230,7 +229,7 @@ abstract class CodeGenBase {
}
}
}
if (!isCancellationRequested) {
if (!this.isCancellationRequested) {
// still in progress
const errorMessage = i18n('AWS.amazonq.featureDev.error.codeGen.timeout')
throw new ToolkitError(errorMessage, { code: 'CodeGenTimeout' })
Expand Down Expand Up @@ -260,6 +259,12 @@ export class CodeGenState extends CodeGenBase implements SessionState {
async interact(action: SessionStateAction): Promise<SessionStateInteraction> {
return telemetry.amazonq_codeGenerationInvoke.run(async (span) => {
try {
action.tokenSource?.token.onCancellationRequested(() => {
this.isCancellationRequested = true
if (action.tokenSource) {
this.tokenSource = action.tokenSource
}
})
span.record({
amazonqConversationId: this.config.conversationId,
credentialStartUrl: AuthUtil.instance.startUrl,
Expand All @@ -276,7 +281,7 @@ export class CodeGenState extends CodeGenBase implements SessionState {
this.currentCodeGenerationId
)

if (!action.tokenSource?.token.isCancellationRequested) {
if (!this.isCancellationRequested) {
action.messenger.sendAnswer({
message: i18n('AWS.amazonq.featureDev.pillText.generatingCode'),
type: 'answer-part',
Expand All @@ -294,7 +299,6 @@ export class CodeGenState extends CodeGenBase implements SessionState {
codeGenerationId,
telemetry: action.telemetry,
workspaceFolders: this.config.workspaceFolders,
isCancellationRequested: action.tokenSource?.token.isCancellationRequested,
})

if (codeGeneration && !action.tokenSource?.token.isCancellationRequested) {
Expand Down

0 comments on commit 0588d8e

Please sign in to comment.