fix: add poll_timeout_ms to prevent upload_and_poll() hanging indefinitely (#3097)#3102
Open
xodn348 wants to merge 1 commit intoopenai:mainfrom
Open
fix: add poll_timeout_ms to prevent upload_and_poll() hanging indefinitely (#3097)#3102xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348 wants to merge 1 commit intoopenai:mainfrom
Conversation
…efinite hang Fixes openai#3097: upload_and_poll() and poll() would hang indefinitely when a vector store file stays stuck in 'in_progress' status. Added poll_timeout_ms parameter (float | None) to: - Files.poll() / AsyncFiles.poll() - Files.create_and_poll() / AsyncFiles.create_and_poll() - Files.upload_and_poll() / AsyncFiles.upload_and_poll() When poll_timeout_ms is set and elapsed time exceeds it, raises TimeoutError with a descriptive message. Uses time.monotonic() for accurate elapsed tracking.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3097: `vector_stores.files.upload_and_poll()` hangs indefinitely when a vector store file stays stuck at `status="in_progress"`.
Root Cause
The `poll()` method uses an unbounded `while True:` loop with no timeout mechanism. If the OpenAI API gets into a state where a file never leaves `in_progress`, the call will block forever.
Fix
Added an optional `poll_timeout_ms: float | None` parameter to all six polling methods:
When `poll_timeout_ms` is set and the elapsed time (tracked with `time.monotonic()`) exceeds the limit while the file is still `in_progress`, a `TimeoutError` is raised with a descriptive message identifying the stuck file. When not set (default `None`), behavior is unchanged — fully backwards compatible.
Usage
Changes
src/openai/resources/vector_stores/files.py: Addedimport time, addedpoll_timeout_msparameter and timeout check logic to all six polling methods (sync + async)