Skip to content

Commit 69516f4

Browse files
authored
fix(amazonq): early stop pagination requests when user decision is made (#7759)
## Problem When a paginated response is in flight, but the user already accepted or rejected a completion, the subsequent paginated requests should be cancelled. This PR also fixes the `codewhispererTotalShownTime` being negative issue by using performance.now() across all timestamp computation. ## Solution This is not a user facing change. --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 7f36a2d commit 69516f4

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

packages/amazonq/src/app/inline/completion.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ export class InlineCompletionManager implements Disposable {
164164
const onInlineRejection = async () => {
165165
try {
166166
vsCodeState.isCodeWhispererEditing = true
167+
if (this.sessionManager.getActiveSession() === undefined) {
168+
return
169+
}
170+
const requestStartTime = this.sessionManager.getActiveSession()!.requestStartTime
171+
const totalSessionDisplayTime = performance.now() - requestStartTime
167172
await commands.executeCommand('editor.action.inlineSuggest.hide')
168173
// TODO: also log the seen state for other suggestions in session
169174
this.disposable.dispose()
@@ -185,6 +190,7 @@ export class InlineCompletionManager implements Disposable {
185190
discarded: false,
186191
},
187192
},
193+
totalSessionDisplayTime: totalSessionDisplayTime,
188194
}
189195
this.languageClient.sendNotification(this.logSessionResultMessageName, params)
190196
// clear session manager states once rejected
@@ -314,6 +320,7 @@ export class AmazonQInlineCompletionItemProvider implements InlineCompletionItem
314320
discarded: false,
315321
},
316322
},
323+
totalSessionDisplayTime: performance.now() - prevSession.requestStartTime,
317324
}
318325
this.languageClient.sendNotification(this.logSessionResultMessageName, params)
319326
this.sessionManager.clear()

packages/amazonq/src/app/inline/recommendationService.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import {
1212
import { CancellationToken, InlineCompletionContext, Position, TextDocument } from 'vscode'
1313
import { LanguageClient } from 'vscode-languageclient'
1414
import { SessionManager } from './sessionManager'
15-
import { AuthUtil, CodeWhispererStatusBarManager } from 'aws-core-vscode/codewhisperer'
15+
import { AuthUtil, CodeWhispererStatusBarManager, vsCodeState } from 'aws-core-vscode/codewhisperer'
1616
import { TelemetryHelper } from './telemetryHelper'
1717
import { ICursorUpdateRecorder } from './cursorUpdateManager'
18-
import { globals, getLogger } from 'aws-core-vscode/shared'
18+
import { getLogger } from 'aws-core-vscode/shared'
1919

2020
export interface GetAllRecommendationsOptions {
2121
emitTelemetry?: boolean
@@ -68,7 +68,7 @@ export class RecommendationService {
6868
if (options.editsStreakToken) {
6969
request = { ...request, partialResultToken: options.editsStreakToken }
7070
}
71-
const requestStartTime = globals.clock.Date.now()
71+
const requestStartTime = performance.now()
7272
const statusBar = CodeWhispererStatusBarManager.instance
7373

7474
// Only track telemetry if enabled
@@ -119,7 +119,7 @@ export class RecommendationService {
119119
}
120120
TelemetryHelper.instance.setFirstSuggestionShowTime()
121121

122-
const firstCompletionDisplayLatency = globals.clock.Date.now() - requestStartTime
122+
const firstCompletionDisplayLatency = performance.now() - requestStartTime
123123
this.sessionManager.startSession(
124124
result.sessionId,
125125
result.items,
@@ -186,6 +186,11 @@ export class RecommendationService {
186186
request,
187187
token
188188
)
189+
// when pagination is in progress, but user has already accepted or rejected an inline completion
190+
// then stop pagination
191+
if (this.sessionManager.getActiveSession() === undefined || vsCodeState.isCodeWhispererEditing) {
192+
break
193+
}
189194
this.sessionManager.updateSessionSuggestions(result.items)
190195
nextToken = result.partialResultToken
191196
}

0 commit comments

Comments
 (0)