fix(core): prevent ModelInfo event emission on aborted signal (#16752)

This commit is contained in:
Sehoon Shon
2026-01-15 12:26:54 -05:00
committed by GitHub
parent f7f38e2b9e
commit 6740886e22
2 changed files with 31 additions and 2 deletions

View File

@@ -679,6 +679,34 @@ describe('Gemini Client (client.ts)', () => {
});
});
it('does not emit ModelInfo event if signal is aborted', async () => {
// Arrange
mockTurnRunFn.mockReturnValue(
(async function* () {
yield { type: 'content', value: 'Hello' };
})(),
);
const controller = new AbortController();
controller.abort();
// Act
const stream = client.sendMessageStream(
[{ text: 'Hi' }],
controller.signal,
'prompt-id-1',
);
const events = await fromAsync(stream);
// Assert
expect(events).not.toContainEqual(
expect.objectContaining({
type: GeminiEventType.ModelInfo,
}),
);
});
it.each([
{
compressionStatus:

View File

@@ -627,8 +627,9 @@ export class GeminiClient {
modelToUse = finalModel;
this.currentSequenceModel = modelToUse;
yield { type: GeminiEventType.ModelInfo, value: modelToUse };
if (!signal.aborted) {
yield { type: GeminiEventType.ModelInfo, value: modelToUse };
}
const resultStream = turn.run(modelConfigKey, request, linkedSignal);
let isError = false;
let isInvalidStream = false;