Skip to content

Land two open community fixes: non-blocking input in async examples (#216), monotonic PollTimer (#204) - #224

Open
deanrie wants to merge 2 commits into
xai-org:mainfrom
deanrie:community/protobuf7-async-examples-poll-timer
Open

deanrie wants to merge 2 commits into
xai-org:mainfrom
deanrie:community/protobuf7-async-examples-poll-timer

Conversation

@deanrie

@deanrie deanrie commented Oct 15, 2026 •

Copy link
Copy Markdown

Summary

Two community fixes that have each sat open and MERGEABLE for over a month with no review, cherry-picked onto current main with their original authorship so they can land in one pass. No changes to the patches themselves beyond the rebase.

  1. Use asyncio.to_thread for non-blocking input in async chat examples (fix: use asyncio.to_thread for non-blocking input in async chat examples #216, @bodapatisaikrishna, 2026-09-18). The README and examples/aio/chat.py called blocking input() inside async def loops; now await asyncio.to_thread(input, "You: "). Fixes [BUG] Blocking Synchronous I/O in Async Example Code (README.md) #213.
  2. fix: account polling elapsed time on the monotonic clock (fix: account polling elapsed time on the monotonic clock #204, @yzxcj797, 2026-09-07). PollTimer measured elapsed time with time.time(), so an NTP step or DST change during a poll could fire the timeout early or never; now time.monotonic(), with tests. Fixes [BUG] Polling timeouts can misfire after wall-clock adjustments #203.

The protobuf 7 commit (#183) that this PR originally carried first landed on main through #223 and shipped in v1.21.0, so it has been dropped here; the branch is rebased onto the release.

If the maintainers prefer to merge the originals individually, this PR can be closed; it exists so the two do not need two separate review passes.

Verification (local, uv sync --locked, after the rebase onto v1.21.0)

  • ruff format --check and ruff check: clean. pyright: 0 errors.
  • pytest -n 4: 872 passed.

Fixes #213, #203. Supersedes #216, #204 if merged.

bodapatisaikrishna and others added 2 commits October 24, 2026 11:20
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

(cherry picked from commit 5bddbf1)
@deanrie
deanrie force-pushed the community/protobuf7-async-examples-poll-timer branch from 8a31b3f to b29ab76 Compare October 24, 2026 08:23
@deanrie deanrie changed the title Land three open community fixes: protobuf 7 support (#183), non-blocking input in async examples (#216), monotonic PollTimer (#204) Land two open community fixes: non-blocking input in async examples (#216), monotonic PollTimer (#204) Oct 24, 2026
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.

[BUG] Polling timeouts can misfire after wall-clock adjustments [BUG] Blocking Synchronous I/O in Async Example Code (README.md)

3 participants