Skip to content

fix(test): the telemetry shutdown test bounds its threads by wall-clock time and fails on a loaded host #2587

Closed as not planned

Description

@dan-petty

Problem Description

tests/test_telemetry_shutdown_sync.py::test_shutdown_joins_all_worker_threads failed once in a full local test run (uv run devops test run --changed, 2026-10-29, host load about 15) and passed three times in a row when run alone. The branch under test changed no telemetry code.

The test bounds threads by wall-clock time: it asserts started.wait(timeout=1.0) for the executor thread to start, and a threading.Timer(1.2, ...) releases the send. Under a loaded host the thread can start after 1.0 s, and the assertion fails. docs/TESTING.md asks tests not to depend on elapsed time.

Reproduction Steps

  1. Run the full suite on a loaded host (16 workers beside other test runs).
  2. The test fails at random; uv run pytest tests/test_telemetry_shutdown_sync.py alone passes.

Expected vs Actual Behavior

  • Expected: the test proves that shutdown() joins the in-flight executor thread without a timing bound that host load can break, for example by waiting on events with no timeout under the test's own overall timeout, or by checking the join with an event that the send sets after shutdown() starts.
  • Actual: an intermittent failure under load.

Environment Diagnostics

origin/main as of 2026-10-29 01:20 UTC, Python 3.14, the devcontainer.

Logs, Traces, or Terminal Output

.pytest_cache/v/cache/lastfailed held only tests/test_telemetry_shutdown_sync.py::test_shutdown_joins_all_worker_threads after the 5 m 48 s run.

Existing Tool Considered

None needed: a test change.

Proposed design

Problem statement

The test test_shutdown_joins_all_worker_threads bounds thread handoff by wall-clock time: it asserts started.wait(timeout=1.0) and releases the send with threading.Timer(1.2, ...). On a loaded host the executor thread starts after 1.0 s and the assertion fails. The project convention in docs/TESTING.md forbids upper bounds on elapsed wall-clock time in tests. The fix replaces the wall-clock bounds with event-based waits bounded only by THREAD_HANDOFF_BOUND_SECONDS and the pytest-timeout hang bound.

Acceptance criteria

Requirement: No wall-clock upper bound on thread start wait

The test SHALL wait for the executor thread to start using THREAD_HANDOFF_BOUND_SECONDS or no timeout, never a fixed wall-clock deadline shorter than that bound.

Scenario: test passes on a loaded host

  • WHEN the test runs on a host with load above 10 and the executor thread starts after 1.0 s
  • THEN the assertion on the started event passes without a wall-clock timeout failure

Requirement: No wall-clock timer to release the send

The test SHALL release the blocked send by setting an event from the test thread, not by a threading.Timer or any other wall-clock delay.

Scenario: send released by event not timer

  • WHEN shutdown() is called while the send is blocked on the finish event
  • THEN the finish event is set by the test thread directly, and no threading.Timer object is created in the test

Requirement: shutdown still joins the in-flight thread

The test SHALL verify that shutdown() joins the in-flight executor thread and leaves no devops-otel thread alive.

Scenario: no otel threads after shutdown

  • WHEN shutdown() returns after the send completes
  • THEN client._executor is None and no thread whose name starts with devops-otel is alive

Existing Tool Considered

No check has run. The body states no external tool is needed: this is a test-internal fix. The written cost is modifying one test function in tests/test_telemetry_shutdown_sync.py, roughly 20 lines of change, with no new dependency and no code to maintain beyond the test itself.

Key questions

  • How should the test wait for the executor thread to start?: Use started.wait(timeout=THREAD_HANDOFF_BOUND_SECONDS) or started.wait() with no timeout, relying on the pytest-timeout hang bound to catch a true hang. The project convention says a test waits with THREAD_HANDOFF_BOUND_SECONDS, never with a deadline of its own. (best practice) [sources: docs/TESTING.md, tests/support/waits.py]
    • Rejected: started.wait(timeout=1.0) (current). Rejected: a fixed 1.0 s wall-clock bound fails on a loaded host, which is the defect this issue fixes.
    • Rejected: started.wait(timeout=THREAD_HANDOFF_BOUND_SECONDS). Chosen: the project convention for thread handoff waits. The bound is generous enough for a loaded host and only a failing test waits it out.
    • Rejected: started.wait() with no timeout. Also valid: the pytest-timeout hang bound catches a true hang. But THREAD_HANDOFF_BOUND_SECONDS is the stated convention and gives a clearer failure message.
  • How should the test release the blocked send so that shutdown() can join it?: Run shutdown() in a separate thread. The test thread sets the finish event to release the send, then joins the shutdown thread with THREAD_HANDOFF_BOUND_SECONDS. This removes the wall-clock timer and makes the release event-driven. (best practice) [sources: docs/TESTING.md, tests/test_telemetry_shutdown_sync.py]
    • Rejected: threading.Timer(1.2, finish.set) (current). Rejected: a wall-clock timer that the project convention forbids. Under load the timer fires late or the test has already failed.
    • Rejected: Run shutdown() in a thread, set finish from the test thread, join the shutdown thread. Chosen: the release is event-driven, no wall-clock delay. The test thread controls when the send unblocks. The join uses THREAD_HANDOFF_BOUND_SECONDS per convention.
    • Rejected: Use a Barrier or Queue to coordinate. Rejected: adds complexity for no benefit over a simple Event. The current test already uses Events; the fix keeps that pattern.
  • What is the purpose of the finish.wait(timeout=3.0) inside the slow_send fake?: It is a safety bound so the fake does not block forever if the test logic is wrong. It is a lower bound on the send duration (the send waits at least until finish is set), which the ast-grep rule allows. It can stay as-is or be replaced with finish.wait() relying on pytest-timeout. [sources: tests/test_telemetry_shutdown_sync.py, docs/TESTING.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/test
    status/new
    value/medium
    effort/low
    on Oct 29, 2026
  2. dan-petty commented on Oct 29, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/test. The change fixes a flaky test that bounds threads by wall-clock time instead of events.
    • Priority: P2-Medium. The failure is intermittent and only appears under host load, so it is not blocking but causes CI noise.
    • Value: Medium. It removes a source of random CI failures that erodes trust in the test suite.
    • Effort: Low. One test file needs its timeout and Timer replaced with event-based waits.
    • Related: fix(tests): the remaining test waits end on an event or a process exit, not on a deadline of their own #2138, which asks for a different change. Both replace wall-clock deadlines with event-based waits in tests, but the candidate targets only test_telemetry_shutdown_sync.py while #2138 covers all remaining deadline-based waits.
  3. added
    priority/p2-medium
    type/bug
    and removed
    type/test
    on Oct 29, 2026
  4. added
    status/ready
    and removed
    status/new
    on Oct 30, 2026
  5. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 07fb4c2 (see proposed design in issue body).

  6. dan-petty commented on Nov 1, 2026

    @dan-petty
    OwnerAuthor

    Superseded by #2690, implemented in pull request #2961.

  7. removed
    status/ready
    on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions