Repository navigation
ci(cancel-superseded): order queue runs by (datetime, id), fail on a non-queue ref - #1923
Merged
Merged
Conversation
…non-queue ref The merge-queue janitor decides which in-flight queue runs a newer run replaced, and it had three ways to get that wrong: * `run["created_at"] < current["created_at"]` compared ISO timestamps as STRINGS. GitHub sometimes emits fractional seconds, and `.` sorts before `Z`, so a run created 500 ms AFTER a whole-second one read as older: the janitor cancelled the LIVE queue run and left the stale one holding a runner. Order is now `(datetime, id)`. * A same-second tie satisfied neither `<`, so the redundant run survived the whole queue. The id (which increases with creation) breaks the tie. * A triggering ref that was not `gh-readonly-queue/<base>/pr-<N>-<sha>` printed `PR #None: cancelling 0` and exited 0 -- success reported for a cleanup that never had a target. It is now a hard error naming the ref. Also fixes `QUEUE_RE`, whose `[^/]+` base segment silently classified a queue ref for a slashed base branch (`release/2.x`) as "not a queue run", and tolerates `URLError` per run so a network blip during cleanup cannot turn a merge_group check red. New `ci/test_cancel_superseded.py` (21 tests) drives the real module with a stubbed API: fractional-second ordering both ways, the same-second tie, multi-run selection, dry-run, 409 tolerance, network tolerance, and the non-queue-ref hard error. Registry entry added, `untested` 5 -> 4, both entry points wired.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
ci/cancel_superseded.pyis the merge-queue janitor: on everymerge_grouprun itcancels the in-flight queue runs for the same PR that a newer queue run replaced, so
they stop holding runners when
mainmoves. It had zero tests, and three ways to getthe decision wrong. All three are reproduced against
origin/mainand are regressioncases in the new module.
1. Timestamps compared as strings (cancels the LIVE run)
run["created_at"] < current["created_at"]is a lexicographic comparison. GitHubsometimes emits fractional seconds, and
.(0x2E) sorts beforeZ(0x5A):The dangerous direction: the run that actually owns the queue slot is cancelled and
the stale one keeps a runner. Order is now
(datetime, id), parsed withdatetime.fromisoformat(fractional seconds, offsets and naive stamps handled).2. A same-second tie cancelled nothing
Two queue runs created in the same second satisfied neither
<, so neither wascancelled and the redundant run survived the whole queue.
idincreases withcreation, so it breaks the tie.
3. A non-queue ref reported success
When the triggering run's ref is not
gh-readonly-queue/<base>/pr-<N>-<sha>,mainprinted
PR #None: cancelling 0 superseded queue run(s): []and exited 0 — successfor a cleanup that never had a target, exactly what a broken event wiring looks like.
It is now
rc 1on stderr naming the ref.Also
QUEUE_REused[^/]+for the base branch, so a queue ref for a slashed base(
gh-readonly-queue/release/2.x/pr-7-abc123) was silently classified as "not aqueue run". Base segment is
.+now.URLErrorduring a cancel is tolerated per run: cleanup is best-effort, and anetwork blip must not turn a
merge_groupcheck red and block the queue.Tests
New
ci/test_cancel_superseded.py, 21 tests, driving the real module with a stubbedAPI (no network, no token): queue-ref parsing (incl. slashed base), fractional-second
ordering in both directions, the same-second tie, multi-run selection, dry-run, 409
tolerance, network tolerance, and the non-queue-ref hard error.
Real output:
RED proven by mutating the fix in place, one at a time, then restoring:
order(run) < cutoff->run["created_at"] < current["created_at"]fractional_second_run_that_is_later,same_second_tie)created_at(run) < created_at(current)same_second_tie)pr is Nonehard errornon_queue_ref_is_a_hard_error)QUEUE_REbase.+->[^/]+parses_a_non_main_base)Ratchet
ci/gate_script_tests.toml:cancel_supersededmoves out ofuntestedwithtests = ["ci/test_cancel_superseded.py"];MAX_UNTESTED5 -> 4. Registered in bothentry points (
ci/local_suites.pyDRIFT_UNITTEST_MODULESand theci-workflow-drift.ymlunittest command) in the same position, plus aci/README.mdbullet.
Part of the untested-gate backlog from #1915 (#1917, #1919, #1922 are done).