Skip to content

fix(test): refine failure tests wait 60 s on real retries #4459

Closed

Description

@dan-petty

Problem Description

Three tests of tests/roadmap/refine/test_roadmap_refine_failure_class.py wait for real on the retry backoff of the model client:

  • test_the_next_round_skips_the_item_until_the_time_passes_and_takes_the_others: 30.3 s
  • test_a_timeout_records_class_step_and_time_and_does_not_mark_the_item_as_at_fault: 15.2 s
  • test_a_success_clears_the_three_keys: 15.2 s

(GitHub runner, shard 2 of run 42938256840 on main, 2026-11-11.) The times are the same on a loaded local host (median 31.5 s, max 32.2 s for the first test over 8 local gate logs), so they are waits, not work.

The cause: the shared fixture scripted_gateway (tests/support/roadmap_refine.py) asks for the shared clock fixture (tests/support/fakes/clock.py, a ClockFake), and its docstring says "Retries wait no time: the clock fixture answers each wait". But the test module defines its own fixture with the same name clock, a bare time_machine.travel(START, tick=False). The module fixture shadows the shared one, so time.sleep and the clock seam are not replaced, and each failing round sleeps through the real backoff of the 5 attempts (about 15 s).

Reproduction Steps

  1. Run uv run pytest tests/roadmap/refine/test_roadmap_refine_failure_class.py -n0 --durations=5.
  2. Read the times of the three tests above.

Expected vs Actual Behavior

Expected: each test takes well under 1 s, because ClockFake answers each retry wait at once.

Actual: 15 s for each failing round, 60 s for the three tests together.

Proposed fix

Build the module fixture on the shared one: request the shared clock (ClockFake) and move it to START with ClockFake.move_to. ClockFake.shift takes the same timedelta the tests pass now. Then assert in one test that the retries recorded their waits in clock.waits, so the shadow cannot come back without a failure.

Environment Diagnostics

GitHub-hosted ubuntu-26.04 runners and the devcontainer on WSL2.

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

The three refine failure tests wait on the real retry backoff. A module clock fixture shadows the shared ClockFake fixture, so time.sleep is not replaced. Each failing round sleeps about 15 seconds, and the three tests take about 60 seconds together. The change makes the module use the shared fake clock and records the retry waits.

Acceptance criteria

Requirement: The module uses the shared fake clock

The failure-class module SHALL use the shared ClockFake fixture for its clock parameter and SHALL move that fake to START before each test.

Scenario: A test requests the module clock

  • WHEN a test in the failure-class module requests the clock fixture
  • THEN the test receives a ClockFake whose wall clock reads START and whose waits list is empty.

Requirement: A failing round records retry waits

A refine round that exhausts the gateway retries SHALL append each retry wait to clock.waits and SHALL NOT call the real time.sleep.

Scenario: A gateway timeout exhausts the retries

  • WHEN a test scripts TIMEOUT for one item and runs one refine round
  • THEN clock.waits is not empty after the round.

Requirement: The timeout test guards the fake clock

The timeout test SHALL assert that clock.waits is not empty after the failing round.

Scenario: The timeout test runs

  • WHEN test_a_timeout_records_class_step_and_time_and_does_not_mark_the_item_as_at_fault runs
  • THEN the test fails if the module shadows the shared ClockFake.

Existing Tool Considered

No alternatives check has run. The open, maintained time-machine library, through the project's existing ClockFake fixture in tests/support/fakes/clock.py, covers the need. It lacks nothing for this test fix. The change writes no production code.

Key questions

  • How should the module fixture use the shared clock fixture without shadowing it?: Replace the module clock fixture with an autouse fixture that requests the shared clock, moves it to START, and leaves the shared ClockFake for the tests. (best practice) [sources: tests/support/fakes/clock.py, tests/roadmap/refine/test_roadmap_refine_failure_class.py, tests/support/roadmap_refine.py]
    • Chosen: Autouse wrapper over the shared clock. It moves the shared ClockFake to START and keeps the shared fake for every test.
    • Rejected: Keep the module time_machine traveller. It shadows the shared ClockFake and leaves real retry sleeps in place.
    • Rejected: Move the clock in every test. It repeats setup in each test and is easy to omit.
  • How should one test prove that retries use the fake clock?: Add an assertion in the timeout test that clock.waits is not empty after the failing round. (best practice) [sources: .ast-grep/rules/test-elapsed-upper-bound.yml, tests/support/fakes/clock.py, tests/roadmap/refine/test_roadmap_refine_failure_class.py]
    • Chosen: Assert clock.waits is not empty. The shared fake records every retry wait, so a shadowed fixture fails the assertion.
    • Rejected: Assert an elapsed time upper bound. A loaded machine makes elapsed time longer, and the rule pack rejects this assertion.
    • Rejected: Assert no clock use. It does not prove that retries pass through the fake clock.
  • Does ClockFake.shift accept the timedelta values that the tests pass?: Yes. ClockFake.shift accepts float | timedelta and advances both the wall and monotonic clocks. [sources: tests/support/fakes/clock.py]
  • Which type should the tests use for the clock parameter?: Use ClockFake from tests.support.fakes.clock, because the shared fixture yields that type. [sources: tests/support/fakes/clock.py, tests/support/roadmap_refine.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    status/new
    value/medium
    effort/low
    on Nov 11, 2026
  2. dan-petty commented on Nov 11, 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/bug. The fix prefix of the title gives the type.
    • Scope: none. The title has the scope test, and .github/labels.yml declares no scope/test label. Add the label to the file to give the scope to this item.
    • Priority: P2-Medium. Wastes 60 s of CI time per run but does not block correctness.
    • Value: Medium. Saves CI wall-clock time and removes host-load dependency from three tests.
    • Effort: Low. Rebuild one module fixture on the shared ClockFake and add one assertion.
    • Related: refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320, which asks for a different change. Both address tests waiting on real time; #1320 is the system-wide refactor for time control, the candidate fixes one module's fixture shadowing.
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

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

  6. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Scope from the CI audit (2026-11-11)

    Another session works on this issue now. This comment only adds the measured cause.

    • The 3 tests of tests/roadmap/refine/test_roadmap_refine_failure_class.py take 30.53, 15.17 and 15.12 s in CI (measured). tenacity calls devops_cli.core.clock.sleep for real. The clock fixture of the file (lines 57-61) only moves the time.
    • Solution: use the shared ClockFake fixture (tests/support/fakes/clock.py). It answers core.clock.sleep and time.sleep.
    • Acceptance: each of the 3 tests takes 1 s or less. An audit hook records 0 real sleep in the file.
    • Saving: 60.8 s of CI worker time per run (measured).
    • fix(tests): refuse real sleeps in tests #4669 (refuse real sleeps in tests) waits for this issue.
  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 11, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 11, 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