Skip to content

fix: use monotonic clock for file processing timeout - #3748

Open
Hughhhhcoder wants to merge 1 commit into
openai:mainfrom
Hughhhhcoder:codex/openai-python-file-timeout
Open

fix: use monotonic clock for file processing timeout#3748
Hughhhhcoder wants to merge 1 commit into
openai:mainfrom
Hughhhhcoder:codex/openai-python-file-timeout

Conversation

@Hughhhhcoder

Copy link
Copy Markdown

Summary

  • Use time.monotonic() for elapsed-time deadlines in both synchronous and asynchronous file-processing polling.
  • Add regression coverage for a wall-clock rollback in both resource variants.

Bug

Files.wait_for_processing() and its asynchronous counterpart used time.time() to measure elapsed time. If the system wall clock moves backwards while a file is still processing, the calculated elapsed time also moves backwards and the timeout can be postponed indefinitely.

Reproduction

With max_wait_seconds=1, poll_interval=5, and a wall clock that changes from 100 to 90 after the first poll:

  • Expected: raise the timeout error once the monotonic deadline has elapsed.
  • Actual before this change: continue polling and enter another five-second sleep.

Root cause

Wall-clock time is adjustable and is not suitable for measuring elapsed durations.

Fix

Use Python's monotonic clock for both the initial timestamp and every deadline check. This does not change the public API, poll interval, terminal states, or error message.

Validation

  • tests/lib/test_file_processing.py: 15 passed
  • Ruff check: passed
  • Ruff format check: passed
  • Isolated synchronous and asynchronous rollback reproducer: passed

Commands used:

PYTHONPATH=/tmp/openai-python-file-timeout-deps-20260828:src python -m pytest -p no:cacheprovider -o addopts= --confcutdir=tests/lib --asyncio-mode=auto -q tests/lib/test_file_processing.py
python -m ruff check --no-cache src/openai/lib/_files.py tests/lib/test_file_processing.py
python -m ruff format --no-cache --check src/openai/lib/_files.py tests/lib/test_file_processing.py

@Hughhhhcoder
Hughhhhcoder requested a review from a team as a code owner August 27, 2026 16:12
@Hughhhhcoder

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 23371b4317

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Security review completed. No security issues were found in this pull request.

Reviewed commit: 23371b4317

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

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.

1 participant