Skip to content

test: wait on conditions instead of fixed sleeps (#1058) - #1111

Merged
napetrov merged 1 commit into
intel:mainfrom
antonwolfy:test/waiting-sleeps
Nov 22, 2026
Merged

napetrov merged 1 commit into
intel:mainfrom
antonwolfy:test/waiting-sleeps

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

Summary

#1058 asks to move the 22 sleeps and timers that scripts/check_test_timing.py counted in 13 files of tests/ to tests/waiting.py, starting with the files that flaked. On main the baseline scripts/test_timing_baseline.json still lists them: test_agent_sandbox.py 2, test_process.py 5, test_pid_state.py 2, test_repo_reach.py 2, test_writers_stop_on_rejected_save.py 2, and one each in test_benchflow_harness.py, test_docker_cmd.py, test_example_runner_processes.py, test_judge_sequential_design.py, test_mutate_changed.py, test_task_harnesses.py, test_tool_preference.py, test_typed_scorer.py. tests/test_repo_batch_lifecycle.py has none left, as the issue's own baseline says. The issue's text says tests/waiting.py and the checker exist only in open #1036; #1036 and #1060 are merged and both are on main.

The sleeps that waited for a child to die, a zombie state, a marker file or the harness start now wait on that condition with poll_until or wait_until. Sleeps that cannot become a wait stay with a # timing-ok: <reason>. The baseline is empty: python scripts/check_test_timing.py reports 0 sleep/Timer call(s) in 0 file(s).

Closes #1058

Changes

  • tests/test_process.py: _gone_soon and _wait_for are poll_until and wait_until calls (a file that never appears now fails with gave up after 10.0 s waiting for <path> to be written). The two interrupt tests that slept 0.3 s before raising KeyboardInterrupt now interrupt once the child has written the marker its SIGTERM handler writes, so the interrupt lands inside the grace on a slow runner too.
  • tests/test_pid_state.py: the two wait loops for the child's cmdline and for the zombie state are wait_until calls.
  • tests/test_repo_reach.py: the wait for the harness pid file is poll_until, with the same assertion message as before.
  • tests/test_agent_sandbox.py, tests/test_example_runner_processes.py, tests/test_mutate_changed.py, tests/test_task_harnesses.py, tests/test_benchflow_harness.py: loops that slept until a pid was gone are poll_until or wait_until; the benchflow one fails with gave up after 5 s waiting for the child of the timed-out bench process to be gone.
  • tests/test_writers_stop_on_rejected_save.py: the wait for the .rejected file is poll_until.
  • Kept with # timing-ok and a reason: test_repo_reach.py (the killed helper must not have written its marker 3 s later) and test_agent_sandbox.py (the surviving child would write its marker after 4 s) are checks that nothing happened, and test_process.py (the SIGHUP changed nothing); test_judge_sequential_design.py is a jitter that shuffles thread order; test_tool_preference.py holds a worker back as the subject of the test; test_typed_scorer.py needs each call to take measurable time; test_writers_stop_on_rejected_save.py keeps the 0.2 s a run that went on would use to start a queued question; test_docker_cmd.py is a SIGINT timer that must land while the main thread blocks in open() of a FIFO, and nothing shows that it does.
  • scripts/test_timing_baseline.json: lowered with check_test_timing.py --update; all 13 files are dropped.
  • No changelog fragment: only files under dokimi/tests/ and dokimi/scripts/ change, and make ci-local asks for none.
  • The same cause at a site the checker does not count (__import__("time").sleep(0.05) in tests/test_container_agent.py) is tracked in check_test_timing: __import__("time").sleep(...) is not counted, so test_container_agent.py still polls with a fixed sleep #1110.

Risk

Test-only. A wait that gives up now ends in pytest.fail naming what it waited for instead of an AssertionError or a failed later assertion. No test is removed, no assertion dropped and no pytest.raises widened (scripts/check_test_narrowing.py: no existing test narrowed).

Testing

On Linux, at 772f3492 (on main 06341ca):

  • make ci-local: 38 passed, 0 failed, 14 skipped (steps that need a tool or a trigger this run lacks: semgrep, micromamba, the atheris fuzz run, the intel-ci matrix, the jobs that run only off a PR, the CLI-surface package step). 25979 tests passed, 19 skipped; the changed-lines coverage step reports no lines with coverage information, since only tests changed.
  • Each converted file passed five runs in a row: test_process.py and test_pid_state.py (89 tests), test_repo_reach.py (91), and the ten other files with test_check_test_timing.py (652).
  • Mutants: breaking the condition a converted wait polls for makes it fail with its text. test_pid_state.py::test_running_zombie_and_reaped_child_are_told_apart (cmdline never matches: gave up after 30 s waiting for the child to exec; zombie state never reached: ... waiting for the killed child to become a zombie), test_repo_reach.py::test_sigterm_to_the_cli_kills_the_harness_and_its_helper (pid file never seen: the harness never started), test_process.py (_wait_for never true: gave up after 10.0 s waiting for ... to be written; _gone_soon inverted: assert _gone_soon(...) fails), test_benchflow_harness.py::test_run_bench_kills_the_process_group_on_timeout (gave up after 5 s waiting for the child of the timed-out bench process to be gone), test_example_runner_processes.py::test_subprocess_background_job_is_killed_on_exit and test_task_harnesses.py::test_command_harness_leaves_nothing_of_the_agent_running (_gone_soon/_pid_gone never true: the pid assertion fails).
  • The flake did not show on main's code under any load tried, so this change is not shown to cure one here: ten parallel runs of the three flaky files (--timeout=20) passed 180 tests in each; 20 runs of test_pid_state.py and test_repo_reach.py beside 32 busy python -c "while 1: pass" processes (twice the 16 cores) passed 97 tests in each; 20 runs of test_process.py under the same 32 processes passed 83 tests in each; 20 runs of the two interrupt tests of test_process.py with the child's SIGTERM handler delayed by 0.6 s passed 2 in each, on main's code and at the tip alike, because after the interrupt the second wait still runs out the grace.
  • test_writers_stop_on_rejected_save.py is not shown to depend on its new wait: with poll_until(rejected.exists) replaced by a call that returns at once all 4 tests still pass, so the 0.2 s timing-ok sleep is what carries the test and the wait is slack there.
  • Not run: the other Python versions and a real CI runner.

Open questions

None.

Revert

A plain revert restores the fixed sleeps and the old baseline. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

Thirteen test files slept a fixed time or ran a timer to wait for a child process, a zombie state, a marker file or the harness start, and flaked on a loaded runner. They now wait with poll_until or wait_until from tests/waiting.py: the pid helpers poll until the pid is gone, the interrupt tests in test_process.py interrupt once the child has handled its SIGTERM instead of after 0.3 s, and the SIGTERM reach test waits for the harness pid file. A failed wait names what it waited for.

The sleeps and the one timer that stay carry a timing-ok reason: checks that nothing happened (the SIGHUP changed nothing, a killed helper wrote no marker), a thread-order jitter, a slow worker or slow call that is the subject of the test, the time a run that went on would use to start a queued question, and a SIGINT that has to land while the main thread blocks in open(), for which no event exists. The timing baseline is now empty.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner November 22, 2026 15:01
@antonwolfy antonwolfy self-assigned this Nov 22, 2026
@exai-bot

exai-bot commented Nov 22, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 14 selected item(s).

CI at 772f349: 20 passing, 3 skipped.

Review details
  • Commit reviewed: 772f349 against merge base 06341ca
  • Coverage: 14 files in 6 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 269k tokens (170k from cache), 14s
  • Tool calls: 19 (17 file_read, 1 ci_status, 1 code_search)
  • Test timing baseline: 1 file
  • Sandbox, Docker, and process lifecycle tests: 5 files
  • Benchmark and task harness tests: 2 files
  • Judge and typed scorer tests: 2 files
  • Repository mutation and rejected-save behavior tests: 3 files
  • Tool preference tests: 1 file

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.07%. Comparing base (06341ca) to head (772f349).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1111      +/-   ##
==========================================
- Coverage   96.08%   96.07%   -0.02%     
==========================================
  Files         461      461              
  Lines       60836    60836              
  Branches    10517    10517              
==========================================
- Hits        58457    58446      -11     
- Misses       1473     1480       +7     
- Partials      906      910       +4     

see 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving 772f349.
Checked: changed tests: 706 passed, pass on main too; full suite with main merged in: 37432 passed, its only failures are main's too; merges onto main.
Optional: 1 nit in line comments.

"tests/test_typed_scorer.py": 1,
"tests/test_writers_stop_on_rejected_save.py": 2
}
"files": {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, not blocking: The description says 22 sleeps and timers in 13 files; the removed baseline counts sum to 21.

Suggestion: Change 22 to 21 in the PR description.

Details

Input: the 13 files entries this diff removes: 2, 1, 1, 1, 1, 1, 2, 5, 2, 1, 1, 1, 2. Observed: they sum to 21. Expected: 21 in the description, which says 22.

@napetrov
napetrov merged commit 4ac46e3 into intel:main Nov 22, 2026
23 checks passed
@antonwolfy
antonwolfy deleted the test/waiting-sleeps branch November 23, 2026 09:57
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.

Tests: move the remaining fixed sleeps to tests/waiting.py

5 participants