Skip to content

Commit 2f1cd0b

Browse files
bdmorganBryanBradfo
authored andcommitted
fix(core): apply retry logic to CodeAssistServer for all users (google-gemini#20507)
1 parent 06f19c8 commit 2f1cd0b

2 files changed

Lines changed: 58 additions & 26 deletions

File tree

packages/core/src/code_assist/server.test.ts

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,26 @@ describe('CodeAssistServer', () => {
7373
LlmRole.MAIN,
7474
);
7575

76-
expect(mockRequest).toHaveBeenCalledWith(
77-
expect.objectContaining({
78-
url: expect.stringContaining(':generateContent'),
79-
method: 'POST',
80-
headers: {
81-
'Content-Type': 'application/json',
82-
'x-custom-header': 'test-value',
83-
},
84-
responseType: 'json',
85-
body: expect.any(String),
86-
signal: undefined,
87-
}),
88-
);
76+
expect(mockRequest).toHaveBeenCalledWith({
77+
url: expect.stringContaining(':generateContent'),
78+
method: 'POST',
79+
headers: {
80+
'Content-Type': 'application/json',
81+
'x-custom-header': 'test-value',
82+
},
83+
responseType: 'json',
84+
body: expect.any(String),
85+
signal: undefined,
86+
retryConfig: {
87+
retry: 3,
88+
noResponseRetries: 3,
89+
statusCodesToRetry: [
90+
[429, 429],
91+
[499, 499],
92+
[500, 599],
93+
],
94+
},
95+
});
8996

9097
const requestBody = JSON.parse(mockRequest.mock.calls[0][0].body);
9198
expect(requestBody.user_prompt_id).toBe('user-prompt-id');
@@ -393,19 +400,26 @@ describe('CodeAssistServer', () => {
393400
results.push(res);
394401
}
395402

396-
expect(mockRequest).toHaveBeenCalledWith(
397-
expect.objectContaining({
398-
url: expect.stringContaining(':streamGenerateContent'),
399-
method: 'POST',
400-
params: { alt: 'sse' },
401-
responseType: 'stream',
402-
body: expect.any(String),
403-
headers: {
404-
'Content-Type': 'application/json',
405-
},
406-
signal: undefined,
407-
}),
408-
);
403+
expect(mockRequest).toHaveBeenCalledWith({
404+
url: expect.stringContaining(':streamGenerateContent'),
405+
method: 'POST',
406+
params: { alt: 'sse' },
407+
responseType: 'stream',
408+
body: expect.any(String),
409+
headers: {
410+
'Content-Type': 'application/json',
411+
},
412+
signal: undefined,
413+
retryConfig: {
414+
retry: 3,
415+
noResponseRetries: 3,
416+
statusCodesToRetry: [
417+
[429, 429],
418+
[499, 499],
419+
[500, 599],
420+
],
421+
},
422+
});
409423

410424
expect(results).toHaveLength(2);
411425
expect(results[0].candidates?.[0].content?.parts?.[0].text).toBe('Hello');

packages/core/src/code_assist/server.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,15 @@ export class CodeAssistServer implements ContentGenerator {
305305
responseType: 'json',
306306
body: JSON.stringify(req),
307307
signal,
308+
retryConfig: {
309+
retry: 3,
310+
noResponseRetries: 3,
311+
statusCodesToRetry: [
312+
[429, 429],
313+
[499, 499],
314+
[500, 599],
315+
],
316+
},
308317
});
309318
return res.data;
310319
}
@@ -352,6 +361,15 @@ export class CodeAssistServer implements ContentGenerator {
352361
responseType: 'stream',
353362
body: JSON.stringify(req),
354363
signal,
364+
retryConfig: {
365+
retry: 3,
366+
noResponseRetries: 3,
367+
statusCodesToRetry: [
368+
[429, 429],
369+
[499, 499],
370+
[500, 599],
371+
],
372+
},
355373
});
356374

357375
return (async function* (): AsyncGenerator<T> {

0 commit comments

Comments
 (0)