Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Jul 2, 2025

Description

image image

This PR fixes an issue where the code indexer would hang indefinitely when using OpenAI embeddings with an account that has insufficient credits/quota. Previously, all HTTP 429 errors were treated as retryable rate-limit errors, causing the indexer to retry endlessly even when the error was due to insufficient funds.

Changes Made

1. Enhanced Error Detection

  • Added isInsufficientQuotaError() method to both OpenAI embedders to detect quota-related 429 errors
  • The method checks for keywords like "insufficient_quota", "quota exceeded", "insufficient funds", "billing", etc.
  • Handles various error response formats from the OpenAI API

2. Modified Retry Logic

  • Updated _embedBatchWithRetries() in both openai.ts and openai-compatible.ts
  • Quota errors now throw immediately without retrying
  • Regular rate limit errors continue to retry with exponential backoff as before

3. User-Friendly Error Messages

  • Added new localized error message: "Failed to create embeddings: Insufficient quota. Please check your OpenAI account balance and add credits to continue."
  • Translations added for all supported languages

4. Comprehensive Test Coverage

  • Added test cases to verify quota errors fail immediately without retries
  • Added test cases to ensure regular rate limits still trigger retry logic
  • All existing tests continue to pass

Testing

Unit Tests

  • ✅ OpenAI Embedder: 27 tests passed
  • ✅ OpenAI Compatible Embedder: 31 tests passed
  • ✅ New test cases verify quota error detection works correctly
  • ✅ Existing retry logic for regular rate limits remains functional

Code Quality

  • ✅ ESLint: No errors or warnings
  • ✅ TypeScript: No type errors
  • ✅ All existing functionality preserved (no regressions)

Verification

Acceptance Criteria Met:

  1. ✅ Indexer fails immediately on insufficient quota errors
  2. ✅ Clear error message displayed to users
  3. ✅ Regular rate limits continue to retry
  4. ✅ All tests pass
  5. ✅ No regression in existing functionality

Manual Testing Recommended:

  • Test with an OpenAI account that has exhausted its credits
  • Verify the error message appears quickly without hanging
  • Test with regular rate limits to ensure retry logic still works

Notes

  • The implementation is backward compatible and only adds new error detection logic
  • The solution handles various OpenAI error response formats for robustness
  • All translations have been added for the new error message in all supported languages

Fixes #5350


Important

Fixes indexer hanging by detecting and handling OpenAI insufficient quota errors without retrying, with enhanced user feedback and test coverage.

  • Behavior:
    • Adds isInsufficientQuotaError() in quota-detection.ts to identify quota-related 429 errors.
    • Updates _embedBatchWithRetries() in openai.ts and openai-compatible.ts to throw on quota errors without retrying.
    • Continues retrying on regular rate limit errors with exponential backoff.
  • User Feedback:
    • Adds localized error message for insufficient quota in multiple language files.
  • Testing:
    • Adds tests in openai.spec.ts and openai-compatible.spec.ts to verify immediate failure on quota errors and retry logic for rate limits.
    • Ensures all existing tests pass without regression.

This description was created by Ellipsis for 3905dcb. You can customize this summary. It will automatically update as commits are pushed.

Copilot AI review requested due to automatic review settings July 2, 2025 19:26
@hannesrudolph hannesrudolph requested review from cte, jr and mrubens as code owners July 2, 2025 19:26
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Jul 2, 2025
@dosubot dosubot bot added the bug Something isn't working label Jul 2, 2025
@delve-auditor
Copy link

delve-auditor bot commented Jul 2, 2025

No security or compliance issues detected. Reviewed everything up to 3905dcb.

Security Overview
  • 🔎 Scanned files: 23 changed file(s)
Detected Code Changes
Change Type Relevant files
Enhancement ► embeddings.json
    Add insufficient quota error messages across language files
► openai-compatible.ts
    Add quota detection for error handling
► openai.ts
    Add quota detection for error handling
► quota-detection.ts
    Add utility for detecting quota-related errors

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR prevents the code indexer from hanging on OpenAI quota errors by detecting insufficient-quota errors and failing immediately, while preserving existing retry behavior for rate limits.

  • Added isInsufficientQuotaError to both embedders and updated retry logic to throw on quota errors
  • Introduced user-friendly localized error messages and tests for quota vs. rate-limit behavior
  • Enhanced diff view to preserve editor focus and updated tooling calls to await the async scroll method

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/services/code-index/embedders/openai.ts Detect quota errors and skip retries in _embedBatchWithRetries
src/services/code-index/embedders/openai-compatible.ts Same quota-detection patch for the compatible embedder
src/services/code-index/embedders/tests/openai.spec.ts Added tests for insufficient-quota and rate-limit scenarios
src/services/code-index/embedders/tests/openai-compatible.spec.ts Added analogous tests
src/integrations/editor/DiffViewProvider.ts Added preserveFocus and focus-restoration logic, made scroll async
src/integrations/editor/tests/DiffViewProvider.spec.ts Updated tests to expect preserveFocus: true
src/core/tools/writeToFileTool.ts Awaited the newly async scrollToFirstDiff call
src/core/tools/searchAndReplaceTool.ts Awaited the newly async scrollToFirstDiff call
src/core/tools/insertContentTool.ts Awaited the newly async scrollToFirstDiff call
src/i18n/locales/*/embeddings.json Added insufficientQuota translation in all supported languages

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jul 2, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jul 2, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jul 2, 2025
@daniel-lxs
Copy link
Member

It looks like the changes for focus preservation have been included in this pull request. Since there is a separate PR for that work, could you please remove the unrelated focus-preservation changes from this one to keep it focused on the OpenAI quota issue?

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jul 3, 2025
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Jul 4, 2025
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider checking error.response?.status in addition to error.status to robustly detect 429 errors when the status code is nested under response.

Suggested change
if (error?.status !== 429) return false
if (error?.status !== 429 && error?.response?.status !== 429) return false

@daniel-lxs daniel-lxs force-pushed the fix/issue-5350-indexer-quota-error branch from 6e28440 to 3905dcb Compare July 4, 2025 22:39
@daniel-lxs daniel-lxs moved this from PR [Changes Requested] to PR [Needs Prelim Review] in Roo Code Roadmap Jul 7, 2025
@hannesrudolph
Copy link
Collaborator Author

Closed in favour of #5404

@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 7, 2025
@github-project-automation github-project-automation bot moved this from PR [Needs Prelim Review] to Done in Roo Code Roadmap Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Needs Preliminary Review size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Indexer hangs on OpenAI embedding with insufficient quota

3 participants