Repository navigation
Description
Problem or Motivation
No rule refuses a real sleep. An audit hook recorded 177 s of real sleep in 629 tests in 96 files, in the 56% of the suite that the audit probed (measured). The ast-grep rule test-elapsed-upper-bound finds 6 of 9 elapsed-time forms and no sleep. src has 23 direct time.sleep calls outside src/devops_cli/core/clock.py.
Saving: It stops the 177 s of real sleep (measured) from coming back.
Found by the CI and test audit of 2026-11-11. The account runs at most 20 hosted jobs at one time (measured), so each job that does no work makes the queue of each pull request longer.
Proposed Solution & Architectural Design
- ruff already selects TID251, and
pyproject.toml:174has a banned-api table. Addtime.sleepwith a per-file ignore forsrc/devops_cli/core/clock.py, and move the 23 call sites todevops_cli.core.clock.sleep. - In the session floor (
tests/conftest.py), addsys.addaudithookfor the standard-librarytime.sleepaudit event (PEP 578). Fail a test that has more than 0.25 s of real sleep, unless it has a mark.
Risk: Tests that still sleep fail, for example the process stop waits in tests/commands/test_ci.py (13.0 s in 1,297 short sleeps). Mark them or route them through the clock.
Target Subsystem
SDLC, Git & PR Governance (pyproject.toml, tests/conftest.py, src/devops_cli/core/clock.py).
Existing Tool Considered
ruff TID251 (banned-api) covers src. No open tool fails a test on a real sleep through the audit event, so the floor part is built: about 30 lines and one floor test (estimated), about 20,000 tokens and 2 hours.
Acceptance Criteria
- ruff fails on a new
time.sleepinsrc. - A probe test that sleeps 1 s for real fails with a clear message.
- The full suite passes with the guard.
Dependencies
Depends on #4466, #4459 and #4666.
Alternatives check of 2026-11-13: partly.
Tool: pytest-fail-slow (https://pypi.org/project/pytest-fail-slow), MIT License, last activity 2024-06-01, not maintained.
Proposed design
Problem statement
Ban real sleeps in the test suite. No rule refuses a real sleep today: an audit hook recorded 177 s of real sleep in 629 tests in 96 files, and src holds 20 direct time.sleep call sites outside src/devops_cli/core/clock.py (a scan of this base; the issue counts 23). The change bans time.sleep with the ruff TID251 banned-api table of pyproject.toml (pyproject.toml:192), with no per-file ignore, because the project's own gates refuse one; the one real call stays in src/devops_cli/core/clock.py under a reasoned # noqa: TID251 with the src noqa: TID251 ceiling at 1. The other src waits move to devops_cli.core.clock.sleep, the two gh-write tests of tests/commands/test_pr_update.py take the clock fake, and the tests that poll a real child process declare a new real_sleep mark. A floor guard in tests/conftest.py fails a test whose real sleep passes 0.25 s unless it declares that mark.
Acceptance criteria
Requirement: Ruff bans time.sleep in src
The ruff TID251 banned-api table in pyproject.toml SHALL name time.sleep, and no per-file-ignore entry of pyproject.toml SHALL waive TID251.
Scenario: The ban carries no per-file ignore
- WHEN a test reads the banned-api table and the ruff per-file-ignore tables from
pyproject.toml - THEN the banned-api table names
time.sleep, and no per-file-ignore entry names TID251
Requirement: The clock seam holds the one recorded waiver
src/devops_cli/core/clock.py SHALL be the only module that calls time.sleep, and its call SHALL carry a # noqa: TID251 comment whose reason names the clock seam, with the src noqa: TID251 ceiling of DEFAULT_SUPPRESSION_CEILINGS set to 1.
Scenario: The one waiver is recorded
- WHEN a test counts the
src noqa: TID251suppressions of the tree and reads their ceiling - THEN the count is 1 and the ceiling is 1
Requirement: The src tree waits through the clock
Every wait in src outside src/devops_cli/core/clock.py SHALL call devops_cli.core.clock.sleep and SHALL NOT call time.sleep.
Scenario: No direct time.sleep stays in src
- WHEN a test scans the modules of
srcfor a directtime.sleepcall - THEN the only module that calls
time.sleepissrc/devops_cli/core/clock.py
Requirement: The floor refuses a real sleep
The test floor SHALL fail a test whose real sleep passes 0.25 s, unless the test declares the real_sleep mark.
Scenario: A one-second probe fails
- WHEN a probe test calls
time.sleep(1.0)and the floor runs it - THEN the run fails, and the message names the real sleep and the 0.25 s budget
Requirement: The floor allows a declared real sleep
The test floor SHALL pass a test that declares the real_sleep mark, and pyproject.toml SHALL declare that mark in its pytest markers table.
Scenario: A marked probe passes
- WHEN a probe test declares the
real_sleepmark and callstime.sleep(1.0) - THEN the floor passes the probe test, and the markers table of
pyproject.tomlnamesreal_sleep
Requirement: The floor sees no sleep on the fake clock
The test floor SHALL record no real sleep for a test that requests the clock fixture.
Scenario: A probe on the fake clock passes
- WHEN a probe test requests the
clockfixture and callstime.sleep(1.0) - THEN the floor records no real sleep and passes the probe test
Requirement: The floor charges a sleep to one test
The floor SHALL attribute each real sleep to the test that caused it.
Scenario: Only the sleeping test fails
- WHEN one test sleeps 0.3 s for real and the test after it sleeps not at all
- THEN only the first test fails for real sleep
Requirement: The process-wait tests declare the mark
Every test that polls a real child process through tests/support/waits.py SHALL declare the real_sleep mark.
Scenario: The signal tests carry the mark
- WHEN a test reads the marks of the tests of
tests/commands/test_ci.pythat wait throughwait_while_running - THEN each of them declares
real_sleep
Requirement: The pr update tests record no real sleep
Every test of tests/commands/test_pr_update.py SHALL record no real sleep above the floor's budget, so each test that scripts a gh write SHALL request the clock fixture or gh_edge.
Scenario: The write interval of the rate limiter waits on the fake clock
- WHEN the floor runs the tests of
tests/commands/test_pr_update.pythat script the gh writes - THEN no test of that module fails for real sleep
Requirement: The suite passes with the floor
The full test suite SHALL pass with the floor guard in place.
Scenario: The test row is green
- WHEN the test row of the gate runs the whole suite with the guard installed
- THEN the row passes and no test fails for real sleep
Existing Tool Considered
The check of 2026-11-13 found pytest-fail-slow (https://pypi.org/project/pytest-fail-slow, MIT License): it fails a test that runs longer than a configured duration, and its fail_slow marker lets a known slow test through. The check found no PyPI release after 2024-06-01; the repository's last commit is 2026-10-11 (https://github.com/jwodder/pytest-fail-slow, fetched 2026-11-14). It lacks the 0.25 s sleep budget, a sleep-specific message, the static ban (ruff TID251 gives that part) and the audit-event hook. No open tool fails a test on the standard-library time.sleep audit event. So the floor part is built: about 30 lines and one floor test, about 20,000 tokens and 2 hours.
Key questions
- Which open, maintained tool or library covers the need to refuse a real sleep in a test?: No tool covers the whole need. pytest-fail-slow fails a test on its whole duration and its
fail_slowmarker lets a known slow test through, so it gives no 0.25 s sleep budget, no sleep-specific message and no audit hook, and a short sleep inside a long test passes it. The check of 2026-11-13 found no PyPI release after 2024-06-01, and the repository's last commit is 2026-10-11. pytest-timeout is already in the project and fails only a hang at its 600 s bound. The floor part is therefore built: about 30 lines and one floor test, about 20,000 tokens and 2 hours. (best practice) [sources: https://pypi.org/project/pytest-fail-slow, https://github.com/jwodder/pytest-fail-slow, pyproject.toml:229, tests/support/config_write_guard.py:87]- Chosen: Build the audit-hook floor. No tool reads the
time.sleepaudit event, and the need is a sleep budget with a sleep-specific message. The floor already installs PEP 578 hooks (sys.addaudithookintests/support/config_write_guard.py:87), and the 4666 probe measured thetime.sleepaudit event. - Rejected: Adopt pytest-fail-slow for the duration rule. It measures the whole test duration, so a short sleep inside a long test passes and a slow test that never sleeps fails. The check found no PyPI release after 2024-06-01.
- Rejected: Reuse pytest-timeout. It fails a test that hangs at the 600 s hang bound (
pyproject.toml:233), not one that sleeps 0.3 s.
- Chosen: Build the audit-hook floor. No tool reads the
- Where does the static ban on
time.sleepinsrclive, and how does the one seam keep its real call?: In the ruff TID251 banned-api table ofpyproject.toml, which already holds the socket bans, withtime.sleepadded and no per-file ignore. The project's own gates refuse a per-file ignore that waives TID251: the lint row requireslinter.per_file_ignoresto resolve to{}, the construct gate reports such a waiver as an escape, theper-file-ignoresceiling is 0, and the owner's 2026-10-22 decision rules out per-file-ignores for findings. The one real call insrc/devops_cli/core/clock.pytherefore stays under a# noqa: TID251comment that names the seam, and thesrc noqa: TID251ceiling goes from 0 to 1 with the reason recorded in the change's proposal, as the ceiling guard allows;src/devops_cli/github/rate_limiter.py:240holds the same shape of one reasoned# noqa: SIM115insrcwith a ceiling of 1. (best practice) [sources: pyproject.toml:192, tests/gate/ruff_config.py:99, tests/gate/construct_gate.py:366, tests/invariants/test_architectural_invariants.py:143, tests/invariants/test_architectural_invariants.py:1405, openspec/changes/archive/2026-10-29-1876-ruff-nesting-cap/design.md:18, src/devops_cli/github/rate_limiter.py:240, tests/invariants/test_architectural_invariants.py:127]- Chosen: Ruff TID251 with no per-file ignore, and the seam's call under a reasoned
# noqa: TID251with the ceiling at 1. The lint row pinslinter.per_file_ignoresto{}and the construct gate reports a per-file ignore that waives TID251, so the ban must carry no per-file ignore; the ceiling guard allows a raised ceiling with a recorded reason, and the project already keeps one reasoned ruff noqa insrcwith a ceiling of 1. - Rejected: Ruff TID251 with a per-file ignore for
src/devops_cli/core/clock.py. Refused by the project's gates:tests/gate/ruff_config.py:99requireslinter.per_file_ignoresto be{},tests/gate/construct_gate.py:374-377reports a per-file ignore that waives TID251 as an escape, the per-file-ignores ceiling is 0, and the owner's 2026-10-22 decision rules it out. - Rejected: An ast-grep rule under
.ast-grep/rules/. Rule-levelignoresis outside the allowlist (tests/gate/construct_gate.py:291-292), and the rule cannot name the one allowed module; ruff resolvesimport time as tandfrom time import sleep, which the ast-grep pattern does not. - Rejected: A scan of the
srctree in adevops cirow. Ruff TID251 already covers the need (AGENTS.md rule 3), and the scan is code the project builds and keeps.
- Chosen: Ruff TID251 with no per-file ignore, and the seam's call under a reasoned
- How does the floor record a real sleep and charge it to one test?: A session-scoped
sys.addaudithookrecords eachtime.sleepaudit event, as the floor already installs PEP 578 hooks for file writes. A function-scoped autouse fixture reads the total before the test and after it and fails the test when the difference passes 0.25 s; it reads the mark throughrequest.node.get_closest_marker, as the floor readsbwrap. Thetime.sleepaudit event exists and the 4666 probe found one stack for every real sleep. (best practice) [sources: tests/conftest.py:641, tests/conftest.py:698, tests/support/config_write_guard.py:87, openspec/changes/archive/2026-11-12-4666-pace-mutations-through-the-clock-seam/proposal.md:29, tests/support/fakes/clock.py:90]- Chosen: Audit hook and a per-test window. The hook sees every
time.sleepcall, also one that a module bound at import, and the shape matches the network and process guards of the floor. - Rejected: Monkeypatch
time.sleepduring the test. A module that boundtime.sleepat import keeps the original function, so the patch misses the call. - Rejected: Measure the duration of each test. A slow test that sleeps not at all would fail, and the failure would name no sleep.
- Chosen: Audit hook and a per-test window. The hook sees every
- Which mark lets a test sleep for real?: A new pytest mark,
real_sleep, declared in themarkerstable ofpyproject.tomland read by the floor throughrequest.node.get_closest_marker. The test declares it and the floor passes the test whatever its real sleep. (best practice) [sources: pyproject.toml:241, tests/conftest.py:703]- Chosen: A new mark,
real_sleep. The floor must tell an allowed wait from a defect, and it already reads marks by name. - Rejected: Reuse the
livemark.livenames a real local tool binary that a test may start (docs/TESTING.md:73), and a live test needs no real sleep.
- Chosen: A new mark,
- Which module holds the one allowed
time.sleepcall insrc?:src/devops_cli/core/clock.py:sleepthere is the one place insrc/devops_clithat supplies the real wait, the target thatdocs/TESTING.md:153names. Each directtime.sleepcall site insrcmoves todevops_cli.core.clock.sleep, and the seam keeps the one real call under the recorded# noqa: TID251. (best practice) [sources: src/devops_cli/core/clock.py:8, docs/TESTING.md:153, docs/adr/0007-tests-double-only-process-edges.md:17]- Chosen: Route each call site through
devops_cli.core.clock.sleep. The module is the one seam for waiting, and the one recorded waiver names it. - Rejected: Keep the calls and add a waiver for each site. A waiver for each site hides a new direct call in those files, and the per-file-ignore route is refused outright.
- Chosen: Route each call site through
- Which tests fail the 0.25 s guard, and how does the change repair them?: Two tests of
tests/commands/test_pr_update.pyonorigin/main2bd87bc:test_pr_edit_fallback_patch_title_body_base_milestone(line 512) andtest_pr_edit_fallback_milestone_failure_fails_with_message(line 598). They request onlycliandprocess_fake, so the write interval of the rate limiter calls the realtime.sleep; the reply measured 3.12 s and 3.09 s, and 0.43 s and 0.28 s withClockFake. Each takesclock: ClockFake, or moves togh_edge, which requestsclock. The change to the file is small, and if refactor(pr): devops pr update acts only on a failed check #4674 deletesdevops pr updatefirst, the two tests are gone and the change leaves them alone. (best practice) [sources: tests/commands/test_pr_update.py:512, tests/commands/test_pr_update.py:598, tests/support/gh_process.py:35, tests/support/fakes/clock.py:80, openspec/changes/archive/2026-11-12-4666-pace-mutations-through-the-clock-seam/design.md:13, openspec/changes/archive/2026-11-12-4670-push-gate/proposal.md:13]- Chosen: Add
clock: ClockFaketo the two tests. The reply measured the real sleep and the fake-clock call times, and theclockfixture replaces both the seam andtime.sleep. - Rejected: Move the two tests to
gh_edge.gh_edgerequestsclockand works, but the two tests script gh writes of their own, so the reply gives this as the second fix. - Rejected: Declare
real_sleepon the two tests. Their sleep is the rate limiter's write interval, a wait the fake clock can answer, so a mark would hide a real defect and keep 6 s of real sleep.
- Chosen: Add
- Which tests keep a real sleep, and why?: The tests that wait for a real child process. The signal tests of
tests/commands/test_ci.pypoll the child throughwait_while_running, which waitsPOLL_INTERVAL_SECONDS(0.01 s) between reads; the reply recorded 13.0 s in 1,297 such sleeps. A fake clock cannot serve a wait on a real process, anddocs/TESTING.md:160keeps that wait unbounded, so those tests declare thereal_sleepmark. (best practice) [sources: tests/support/waits.py:35, tests/support/waits.py:60, tests/commands/test_ci.py:2690, docs/TESTING.md:160, docs/adr/0007-tests-double-only-process-edges.md:30]- Chosen: Declare the
real_sleepmark on the tests that wait for a real process. The wait on the real process is the point of the test, and the mark records that decision. - Rejected: Route the wait helper through
devops_cli.core.clock.sleep. A wait on a real child process reads the wall clock, and a fake clock would return at once with no wait. - Rejected: Make the poll interval of
wait_while_runninglonger. It changes how fast a passing test sees its event and gives no sleep budget; the guard still charges the poll sleeps.
- Chosen: Declare the
- Does this item still wait on fix(test): bootstrap-k8s test waits 45 s for the Docker poll #4466, fix(test): refine failure tests wait 60 s on real retries #4459 and fix(github): pace mutations through the clock seam #4666?: No. Each is delivered: their OpenSpec changes are archived (
2026-11-11-4466-bootstrap-k8s-test-waits-45-s,2026-11-11-4459-refine-failure-tests-wait-60-sand2026-11-12-4666-pace-mutations-through-the-clock-seam), and the reply cites the merged PR fix(github): pace mutations through the clock seam #5063 of fix(github): pace mutations through the clock seam #4666, which already routes the rate limiter's waits through the seam. Sodependenciesis empty. [sources: openspec/changes/archive/2026-11-11-4466-bootstrap-k8s-test-waits-45-s/proposal.md, openspec/changes/archive/2026-11-11-4459-refine-failure-tests-wait-60-s/proposal.md, openspec/changes/archive/2026-11-12-4666-pace-mutations-through-the-clock-seam/proposal.md, openspec/changes/archive/2026-11-12-4666-pace-mutations-through-the-clock-seam/tasks.md] - How many direct
time.sleepcall sites doessrchold outside the seam?: 20, not the 23 of the issue. A scan of the tree fortime.sleep(lists 20 call sites undersrcoutsidesrc/devops_cli/core/clock.py, for examplesrc/devops_cli/ai/chaos/injector.py:129,src/devops_cli/commands/pr.py:1824andsrc/devops_cli/watchers/live_resource.py:45; the 21st hit insrcis the seam itself,src/devops_cli/core/clock.py:9. [sources: src/devops_cli/ai/chaos/injector.py:129, src/devops_cli/ai/client/structured.py:251, src/devops_cli/commands/pr.py:1824, src/devops_cli/watchers/live_resource.py:45, src/devops_cli/core/clock.py:9]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 11, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.(tests)scope of the title gives the scope.It saves 177 s of CI time and prevents regression, but does not block a release.It stops 177 s of wasted test time and prevents new real sleeps from entering the suite.It needs a ruff config change, 23 call-site moves, and about 30 lines of audit hook code.Both eliminate real sleep in tests, but #4666 routes one call site through the clock seam while the candidate adds a general ruff rule and an audit hook guard.dan-petty commentedon Nov 12, 2026
Two tests still sleep for real after #5063
PR #5063 (for #4666) sends the waits of the rate limiter through
devops_cli.core.clock.sleep. A test that requests theclockfixture, orgh_edge, which requestsclock, does not wait for real.Two tests in
tests/commands/test_pr_update.pyrequest onlycliandprocess_fake. They script gh writes (gh pr editand twogh api --method PATCHcalls). Thus the write interval of the rate limiter callstime.sleepfor real.origin/main2bd87bc)clock: ClockFaketest_pr_edit_fallback_patch_title_body_base_milestone(512)test_pr_edit_fallback_milestone_failure_fails_with_message(598)Command:
uv run pytest -p no:cacheprovider --durations=0 --no-cov -n0 <the two node IDs>, on a worktree atorigin/main2bd87bc.The 0.25 s guard of this issue will fail these two tests. The fix: add
clock: ClockFaketo the parameters of the two tests, or move them togh_edge. I measured the first fix in the table above. If the deletion ofdevops pr updateremoves these two tests first, do not change them.This gap is the open part of the first acceptance criterion of #4666: "An audit hook records 0 real sleep in
tests/commands/test_pr_*.py".devops-cli-service commentedon Nov 14, 2026
Alternatives check: partly
Reason: The searches found pytest-fail-slow, an open, maintained pytest plugin that fails any test whose wall-clock duration exceeds a configured threshold, so it would fail the 1 s sleep probe and can allow named slow tests through markers. It measures whole-test duration rather than real sleep, so it does not give the 0.25 s sleep budget, a sleep-specific message, or the static ban on
time.sleep(which ruff TID251 already provides), and no tool that fails a test on the standard-library sleep audit event was found.Tool: pytest-fail-slow (https://pypi.org/project/pytest-fail-slow)
Covers:
Lacks:
time.sleepinsrc(ruff TID251 already does that part)devops_cli.core.clock.sleepTools considered:
Searches run:
Sources:
Checked on 2026-11-13. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 14, 2026
Status set to Ready at 0410772 (see proposed design in issue body).
fix(tests): refuse real sleeps in tests
fix(tests): refuse real sleeps in tests
fix(tests): refuse real sleeps in tests
fix(tests): refuse real sleeps in tests
fix(tests): refuse real sleeps in tests
devops-cli-service commentedon Nov 18, 2026
Released in v0.179.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.179.0
devops-cli-service commentedon Nov 18, 2026
Live since 2026-11-18 20:24 UTC