Repository navigation
Description
Problem Description
decide_all of src/devops_cli/roadmap/decision_step.py can hang for good, and pytest-timeout (600 s, signal) does not stop it. On 2026-11-11 a full local run (uv run pytest -p no:cacheprovider --durations=60 at origin/main 776054b, 16 xdist workers, load average 35 to 50) held worker gw14 on tests/roadmap/test_roadmap_decision_step.py::test_the_requests_are_answered_in_order_and_each_is_one_request for more than 16 minutes at about 5% CPU. Every other worker was idle. The run ended only when the worker was killed with SIGABRT. The full gate of the same hour hit its 1800 s test timeout, maybe for the same cause.
The traceback that faulthandler printed at SIGABRT:
- Main thread:
decide_all(decision_step.py:174), inThreadPoolExecutor.__exit__→shutdown→Thread.join. - Pool thread:
_decide_one(decision_step.py:160) →asyncio.run→run_until_complete→_run_once→selectors.select, with no event that ends the wait.
The pool runs each request in its own thread with its own event loop (asyncio.run), and the test passes one model (jev.model) to all of them. A model with one httpx2.AsyncClient shared by event loops in other threads is a possible cause: an async connection pool is bound to the loop that first used it.
The test passes alone: uv run pytest tests/roadmap/test_roadmap_decision_step.py gives 10 passed serially and with -n 4. So the hang depends on the order of the tests or on timing under load.
Reproduction Steps
- Run the full suite with xdist on a loaded host:
uv run pytest -p no:cacheprovider. - When the run stops near its end, list the workers (
ps --ppid <pytest pid> -o etime,pcpu,args) and find the one that stays ontest_the_requests_are_answered_in_order_and_each_is_one_request. - Send
kill -ABRT <worker pid>and read the traceback in the output.
Expected vs Actual Behavior
Expected: decide_all returns, or fails within its timeout of 30 s, and pytest-timeout stops any test after 600 s.
Actual: the worker waits for good, and pytest-timeout does not stop it. A CI shard with this hang runs until its 30-minute job timeout.
Environment Diagnostics
Devcontainer on WSL2, 16 CPUs, CPython 3.14.10, pytest-xdist 3.8.0, pytest-timeout 2.4.0.
Logs, Traces, or Terminal Output
Found by the measurement of #4405.
Pre-Submission Checklist
- I have verified that no sensitive credentials, private keys, or internal tokens are contained in this issue report.
- I have checked existing issues and pull requests to ensure this is not a duplicate.
Proposed design
Problem statement
decide_all can hang forever when a caller passes one decision model to several requests. Each request runs in a thread with its own event loop. A model with one httpx2.AsyncClient can be bound to the first loop. pytest-timeout cannot stop the worker. The fix sends every request on one event loop and enforces the timeout.
Acceptance criteria
Requirement: One event loop for all requests
decide_all SHALL run every request on one event loop in the calling thread.
Scenario: A shared model records the running loop
- WHEN decide_all receives three requests and one model that records asyncio.get_running_loop and the thread name.
- THEN Every recorded loop is the same loop, and no request runs in a ThreadPoolExecutor thread.
Requirement: Timeout ends a stuck request
decide_all SHALL raise TimeoutError when the requests do not finish within timeout.
Scenario: A model waits forever
- WHEN A fake model waits forever and decide_all runs with timeout=0.2.
- THEN decide_all raises TimeoutError within 2 seconds and returns control to the caller.
Requirement: First error raises
decide_all SHALL raise the first request error so the step can fail open.
Scenario: A request fails with HTTP 503
- WHEN A fake model raises ModelHTTPError with status 503 for a request.
- THEN decide_all raises ModelHTTPError with 503 in its text.
Requirement: Response order
decide_all SHALL return the responses in the order of requests.
Scenario: Three requests return different answers
- WHEN decide_all receives requests for a, b, and a and b.
- THEN The probabilities are {'a': 0.7}, {'b': 0.1}, and {'a': 0.7, 'b': 0.1} in that order.
Requirement: A built model closes on its request loop
When decide_all builds a model for a request, it SHALL close that model's httpx2.AsyncClient on the same event loop that ran the request.
Scenario: The fake built model records its close loop
- WHEN decide_all builds a fake model for one request and the request completes.
- THEN The fake records that aclose ran on the same loop as decide.
Existing Tool Considered
No check has run. No open, maintained tool or library covers this internal concurrency defect. The change edits decide_all and its tests. The written cost is about 6,000 tokens to build, 2,000 tokens to keep and fix, and about 2 hours of elapsed time.
Key questions
- How can decide_all keep one shared model without crossing event loops?: Run all requests on one event loop in the calling thread. Remove ThreadPoolExecutor and use asyncio.gather. A model's async client then stays on the loop that first used it. (best practice) [sources: src/devops_cli/roadmap/decision_step.py:160, src/devops_cli/roadmap/decision_step.py:174, tests/roadmap/test_roadmap_decision_step.py]
- Chosen: One event loop with asyncio.gather. Keeps one loop for the shared model and removes cross-loop client use.
- Rejected: One thread for each request with a model for each request. A caller-supplied model cannot be cloned, and each thread still has its own loop.
- Rejected: One asyncio.run for each request in sequence. Each asyncio.run creates a new loop, so the shared client still crosses loops.
- Rejected: AnyIO task group. Adds a dependency for behavior that asyncio already provides.
- How does decide_all stop a request that never completes?: Wrap each request in asyncio.wait_for with the timeout inside the single loop. The outer timeout raises TimeoutError even when the model's own timeout does not fire. (best practice) [sources: src/devops_cli/roadmap/decision_step.py:160, src/devops_cli/roadmap/decision_step.py:174, tests/roadmap/test_roadmap_decision_step.py]
- Chosen: Outer asyncio.wait_for for each request. Adds a bounded wait that the event loop can cancel and report.
- Rejected: Rely on the model's timeout setting. The reported hang shows that the model timeout did not stop the wait.
- Rejected: A signal alarm in the calling thread. Signals are not reliable in threads and xdist workers.
- Rejected: A subprocess for each request. The cost is too high and it changes the model boundary.
- Should the public signature and return order of decide_all stay the same?: Yes. Keep the synchronous signature, the model argument, the model_name argument, the settings argument and the timeout argument. Return the responses in request order. (best practice) [sources: src/devops_cli/roadmap/decision_step.py:168, src/devops_cli/roadmap/decision_point.py, src/devops_cli/roadmap/intake/intake.py, src/devops_cli/roadmap/stage/stage_screen_eval.py, tests/roadmap/test_roadmap_decision_step.py]
- Chosen: Keep the synchronous signature and request order. All callers keep their current contract, and the tests keep their order check.
- Rejected: Make decide_all async. It breaks every caller and adds no benefit for this fix.
- Rejected: Return responses as they complete. It breaks the request-order contract and the current test.
- Which test shows the fix without a network or a loaded host?: Use a fake model that records the running loop and thread name. Use a second fake model that waits forever for the timeout test. Do not use a loaded xdist run as the regression test. (best practice) [sources: tests/roadmap/test_roadmap_decision_step.py]
- Chosen: A fake model records the loop and thread, and a blocking fake tests the timeout. It is deterministic, offline and fast.
- Rejected: Reproduce with 16 xdist workers under load. It is slow and not deterministic.
- Rejected: Use pytest-timeout to stop the test. The defect shows that pytest-timeout does not stop this wait.
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.(roadmap)scope of the title gives the scope.A hang that blocks a CI worker for 30 minutes and defeats pytest-timeout is a critical reliability defect.The hang makes the full test gate unreliable and can block all CI shards.The fix is to give each thread its own async client or use a thread-local pattern in decision_step.py.Both deal with test hangs under load, but #2138 fixes test wait patterns while the candidate fixes a shared httpx2.AsyncClient in production code.devops-cli-service commentedon Nov 11, 2026
Status set to Ready at 453aed0 (see proposed design in issue body).
dan-petty commentedon Nov 11, 2026
Two CI shards had this hang on 2026-11-11, with
Tests & Coverage (shard 2 of 4)stopped by the 30-minute job timeout:fix/4529-caller-gate-parameter-span): shard 2 ran from 07:52 to 08:22 UTC and was cancelled.Other runs of the same hour passed shard 2 in 5 to 8 minutes, so the hang is intermittent.
dan-petty commentedon Nov 11, 2026
One more occurrence on 2026-11-11, on PR #4551 (a change to the Collector config and one k8s gate check, so no change to the code under test):
dan-petty commentedon Nov 11, 2026
One more occurrence in CI, 2026-11-11: PR #4556, run 42997364718, job "Tests & Coverage (shard 3 of 4)". The shard printed its last progress line at 09:48:19Z, after about 4300 of 5461 tests, and printed nothing more. The job was cancelled at its 30-minute timeout (10:13:34Z, "The operation was canceled"). pytest-timeout (600 s,
signal) did not stop it. The same tests of the same commit pass locally, and the change of the pull request does not touchdecision_step.py. I ran the failed jobs again.dan-petty commentedon Nov 11, 2026
The hang occurred in CI on 2026-11-11. Job
Service Image Tests (shard 4 of 6)of pull request #4544 (run 43008141206, job 130480700754) printed its last test dots at 11:04:44Z. It then printed nothing until the 30-minute job timeout canceled it at 11:29:23Z. pytest-timeout did not stop it.Shard 4 of 6 holds
tests/roadmap/test_roadmap_decision_step.py(shard_test_files(4, 6, Path("."))). The same pull request passed this shard in about 6 minutes on its previous head, and the new head changed only Markdown files. Thus the hang depends on timing, as this issue says.devops-cli-service commentedon Nov 11, 2026
Released in v0.112.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.112.0
devops-cli-service commentedon Nov 11, 2026
Live since 2026-11-11 14:13 UTC