#15585: fix: add retry/backoff for Gemini embedding API calls
stale
size: S
Cluster:
Gemini API Enhancements
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
#21843: fix: add retry/backoff to Gemini embedding batch API calls
by slegarraga · 2026-02-20
95.1%
#8675: fix: Gemini batch embeddings state path, enum values, and download URL
by seasalim · 2026-02-04
78.7%
#11472: fix: retry media fetch on transient network errors
by openclaw-quenio · 2026-02-07
76.6%
#12995: feat(infra): Add retry with exponential backoff for transient failures
by trevorgordon981 · 2026-02-10
76.4%
#23497: feat(retry): add retryHttpAsync utility with comprehensive coverage
by thinstripe · 2026-02-22
75.6%
#14314: fix(agent-runner): auto-recover from Gemini INVALID_ARGUMENT errors
by thebtf · 2026-02-11
75.1%
#16786: fix: support google-antigravity OAuth for Gemini embeddings
by outsourc-e · 2026-02-15
74.9%
#8309: fix: add emb_ prefix to batch embedding custom_id for OpenAI compli...
by vishaltandale00 · 2026-02-03
74.7%
#15301: Feat/gemini overflow and tags
by divisonofficer · 2026-02-13
73.8%
#20315: fix(memory): add gemini-embedding-001 to GEMINI_MAX_INPUT_TOKENS
by Clawborn · 2026-02-18
73.8%