Skip to content

Commit 1a783fe

Browse files
authored
fix(codewhisperer): only send one empty user decision per pagination session (#2921)
1 parent 481f71c commit 1a783fe

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/codewhisperer/service/recommendationHandler.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ export class RecommendationHandler {
282282
})
283283
this.recommendations = isCloud9() ? recommendation : this.recommendations.concat(recommendation)
284284
this._onDidReceiveRecommendation.fire()
285-
} else {
285+
}
286+
// send Empty userDecision event if user receives no recommendations in this session at all.
287+
if (this.recommendations.length === 0 && nextToken === '') {
286288
TelemetryHelper.instance.recordUserDecisionTelemetryForEmptyList(
287289
requestId,
288290
sessionId,

src/test/codewhisperer/service/recommendationHandler.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,39 @@ describe('recommendationHandler', function () {
130130
codewhispererLanguage: 'python',
131131
})
132132
})
133+
134+
it('should call telemetry function that records a Empty userDecision event', async function () {
135+
const mockServerResult = {
136+
recommendations: [],
137+
nextToken: '',
138+
$response: {
139+
requestId: 'test_request_empty',
140+
httpResponse: {
141+
headers: {
142+
'x-amzn-sessionid': 'test_request_empty',
143+
},
144+
},
145+
},
146+
}
147+
const handler = new RecommendationHandler()
148+
sinon.stub(handler, 'getServerResponse').resolves(mockServerResult)
149+
sinon.stub(performance, 'now').returns(0.0)
150+
handler.startPos = new vscode.Position(1, 0)
151+
TelemetryHelper.instance.cursorOffset = 2
152+
await handler.getRecommendations(mockClient, mockEditor, 'AutoTrigger', config, 'Enter')
153+
const assertTelemetry = assertTelemetryCurried('codewhisperer_userDecision')
154+
assertTelemetry({
155+
codewhispererRequestId: 'test_request_empty',
156+
codewhispererSessionId: 'test_request_empty',
157+
codewhispererPaginationProgress: 0,
158+
codewhispererTriggerType: 'AutoTrigger',
159+
codewhispererSuggestionIndex: -1,
160+
codewhispererSuggestionState: 'Empty',
161+
codewhispererSuggestionReferenceCount: 0,
162+
codewhispererCompletionType: 'Line',
163+
codewhispererLanguage: 'python',
164+
})
165+
})
133166
})
134167

135168
describe('isValidResponse', function () {

0 commit comments

Comments
 (0)