Skip to content

fix: add poll_timeout_ms to prevent upload_and_poll() hanging indefinitely (#3097)#3102

Open
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/issue-3097-upload-poll-timeout
Open

fix: add poll_timeout_ms to prevent upload_and_poll() hanging indefinitely (#3097)#3102
xodn348 wants to merge 1 commit intoopenai:mainfrom
xodn348:fix/issue-3097-upload-poll-timeout

Conversation

@xodn348
Copy link
Copy Markdown

@xodn348 xodn348 commented Apr 19, 2026

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:

  • `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 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

# Raises TimeoutError if still in_progress after 30 seconds
file = client.vector_stores.files.upload_and_poll(
    vector_store_id="vs_abc",
    file=open("data.pdf", "rb"),
    poll_timeout_ms=30_000,
)

Changes

  • src/openai/resources/vector_stores/files.py: Added import time, added poll_timeout_ms parameter and timeout check logic to all six polling methods (sync + async)

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vector_stores.files.upload_and_poll() can hang indefinitely with file status stuck at in_progress

1 participant