Repository navigation
Description
Problem
The real-sleep guard of #4669 (refuse_real_sleeps in tests/conftest.py) adds the seconds of each time.sleep call during a test, and fails the test above 0.25 s. wait_until in tests/support/waits.py polls its condition with a real sleep of 0.01 s (POLL_INTERVAL_SECONDS) until the condition holds, within THREAD_HANDOFF_BOUND_SECONDS. So each poll counts toward the budget of the guard. When a thread handoff takes more than 0.25 s on a loaded runner, the test fails, although wait_until gives the handoff a generous bound on purpose (#1664).
Evidence: on PR #6692 (head f78aa20, 2026-11-21), Tests & Coverage shard 4 of 5 failed with one error. The PR does not change this module.
ERROR tests/github/test_github_session.py::test_closing_a_session_cancels_a_request_waiting_out_a_retry - Failed: real sleep of 0.45 s exceeded 0.25 s budget; fake the clock with the `clock` fixture or mark the test with `@pytest.mark.real_sleep`
The test fakes the retry wait (_sleep_on_the_loop, an anyio sleep). Its only real sleeps are the polls of wait_until(lambda: bool(github_api.sent)). 18 test files call wait_until, so each of them can fail in the same way under load.
Expected
A test that waits for a thread handoff with wait_until passes under load, and the guard still fails a test that sleeps real time where it could fake the clock. The budget of 0.25 s stays as it is.
Acceptance criteria
- A test shows that a
wait_untilwhose condition holds after more than 0.25 s of polling does not fail the real-sleep guard. - A test shows that a plain
time.sleepof more than 0.25 s in a test still fails the guard.
Dependencies
None. Related: #4669, #6317, #1664.
Alternatives check of 2026-11-21: none.
Tool: none found.
Reason: Searches found only clock-faking libraries (freezegun, time-machine) and no pytest plugin with a per-test real-sleep budget or a way to exempt a poll sleep; the guard is the repository's own conftest code.
Lacks:
- No per-test real-sleep budget
- No exemption for a wait helper's poll sleeps
- Fakes clocks instead of allowing a real handoff wait
Proposed design
Problem statement
The real-sleep guard in tests/conftest.py charges the poll sleeps of wait_until to the test's 0.25 s budget. A slow thread handoff then fails a test that only waits for the handoff. The change exempts the poll sleeps of wait_until and keeps the guard for every other real sleep.
Acceptance criteria
Requirement: wait_until polls stay off the real-sleep budget
wait_until SHALL poll with a real sleep that the real-sleep guard does not charge to the test's budget.
Scenario: A poll past the budget
- WHEN A test monkeypatches
tests.support.waits.POLL_INTERVAL_SECONDSto0.3and callswait_untilwith a condition that is false once and then true. - THEN The test passes, and
tests.support.sleep_budget.charged_seconds()returns0.0.
Requirement: A plain real sleep still fails the guard
The real-sleep guard SHALL fail a test whose time.sleep call takes its real-sleep total above 0.25 s.
Scenario: A plain sleep over the budget
- WHEN A
pytesterrun loads the real-sleep guard and executes a test that callstime.sleep(0.3)with no exemption active. - THEN The run reports one teardown error that matches
real sleep ofandexceeded 0.25 s budget.
Requirement: The exemption covers only wait_until polls
The real-sleep guard SHALL charge a real sleep that a test makes outside a wait_until poll to the test's budget.
Scenario: A sleep outside the exemption
- WHEN A test calls
time.sleep(0.05)with nowait_untilpoll active. - THEN
tests.support.sleep_budget.charged_seconds()returns a value of at least0.05.
Existing Tool Considered
The alternatives check in the issue body records verdict none and names no tool. No open, maintained tool covers a per-test real-sleep budget with an exemption for a poll helper. The change builds about 25 lines in tests/support/sleep_budget.py and the wrapper in tests/conftest.py, plus tests. Written cost: about 8,000 tokens to build, keep and fix that code, and about 2 hours elapsed.
Key questions
- Where do the polls of
wait_untilcharge the real-sleep budget?:refuse_real_sleepsintests/conftest.pywrapstime.sleepand adds each call's seconds to the test's total.wait_untilintests/support/waits.pysleepsPOLL_INTERVAL_SECONDSper poll. The guard reports the total at teardown, as the reply'sERROR at teardownshows. [sources: tests/conftest.py:793, tests/support/waits.py:37, tests/github/test_service_limits.py:1060] - How does the guard know that a sleep is a poll of
wait_until?:wait_untilenters a narrow thread-local exemption in a newtests/support/sleep_budget.pyaround each poll sleep. Thetime.sleepwrapper charges a sleep only when that exemption is not active. The module holds the budget, the thread-local flag,charged_seconds()andreset(). (best practice) [sources: tests/conftest.py:793, tests/support/waits.py:37]- Chosen: An explicit exemption context manager that only
wait_untilenters. It is narrow, it has one call site, the guard keeps charging every other sleep, and no test file changes. - Rejected: Detect the caller frame in the wrapper. A stack walk on every sleep is slow and fragile, and it exempts any sleep that a test makes through that module.
- Rejected: Mark each of the 18 test files with
@pytest.mark.real_sleep. It hides every real sleep in those tests, so the guard loses its value there, and it edits many files. - Rejected: Subtract the polling time from the total after
wait_untilreturns. It needs a second global counter that can drift, and it hides an over-budget sleep until after it happens.
- Chosen: An explicit exemption context manager that only
- When does the guard fail a test whose real sleeps pass the budget?: The guard fails at the teardown of the test, as the reply's
ERROR at teardownshows. The change keeps that timing. [sources: tests/conftest.py:793, tests/github/test_service_limits.py:1060] - How does the test show that a plain
time.sleepstill fails the guard?: Apytesternested run loads the real-sleep guard and executes a test that callstime.sleep(0.3)with no exemption. The run reports one teardown error with the budget message. (best practice) [sources: tests/conftest.py:793, tests/github/test_service_limits.py:1060]- Chosen: A
pytesternested run that loads the real guard. The guard fails at teardown, so a test cannot catch the failure around the sleep call; the nested run observes the real teardown error. - Rejected:
pytest.raises(pytest.fail.Exception)aroundtime.sleep(0.3). The guard reports the failure at teardown, not at the call, so the context manager does not catch it. - Rejected: Call the charge function directly. It does not show that a plain
time.sleepstill fails the guard.
- Chosen: A
- How does the test make one poll pass the budget without a long wait?: The test monkeypatches
tests.support.waits.POLL_INTERVAL_SECONDSto0.3.wait_untilreads the module constant at each call, so one real poll sleep passes the 0.25 s budget and the test costs 0.3 s. (best practice) [sources: tests/support/waits.py:37, tests/conftest.py:793]- Chosen: Patch
POLL_INTERVAL_SECONDSto0.3and keep the real sleep. The sleep goes through the realtime.sleeppath, and the test costs 0.3 s. - Rejected: Poll for 0.26 s at the real 0.01 s interval. It costs 26 polls, and its timing depends on the load of the runner.
- Rejected: Fake the poll sleep at a seam. The guard then sees no sleep, so the test cannot show that the guard exempts it.
- Chosen: Patch
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 21, 2026
The guard causes CI test shards to fail under load, which is a CI failure.Both concern the real-sleep guard in tests/conftest.py; #4669 added the guard and the candidate fixes a false positive in it.devops-cli-service commentedon Nov 21, 2026
Next step: the alternatives check records a verdict. See the section Proposed design of the body.
dan-petty commentedon Nov 21, 2026
One more test fails for this cause. CI run of PR #6697 (head 5b2d17a, a documentation-only change), job Tests & Coverage (shard 3 of 5), https://github.com/dan-petty/devops-cli/actions/runs/44955966509/job/137004044493:
ERROR at teardown of tests/github/test_service_limits.py::test_each_github_request_of_a_round_names_the_workers_repository_and_its_job_row[webhook] - Failed: real sleep of 0.30 s exceeded 0.25 s budgetThe test fakes the clock of the manager (
_manager(..., clock=_Clock()), line 1057) and waits withwait_until(lambda: len(seen) == 3)(line 1060), so the polls ofwait_untilare the real sleep that the guard counts.devops-cli-service commentedon Nov 21, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (10)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 21, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
4 remaining items
docs(openspec): plan #6696 Exempt wait_until polls from the sleep bud…
dan-petty commentedon Nov 22, 2026
One more test fails for this cause, in the CI run of PR #6719 (head 477d709, job Tests & Coverage (shard 1 of 5)):
ERROR tests/github/test_service_limits.py::test_a_suspended_installation_halts_the_service[gh-says-the-installation-is-suspended] - Failed: real sleep of 0.29 s exceeded 0.25 s budget. It is the second test of this file with the same cause (the first is in the comment above).devops-cli-service commentedon Nov 22, 2026
The draft pull request #6737 holds the final title and body. In mode
onofroadmap.fix_checks.mode, the watch row marks it ready when its checks pass, and a fix-checks Job repairs a failed check whose name gives the class test, lint or types. In each other case the watch row stops the item: another failed check, a cancelled check, a conflict, a fix-checks Job that ended with no repair, or another mode.Spend: 73 model requests, 2974229 input tokens, 28864 output tokens.
devops-cli-service commentedon Nov 22, 2026
Released in v0.192.1: https://github.com/dan-petty/devops-cli/releases/tag/v0.192.1
devops-cli-service commentedon Nov 22, 2026
Live since 2026-11-22 04:24 UTC