fix: fatal hard-crash on loop detection via unhandled AbortError (#20108)

Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
This commit is contained in:
hsm207
2026-04-23 18:51:21 +02:00
committed by GitHub
parent dba9b9a0ff
commit ff28d55100
2 changed files with 1 additions and 14 deletions
-4
View File
@@ -1244,9 +1244,6 @@ ${JSON.stringify(
count: 2,
});
const abortSpy = vi.spyOn(AbortController.prototype, 'abort');
// Act
const stream = client.sendMessageStream(
[{ text: 'Hi' }],
new AbortController().signal,
@@ -1267,7 +1264,6 @@ ${JSON.stringify(
// Assert
expect(events).toContainEqual({ type: GeminiEventType.LoopDetected });
expect(abortSpy).toHaveBeenCalled();
expect(finalResult).toBeInstanceOf(Turn);
});
+1 -10
View File
@@ -684,9 +684,6 @@ export class GeminiClient {
// Re-initialize turn with fresh history
turn = new Turn(this.getChat(), prompt_id);
const controller = new AbortController();
const linkedSignal = AbortSignal.any([signal, controller.signal]);
const loopResult = await this.loopDetector.turnStarted(signal);
if (loopResult.count > 1) {
yield { type: GeminiEventType.LoopDetected };
@@ -747,7 +744,7 @@ export class GeminiClient {
const resultStream = turn.run(
modelConfigKey,
request,
linkedSignal,
signal,
displayContent,
);
let isError = false;
@@ -783,7 +780,6 @@ export class GeminiClient {
}
if (loopDetectedAbort) {
controller.abort();
return turn;
}
@@ -795,10 +791,8 @@ export class GeminiClient {
boundedTurns,
isInvalidStreamRetry,
displayContent,
controller,
);
}
if (isError) {
return turn;
}
@@ -1252,10 +1246,7 @@ export class GeminiClient {
boundedTurns: number,
isInvalidStreamRetry: boolean,
displayContent?: PartListUnion,
controllerToAbort?: AbortController,
): AsyncGenerator<ServerGeminiStreamEvent, Turn> {
controllerToAbort?.abort();
// Clear the detection flag so the recursive turn can proceed, but the count remains 1.
this.loopDetector.clearDetection();