SIGN IN SIGN UP

fix: use monotonic clock for file processing timeout (#3748)

## 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:

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

---------

Co-authored-by: Marcus Wood <marcuswood@openai.com>
H
HughChaw committed
58aca1dcfd8d04a3c6352fa2c34b3035ea850f57
Parent: 841d929
Committed by GitHub <noreply@github.com> on 9/30/2026, 12:51:54 AM