Repository navigation
fix(calibration): enforce remote image total_timeout across headers and redirects - #3848
Merged
Merged
Conversation
total_timeout only started once the final response headers had arrived: requests.get(stream=True, timeout=...) was called before the watchdog, so delayed headers, header drip, and chains of individually fast redirects could exceed the budget and still return success. The deadline is now absolute and covers the request/redirect/header phase, the body read, and decode; per-attempt timeouts are clamped to the remaining budget. Adds regression tests for slow headers, a redirect chain, header drip, and slow decoding.
ZX-ModelCloud
force-pushed
the
fix/image-total-timeout
branch
from
November 13, 2026 09:26
e6eccd1 to
7c08f9d
Compare
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.
TL;DR
load_image_from_url'stotal_timeoutis now an absolute deadline that covers the request/redirect/header phase, body streaming, and decoding. Previously the watchdog started only after the final response headers arrived, so delayed headers, header drip, and chains of individually fast redirects could exceed the budget and still return success. Net:+283/-4across 4 files.Fixes #3832.
1. The problem
The deadline started inside the body loop, after
requests.get(...)had already returned the final headers:flowchart TD A[load_image_from_url] --> B[deadline = monotonic + total_timeout] B --> C[requests.get stream=True timeout=per-read] C --> D[redirect chain resolved inside requests] D --> E[final headers arrive] E --> F[fresh body deadline = monotonic + remaining] F --> G[body watchdog] G --> H[Image.open + image.load] H --> I[return image] classDef fail fill:#f8d7da,stroke:#b02a37,color:#000; class C,D,E fail;gptqmodel/utils/image.py:157(pre-fixmain)gptqmodel/utils/image.py:189-193gptqmodel/utils/image.py:157gptqmodel/utils/image.py:3262. The new flow
One absolute
deadlineis computed perload_image_from_urlcall and shared by every attempt, the request phase, the body stream, and decoding:flowchart TD A[load_image_from_url] --> B[deadline = monotonic + total_timeout] B --> C{remaining > 0} C -- no --> Z[ImageFetchError: total time limit] C -- yes --> D[_get_response: daemon thread + deadline wait] D -- deadline --> Z D -- response --> E[deadline check after headers] E -- expired --> Z E --> F[body read with watchdog scheduled from deadline] F -- expired --> Z F --> G[deadline check after body] G -- expired --> Z G --> H[Image.open + pixel limit] H --> I[image.load] I --> J{deadline expired} J -- yes --> K[image.close + ImageFetchError] J -- no --> L[return image] classDef fail fill:#f8d7da,stroke:#b02a37,color:#000; class Z,K fail;_clamp_timeoutcaps the connect/read values at the remaining budget, sorequestscannot wait past the deadline even when the caller supplied a largertimeout. When the caller gives up, the helper thread is cancelled: an already-arrived response is closed immediately, and a request still blocked insiderequestsis released as soon as the server completes or closes the connection.3. Failure and ambiguity contract
ImageFetchErrorwithtotal time limit; not retriedImageFetchError; image closed4. Change inventory
gptqmodel/utils/image.pytests/test_image_fetch.pydocs/remote-image-fetch-bounds.mdREADME.md5. Tests
tests/test_image_fetch.py(26 passed):test_slow_headers_are_bounded_by_total_timeouttest_redirect_chain_is_bounded_by_total_timeouttest_header_drip_is_bounded_by_total_timeouttest_decode_time_is_bounded_by_total_timeouttest_slow_drip_body_is_bounded_by_total_timeout6. Validation
The scaled budgets used by the tests exercise the same deadline path as the default 120-second configuration; no model, kernel, or checkpoint code is touched.
7. Reviewer notes
docs/remote-image-fetch-bounds.md, linked fromREADME.md.requestsappliestimeoutper socket read; a trickling header stream can reset that timer indefinitely. The thread is a daemon and is cancelled when the caller's deadline expires.total_timeoutremains a caller-visible argument; no environment-variable switch is introduced.