← Back to PRs

#15585: fix: add retry/backoff for Gemini embedding API calls

by WalterSumbon open 2026-02-13 16:55 View on GitHub →
stale size: S
Fixes #15546 ## Problem Gemini embedding path (, , ) lacks the retry/backoff handling that OpenAI and Voyage paths already have. When Gemini hits rate limits (429) or server errors (5xx), calls fail immediately with no retry, causing gateway instability. ## Solution Wrapped all Gemini embedding fetch calls in with: - **3 attempts** - **Exponential backoff** (300ms to 2s) - **Jitter** (0.2) - **Retry on 429 and 5xx errors** ## Implementation Added wrapper to: 1. (2 fetch calls: file upload + batch create) 2. 3. Pattern matches existing OpenAI/Voyage implementation for consistency. ## Testing - ✅ `pnpm build` passing - ✅ `pnpm check` passing - ✅ Code follows existing retry pattern from `batch-openai.ts` and `batch-voyage.ts` ## Impact - Prevents gateway crashes when Gemini hits daily quota (429) - Handles transient server errors (5xx) gracefully - Consistent retry behavior across all embedding providers <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR adds `retryAsync`-based retry/backoff handling to Gemini batch embedding requests to match the existing OpenAI/Voyage patterns. The Gemini batch flow (file upload → batch create → status polling → result download) now wraps the HTTP calls with 3 attempts, exponential backoff (300ms–2s), jitter, and retries for 429/5xx. The other change is a small formatting-only update in `src/hooks/config.ts` (Windows `PATHEXT` parsing array literal). <h3>Confidence Score: 3/5</h3> - This PR is likely safe to merge but has a retry gap for thrown fetch/network errors that can undermine the intended resiliency improvements. - The retry/backoff logic for HTTP 429/5xx is consistent with existing providers, but the current `shouldRetry` predicates won’t retry when `fetch` throws (no `status`), which is a common transient failure mode and contradicts the PR’s stated goal of preventing instability under transient conditions. - src/memory/batch-gemini.ts <sub>Last reviewed commit: a08ffc4</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs