fix: remove 400 errors from model history

This commit is contained in:
Jack Wotherspoon
2026-01-19 21:34:43 -05:00
parent 4b4bdd10b6
commit 53994b2ff0
2 changed files with 7 additions and 6 deletions

View File

@@ -1279,13 +1279,10 @@ describe('GeminiChat', () => {
expect(mockLogContentRetry).toHaveBeenCalledTimes(1);
expect(mockLogContentRetryFailure).toHaveBeenCalledTimes(1);
// History should still contain the user message.
// History should NOT contain the failed user message,
// to prevent invalid content from breaking subsequent requests.
const history = chat.getHistory();
expect(history.length).toBe(1);
expect(history[0]).toEqual({
role: 'user',
parts: [{ text: 'test' }],
});
expect(history.length).toBe(0);
});
describe('API error retry behavior', () => {

View File

@@ -380,6 +380,8 @@ export class GeminiChat {
}
if (isConnectionPhase) {
// Remove failed user content so it doesn't break subsequent requests
this.history.pop();
throw error;
}
lastError = error;
@@ -429,6 +431,8 @@ export class GeminiChat {
new ContentRetryFailureEvent(maxAttempts, lastError.type, model),
);
}
// Remove failed user content so it doesn't break subsequent requests
this.history.pop();
throw lastError;
}
} finally {