Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions packages/core/src/core/geminiChat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
modelConfigService: {
getResolvedConfig: vi.fn().mockImplementation((modelConfigKey) => {
const model = modelConfigKey.model ?? mockConfig.getModel();
const thinkingConfig = model.startsWith('gemini-3')

Check warning on line 172 in packages/core/src/core/geminiChat.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-3". Please make sure this change is appropriate to submit.
? {
thinkingLevel: ThinkingLevel.HIGH,
}
Expand Down Expand Up @@ -918,7 +918,7 @@
);
});

it('should use thinkingLevel and remove thinkingBudget for gemini-3 models', async () => {

Check warning on line 921 in packages/core/src/core/geminiChat.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-3". Please make sure this change is appropriate to submit.
const response = (async function* () {
yield {
candidates: [
Expand All @@ -934,7 +934,7 @@
);

const stream = await chat.sendMessageStream(
{ model: 'gemini-3-test-only-model-string-for-testing' },

Check warning on line 937 in packages/core/src/core/geminiChat.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-3". Please make sure this change is appropriate to submit.
'hello',
'prompt-id-thinking-level',
new AbortController().signal,
Expand All @@ -945,7 +945,7 @@

expect(mockContentGenerator.generateContentStream).toHaveBeenCalledWith(
expect.objectContaining({
model: 'gemini-3-test-only-model-string-for-testing',

Check warning on line 948 in packages/core/src/core/geminiChat.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-3". Please make sure this change is appropriate to submit.
config: expect.objectContaining({
thinkingConfig: {
thinkingBudget: undefined,
Expand All @@ -957,7 +957,7 @@
);
});

it('should use thinkingBudget and remove thinkingLevel for non-gemini-3 models', async () => {

Check warning on line 960 in packages/core/src/core/geminiChat.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-3". Please make sure this change is appropriate to submit.
const response = (async function* () {
yield {
candidates: [
Expand Down Expand Up @@ -1028,7 +1028,7 @@
});

describe('sendMessageStream with retries', () => {
it('should not retry on invalid content if model does not start with gemini-2', async () => {

Check warning on line 1031 in packages/core/src/core/geminiChat.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Found sensitive keyword "gemini-2". Please make sure this change is appropriate to submit.
// Mock the stream to fail.
vi.mocked(mockContentGenerator.generateContentStream).mockImplementation(
async () =>
Expand Down Expand Up @@ -1279,13 +1279,10 @@
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', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/core/geminiChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Loading