[BUG] Polling timeouts can misfire after wall-clock adjustments
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
Research direction
Start with PollTimer in xai_sdk/poll_timer.py, identified by the reproduction, and inspect how it records the start time and computes elapsed duration. Add a focused regression test covering an independent wall-clock adjustment while monotonic time advances normally. Done means both sync and async polling paths retain the requested timeout behavior without public API changes.
Written by the indexing model from the issue text.
Description
Confirmation of Issue Source
- I confirm that this issue is with the xAI SDK Python library (e.g., client behavior, SDK methods, or documentation) and not with the xAI API itself (e.g., model output, API errors, or quota issues).
Describe the Bug
PollTimer measures elapsed duration with time.time(), which is a wall clock and can move forward or backward after NTP corrections, manual clock changes, or VM suspend/restore. A forward adjustment can make an otherwise healthy deferred chat, collection indexing, or video-generation operation time out immediately. A backward adjustment can extend polling beyond the caller's requested timeout.
Both sync and async polling paths share this helper, so the behavior affects both clients.
Steps to Reproduce
On current main (4dab6a4), this deterministic reproduction simulates a forward wall-clock adjustment:
import datetime
from unittest.mock import patch
from xai_sdk.poll_timer import PollTimer
with patch("xai_sdk.poll_timer.time.time", side_effect=[100.0, 10_000.0]):
timer = PollTimer(
timeout=datetime.timedelta(seconds=10),
interval=datetime.timedelta(seconds=20),
)
print(timer.sleep_interval_or_raise())
Actual result:
TimeoutError: Polling timed out after 9900.0s
Expected result: elapsed timeout accounting should be unaffected by wall-clock changes. Python's time.monotonic() is intended for measuring durations and cannot go backward.
Proposed Fix
Use time.monotonic() for the start timestamp and elapsed-time calculation, with a focused regression test that changes the wall clock independently of monotonic elapsed time. This is an internal implementation change with no public API or normal-case timing change.
- Dominant language
- Python
- Stars
- 578
- Forks
- 191
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from xai-org/xai-sdk-python
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
xai-org/xai-sdk-python#213 ·
-
[FEATURE] Make version-gated proto imports statically analyzable (`src/xai_sdk/proto/__init__.py`) Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
xai-org/xai-sdk-python#177 ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 30/100
xai-org/xai-sdk-python#215 ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 38/100
xai-org/xai-sdk-python#214 ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 45/100
xai-org/xai-sdk-python#212 ·
All issues in xai-org/xai-sdk-python
Similar issues
-
area/auth bug comp/agent P3 platform/discord type/security
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
NousResearch/hermes-agent#117848 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100