Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/giant-badgers-deny.md
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
22 changes: 21 additions & 1 deletion src/api/providers/openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Copy Markdown
Contributor

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.ts should be updated with tests for this retry behavior, covering:

  1. Successful request on first attempt (no retry)
  2. Bedrock network error followed by successful retry
  3. Exhausting all 3 attempts and throwing the error
  4. Non-Bedrock errors being thrown immediately without retry

console.log(`[OpenRouter] Retrying Bedrock network error (attempt ${attempts}/3): ${msg}`)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Off-by-one in retry count — the condition attempts < 3 on line 444 allows only 2 retries (3 total attempts), but the changeset says "up till 3 times" and this log message says attempt ${attempts}/3 which will only ever print 1/3 and 2/3, never 3/3.

If the intent is 3 retries (as the changeset states), change the condition to attempts <= 3. If 2 retries is intentional, update the log to attempt ${attempts}/2 and the changeset description.

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.
Expand Down
Loading