Skip to content

Codex device-poll tests: fake asyncio.sleep only on the test's own thread - #13457

Merged
danielhanchen merged 1 commit into
mainfrom
ci-codex-device-poll-sleep-scope
Oct 12, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci-codex-device-poll-sleep-scope

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

studio/backend/tests/test_openai_codex_subscription.py::test_device_poll_shape_structured_pending_slow_down_and_exchange timed out in (Python 3.13, l-r) on #13445, which only touched unrelated tests:

FAILED tests/test_openai_codex_subscription.py::test_device_poll_shape_structured_pending_slow_down_and_exchange - Failed: Timeout (>330.0s) from pytest-timeout.

At the timeout, the test thread was inside pytest's assertion repr (pprint.pformat) for that assert.

Cause: both device-poll tests (from #8511) do monkeypatch.setattr(codex_auth.asyncio, "sleep", fake_sleep). codex_auth.asyncio is the asyncio module itself, so this replaces asyncio.sleep for every event loop in the process, not just the poll under test. An event loop that an earlier test left running in the same xdist worker then gets the instant fake on every tick. It spins and appends to sleeps, sleeps == [1, 1, 6] fails, and rendering that list runs past the timeout. The product code is fine.

Reproduced on main: with one background event loop calling asyncio.sleep(0.01) during the test, it fails with assert [1, 1, 6, 0.01, 0.01, ...] == [1, 1, 6].

Fix

A _patch_poll_sleep(monkeypatch, record = None) helper, used by both tests. The fake records and returns at once only on the thread that installed it; any other thread's asyncio.sleep goes to the real one.

Verification

main this PR
with a background event loop running (repro) fails: sleeps flooded passes; the background loop sleeps for real
whole file 86 passed 86 passed

Sabotage, product changed, this PR's test: changing the slow_down backoff in openai_codex_auth.py from + 5 to + 4 fails with [1, 1, 5] == [1, 1, 6].

Formatted with the repo's ruff-format-with-kwargs hook.

…read

codex_auth.asyncio is the asyncio module, so patching its sleep replaced asyncio.sleep for every event loop in the worker. A loop left running by an earlier test then spun on the instant fake and flooded the recorded sleeps, and the assert's repr of that list ran past the 330 s pytest-timeout (seen on #13445). Route other threads to the real sleep.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T16:26:12.732966Z 1afbbd0 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 1afbbd0f16

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@danielhanchen
danielhanchen merged commit c6db48d into main Oct 12, 2026
@danielhanchen
danielhanchen deleted the ci-codex-device-poll-sleep-scope branch October 12, 2026 16:31
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.

1 participant