Skip to content

Commit 1d3d4e1

Browse files
Samiya CaurDevtools-frontend LUCI CQ
authored andcommitted
[AiAssistance] Abort ongoing conversation on navigation to old chat
Earlier, the mutex was blocking completion of ongoing conversation step before navigating to the old chat. Bug: 396609285 Change-Id: I0669cef72bacedca32886a33f0ddccc4b348c401 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6304521 Commit-Queue: Samiya Caur <[email protected]> Reviewed-by: Ergün Erdoğmuş <[email protected]>
1 parent beff1b5 commit 1d3d4e1

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

front_end/core/host/AidaClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export class AidaClient {
326326
let {promise, resolve, reject} = Promise.withResolvers<string|null>();
327327
options?.signal?.addEventListener('abort', () => {
328328
reject(new AidaAbortError());
329-
});
329+
}, {once: true});
330330
return {
331331
write: async(data: string): Promise<void> => {
332332
resolve(data);

front_end/panels/ai_assistance/AiAssistancePanel.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
11311131
if (this.#currentConversation === conversation) {
11321132
return;
11331133
}
1134+
this.#cancel();
11341135
this.#currentConversation = conversation;
11351136
this.#messages = [];
11361137
await this.#doConversation(conversation.history);
@@ -1170,6 +1171,7 @@ export class AiAssistancePanel extends UI.Panel.Panel {
11701171
#runAbortController = new AbortController();
11711172
#cancel(): void {
11721173
this.#runAbortController.abort();
1174+
this.#runAbortController = new AbortController();
11731175
this.#isLoading = false;
11741176
this.requestUpdate();
11751177
}
@@ -1221,7 +1223,6 @@ export class AiAssistancePanel extends UI.Panel.Panel {
12211223
}
12221224
// Cancel any previous in-flight conversation.
12231225
this.#cancel();
1224-
this.#runAbortController = new AbortController();
12251226
const signal = this.#runAbortController.signal;
12261227
const context = this.#getConversationContext();
12271228
// If a different context is provided, it must be from the same origin.
@@ -1277,10 +1278,11 @@ export class AiAssistancePanel extends UI.Panel.Panel {
12771278
async *
12781279
#saveResponsesToCurrentConversation(items: AsyncIterable<ResponseData, void, void>):
12791280
AsyncGenerator<ResponseData, void, void> {
1281+
const currentConversation = this.#currentConversation;
12801282
for await (const data of items) {
12811283
// We don't want to save partial responses to the conversation history.
12821284
if (data.type !== ResponseType.ANSWER || data.complete) {
1283-
this.#currentConversation?.addHistoryItem(data);
1285+
currentConversation?.addHistoryItem(data);
12841286
}
12851287
yield data;
12861288
}

test/e2e/ai_assistance/ai_assistance_test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,13 @@ describe('AI Assistance', function() {
244244
return await submitAndWaitTillDone(waitForSideEffect);
245245
}
246246

247+
async function openConversationFromHistory(historyEntrySelector: string) {
248+
const {frontend} = getBrowserAndPages();
249+
await frontend.bringToFront();
250+
await frontend.locator('aria/History').click();
251+
await frontend.locator(historyEntrySelector).click();
252+
}
253+
247254
it('gets data about elements', async () => {
248255
const result = await runAiAssistance({
249256
query: 'Change the background color for this element to blue',
@@ -506,6 +513,43 @@ STOP`,
506513
});
507514
});
508515

516+
it('aborts ongoing conversation when previous chat is opened from history', async () => {
517+
await runAiAssistance({
518+
query: 'Change the background color for this element to blue',
519+
messages: [
520+
`THOUGHT: I can change the background color of an element by setting the background-color CSS property.
521+
TITLE: changing the property
522+
ACTION
523+
await setElementStyles($0, { 'background-color': 'blue' });
524+
STOP`,
525+
'ANSWER: changed styles',
526+
],
527+
node: 'div',
528+
});
529+
530+
const {frontend} = getBrowserAndPages();
531+
await frontend.bringToFront();
532+
await frontend.locator('aria/New chat').click();
533+
534+
await sendAiAssistanceMessage({
535+
query: 'Change the background color for this element to green',
536+
messages: [
537+
`THOUGHT: I can change the background color of an element by setting the background-color CSS property.
538+
TITLE: changing the property
539+
ACTION
540+
await setElementStyles($0, { 'background-color': 'green' });
541+
STOP`,
542+
],
543+
node: 'div',
544+
waitForSideEffect: true,
545+
});
546+
547+
await openConversationFromHistory('aria/Change the background color for this element to blue, unchecked');
548+
await openConversationFromHistory('aria/Change the background color for this element to green, unchecked');
549+
550+
frontend.waitForSelector('aria/Canceled');
551+
});
552+
509553
it('modifies styles to a selector with high specificity', async () => {
510554
await runAiAssistance({
511555
query: 'Change the color for this element to rebeccapurple',

0 commit comments

Comments
 (0)