fix(core): retain user message in history on stream failure (#10608)

This commit is contained in:
Sandy Tao
2025-10-06 16:32:35 -07:00
committed by GitHub
parent 4cd3728039
commit e705f45c5f
2 changed files with 6 additions and 6 deletions

View File

@@ -899,9 +899,13 @@ describe('GeminiChat', () => {
expect(mockLogContentRetry).toHaveBeenCalledTimes(1);
expect(mockLogContentRetryFailure).toHaveBeenCalledTimes(1);
// History should be clean, as if the failed turn never happened.
// History should still contain the user message.
const history = chat.getHistory();
expect(history.length).toBe(0);
expect(history.length).toBe(1);
expect(history[0]).toEqual({
role: 'user',
parts: [{ text: 'test' }],
});
});
describe('API error retry behavior', () => {

View File

@@ -327,10 +327,6 @@ export class GeminiChat {
),
);
}
// If the stream fails, remove the user message that was added.
if (self.history[self.history.length - 1] === userContent) {
self.history.pop();
}
throw lastError;
}
} finally {