fix: account polling elapsed time on the monotonic clock - #204
Open
yzxcj797 wants to merge 1 commit into
Open
Conversation
PollTimer measured elapsed duration with time.time(), a wall clock. NTP corrections, manual clock changes or VM suspend/restore move it: a forward adjustment can make an otherwise healthy deferred chat, collection indexing or video-generation poll time out immediately, and a backward adjustment can extend polling beyond the caller's requested timeout. Both the sync and async polling paths share this helper. Use time.monotonic(), which cannot go backward, for the start timestamp and the elapsed-time computation. No public API change and no normal-case timing change. Fixes xai-org#203
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.
Fixes #203.
Summary
PollTimermeasured elapsed duration withtime.time()— a wall clock. NTP corrections, manual clock changes or VM suspend/restore move it:TimeoutError: Polling timed out after 9900.0son a poll that had run for ~0s);Both the sync and async polling paths share this helper. The fix uses
time.monotonic()— which cannot go backward — for the start timestamp and the elapsed-time computation. Internal change only: no public API and no normal-case timing difference.Testing
New
tests/poll_timer_test.py(deterministic, mocks only the clock):9.5instead of raising;3/3 pass with the fix; differential with
poll_timer.pyreverted fails all three (the first returns the full interval, the others never raise).