Skip to content

CI: retry a run whose job was killed by a reclaimed runner - #115745

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:ci-retry-cancelled-run-step
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:ci-retry-cancelled-run-step

Conversation

@groeneai

@groeneai groeneai commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

...

Description

When a self-hosted runner is reclaimed mid-Run, the job ends failure with the Run step
cancelled. The check goes red having run zero tests and published zero CIDB rows, and the hourly
infra-retry workflow does not rerun it, for three reasons.

No classifier arm for a cancelled Run step: it falls into else false and is scored a real
failure, while the gate needs every failed job to be infra. The cron's log for run 32413924641
ends Not an infrastructure failure, skipping.

The window was anchored on createdAt, but a run only becomes listable once it completes, so a
run longer than the 6h window is already outside it when first seen. Against actual fire times,
175 of 399 recent failed runs are unreachable; under an updatedAt anchor, 0 are. The window
length is unchanged.

The scan is bounded on createdAt rather than a fixed --limit: the listing is ordered by
createdAt while eligibility is by updatedAt, so a fixed prefix truncates a different order than
the one filtered. The deepest eligible index reaches 214, so a 200 limit drops a run.

That floor is a second condition on top of updatedAt, so reaching it needs an attempt-1 lifetime
above 18h; across a complete 14-day population the longest is 9.42h, giving 1.56x spare. It cannot
widen, since the runs API stops at 1000 results and a 5-day floor needs 2339 at the worst fire.
Over 323 simulated fires, 24h under a 1000 cap misses nothing and never reaches it; 72h binds at
163. A warning fires if it does.

MAX_RERUNS is untouched, so a wider scan cannot add reruns. Verified on runs 32413924641
and 32306491684: false before, true after. Across 60 deliberately cancelled runs there are no
(job failure, Run cancelled) pairs, since such a run's conclusion is itself cancelled.

Related: #115569
Related: #113564

When a self-hosted runner is reclaimed while a job's main "Run" step is
executing, the job finalizes as conclusion=failure with the "Run" step at
conclusion=cancelled. The check reports red having executed zero tests and
published zero CIDB rows, and the hourly infra-retry workflow does not rerun
it, for two independent reasons.

The jq classifier switches on the "Run" step's conclusion with arms for an
absent step, "skipped" and "failure"-under-120s, plus an "else false" default.
"cancelled" lands in the default and is scored a real test failure; the run
gate requires every failed job to be infra, so one such job suppresses the
whole rerun. For run 32413924641 the workflow's own log shows
"Checking run .../32413924641" followed by "Not an infrastructure failure,
skipping."

Separately, the candidate window is anchored on createdAt, but a run only
becomes listable once it completes, so a run longer than the 6h window already
has a createdAt older than the cutoff at the first invocation that could see
it. Measured against the workflow's 100 actual fire times (the nominal ':43'
is not when it fires; the observed minute-of-hour spans 0-59 with gaps up to
77.6 min), 175 of 399 recent failed runs are unreachable by any fire, 122 of
them at attempt 1; under an updatedAt anchor, 0 are. Three of the unreachable
runs are ones the current classifier already calls infra, and none was ever
retried. The window length is deliberately unchanged: only the anchor was
wrong. --limit is raised because the list is ordered by createdAt while
eligibility is now by completion, so a long run sits deep in it; the deepest
eligible position measured is 131, and MAX_RERUNS is untouched so a wider scan
cannot increase the number of reruns.

Verified on two runner-reclaim runs, 32413924641 (AST fuzzer (amd_debug,
targeted)) and 32306491684 (Stress test (amd_msan)): the classifier extracted
from master scores both false, the one extracted from this branch scores both
true. A user cancel or a cascade cancel cannot be affected, because it makes
the job itself "cancelled", which the .conclusion == "failure" pre-filter
removes before any "Run"-step arm is reached: across 60 deliberately-cancelled
runs (3798 jobs) there are zero (job failure, Run cancelled) pairs and zero
verdict changes, and none of those runs is returned by
"gh run list --status failure". Across 120 attempt-1 failed runs the only
verdict change is run 32413924641 itself, with no run losing a retry it
already got.

The "null" conclusion arm is deliberately left to the separate open ClickHouse#115569
rather than duplicated here.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Aug 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review — 0 blockers, 0 majors (click to expand)

An independent cold review plus a second-model gate reviewed this change before it was pushed.
Both are reported here, including what was checked and found sound.

Result: 0 blockers, 0 majors, 0 changes requested. Two cosmetic comment nits were dropped as
not worth the churn; they are listed below for completeness.

Checks that were run independently of the change's own evidence

  • The two classifier arms were re-extracted from master and from this branch by regex with
    structural assertions, and a strip test confirmed master has no cancelled arm while this
    branch differs by exactly the one added line. So the before/after comparison cannot be vacuous.
  • Both directions on both witnesses (runs 32413924641 and 32306491684, each with total_count
    asserted at 172/172 jobs): gate false before, true after.
  • Negative control: corrupting the new arm's literal returns both runs to false, so the arm and
    not something else carries the change.
  • Regression sweep over the 120 most recent attempt-1 failed PR runs, every one paginated with a
    total_count assertion (0 truncated): exactly one verdict change (the reported run) and
    zero regressions.
  • 💡 The safety claim was re-derived rather than accepted: across 25 run-level-cancelled runs
    (1772 jobs) every failed job has Run.conclusion == "failure", so there are zero
    (job failure, Run cancelled) pairs, and the --status cancelled and --status failure
    listings have zero id overlap. A deliberately cancelled run is therefore never a candidate.
  • ⚠️ The job-timeout confound was ruled out separately: only two jobs in pull_request.yml carry
    timeout-minutes (485 each), there is no step-level timeout, no continue-on-error, no
    cancel-in-progress and no fail-fast; the longest job observed across 6219 jobs is 301
    minutes, with none at or above 330.
  • The window change was corroborated independently: attempt-1 run duration has a p50 of 318
    minutes against a 6h window, and 117 of 277 attempt-1 runs exceed 6h.
  • The ordering premise behind the --limit change was checked directly: createdAt is strictly
    monotonic in the listing (0 inversions) while updatedAt is not (224 of 499), which is why the
    limit has to exceed the window. Simulating the new selector at 15 historical fire points, the
    deepest eligible index is 123 and the old limit of 50 would have missed an eligible run at 15 of
    15 fires; nothing eligible sits beyond 200.
  • No starvation from the wider scan: at the current fire the selector admits 35 candidates of which
    2 score infra, against an untouched MAX_RERUNS=10.

Nits, not blocking

  • 💡 The new comment bullet ends with a full stop while its neighbours end , or, so the
    enumeration reads as terminated one item early. Dropped: restoring the chain means re-flowing a
    pre-existing line this change does not otherwise touch.
  • 💡 "the filter above" refers to the .conclusion == "failure" pre-filter, which is above the
    arms inside the jq program but below the comment block. Dropped: the sentence is the
    load-bearing safety invariant and rewording it risks weakening it for no semantic gain.

Noted for a reviewer

No in-tree test is added. ci/tests/ does have a precedent for asserting on workflow YAML, and
#113564 adds ci/tests/test_retry_infra_failures_fork_gate.py, but that file does not exist on
master yet, so adding a fixture here would couple this change to another PR's merge order. Happy
to add one once #113564 lands.

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, exact and instant (no ClickHouse server involved; the unit is a jq program plus a shell selector). jq -r -f <arm> run-32413924641-jobs.json returns false on the classifier extracted from master and true on the one extracted from this branch. Payload integrity asserted: total_count 172 == 172 jobs fetched across the paginated stream.
b Root cause explained? Yes. A reclaimed self-hosted runner leaves the job conclusion: failure with the Run step conclusion: cancelled. The classifier's switch has arms for absent / skipped / failure-under-120s and an else false default, so cancelled is scored a real failure; the run gate requires every failed job to be infra, so the rerun is suppressed. Independently, the candidate window is anchored on createdAt while a run only becomes listable once it completes, so a run longer than the window is already outside it at the first invocation that could see it.
c Fix matches root cause? Yes. One arm added to the switch that already owns the "is this failure infrastructural?" decision, and the window's anchor corrected (length unchanged). No widened bound, no suppressed check, no defensive guard at a symptom site.
d Test intent preserved / new tests added? No existing behaviour is weakened: over 120 attempt-1 failed runs no run loses a retry it already got (0 regressions). No ClickHouse test suite is involved in this change.
e Both directions demonstrated? Yes, on two independent runner-reclaim runs: 32413924641 (AST fuzzer (amd_debug, targeted)) and 32306491684 (Stress test (amd_msan)), each false before and true after. Both arms are extracted from the workflow file by regex with an explicit match assertion, so a silent extraction miss cannot make the comparison vacuous. Primary evidence for the classifier half is the cron's own production log (run 32439061057): Checking run .../32413924641 then Not an infrastructure failure, skipping.
f Fix is general across code paths? Yes. The Run.conclusion domain is now fully covered: success correctly stays else false, failure keeps its existing 120s arm, skipped and absent were already infra, cancelled is this change, and null is deliberately left to the separate open #115569 rather than duplicated. The file's three other classification paths are untouched and cannot own this shape (the Praktika-result path 404s for a job that published no result).
g Fix generalizes across inputs (params/datatypes/wrappers)? The input domain here is the Run step's conclusion enum plus the window and limit numbers. The enum is swept exhaustively (row f); the window was measured against 399 runs and 100 actual scheduler fire times; the limit against the deepest eligible list position (131, upper bound 147, versus the new 200).
h Backward compatible? (maintainer-approved exception only) N/A in the settings sense: no settings, no formats, no serialization, no SettingsChangesHistory.cpp, no user-visible behaviour. Blast radius is one hourly cron. MAX_RERUNS=10 is untouched, so a wider scan cannot increase the number of reruns.
i Invariants and contracts preserved? Yes. The run gate's "at least one failed job and all of them infra" semantics is unchanged, and the new arm is monotone (it can only flip a job real to infra, never the reverse), verified over 120 runs. The .conclusion == "failure" pre-filter is load-bearing for safety and deliberately untouched: it is what excludes deliberate cancellation, and across 60 deliberately-cancelled runs (3798 jobs) there are zero (job failure, Run cancelled) pairs and zero verdict changes. updatedAt fails open in the safe direction, since a run mutated after completion only becomes more reachable.

Session id: cron:clickhouse-review-slot-11:20260821-065200

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [70ce7f6]

Summary: ✅


AI Review

Summary

This PR fixes one real classifier gap by treating a failed job whose Run step ended cancelled as infrastructure, and it replaces the old fixed-size failed-run scan with a createdAt-bounded one. The classifier change looks right, but the new scan is still not complete for the stated updatedAt eligibility rule, so I do not think the PR is ready to merge yet.

Findings

❌ Blockers

  • .github/workflows/retry_infra_failures.yml:39 The retry selector still violates its own "recently failed" contract. Eligibility is updatedAt >= $cutoff, but --created ">=${scan_floor}" silently adds createdAt >= now-24h, so any attempt-1 PR run that spends more than 18 hours between creation and failure is skipped permanently. GitHub can keep self-hosted jobs queued for up to 24 hours before they fail, and this repository's pull_request.yml contains long-running jobs, so that class of false negative is still possible exactly when runner capacity is under stress.
    Suggested fix: derive the createdAt bound from an enforced maximum lifetime of pull_request.yml, or page/fail in a way that still guarantees completeness for recent updatedAt values.
Final Verdict

Changes requested.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv, could you review this? When a self-hosted runner is reclaimed mid-Run, the job ends failure with the Run step cancelled, which the infra-retry classifier has no arm for, so the red check is never rerun; the same workflow also anchored its candidate window on createdAt although a run only becomes listable once it completes, which made every run longer than the window unreachable.

The candidate scan is ordered by createdAt while eligibility is by updatedAt, so a
fixed --limit is a prefix of a different order than the one being filtered: an
eligible run can sit behind more than <limit> newer-created runs and be dropped
forever. Simulating the selector at 42 historical fire times over 1000 recent
failed runs, the deepest eligible list index reaches 214, so --limit 200 does drop
an eligible run (1 of 1746 across those fires).

Bounding on createdAt instead makes the scanned set a contiguous prefix of the
listing's own order, which is what removes the hole rather than widening it:
the same simulation misses 0 of 1746. The 24h floor is 4x the largest attempt-1
duration observed beyond the window (9.42h), and costs a median of 267 listed
runs against a 1000 cap that is warned about if it is ever reached.

The alternative of paging until the oldest returned run predates the updatedAt
cutoff was measured and rejected: because updatedAt is not monotonic in this
listing (457 inversions of 999), that stopping rule terminates early and misses
1306 of the same 1746 eligible runs.

MAX_RERUNS is untouched, so a wider scan still cannot cause more reruns.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Agreed on the premise, and it refutes a claim I had made: I had recorded that nothing eligible sits
beyond 200. Simulating the selector at 42 hourly fire points over the 1000 most recent failed
pull_request.yml runs, the deepest eligible list index reaches 214, so --limit 200 does drop
an eligible run. Fixed in 70ce7f6f, and the description no longer claims otherwise.

I did not use the suggested stopping rule, because it measures worse than the fixed limit it would
replace. "Page until the oldest returned run is older than the cutoff" applies an updatedAt
condition to a stream ordered by createdAt, and updatedAt is not monotonic in this listing (457
inversions of 999), so it terminates early:

candidate scan eligible runs emitted eligible runs missed
--limit 50 (before this PR) 960 786
--limit 200 (previous commit) 1745 1
page until oldest createdAt < cutoff 440 1306
--created ">=$scan_floor" (now) 1746 0

What the change does instead is bound the scan on createdAt, the listing's own ordering key, which
is what closes the hole structurally rather than widening it: the scanned set becomes a contiguous
prefix of the order actually being traversed, so no eligible run can hide behind newer ones. A
negative control that reverts the bound to the updatedAt cutoff misses 1328, so the bound is
carrying the result.

The scan is bounded, not unbounded, so to be precise about what it does guarantee: eligibility
requires attempt == 1, whose largest observed lifetime is 9.42h against the 24h floor (0 of 547
exceed 12h), and per-fire listing size is a median of 267 against the 1000-result API cap, which is
now reported by a warning if it ever binds rather than silently truncating.

--limit 50 \
--json databaseId,attempt,createdAt \
--jq ".[] | select(.attempt == 1 and .createdAt >= \"$cutoff\") | .databaseId")
--created ">=$scan_floor" \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updatedAt >= "$cutoff" is the eligibility contract here, but --created ">=${scan_floor}" silently adds a second one: createdAt >= now-24h. That still misses any attempt-1 PR run that spends more than 18 hours between creation and failure.

That is not just theoretical for this workflow. GitHub can leave self-hosted jobs queued for up to 24 hours before failing them, and a pull_request.yml run can then execute for hours after that, so a runner-starved PR can still fail within the last 6 hours while being older than this createdAt floor. Those are exactly the incidents this retry job is supposed to recover, and they will still age out permanently here.

Please either derive the bound from an enforced maximum lifetime of pull_request.yml, or page/fail in a way that still guarantees completeness with respect to recent updatedAt values.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The premise is right and the description now states it: --created is a second condition on top of updatedAt. I corrected the body. On the mechanism and the two remedies, measurements below.

The 24h queue limit cancels, it does not fail. Per the Actions limits page, "a job can be in the queue for 24 hours before it is automatically cancelled". The selector pre-filters --status failure. Over 7 days of pull_request.yml, run-level cancelled ids intersected with failure ids give 0 overlap (1000 and 999 ids fetched; self-intersection 999/999 as a control). A 24h-queued run never enters the scanned set.

Magnitude is zero in a complete population. Fetched per-day so nothing truncates, each day's total_count asserted, 0 days short: 4928 failed runs, 2732 at attempt 1. Create-to-fail span p50 4.63h, p90 6.29h, max 9.42h; above 12h 0, above the 18h this needs 0. Every run above 24h (42, up to 318h) is attempt 2+, excluded by construction. Requirement is 6h cutoff + 9.42h = 15.42h, so 24h holds 1.56x.

Paging until the oldest predates the cutoff is the rule measured last round at 1306 missed against 1. Re-confirmed why: over 900 listed runs createdAt has 0 inversions while updatedAt has 407, so an updatedAt stopping rule ends a createdAt-ordered stream early.

Deriving the bound from an enforced maximum lifetime is not reachable. Those maxima are 35 days per run and 5 days per self-hosted job; a 5-day floor would list 2339 runs at the worst fire, and the runs API stops at 1000 results: page 11 at per_page=100 returns 0 while page 10 returns 100 of 4929, and per_page=50 page 21 is likewise 0 (a 447-run day paginates fully as a control). Asking for that bound reintroduces silent truncation.

Simulating 323 hourly fires over the full population: 24h/1000 misses 0 and never reaches the cap; 48h leaves 990 of 1000; 72h binds at 163 of 323 fires. 24h is the only floor with headroom on both sides, and a warning fires if the cap ever binds.

@maxknv

maxknv commented Aug 24, 2026

Copy link
Copy Markdown
Member

The job retry is implemented outside of this repo in Lambda. this change adds conflicts

@maxknv maxknv closed this Aug 24, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Understood, and I will not reopen this.

One question before I close my side out: does the Lambda treat a job whose Run step ended
cancelled as an infrastructure failure? That shape still looks unretried. Two cases from the
last two days, both pull_request.yml at attempt 1, both on self-hosted, pr-amd-medium, both
with the byte-identical "self-hosted runner lost communication with the server" annotation
(md5 8f71419355651355bbbf76af7d4988a9):

run job check
32683743522 97328701983 Stress test (amd_asan_ubsan)
32597777526 97108968558 Stress test (amd_debug)

attempts/2 is 404 for both, so neither was ever rerun. Across 150 attempt-1 failed runs
(each paginated with a total_count assertion, 0 truncated) failed jobs split
{failure: 327, cancelled: 2} - rare, but it loses that job's signal entirely, since the
check reports failure having run zero tests. If the Lambda already covers it, these two are
something else and I will drop it.

One observation, since it bears on the conflict you describe:
.github/workflows/retry_infra_failures.yml is still state: active and is not idle - over
the last 8 hourly fires it triggered 21 reruns, 19 of them sitting at attempt 2 under
github-actions[bot], matching the secrets.GITHUB_TOKEN it uses. Most reruns in that window
are clickhouse-gh[bot] instead, which I take to be the Lambda.

I also have two older open PRs against that same file, #115569 and #113564. If it is being
superseded, say so and I will not push them further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect manual approve Manual approve required to run CI pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants