mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 12:54:07 -07:00
fix(core): retain user message in history on stream failure (#10608)
This commit is contained in:
@@ -899,9 +899,13 @@ describe('GeminiChat', () => {
|
|||||||
expect(mockLogContentRetry).toHaveBeenCalledTimes(1);
|
expect(mockLogContentRetry).toHaveBeenCalledTimes(1);
|
||||||
expect(mockLogContentRetryFailure).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();
|
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', () => {
|
describe('API error retry behavior', () => {
|
||||||
|
|||||||
@@ -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;
|
throw lastError;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user