Skip to content

fix(github): pace mutations through the clock seam - #5063

Merged
dan-petty merged 2 commits into
mainfrom
fix/4666-rate-limiter-clock
Nov 12, 2026
Merged

dan-petty merged 2 commits into
mainfrom
fix/4666-rate-limiter-clock

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

The rate limiter called the stdlib time.sleep for its pause before a request and for its backoff after a rate limit, so ClockFake could not answer these waits. Each command test that sent two gh writes waited the one-second write interval for real. Both waits now go through devops_cli.core.clock.sleep, which calls time.sleep in production, so each real wait keeps its length. The gh_edge fixture requests the clock fixture, so the waits of the rate limiter in a command test take no real time. PacedClock of the GitHub API fake replaces the limiter's clock name, not its time name, so the fake records the pauses in paced as before. Two rate limiter tests that recorded the waits on the stdlib time.sleep read clock.waits, and the test of two threads holds both pauses with clock.concurrent_sleeps(2).

Closes #4666

Change: openspec/changes/archive/2026-11-12-4666-pace-mutations-through-the-clock-seam/

The rate limiter called the stdlib time.sleep for its pause before a
request and for its backoff after a rate limit, so ClockFake could not
answer these waits. Each command test that sent two gh writes waited
the one-second write interval for real.

The limiter now waits through devops_cli.core.clock.sleep. The gh_edge
fixture requests the clock fixture, and the GitHub API fake records the
pauses on the limiter's clock name.
@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/github GitHub Projects v2, Views, Milestones, Labels, and PR automation labels Nov 12, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Fail-to-pass

uv run devops ci fail-to-pass --base origin/main (exit 0): 3 failed on base, 224 passed, 8 errored, in tests/github/test_github_rate_limiter.py and tests/github/test_service_limits.py.

  • Failed on base, pass on this branch:
    • test_a_write_waits_its_interval_through_the_clock_seam: "the rate limiter waited 1.0 s through time.sleep"
    • test_a_retry_waits_its_backoff_through_the_clock_seam: the waits went to the stdlib time.sleep and none went to ClockFake.
    • test_the_writes_of_a_command_test_over_gh_edge_wait_through_the_clock_fake: assert (2, [1.0, 2.0]) == (2, [])
  • The 8 errors on base are setup errors: the replay overlays the new tests/support/fakes/github.py, which replaces rate_limiter.clock, and the base module has no such name. Each of the 8 tests passes on this branch.

Before and after: real sleep in the pr and gh command tests

Measured with a PEP 578 audit hook on the stdlib time.sleep event (the audit probe of the CI audit), pytest -n 4 on tests/commands/test_pr_*.py and tests/commands/test_gh_cmd.py (304 tests), on the same host.

File Real sleep before Real sleep after
test_pr_cmd.py 37.92 s (74 calls) 0 s
test_pr_title_labels.py 12.44 s (23 calls) 0 s
test_gh_cmd.py 7.20 s (38 calls) 0 s
test_pr_update.py 6.00 s (6 calls) 6.00 s (6 calls)
test_pr_form_check.py 4.48 s (8 calls) 0 s
test_pr_status.py 4.28 s (21 calls) 0 s
Total 72.31 s (170 calls) 6.00 s (6 calls)
  • Sum of the test times: 103.0 s before, 34.7 s after.
  • Run time of the 304 tests with 4 workers: 40.96 s before, 28.99 s after.
  • A stack probe on the same event found one source for each real sleep before the change: rate_limiter.py:1103.

Not done here

The two pr edit tests of tests/commands/test_pr_update.py (test_pr_edit_fallback_patch_title_body_base_milestone and test_pr_edit_fallback_milestone_failure_fails_with_message) use process_fake with no gh_edge, so they still wait 6 s for real. The deletion of devops pr update changes that file now, so this pull request does not touch it. The fix there is to add clock: ClockFake to the two tests, or to use gh_edge.

Checks run locally

  • 102 test files that use gh_edge, github_api, github_api_and_gh, fresh_quota or the rate limiter: 2818 passed. The 4 other test files that patch time.sleep: 118 passed.
  • The two rewritten rate limiter tests passed 8 runs in a row.
  • ruff check, ruff format --check, mypy on the rate limiter, devops ci docs, devops openspec check, and the pre-push hook passed.

@dan-petty
dan-petty marked this pull request as ready for review November 12, 2026 13:34
@dan-petty
dan-petty merged commit 2bd87bc into main Nov 12, 2026
24 checks passed
@dan-petty
dan-petty deleted the fix/4666-rate-limiter-clock branch November 12, 2026 13:36
@dan-petty

Copy link
Copy Markdown
Owner Author

Review findings after the merge

This PR merged before the fix round. Thus I pushed no commit. I did the work below on the issues.

Finding 1 (major), tests/commands/test_pr_update.py: the first acceptance criterion of #4666 is not met, and no issue records the gap.

dan-petty pushed a commit that referenced this pull request Nov 12, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.119.0](v0.118.0...v0.119.0)
(2026-11-12)


### Features

* **repos:** the claim sets In Progress
([#5111](#5111))
([06ef1c6](06ef1c6))
* **roadmap:** a fix-plan step repairs a plan PR with open findings
([#5104](#5104))
([ca5b16d](ca5b16d))
* **roadmap:** extend stage review rounds while open findings drop
([#5090](#5090))
([bacf713](bacf713))
* **roadmap:** re-anchor a stale citation that matches one line
([#5040](#5040))
([16356d8](16356d8))


### Bug Fixes

* **ci:** keep failed test IDs in the service image shard summary
([#5106](#5106))
([88589ef](88589ef))
* **github:** count each page of a paginated GitHub read
([#5070](#5070))
([908e24a](908e24a))
* **github:** keep the metrics permissions out of the runner Job token
([#5064](#5064))
([fb549ff](fb549ff))
* **github:** pace mutations through the clock seam
([#5063](#5063))
([2bd87bc](2bd87bc))
* **k8s:** delete the CoreDNS files that k3s never applies
([#5055](#5055))
([463f601](463f601))
* **monitoring:** tidy LLM stack windows, units and lines
([#5052](#5052))
([375d724](375d724))
* **roadmap:** a refused kept plan uses no stage gate return
([#4983](#4983))
([b8adbca](b8adbca))
* **roadmap:** count a command as removed only when MUST NOT governs it
([#4985](#4985))
([2e6f407](2e6f407))
* **roadmap:** cut prose after a cited stage command
([#4982](#4982))
([a172563](a172563))
* **roadmap:** name every module of a group with no named test
([#5089](#5089))
([27a0e79](27a0e79))
* **roadmap:** stage returns every open review finding to the planner
([#5067](#5067))
([21b116e](21b116e))
* **roadmap:** the alternatives check reads the tools in use
([#5062](#5062))
([8903233](8903233))
* **roadmap:** the constants gate reads 6_500 and no new value
([#5080](#5080))
([8a7b113](8a7b113))
* **roadmap:** the constants gate reads only a stated value
([#5042](#5042))
([cf4733e](cf4733e))
* **telemetry:** read repository traffic as the GitHub App
([#4932](#4932))
([7c42823](7c42823))
* **tests:** close the UDP, DNS and git gaps of the network floor
([#5101](#5101))
([047ee48](047ee48))
* **tests:** repair the bwrap contract suite and gate it
([#5110](#5110))
([9a0659d](9a0659d)),
closes [#4715](#4715)


### Performance Improvements

* **ci:** build the Service image once for its test shards
([#5079](#5079))
([dcf5bd5](dcf5bd5))
* **ci:** run only the required checks on the release PR
([#5057](#5057))
([8174071](8174071))
* **ci:** stop the cache export of pull request image builds
([#5113](#5113))
([ba30820](ba30820))
* **roadmap:** consolidate keeps its vectors in the shared tiers
([#5099](#5099))
([2a8bf1a](2a8bf1a))


### Code Refactoring

* **roadmap:** one Status writer for every job
([#5109](#5109))
([24cfedc](24cfedc))

---
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

scope/github GitHub Projects v2, Views, Milestones, Labels, and PR automation type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(github): pace mutations through the clock seam

1 participant