Skip to content

fix: retry Amazon Bedrock network connection lost errors#5569

Merged
kevinvandijk merged 3 commits intoKilo-Org:mainfrom
romeoscript:bugfix/bedrock-network-error
Feb 21, 2026
Merged

fix: retry Amazon Bedrock network connection lost errors#5569
kevinvandijk merged 3 commits intoKilo-Org:mainfrom
romeoscript:bugfix/bedrock-network-error

Conversation

@romeoscript
Copy link
Copy Markdown

@romeoscript romeoscript commented Jan 31, 2026

Context

fixes #5563

Implementation

Implements an automatic retry mechanism (up to 3 attempts with exponential backoff) for "Amazon Bedrock error: Network connection lost" failures in the OpenRouter provider to improve stability with large contexts.

How to Test

  1. Launch the Extension: Run the extension in debug mode (F5).

  2. Select a Model: Choose a model that routes through Amazon Bedrock (e.g., Claude 3.5 Sonnet via OpenRouter or openai/gpt-5.2-codex if applicable).

  3. Simulate High Load:

    • Open a workspace with a large context or perform a task that involves reading many files to maximize the payload size.
    • Send a complex request to the model.
  4. Verify Retry Logic:

  • Open the Output panel in VS Code (View ->
  • Output
  • ) and select Kilo Code (or the extension's output channel).
  • If the "Network connection lost" error occurs, verify that you see the log message: [OpenRouter] Retrying Bedrock network error (attempt 1/3): ...
  • Confirm that the extension creates a new request automatically instead of immediately failing with an error.

Get in Touch

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 31, 2026

🦋 Changeset detected

Latest commit: 30eb061

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kilo-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Aleksei-Michnik
Copy link
Copy Markdown

Awesome, thanks for the fix! When can we expect it to be released?

@Aleksei-Michnik
Copy link
Copy Markdown

Still encountering the error. It's a real road blocker. Kilo speed, guys! Should a PR review take weeks, really?

@lambertjosh
Copy link
Copy Markdown
Contributor

A small amount of queries are consistently timing out on both Bedrock and Anthropic. We are investigating, unfortunately retrying is unlikely to help as in our analysis so far it is a consistent error once in this state.

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

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Feb 21, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
src/api/providers/openrouter.ts 445 Off-by-one in retry count: attempts < 3 allows only 2 retries (3 total attempts), but changeset and log message imply 3 retries
Files Reviewed (2 files)
  • .changeset/giant-badgers-deny.md - 0 issues
  • src/api/providers/openrouter.ts - 1 issue

Fix these issues in Kilo Cloud

Copy link
Copy Markdown
Contributor

@kevinvandijk kevinvandijk left a comment

Choose a reason for hiding this comment

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

I don't think this is the right solution but it can't hurt to have a retry option in here I think. Thanks!

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}`)
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Amazon Bedrock error: Network connection lost

4 participants