Embeddings quota exhaustion (OpenAI 429 insufficient_quota) is retried briefly then marked failed; no request timeout on OpenAI embeddings client
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 (nofrom e), so no later classifier can see the 429.hindsight_api/engine/memory_engine.py~L4814-4825: every exception except_is_non_retryable_task_errorgetsRetryTaskAt(now + worker_task_retry_backoff_seconds)up toworker_max_retries, thenfailed. TheProviderRateLimitResetError → DeferOperationpath (~L4723) is only reachable from the chat-LLM providers.hindsight_api/engine/embeddings.py~L993:client_kwargs = {"api_key": ..., "max_retries": self.max_retries}— notimeout(SDK default 600 s × (1+retries)). The factory (~L2256-2270) does not passmax_retries/timeoutfor provideropenai, soHINDSIGHT_API_EMBEDDINGS_MAX_RETRIESetc. have no effect there.
Reproduction
- Run with
HINDSIGHT_API_EMBEDDINGS_PROVIDER=openaiand an OpenAI key whose project has no credits. POST /v1/default/banks/{bank}/memories(async retain).- After ~4 minutes the operation is
failedwithException: 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.