Skip to content

fix(telemetry): wait for abandoned dispatch workers before a test ends - #2282

Merged
dan-petty merged 3 commits into
mainfrom
fix/2277-otel-exporter-thread-outlives-test
Oct 26, 2026
Merged

dan-petty merged 3 commits into
mainfrom
fix/2277-otel-exporter-thread-outlives-test

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

A command that passes its dispatch timeout leaves its worker thread running, because Python cannot stop a thread.
When that worker ends its command, it calls get_tracer().
If the test floor has already reset the tracer and restored the environment, get_tracer() builds a tracer from the real settings: telemetry on and endpoint port 4318.
The devops-otel thread of that tracer then connects to loopback port 4318 while another test runs, and the floor guard fails that test.
The failure is intermittent because the order of the worker and the floor teardown depends on the load of the host.

#2274 made OTelTelemetryClient.shutdown() wait for its threads, and the failure stayed.
At the reset, the tracer that leaked did not exist yet, so no reset could reach it.

This change:

  • Names the dispatcher worker thread devops-mcp-dispatch (CONST_MCP_DISPATCH_THREAD_NAME).
  • Adds the autouse fixture finish_abandoned_dispatch_workers to the test floor. It depends on isolate_devops_cli_config, so it tears down before the tracer reset and before the restore of the environment. A worker therefore ends against the isolated tracer, which is off and points at the refusing port.
  • Makes a test that does not release its hung command fail in its own teardown, naming the stuck worker, not in a later test.
  • Adds a floor invariant test: a second test must not start before the worker of the first test has ended.
  • Updates docs/TESTING.md for the new duty of the floor.

The port is not added to a list of allowed connections. The floor is right to refuse it.

Closes #2277

Change: openspec/changes/archive/2026-10-26-2277-join-abandoned-dispatch-workers/

A dispatch that passes its timeout leaves its worker thread running.
When the worker ends its command, it calls get_tracer(). If the floor has
already reset the tracer and restored the environment, get_tracer() builds
a tracer from the real settings: telemetry on, endpoint port 4318. Its
devops-otel thread then connects during another test, and the floor guard
fails that test.

Name the worker thread, and add a floor fixture that waits for it while the
test's isolation holds. A test that does not release its hung command now
fails in its own teardown.

Refs #2277
@dan-petty

Copy link
Copy Markdown
Owner Author

Verification, run from a clean worktree rebased on origin/main (7f1145a):

  • uv run devops ci: test (11055 passed) and coverage pass, and so do all other steps except uv check. uv check fails on main too: ty v0.0.92 flags a redundant cast in src/devops_cli/ai/tools/__init__.py. This change does not touch that file. The diagnostic is filed as its own issue.
  • The test step took 6m 18s on this run, over the 5 minute budget, because other agents ran their own devops ci on the same host at that time. An earlier run of the same tests, with no such load, took 4m 32s. The new tests add less than 1 second.
  • uv run devops ci fail-to-pass --base origin/main exits 0 and lists test_a_dispatch_worker_abandoned_by_a_timeout_is_finished_before_the_next_test_starts as failed on base. On base, that test fails with an ImportError for CONST_MCP_DISPATCH_THREAD_NAME, because the replay puts the new tests/conftest.py over the old source. The failure for the real cause was seen before the fix existed: the second inner test failed with assert [] == ['_hang_2277'], because it started while the abandoned worker was still running.
  • Reproduction of the cause: a scratch test released an abandoned worker after the fixtures had torn down. The worker built a tracer with enabled=True and the real endpoint, and devops-otel_0 exported while the next test was in setup. The next test then failed at teardown with "network edge reached without a fake". With this change, the same leak fails in the test that causes it and names the stuck worker.

@dan-petty
dan-petty marked this pull request as ready for review October 26, 2026 03:57
@dan-petty
dan-petty merged commit 51e8e61 into main Oct 26, 2026
17 checks passed
@dan-petty
dan-petty deleted the fix/2277-otel-exporter-thread-outlives-test branch October 26, 2026 03:57
dan-petty pushed a commit that referenced this pull request Oct 26, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.6.1](v0.6.0...v0.6.1)
(2026-10-26)


### Bug Fixes

* **ai:** the rag index keeps each project's chunks apart, deletes a
removed file's points before forgetting it, and refills a project its
collection lost
([#2283](#2283))
([ad7c38b](ad7c38b))
* **cli:** repos sync and branches sync report a failed fetch or pull
instead of printing success
([#2276](#2276))
([bf72be1](bf72be1))
* **github:** pace GraphQL porcelain commands against graphql quota
([#2280](#2280))
([7f1145a](7f1145a)),
closes [#1415](#1415)
* **roadmap:** intake keeps the fields a person set on a card added
during its planning
([#2278](#2278))
([21654c6](21654c6))
* **roadmap:** intake leaves the sub-issues of a candidate's source out
of the duplicate check
([#2275](#2275))
([214028c](214028c))
* **telemetry:** wait for abandoned dispatch workers before a test ends
([#2282](#2282))
([51e8e61](51e8e61))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
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.

fix(telemetry): no devops-otel exporter thread outlives its test, so no later test fails on a connection to port 4318

1 participant