Repository navigation
Closed
Labels
Milestone
Description
Friction
- On 2026-10-18 the pre-commit hook failed on an unrelated change because
tests/test_server_service.py::test_a_budget_refusal_in_the_model_lane_holds_the_release_lane_tooraised_queue.Empty. It passed when rerun (30 of 30) and in the hook's next run. The host load average was 30 to 50, with severaldevops ciruns sharing 16 CPUs. - The same day,
Tests & Coveragefailed on pull request feat(github): the github session sends rest requests through gidgethub, paced, charged and classified by status and headers #1661 in GitHub Actions (4 workers, 10,609 tests) with one unrelated failure:tests/test_review_embeddings_unserved.py::test_once_the_model_answers_lookups_stop_taking_turns. Itsthreading.Barrier(WORKERS, timeout=2.0)(:201) broke because one worker's request did not arrive within 2 s, so one lookup failed (together.brokenwas True and 4 embedding requests arrived instead of 5). The same commit had passed the full gate locally. So this is not only a loaded-workstation problem: the hosted runner hits it too. - The service test waits at most 1 s for a worker thread to finish its round. Under that load a ready thread can wait longer than 1 s for a CPU, so the test fails although the code is right.
- A flaky failure in the pre-commit or pre-push gate costs a full rerun of the gate (5 to 13 minutes under load), and it teaches agents to rerun failures instead of reading them. The owner's rule is that CI gate speed is P0.
Evidence
Checked at release/v0.2.37 30b8fdd.
_Rounds.wait(tests/test_server_service.py:954-959) callsself.done.get(timeout=1.0)for each expected round, thenworker.wait_active(1.0)._Rounds.held(:961-966) callswait_active(1.0). About 36 calls in that file go through these helpers or through anEvent.wait(timeout=1.0)such as:155,:176,:428,:441,:460,:539,:544and:735.- Across
tests/, 38 waits on a thread, queue, event or future use a deadline of 2 s or less, in 11 files:test_server_service.py,test_ai_client_security.py,test_k8s_port_forward_daemon.py,test_roadmap_intake.py,test_rag_query_telemetry.py,test_roadmap_github_store.py,test_roadmap_run.py,test_k8s_service.py,test_ai_request_priority.py,test_ai_review_pool.pyandtest_review_embeddings_unserved.py. - Locally the Barrier test failed 5 of 26 current-tree full runs on 2026-10-18, at mean load 11-29. Two failures came at load 11-14 with no other suite running, so the suite's own 16 workers are enough to break a 2 s handoff. Each failure clears the gate's verdict and costs a rerun of about 200 s.
- A wait that expects its event returns as soon as the event happens, so a longer bound costs nothing when the test passes. Only a failing test waits the whole bound.
Remedy
- One named bound for waits that expect something to happen, for example
THREAD_HANDOFF_BOUND_SECONDS = 30.0, in one shared test-support module (with test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312's layout once it lands). Every wait that expects its event uses it. - A wait that checks nothing happens keeps a short window, but only where the test first waits for the workers to go idle, as
_Rounds.heldalready does, so a late event cannot slip past the check. - No retry or rerun plugin: the bound fixes the cause.
- Related: the per-test timeout draft (pytest-timeout) bounds a test that hangs; refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320 fakes wall-clock reads. Neither covers a real thread handoff.
Acceptance criteria
- Tests first: a test of the shared helper shows that a wait whose event fires after 1.5 s succeeds with the bound, and the same wait with a 1 s deadline fails.
-
grep -rnE '\.(wait|get|join|result|acquire|wait_active)\((timeout=)?(0?\.[0-9]+|1(\.0)?|2(\.0)?)\)' testsmatches only waits that check nothing happens, each one after an idle wait, and each one says so in a comment. - Every
threading.Barrier(..., timeout=...)undertests/uses the bound, starting withtests/test_review_embeddings_unserved.py:201. -
tests/test_server_service.pyandtests/test_review_embeddings_unserved.pyeach pass 20 runs in a row with-n logicalwhile two otherdevops ciruns share the host. - The suite's wall time is unchanged within noise.
Proposed design
Problem statement
Tests fail under load because they use short timeouts (1-2 seconds) when waiting for background threads to complete their work, but the threads can take longer than the timeout in a high-load environment.
Acceptance criteria
- Criterion 1: A shared helper function is created that uses a generous bound for waits expecting something to happen, and tests using this helper pass under load.
Verification: Run tests with-n logicalwhile two otherdevops ciruns share the host, ensuring 20 consecutive runs oftests/test_server_service.pyandtests/test_review_embeddings_unserved.pyboth pass. - Criterion 2: All waits in tests that expect an event to occur use a generous bound instead of 1-2 seconds.
Verification: Runninggrep -rnE '\.(wait|get|join|result|acquire|wait_active)\((timeout=)?(0?\.[0-9]+|1(\.0)?|2(\.0)?)\)' testsmatches only waits that check nothing happens, each one after an idle wait, and each one says so in a comment. - Criterion 3: Every
threading.Barrier(..., timeout=...)undertests/uses the generous bound instead of 2 seconds.
Verification: Verify thattests/test_review_embeddings_unserved.py:201and all other barriers in tests use a timeout greater than 2 seconds. - Criterion 4: The wall clock time for the test suite remains unchanged within noise after implementing the generous bounds.
Verification: Run the full test suite and measure its wall clock time, ensuring no significant increase compared to baseline.
Key questions
- What is the recommended bound for waits that expect something to happen?: A generous bound of 30.0 seconds is recommended for waits that expect an event to occur. (proposed)
- Which existing tests use short timeouts that are causing failures under load?: Tests in
tests/test_server_service.pyandtests/test_review_embeddings_unserved.pyare identified as using short timeouts (1-2 seconds) that cause failures under load. [sources: tests/test_server_service.py:954-959, tests/test_server_service.py:961-966, tests/test_review_embeddings_unserved.py:201] - How many files across the tests directory are using short timeouts?: 38 waits on threads, queues, events or futures use a deadline of 2 seconds or less in 11 files. [sources: tests/test_server_service.py, tests/test_ai_client_security.py, tests/test_k8s_port_forward_daemon.py, tests/test_roadmap_intake.py, tests/test_rag_query_telemetry.py, tests/test_roadmap_github_store.py, tests/test_roadmap_run.py, tests/test_k8s_service.py, tests/test_ai_request_priority.py, tests/test_ai_review_pool.py, tests/test_review_embeddings_unserved.py]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 18, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
The candidate is about improving test reliability by adjusting timeouts for thread synchronization.Flaky tests under load cause full reruns of the CI gate, violating the owner's rule that CI gate speed is P0.Fixing flaky tests improves developer productivity and CI reliability, especially under load conditions.The change involves modifying test code to use a shared bound for waits, requiring updates in multiple files.dan-petty commentedon Oct 18, 2026
Status set to Ready at 25e2cda (see proposed design in issue body).
dan-petty commentedon Oct 18, 2026
Amendment (2026-10-18): folded here by intake under the agent filing quota
The cycle's agent filing allowance (#1153) was used, so
devops roadmap intakefiled nothing and named this item as the nearest. The candidate below is related work that can land with this item or be filed on its own in a later cycle. Candidate title: "fix(tests): test workers start no idle OpenBLAS threads, so a full suite holds 240 fewer tasks against pids.max".Friction
pthread_createfailure seen in one agent's failed pre-push shows the cgroup limit was reached; when it is, thread and process creation in tests can fail and the gate has to be run again. Whether that failure, rather than a timing flake, failed that push's test row is not shown.git pushdoes nothing:devops ci's environment allowlist drops it.Evidence
Checked at release/v0.2.37 30b8fdd.
tests/test_ci_repeat.py:19importsnumpy.randomat module level, so every worker loads numpy while collecting. With that file ignored, a full collection loads no numpy and the process holds 1 task instead of 16.import numpy, 31 afterimport scipy.linalg; withOPENBLAS_NUM_THREADS=1, 1 in each case.src/devops_cli/core/process.py:45-102has noOPENBLAS_orOMP_entry, sobuild_subprocess_env()drops both.Remedy
os.environ.setdefault("OPENBLAS_NUM_THREADS", "1")at the very top of tests/conftest.py, before anything imports numpy. This covers the gate, the pre-commitci testhook and direct pytest runs, and child processes inherit it.OPENBLAS_NUM_THREADSis OpenBLAS's documented setting.tests/test_ci_repeat.py:19into the test that uses it.Acceptance criteria
import numpyin a fresh subprocess started with the test environment leaves the process at 1 task (read from/proc/self/statusThreads:)./proc).test(cli): tests wait for a background thread with one generous bound…
dan-petty commentedon Oct 19, 2026
What changed
#1701, merged into
release/v0.2.37as f66a8e3.23 file(s) changed.
How it was verified
Check runs at 2f1ebad:
Acceptance Criteria of
docs/agent/tasks/task-1664-thread-handoff-bound.md:test_a_wait_for_an_event_that_fires_after_a_second_and_a_half_fails_with_a_one_second_deadlinedriveswait_untilon a clock only its sleeps move, with the condition true from 1.5 s, and a one-second deadline returns False;test_a_wait_for_an_event_that_fires_after_a_second_and_a_half_succeeds_with_the_boundsees an event a real timer sets after 1.5 s within the bound.test_a_poll_that_oversleeps_its_deadline_does_not_count_a_later_eventfailed on the earlierwait_until, which read the condition before checking the deadline (assert (True, True) == (False, True)).test_a_condition_that_already_holds_is_read_once_and_not_waited_forasserts no sleep; await_untilthat slept before its first read failed it ((True, 1, [0.01]) == (True, 1, [])), and one that ignored its deadline for a second failed the one-second case. With the bound set to 1.0 the bound case failed (assert False is True).grep -rnE '\.(wait|get|join|result|acquire|wait_active)\((timeout=)?(0?\.[0-9]+|1(\.0)?|2(\.0)?)\)' testsmatches only the four windows that check nothing happens, each after an asserted wait for the competing thread and each with its comment.threading.Barrier(..., timeout=...)undertests/uses the bound: the one intests/test_review_embeddings_unserved.pyand the new one intests/test_server_service.py.src: an earlyreturninShell._terminate_process_groupfails both fix(ai): agent toolset instructions, deferred-tool context, the sampling-model stub, harness memory and shell process groups #958 tests, and SIGKILL replaced bypassfailstest_stop_command_kills_a_member_that_ignores_sigterm; one lock around every Service round fails the cross-blocking check ((202, True, [0]) == (202, True, [1])); a per-repository lock failstest_a_webhook_runs_the_release_lane_while_the_model_lanes_round_is_blocked(model_blockedandmodel_releasedFalse); and aclose()that no longer shuts the response failstest_closing_a_followed_log_ends_a_read_blocked_on_a_quiet_container(ended_by_shutdownFalse). Before, with each hold on its observer's bound, review saw the harness andclose()mutants pass, the single lock get past the cross-blocking check, and the per-repository lock pass 3 of 18 runs.tests/test_server_service.pyandtests/test_review_embeddings_unserved.pypassed 20 runs in a row with-n logicalwhile two full-suite runs looped beside them, each restarted as it ended (six runs, all passing), with other agents' work on the host: load average 22.9-65.0, mean 41.8, on 16 CPUs. The two concurrent runs were the gate's test row (pytest -n logical tests), not wholedevops ciruns.git checkout <merge>^ && uv run pytest -n logical -q tests, thengit checkout <merge> && uv run pytest -n logical -q tests, twice each and alternating; the two means should differ by less than the runs of one commit do. Measured before the rebase, against 83939e6, with other agents' work holding the load average at 14-34, the suite took 372 s and 253 s at 83939e6 and 312 s and 401 s with this change, alternating. Runs of one commit differed by 90-120 s, more than the 44 s between the means, so that host gave no fair comparison.tests/test_openblas_worker_threads.pystarts a process at the repository root withOPENBLAS_NUM_THREADSremoved from its environment, which importstests.conftestand then numpy, and readsThreads:from/proc/self/status. It reads 1, and 16 with numpy imported above the setdefault (assert '16' == '1'); it also passes withOPENBLAS_NUM_THREADS=4exported, which the conftest's setdefault keeps./procevery 50 ms: 17 threads in each worker before (272 in all); after, 2 in each worker, briefly 3 in some (33 in all at the peak) while OpenTelemetry's resource detection runs. That thread is theThreadPoolExecutoringet_aggregated_resources(opentelemetry/sdk/resources/__init__.py), started when collection importsdevops_cli.ai.agents.agent, which loads pydantic_ai and logfire; it ends once detection returns. So the amendment's "at most 2 tasks per worker at collection" is not met for that moment: moved to fix(telemetry): devops-cli metrics reach prometheus in one hop, a late sample no longer drops a whole batch, and the collector runs only what its pipelines use #1132 (amendment of 2026-10-19).test_a_served_lookup_looks_up_no_service_hostrecordssocket.getaddrinfo. Before the fixture answered the collection check it failed with sixexample.comlookups and took 3.05 s; it now finds none.tests/test_review_embeddings_unserved.pyalone (-n0) took 5.9 s before and 2.9 s after,test_once_the_model_answers_lookups_stop_taking_turns3.08 s before and 0.03 s after.feat(release): v0.2.37 (#1720)