Skip to content

fix(amazonq): fix UTDE suggestion state for pagination cases #1433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ const getFileContext = (params: {
}
}

const emitServiceInvocationTelemetry = (telemetry: Telemetry, session: CodeWhispererSession) => {
const emitServiceInvocationTelemetry = (telemetry: Telemetry, session: CodeWhispererSession, requestId: string) => {
const duration = new Date().getTime() - session.startTime
const data: CodeWhispererServiceInvocationEvent = {
codewhispererRequestId: session.responseContext?.requestId,
codewhispererRequestId: requestId,
codewhispererSessionId: session.responseContext?.codewhispererSessionId,
codewhispererLastSuggestionIndex: session.suggestions.length - 1,
codewhispererCompletionType:
Expand Down Expand Up @@ -490,21 +490,11 @@ export const CodewhispererServerFactory =
}

// Emit service invocation telemetry for every request sent to backend
emitServiceInvocationTelemetry(telemetry, session)
emitServiceInvocationTelemetry(telemetry, session, suggestionResponse.responseContext.requestId)

// Exit early and discard API response
// session was closed by consequent completion request before API response was received
// and session never become ACTIVE.
// Emit Discard trigger decision here, because we will have session and requist IDs only at this point.
// session was closed by user already made decisions consequent completion request before new paginated API response was received
if (session.state === 'CLOSED' || session.state === 'DISCARD') {
// Force Discard user decision on every received suggestion
session.suggestions.forEach(s => session.setSuggestionState(s.itemId, 'Discard'))
await emitUserTriggerDecisionTelemetry(
telemetry,
telemetryService,
session,
timeSinceLastUserModification
)
return EMPTY_RESULT
}

Expand Down Expand Up @@ -563,6 +553,9 @@ export const CodewhispererServerFactory =
if (cachedSuggestion) cachedSuggestion.insertText = suggestion.insertText.toString()
})

// TODO: need dedupe after right context merging but I don't see one
session.suggestionsAfterRightContextMerge.push(...suggestionsWithRightContext)

session.codewhispererSuggestionImportCount =
session.codewhispererSuggestionImportCount +
suggestionsWithRightContext.reduce((total, suggestion) => {
Expand All @@ -571,7 +564,10 @@ export const CodewhispererServerFactory =

// If after all server-side filtering no suggestions can be displayed, and there is no nextToken
// close session and return empty results
if (suggestionsWithRightContext.length === 0 && !suggestionResponse.responseContext.nextToken) {
if (
session.suggestionsAfterRightContextMerge.length === 0 &&
!suggestionResponse.responseContext.nextToken
) {
sessionManager.closeSession(session)
await emitUserTriggerDecisionTelemetry(
telemetry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class CodeWhispererSession {
character: 0,
}
suggestions: CachedSuggestion[] = []
suggestionsAfterRightContextMerge: InlineCompletionItemWithReferences[] = []
suggestionsStates = new Map<string, UserDecision>()
acceptedSuggestionId?: string = undefined
responseContext?: ResponseContext
Expand Down
Loading