-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: retry Amazon Bedrock network connection lost errors #5569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": patch | ||
| --- | ||
|
|
||
| Retry Amazon Bedrock network connection lost errors up till 3 times |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -429,7 +429,27 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH | |
|
|
||
| let stream | ||
| try { | ||
| stream = await this.client.chat.completions.create(completionParams, requestOptions) | ||
| // kilocode_change start | ||
| let attempts = 0 | ||
| while (true) { | ||
| try { | ||
| attempts++ | ||
| stream = await this.client.chat.completions.create(completionParams, requestOptions) | ||
| break | ||
| } catch (error: any) { | ||
| const msg = error?.message || "" | ||
| const isBedrockNetworkError = | ||
| msg.includes("Amazon Bedrock error") && msg.includes("Network connection lost") | ||
|
|
||
| if (isBedrockNetworkError && attempts < 3) { | ||
| console.log(`[OpenRouter] Retrying Bedrock network error (attempt ${attempts}/3): ${msg}`) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: Off-by-one in retry count — the condition If the intent is 3 retries (as the changeset states), change the condition to |
||
| await new Promise((resolve) => setTimeout(resolve, attempts * 2000)) | ||
| continue | ||
| } | ||
| throw error | ||
| } | ||
| } | ||
| // kilocode_change end | ||
| } catch (error) { | ||
| // kilocode_change start | ||
| // KiloCode backend errors are already user-readable and should be handled upstream. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: The retry logic is correct but lacks test coverage.
Per the project's code quality rules, all code changes should have test coverage. The existing test file
src/api/providers/__tests__/openrouter.spec.tsshould be updated with tests for this retry behavior, covering: