Skip to content

fix(telemetry): make the shutdown thread test wait for events and not for timers #2690

Description

@dan-petty

Problem or Motivation

tests/test_telemetry_shutdown_sync.py::test_shutdown_joins_all_worker_threads failed once in a full uv run devops ci run with 16 workers on a loaded host. The run was on the branch of #2665, which does not touch telemetry. The test passes alone and passed in the run before.

The failure: after client.shutdown(), two devops-otel threads were still alive. The test waits for a thread with fixed timers (a threading.Timer(1.2, ...), started.wait(timeout=1.0) and finish.wait(timeout=3.0)). A loaded host stretches these times, and docs/TESTING.md says a test must not depend on them.

Proposed Solution & Architectural Design

Make the test wait for the events it needs, with THREAD_HANDOFF_BOUND_SECONDS from tests/support/waits.py, and not with its own timers.

Target Subsystem

tests/test_telemetry_shutdown_sync.py, src/devops_cli/telemetry/.

Existing Tool Considered

tests/support/waits.py (wait_until, THREAD_HANDOFF_BOUND_SECONDS).

Acceptance criteria

  • The test passes in a full uv run devops ci run on a loaded host.

Proposed design

Problem statement

The test test_shutdown_joins_all_worker_threads uses fixed timers (1.0 s, 1.2 s, 3.0 s) to coordinate with worker threads. On a loaded host these timers expire before the threads finish, so the test fails. The test must wait for the events it needs using THREAD_HANDOFF_BOUND_SECONDS from tests/support/waits.py, and must not use its own fixed timers.

Acceptance criteria

Requirement: Waits use the shared bound

The test SHALL use THREAD_HANDOFF_BOUND_SECONDS from tests/support/waits.py for every wait on a thread event, and SHALL NOT use a threading.Timer with a fixed delay or an Event.wait with a timeout below that bound.

Scenario: No fixed timer in test source

  • WHEN The test file tests/test_telemetry_shutdown_sync.py is read
  • THEN No threading.Timer with a fixed delay and no Event.wait with a timeout below THREAD_HANDOFF_BOUND_SECONDS appears in the test

Requirement: Shutdown blocks on in-flight send

The test SHALL verify that client.shutdown() does not return until the in-flight executor thread has completed its send.

Scenario: Shutdown waits for in-flight send

  • WHEN A send is in-flight and blocked on the finish event, and shutdown is called
  • THEN shutdown returns only after the send completes, and client._executor is None

Requirement: No otel threads remain after shutdown

After client.shutdown() returns, the test SHALL assert that no thread whose name starts with devops-otel is alive.

Scenario: All otel threads joined

  • WHEN shutdown has returned and the in-flight send has completed
  • THEN threading.enumerate() contains no alive thread whose name starts with devops-otel

Existing Tool Considered

No external tool is needed. The project already has tests/support/waits.py, which provides THREAD_HANDOFF_BOUND_SECONDS (30.0 s) and wait_until. No check has run. The change uses this existing module and adds no new dependency.

Key questions

  • How should the test release the in-flight send without a fixed timer?: Run client.shutdown() in a daemon thread, set the finish event from the main thread, and wait for the shutdown thread with THREAD_HANDOFF_BOUND_SECONDS. (best practice) [sources: docs/TESTING.md:137, tests/support/waits.py:33]
    • Rejected: threading.Timer with a fixed delay. A fixed delay is a deadline of its own, which TESTING.md forbids for thread waits.
    • Rejected: Run shutdown in a thread, release from main, wait with the bound. No fixed timer. The wait returns as soon as the event fires, so a passing test is not slowed.
    • Rejected: Call finish.set() before shutdown(). The send may complete before shutdown is called, so the test no longer verifies that shutdown blocks on an in-flight send.
  • What bound should the waits use?: THREAD_HANDOFF_BOUND_SECONDS (30.0 seconds) from tests/support/waits.py. [sources: tests/support/waits.py:33, docs/TESTING.md:137]
  • Should the test keep monkeypatch.setattr for _send_payload_sync?: Yes. The issue scope is the timers. Changing the patch mechanism is a separate concern tracked by the TESTING.md migration. (best practice) [sources: tests/test_telemetry_shutdown_sync.py, docs/TESTING.md]
    • Rejected: Keep monkeypatch.setattr for _send_payload_sync. The issue scope is the timers. The existing patch is the current approach.
    • Rejected: Use a seam or fake for the send. Out of scope. The TESTING.md migration to seams is tracked separately.

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 by replacing timers with event-based waits.
    • Priority: P2-Medium. A flaky CI test breaks builds on loaded hosts but does not affect production users.
    • Value: Medium. Reliable CI is needed for the team, but the change does not alter user-facing behaviour.
    • Effort: Low. One test file changes its wait strategy using an existing helper in tests/support/waits.py.
    • Possible duplicate: fix(test): the telemetry shutdown test bounds its threads by wall-clock time and fails on a loaded host #2587, which may ask for the same change. The model names Replace fixed timers in test_shutdown_joins_all_worker_threads with event-based waits using THREAD_HANDOFF_BOUND_SECONDS as the change that both ask for. Both items fix the same test in the same file by replacing wall-clock timers with event-based waits. A person closes one of the two if that is so.
  3. added
    priority/p2-medium
    type/bug
    scope/telemetry
    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 46fd02d (see proposed design in issue body).

  6. added
    status/in-progress
    and removed
    status/ready
    on Oct 31, 2026
  7. removed
    status/in-progress
    on Nov 1, 2026
  8. added a commit that references this issue 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-mediumscope/telemetrysource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions