hindsight icon indicating copy to clipboard operation
hindsight copied to clipboard

Embeddings quota exhaustion (OpenAI 429 insufficient_quota) is retried briefly then marked failed; no request timeout on OpenAI embeddings client

Open choi138 opened this issue 1 month ago • 0 comments

Summary

An embeddings-provider quota exhaustion (OpenAI 429 insufficient_quota / "no credits remaining") is retried on the generic worker policy (60 s × 3) and then marked permanently failed, instead of being deferred like the equivalent LLM error. The OpenAI embeddings client is also built without a timeout, so one request can block a retain for up to 40 minutes.

Version

hindsight-api-slim 1.0.0 (ghcr.io/vectorize-io/hindsight:1.0.0), embeddings provider openai.

Where

  • hindsight_api/engine/retain/embedding_utils.py ~L136-139: except Exception as e: raise Exception(f"Failed to generate batch embeddings: {str(e)}") drops the original type/status (no from e), so no later classifier can see the 429.
  • hindsight_api/engine/memory_engine.py ~L4814-4825: every exception except _is_non_retryable_task_error gets RetryTaskAt(now + worker_task_retry_backoff_seconds) up to worker_max_retries, then failed. The ProviderRateLimitResetError → DeferOperation path (~L4723) is only reachable from the chat-LLM providers.
  • hindsight_api/engine/embeddings.py ~L993: client_kwargs = {"api_key": ..., "max_retries": self.max_retries} — no timeout (SDK default 600 s × (1+retries)). The factory (~L2256-2270) does not pass max_retries/timeout for provider openai, so HINDSIGHT_API_EMBEDDINGS_MAX_RETRIES etc. have no effect there.

Reproduction

  1. Run with HINDSIGHT_API_EMBEDDINGS_PROVIDER=openai and an OpenAI key whose project has no credits.
  2. POST /v1/default/banks/{bank}/memories (async retain).
  3. After ~4 minutes the operation is failed with Exception: Failed to generate batch embeddings: Error code: 429 - {'error': {'message': 'You have no credits remaining.... Nothing re-tries it when credits return. We accumulated 362 such failures in two days.

Expected

Quota exhaustion should defer the operation (DeferOperation, no retry_count consumed) with a reset hint or a configurable window, and the embeddings client should carry a request timeout.

Reference fix

Branch with tests (18 unit tests): https://github.com/choi138/hindsight/tree/fix/embeddings-quota-defer (commit 5d6e68817). Adds HINDSIGHT_API_EMBEDDINGS_QUOTA_DEFER_SECONDS (default 900) and HINDSIGHT_API_EMBEDDINGS_REQUEST_TIMEOUT (default 60), preserves the cause with EmbeddingBatchError ... from e, and wires timeout/max_retries for the openai-family providers.

choi138 avatar Oct 15 '26 05:10 choi138