mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 19:44:30 -07:00
fix: fatal hard-crash on loop detection via unhandled AbortError (#20108)
Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user