Skip to content

Indexer hangs on OpenAI embedding with insufficient quotaΒ #5350

@hannesrudolph

Description

@hannesrudolph

App Version

0.0.6085 (1be6fce)

API Provider

OpenAI

Model Used

text-embedding-3-small

πŸ” Steps to Reproduce

  1. Configure the extension to use OpenAI for embeddings.
  2. Use an OpenAI API key that has run out of credits.
  3. Start the indexing process for a workspace.
  4. The indexing process hangs indefinitely with no error message.

πŸ’₯ Outcome Summary

Expected: An error message should appear indicating that the OpenAI account has insufficient funds, and the indexing process should stop.

Actual: The indexing process hangs without any error or notification, endlessly retrying in the background.


πŸ› οΈ Contributing & Technical Analysis

βœ… I'm interested in implementing this feature
βœ… I understand this needs approval before implementation begins

How should this be solved?

The root cause is that the OpenAI embedder classes treat all 429 HTTP errors as retryable rate-limit errors. The application should differentiate between a temporary rate limit and a permanent quota issue.

What will change:

  • The error handling logic in _embedBatchWithRetries within src/services/code-index/embedders/openai.ts and src/services/code-index/embedders/openai-compatible.ts will be updated.
  • When a 429 error occurs, the error message from the API will be inspected for keywords like "insufficient_quota".
  • If a quota error is detected, the process will fail immediately with a new, specific error message instead of retrying.

User interaction:

  • Instead of the indexer hanging, the user will see a clear error message in the extension explaining that their OpenAI account has insufficient funds.

Acceptance Criteria

Given the user has configured the OpenAI embedder
And their OpenAI account has insufficient quota
When the indexing process is started
Then the process should fail quickly
And a clear error message is displayed, indicating an insufficient quota issue
But the application should not hang or enter a retry loop for this error

Technical Considerations

Implementation approach:

  • Key files to modify:

    • src/services/code-index/embedders/openai.ts
    • src/services/code-index/embedders/openai-compatible.ts
    • src/i18n/locales/en/embeddings.json (to add the new error message)
    • src/services/code-index/embedders/__tests__/openai.spec.ts (to add a new test case)
    • src/services/code-index/embedders/__tests__/openai-compatible.spec.ts (to add a new test case)
  • Integration points: The change is isolated to the embedding-creation logic and its error handling.

  • Similar patterns in codebase: The existing error handling for 401 authentication errors in the same files serves as a good pattern for adding this new error condition.

Trade-offs and Risks

Alternatives considered:

  • A generic timeout could be implemented, but this would not provide a specific reason for the failure to the user. Distinguishing the error type is a much better user experience.

Potential risks:

  • The string matching for "insufficient_quota" might be brittle if OpenAI changes their error messages. The implementation should be flexible enough to check for multiple keywords or error codes if available in the error response body.

Metadata

Metadata

Assignees

Labels

Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions