Mirror: fix: retry Amazon Bedrock network connection lost errors (#5569)#35
Mirror: fix: retry Amazon Bedrock network connection lost errors (#5569)#35jeremylongshore wants to merge 1 commit intomainfrom
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Review Summary by QodoAdd retry logic for Amazon Bedrock network errors
WalkthroughsDescription• Add retry logic for Amazon Bedrock network connection errors • Implements exponential backoff with max 3 attempts • Detects Bedrock-specific network errors and retries automatically Diagramflowchart LR
A["API Request"] --> B["Attempt Chat Completion"]
B --> C{Bedrock Network Error?}
C -->|Yes & Attempts < 3| D["Wait 2s * Attempt"]
D --> B
C -->|No or Max Attempts| E["Throw Error"]
B -->|Success| F["Return Stream"]
File Changes1. src/api/providers/openrouter.ts
|
📝 WalkthroughWalkthroughThe OpenRouter API provider now implements a retry mechanism with exponential backoff for Bedrock network errors. When a network error occurs during chat completion requests, the system automatically retries up to 3 times with increasing delays before propagating the error. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Failed to generate code suggestions for PR |
Code Review by Qodo
1. console.log leaks error details
|
| 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}`) |
There was a problem hiding this comment.
1. console.log leaks error details 📘 Rule violation ⛨ Security
The new retry logic logs the raw error.message, which may contain sensitive/internal details and is unstructured for auditing. This violates secure logging requirements and can expose information in logs.
Agent Prompt
## Issue description
The retry code logs raw `error.message` via `console.log`, which is unstructured and may leak sensitive/internal error details.
## Issue Context
This code runs in a provider integration path; logs should be structured and must not include sensitive data.
## Fix Focus Areas
- src/api/providers/openrouter.ts[445-451]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| } catch (error: any) { | ||
| const msg = error?.message || "" | ||
| const isBedrockNetworkError = | ||
| msg.includes("Amazon Bedrock error") && msg.includes("Network connection lost") | ||
|
|
There was a problem hiding this comment.
2. Retry misses wrapped errors 🐞 Bug ✓ Correctness
The new retry condition only checks error.message, but OpenRouter errors are often wrapped with the meaningful message inside error.error.message and/or error.error.metadata.raw. This can cause the Bedrock network retry to never trigger even when the underlying error matches.
Agent Prompt
### Issue description
The Bedrock retry logic only checks `error.message`, but OpenRouter errors are frequently wrapped (e.g., `error.error.message` and/or `error.error.metadata.raw`). As a result, the intended Bedrock retry may not trigger.
### Issue Context
This file already contains utilities and schema definitions for extracting the “real” upstream error message from `metadata.raw`. The retry logic should use the same extraction approach.
### Fix Focus Areas
- src/api/providers/openrouter.ts[435-455]
- src/api/providers/openrouter.ts[76-140]
- src/api/providers/openrouter.ts[865-881]
### Implementation notes
- Create a small helper (local function) like `getOpenRouterErrorMessage(error: any): string` that tries, in order:
- `error?.message`
- `error?.error?.message`
- `extractErrorFromMetadataRaw(error?.metadata?.raw)`
- `extractErrorFromMetadataRaw(error?.error?.metadata?.raw)`
- fallback `String(error)`
- Use the returned string for `isBedrockNetworkError` matching.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
@greptileai review |
|
Merged into |
Mirror of Kilo-Org#5569
This PR mirrors the upstream change for multi-AI review analysis.
Bot Review Tracker
Links
Summary by CodeRabbit