Skip to content

Bound the docker buildx retry ladder by wall clock, not by the timeout divisor - #117578

Merged
alexey-milovidov merged 14 commits into
ClickHouse:masterfrom
groeneai:groeneai/bound-buildx-retry-ladder-by-wall-clock
Sep 13, 2026
Merged

alexey-milovidov merged 14 commits into
ClickHouse:masterfrom
groeneai:groeneai/bound-buildx-retry-ladder-by-wall-clock

Conversation

@groeneai

@groeneai groeneai commented Sep 1, 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):

The docker image build jobs no longer lose a leg to a transient registry error that clears within seconds.

Description

Docker keeper image gave no verdict for head-distroless-amd64 or its library image test:
docker.io returned 500 Internal Server Error for the ubuntu:22.04 manifest twice, two
seconds apart. The ladder matched, then exhausted its budget:

the two ladder lines from that job.log
[09:25:16] Retryable error [unexpected status from HEAD request] found, retry 1/2
[09:25:18] ERROR: command failed after 2/2 attempt(s), exit code: 1

BUILDX_RETRIES was both the ladder's attempt cap and the divisor sizing each invocation's
timeout, so one number budgeted two classes whose costs differ by three orders of
magnitude; #113869 lowered it 5 -> 2. At 2 attempts a cheap failure gets one 2s backoff, so a
per-request brownout exhausts it in 2s, and the job failed holding 17854 of its 18000s unused.

Each class now gets its own bound: BUILDX_RETRIES = 4 caps attempts,
BUILDX_EXPENSIVE_ATTEMPTS = 2 is the only input to the buildx_timeout divisor, and
BUILDX_RETRY_DEADLINE = 30 is the wall clock past which no attempt starts. So the per-invocation
timeout is unchanged, and the deadline holds the expensive class at 2 attempts. One
invocation's worst case grows by 28s: at most 15 * 28 = 420s per job against a
BUILDX_JOB_RESERVE of 3600s. Whether the job cap should move is a separate question:
#113869 (comment)

Second, independent: test_docker_library selected images by suffix alone, so a failed build was
tested anyway and reported image does not exist!, the second red row.

At retry_deadline=None the printed transcript is byte-identical; replaying the captured stderr
gives 2/2 attempt(s) before and 4/4 after. The apt ladder keeps its 2 attempts; six retry loops
outside Shell.run are untouched. Unchanged from master: Shell.run matches any stderr line, so a
permanent error preceded by a retryable signature is still retried (3 attempts/66s against
master's 2/42s at 20s each, inside the 28s above).

Also from review: a report callback is absorbed by the back-off it runs inside, so a callback no
longer than that leaves the ladder unchanged; a slower one spends the deadline itself and can use
up a start the ladder would otherwise have had. No in-tree caller passes both. The exception path
also reaps the child it kills, so a cancelled retry cannot report None.

Related: #117419

Failing report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=117419&sha=b27939921a57ea5d41e0eb5df09d1acdc4c7266f&name_0=PR&name_1=Docker%20keeper%20image


Workflow [PR]
Sync PR [sync-upstream/pr/117578]

Version info

  • Merged into: 26.9.1.1344 (included in 26.9 and later)

groeneai and others added 7 commits September 1, 2026 14:11
…t divisor

`BUILDX_RETRIES` was both the attempt cap for the retry ladder and the divisor
that sizes each invocation's `timeout` bound, so one number budgeted two error
classes whose per-attempt costs differ by three orders of magnitude. Raising the
cap shrinks every invocation's bound, which is why it went from 5 to 2 when the
`timeout` wrapper was added.

At 2 attempts the ladder for a cheap failure spans a single 2s backoff, so one
transient registry error consumes the whole budget in 2 seconds. In the report
below the `ubuntu:22.04` manifest returned `500 Internal Server Error` twice
inside those 2 seconds, having resolved fine four times in the preceding two
minutes, and the job then failed holding 17854 of its 18000s unused.

Give each class its own bound:

  BUILDX_RETRIES            = 4   attempt cap
  BUILDX_EXPENSIVE_ATTEMPTS = 2   the only input to the buildx_timeout divisor
  BUILDX_RETRY_DEADLINE     = 30  wall clock the ladder may span

`buildx_timeout` now divides by `BUILDX_EXPENSIVE_ATTEMPTS`, which is 2 exactly
where `BUILDX_RETRIES` was 2, so it returns the same values as before and the
per-invocation bound does not move. The deadline is what holds the expensive
class at 2 attempts. It is anchored at the first retryable failure, because an
attempt may legitimately run for its whole bound before failing, and enforced
twice: once before the sleep against the nominal delay, and once after it by
re-reading the clock, since `time.sleep` may return late on a loaded runner.
`on_retry` fires after the second check, so it never announces an attempt that
is then cancelled.

`retry_deadline` is additive on `Shell.run` and `Result.from_commands_run`. Left
at `None` the eligibility test reduces to the `retry < retries - 1` the three
failure paths already used, and the printed transcript is unchanged. The worst
case for one invocation grows by exactly `BUILDX_RETRY_DEADLINE` - 2 = 28s,
independently of the bound, so at most 15 * 28 = 420s per job against a
`BUILDX_JOB_RESERVE` of 3600s.

Related: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=117419&sha=b27939921a57ea5d41e0eb5df09d1acdc4c7266f&name_0=PR&name_1=Docker%20keeper%20image
Related: ClickHouse#117419
Related: ClickHouse#113869

Co-Authored-By: Claude Opus 5 <[email protected]>
…uild

`test_docker_library` picked images by architecture suffix alone, so a build that
had already failed was still handed to the official-images test, which then
failed with `image does not exist!`. That is a second red row restating the
first, and it fires for any failed build, not just a registry one.

Skip the images whose build result is not ok. `Result.is_ok` counts `SKIPPED` and
`XFAIL` as ok, so this cannot turn a green job red, and the build's own FAIL row
still fails the job. A `SKIPPED` row for the untested image would be invisible in
the workflow report anyway, since `Result._flat_failed_leaves` keeps only failing
leaves.

Related: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=117419&sha=b27939921a57ea5d41e0eb5df09d1acdc4c7266f&name_0=PR&name_1=Docker%20keeper%20image
Related: ClickHouse#117419

Co-Authored-By: Claude Opus 5 <[email protected]>
Deferring the callback past the sleep left its explanation above
`pending_notice = matched`, where neither half still applied: the
"only where another attempt follows" condition is now enforced one
block up by `_another_attempt_follows`, and the swallowed reporting
failure it also described lives at the call site. Keep the part that
is not visible from the code, at the site that has the code.

Co-Authored-By: Claude Opus 5 <[email protected]>
The deadline was read once after the backoff sleep, and the caller-supplied
`on_retry` callback then ran before `Popen` with no further check. A callback
that takes longer than the window that is left therefore let an attempt start
after the deadline had already passed.

Measured on the previous revision with a 5s deadline and a 6s callback: two
processes started and the ladder reported 2/4 attempts. With the check moved to
the last position before the attempt, one process starts and it reports 1/4.
The transcript alone does not show this, because the deadline message is printed
either way, so the oracle has to count processes.

The announcement is gated on the same predicate, so a retry that will not run is
still not announced. The two predicates stay separate deliberately:
`_another_attempt_follows` predicts against the nominal delay before the sleep,
while `_deadline_passed` reads the actual clock after it.

No call site passes `retry_deadline` and `on_retry` together today, so nothing
in the tree reaches this. The knob lives in a shared `praktika` primitive and
`Docker.pull_image`, which already takes a callback, is the natural next
consumer.
Both call-site-visible descriptions of `retry_deadline` claimed it bounds the
span of the retry ladder. It does not. The predicate is evaluated only at a
failure and only decides whether a further attempt starts; nothing interrupts an
attempt that is already running. The ladder can therefore outlast the deadline
by one attempt's own bound, which at the buildx call sites is 30s plus up to
2820s (`BUILDX_TIMEOUT` 2700 plus `BUILDX_TIMEOUT_KILL_AFTER` 120).

That is the same conflation of two cost classes into one number that this branch
removes from `BUILDX_RETRIES`, so restating it in the new knob's own contract
was self-defeating. Documentation only, no behaviour change.
`.claude/CLAUDE.md:7` asks for literal class and function names in comments to be
written as inline code, and the rule predates this branch's base, so it binds
here. Four of the comments added on this branch missed it.

The pre-existing bare names elsewhere in these two files are left as they are;
this is not a repo-wide sweep.
The comment above `BUILDX_RETRIES` said `BUILDX_RETRY_DEADLINE`, not the count,
is what bounds how long the ladder may run for. Both halves are wrong: the count
does bound the span, and the deadline does not, because an attempt already
running is never interrupted, so the ladder can outlast the deadline by that
attempt's own bound. It also contradicted this branch's own wording at
`ci/jobs/docker_server.py:399` and `ci/praktika/result.py:940`.

The sentence's point is kept: raising the count is safe because the deadline,
not the count, decides how long further attempts stay eligible to start.

Comment only, so the code is token-identical.
@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 Sep 1, 2026
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 4 gate findings + 4 of my own,
over 3 review rounds and 2 fix rounds).

# Sev Finding Verdict Evidence / action
1 warn A slow on_retry callback can start a retry after retry_deadline, because the last deadline check runs before the callback and nothing rechecks before Popen (ci/praktika/utils.py) AGREE, fixed @ e4c7966b944eaf7 The cancellation check is now the last thing before the attempt, and the announcement is gated on the same predicate. No in-tree caller passes retry_deadline and on_retry together today, but the knob lives in a shared primitive and Docker.pull_image already has the callback.
2 warn retry_deadline is documented as bounding the ladder's total span, which it does not: nothing interrupts an attempt already running, so the ladder can outlast it by one attempt's own bound (ci/praktika/result.py, ci/jobs/docker_server.py) AGREE, fixed @ 9e9319756d23743 plus 5ac563c2cac5e66 All three doc sites now state what the deadline gates. This is the same conflation the change removes, so it must not survive in the new knob's own contract. The third site, at the constant's definition, was missed by my own round-1 plan and fixed in round 3.
3 nit New comments leave buildx_timeout, Popen, time.sleep and the BUILDX_* constants unbackticked, against .claude/CLAUDE.md:7 AGREE, fixed @ 82ee0d76b4919bb none
4 warn Opening the log file after the final deadline check can still start an attempt after the deadline, so the check should be repeated inside with open(log_file, "w") immediately before Popen (ci/praktika/utils.py) DISAGREE, terminal open(log_file, "w") truncates, and that file is read straight back at result.py:1012 to become Result.info. A deadline read placed after the open can only fire after the truncation, so its one reachable effect is to cancel with an empty log, i.e. to report the failure with no output at all. Untouched, the same timeline starts the attempt late, the attempt writes its log, and the diagnostics survive. The check therefore already sits at the last point where cancelling is free, and the gap is not closeable in any case: Popen's own fork and exec stay inside it. The 4 s open in the scenario was injected into the unit under test; log_file is a local regular file that praktika itself creates under the job temp dir, or /dev/null.
5 nit In the exception handler a stop caused by the deadline prints only Final attempt failed, no more retries left., not the deadline line the two other termination sites print, so a job log reads it as count exhaustion (ci/praktika/utils.py) AGREE, noted, not fixed Diagnostic only: no behaviour, exit code or attempt count changes, and the preceding Retry N/4: exception line makes the count mismatch visible. Reachable only from the second attempt onward (at the first, the anchor is set in the same statement, so no elapsed time exists yet) and only when an exception is raised before Popen, which needs a log-file or spawn failure. Left as is rather than spent another fix round on a log string. Raised in my own pass first, reached independently by the gate.

Severity: blocker / warn / nit. DISAGREE verdicts carry recorded evidence and are terminal
per finding. Findings on hunks unchanged by a fix round are auto-dropped.

Also noticed and deliberately not raised, all pre-existing or unreachable from any caller: a
string retry_errors is normalised to a list only inside the retries < 2 branch; retries=0
leaves the attempt counter unbound in the final report; and with both retry_deadline and
on_retry set, a deadline that expires during the backoff now drops the warning the callback
would have recorded, which no in-tree caller can reach and which fails in the safer direction.

Session id: cron:clickhouse-review-slot-49:20260901-192000

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 1, 2026
@clickhouse-gh clickhouse-gh Bot closed this Sep 1, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 1, 2026
@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Replaying the failing leg's captured stderr through Shell.run reproduces the ladder exactly every run; the outcome is a pure function of that stderr, so there is no failure rate to quote.
b Root cause explained? BUILDX_RETRIES was both the ladder's attempt cap and the divisor sizing each invocation's timeout bound, so one number budgeted a ~1s registry error and a 2700s mirror wedge alike. At 2 attempts a cheap failure gets one 2s backoff, so a per-request brownout exhausts the ladder in 2 seconds while the job still holds 17854 of its 18000s.
c Fix matches root cause? Yes, and it is not a band-aid: nothing was widened or weakened. The single counter is split into three constants with one job each, so the attempt count stops cheap failures, a wall clock stops expensive ones, and the divisor is decoupled from both. buildx_timeout returns byte-identical values, verified over four input pairs.
d Test intent preserved / new tests added? No committed test exists to weaken: ci/tests and the CI Tests job were removed by #115650, and .claude/CLAUDE.md prescribes a throwaway test for CI-script changes rather than a committed one. The throwaway harness carries 53 assertions, every arm paired with a control that must go the other way.
e Both directions demonstrated? Yes, on the same captured stderr: after 2/2 attempt(s) before the change, which is verbatim the failing job's own line, and after 4/4 attempt(s) after it. Control: a permanent build error with no matching token still fails on its first attempt on both trees.
f Fix is general across code paths? All 13 invariant carriers were checked by grep with exit-code discipline and positive controls, not by reading. The deadline sits in Shell.run, the layer that owns the ladder, instead of being re-implemented at the call site. Both call sites passing retries=BUILDX_RETRIES get it; there is no third. The apt-mirror fallback predicates are untouched.
g Fix generalizes across inputs (params/datatypes/wrappers)? The matrix is walked, not sampled: retry_deadline in {absent, None, 0.001, 3, 5, 6, 30}; failure classes {matching token, no token, timeout expiry, exception before Popen}; retries in {2, 3, 4}; sleep overshoot in {1x, 3x}; strict in {False, True}; on_retry in {absent, instantaneous, slow enough to outlast the deadline}. Boundaries included: the model walks the deadline to the exact point where a third expiry becomes reachable (66 vs 67). The callback-duration axis was added after review found that sampling it only at zero hid a real gap, described in row i.
h Backward compatible? Yes. No setting, no serialization, no user-visible behaviour, so SettingsChangesHistory.cpp is not involved. retry_deadline is appended after on_retry and before **kwargs, and the only many-positional caller passes six positional arguments ending at stdin_str. Left at its None default the printed transcript is byte-identical, which is asserted rather than argued.
i Invariants and contracts preserved? The deadline is the one exit that fires before Popen, so both of its consequences were chased: the attempt count is reported as the number that actually ran, and proc can still be None there if every prior attempt raised before spawning. The second one raised an AttributeError when I probed it, and is fixed and covered by its own arm. strict still raises, and on_retry still announces only an attempt that will really run, now enforced by a post-sleep clock re-read rather than assumed from the nominal delay. The intended invariant is that no attempt starts after the deadline, and the first version did not keep it: the last check sat before the caller-supplied callback, so caller code ran inside an unguarded window. Measured with a 5s deadline and a 6s callback, two processes started; the check is now the last statement before the attempt, one process starts, and the arm asserting it counts processes rather than reading the log, because the log prints the deadline message either way.

Session id: cron:clickhouse-impl-slot-40:20260901-171600

@clickhouse-gh

clickhouse-gh Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e1f4156]

Summary: ✅


AI Review

Summary

This PR splits the docker buildx retry budget into a retry count, an expensive-attempt divisor, and a wall-clock deadline, and it stops test_docker_library from testing images whose build already failed. The docker_library change looks fine, but the shared retry_deadline helper still lets on_retry latency suppress later retries, so the main retry-ladder contract is not fully preserved yet.

Findings

⚠️ Majors

  • ci/praktika/utils.py:358-368, ci/praktika/utils.py:467-471, ci/praktika/utils.py:513-527 The PR’s contract is that a reporting callback no longer shortens the retry ladder, but _another_attempt_follows still measures admission against max(time.monotonic(), attempt_end + next_delay) after the deferred _announce runs. If on_retry takes longer than the remaining back-off, that extra wall-clock time still advances the deadline and suppresses retries that the same ladder would admit without the callback. I reproduced this on the current head with retries=4, retry_deadline=10, and immediate retryable failures: no callback starts 3 attempts, while on_retry sleeping 9 seconds starts only 2. Suggested fix: make the retry-admission decision independent of synchronous reporting work, or deliver the notice on a path that cannot feed back into deadline timing.
Final Verdict

Changes requested: keep the existing ci/praktika/utils.py thread open until on_retry can no longer change retry admission in deadline mode.

@groeneai

groeneai commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @maxknv @leshikus, could you review this? BUILDX_RETRIES was both the buildx retry ladder's attempt cap and the divisor sizing each invocation's timeout, so one number budgeted a 1 second registry error and a 2700 second mirror wedge alike, and a transient docker.io 500 exhausted the ladder in 2 seconds while the job still held 17854 of its 18000 seconds. This splits it into three constants and adds a wall-clock deadline in Shell.run, which is the shared primitive, so the praktika side is the part worth a close look.

Comment thread ci/praktika/utils.py Resolved
Comment thread ci/praktika/utils.py Resolved
groeneai and others added 4 commits September 1, 2026 21:44
`retry_deadline` and `on_retry` could disagree about whether a retry happened.
The callback ran between the deadline check and `Popen`, so a callback whose own
duration crossed the deadline was reported as a retry that the check then
cancelled: with `retry_deadline=5`, a 2s backoff and a callback sleeping 6s, one
process ran and the caller was still told a retry had (1/3). That contradicts
`Docker.pull_image`, which documents `on_retry` as called once per actual retry.

Moving the check ahead of the callback is what put the callback inside that
window; moving the callback back to the failure site does not help, because the
deadline is wall clock and the callback spends it wherever it runs before the
attempt (measured: same 1 process, same notice). So announce after the readers
have started instead. The retry is then certain to have run, and the readers
drain the pipes, so caller code of any duration cannot block the child.

The note in the first commit of this branch that `on_retry` "fires after the
second check, so it never announces an attempt that is then cancelled" described
that original order and stopped being true when the check moved; it holds again
now, for the stronger reason that the attempt is already running.

The deadline still admits exactly the attempts it did. In the case above the
second attempt now starts at 2.0s, inside the 5s deadline, where before the
callback consumed the window and it never started at all: the callback no longer
decides whether an eligible retry runs. Attempt start times, not attempt counts,
are what pins this - the count legitimately moves from 1 to 2 - and the
transcript pins neither, since `Retry deadline of Ns reached` prints on both
paths.

With `retry_deadline` left at `None` the callback fires exactly as before, on the
same attempts with the same arguments, which is every in-tree caller today.

Co-Authored-By: Claude Opus 5 <[email protected]>
This branch made `terminal` in the exception handler consult the deadline as well
as the attempt count, but left the message that reports it saying only that the
count ran out. A spawn or log-file error under a deadline therefore printed
`Final attempt failed, no more retries left.` with retries still unspent: with
`retries=4` and a 3s deadline the ladder stops after 2 attempts and blamed the
count. The two non-exception termination sites already distinguish the two
causes; this is the third.

`terminal` with `retry < retries - 1` can only mean the deadline refused the next
attempt, since that is the sole other reason `_another_attempt_follows` returns
false, so the count message is kept for real count exhaustion and is unchanged
wherever `retry_deadline` is `None`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Queueing the notice past the backoff was applied to every caller, but only a
deadline can cancel the attempt it describes, so callers that pass none were
paying an ordering change for a case they cannot reach. Both callbacks in the
tree are in that group: `Docker.pull_image` takes `on_retry` and no deadline.
Announce at the failure site as before when `retry_deadline` is `None`, and queue
only when one is set.

This makes the branch's "unchanged with `retry_deadline` left at `None`" claim
hold for callback callers too, which it did not: the transcript of a run whose
callback throws is now byte-identical to the merge base, where at the previous
commit it was not, and the same arm still separates the two revisions. The note
in that commit that the callback then "fires exactly as before" was too strong -
the attempts and arguments matched, the moment did not - and it is accurate now.

A deadline-carrying caller keeps the notice tied to a started attempt, so nothing
about the case that motivated the deferral changes: with `retry_deadline=5` and a
callback sleeping 6s, one retry runs, one notice is sent, and no attempt starts
past 5s.

Co-Authored-By: Claude Opus 5 <[email protected]>
Announcing between the readers starting and `proc.wait` put caller code on the
only path to the cleanup that reaps the child, so a callback raising something
`Shell.run` does not catch, a `KeyboardInterrupt` for instance, left the retry
running. Announcing after the wait instead keeps every property the earlier
placement had, since an attempt that has finished has certainly started, and the
child is already reaped when the callback is entered: with a 1s child, the notice
now follows that attempt's own streamed output rather than preceding it.

Co-Authored-By: Claude Opus 5 <[email protected]>
…dx-retry-ladder-by-wall-clock

Master moved `test_docker_library` out of `ci/jobs/docker_server.py` into
`ci/jobs/scripts/docker_server/docker_library.py`, which is the whole conflict:
this branch had edited the copy master deleted. Master's removal is applied and
the branch's one edit there - skipping an image whose build failed, since it does
not exist - is re-applied at the new location, where it would otherwise be lost
silently. The retry-ladder change itself merged cleanly.
@clickhouse-gh
clickhouse-gh Bot requested review from leshikus and maxknv September 12, 2026 22:06
Comment thread ci/praktika/utils.py
Comment on lines +461 to +464
if pending_notice is not None:
# Only past here is a deadline-cancellable retry certain to have run,
# and the child is already reaped, so caller code cannot strand it.
_announce(pending_notice, retry)

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.

retry_deadline is still spending wall-clock budget on on_retry for the next retry. pending_notice is flushed here before the code decides whether this failed attempt may itself be retried again, so a slow callback can suppress later retries even when the ladder would admit them without the callback.

I reproduced it on the current head with retries=4, retry_deadline=10, immediate retryable failures, and an on_retry callback that consumes 5 seconds: Shell.run starts attempts at t=[0, 2]; without the callback it starts t=[0, 2, 6]. That means the reporting hook still changes retry behavior in the deadline mode this patch introduces. The retry/stop decision for the just-finished attempt needs to happen before _announce, or the notice needs to be queued so it cannot burn the remaining deadline budget.

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.

Reproduced on 81cd07466fed, with your numbers: retries=4, retry_deadline=10, immediate retryable failures and a 5 s on_retry start attempts at t=[0.0, 2.0], against t=[0.0, 2.0, 6.0] with no callback. The oracle counts child processes and the start time each child records itself, so it does not depend on the transcript. Fixed in 6ca8fdf, but not with either shape you suggested, because I built and measured both first:

  • Retry/stop decision before _announce is inert. Taking the decision on a clock snapshot captured before the flush, so the callback cannot influence it at all, still gives t=[0.0, 2.0]: the pre-sleep check now admits the third attempt, and the post-sleep _deadline_passed() recheck then cancels it 4 s later (invocation 7.0 s -> 11.0 s). That recheck cannot go instead: with it off, the duration-grid search exceeds this ladder's invocation bound, 5685 s against 5670 s at a 3x sleep overshoot and 5703 s at 10x.
  • Queueing the notices until the ladder stops does give t=[0.0, 2.0, 6.0], and it always burns the whole deadline and then pays every callback on top: 7.0 s -> 16.1 s for that one invocation. The hook stops shortening the ladder by gaining the power to lengthen it.

What landed instead: the back-off runs from the end of the attempt rather than from whenever the ladder gets round to sleeping. The next attempt is due at attempt_end + delay, so announcing the previous retry is spent inside the back-off instead of being added to it, and the admission check compares that same wake target against the deadline. On your case: t=[0.0, 2.0, 7.0], so the third retry is admitted; with no callback, or a cheap one, starts are unchanged at t=[0.0, 2.0, 6.0]. A retry that the post-sleep recheck cancels is still never announced, and restoring the pre-deferral announce site reddens that check, so it is not vacuous.

Two notes on scope, since the hook is not reachable with a deadline today. No call site combines on_retry with retry_deadline (AST sweep over every .py under ci/, including ** splats), and Docker.pull_image does not accept retry_deadline; the only callback that exists, DockerImage._warn_pull_retried, costs 0.99 ms per call over a 200-call mean, which is 0.003% of BUILDX_RETRY_DEADLINE. And on the no-deadline path the gap between attempts is now max(callback, delay) rather than callback + delay, which for that callback is under a millisecond.

Separately, your sibling finding about the exit code was right and is fixed in e1f4156: proc.kill() only signals, so Popen.returncode stayed None, and this branch added a loop exit that reads it. With Thread.start raising the way thread exhaustion would, a live child and a deadline the back-off wakes past, master returns 1 and this branch returned None, printing command failed after 1/4 attempt(s), exit code: None. Waiting after the kill returns -9 there and reaps the child.

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.

I re-ran this on the current head, and the issue is still present once the callback is longer than the nominal back-off. The 5 s case is fixed, but ci/praktika/utils.py:358-368 still makes _another_attempt_follows compare the deadline against max(time.monotonic(), attempt_end + next_delay), and ci/praktika/utils.py:467-471 flushes pending_notice before the next retry decision at ci/praktika/utils.py:513-527. Any on_retry work beyond the remaining delay still advances the admission clock.

Concrete repro on e1f4156: retries=4, retry_deadline=10, immediate retryable failures. With no callback, Shell.run starts 3 attempts; with on_retry sleeping 9 seconds, it starts only 2. So the callback can still suppress a later retry that the same ladder would admit without it.

…adline

`retry_deadline` measures wall clock from the first retryable failure, and the
deferred `on_retry` announcement runs between an attempt being reaped and the
decision about the next one, so the callback's own duration was charged against
the budget. With `retries=4`, `retry_deadline=10`, immediate retryable failures
and a callback that consumes 5 s, the ladder started attempts at t=[0, 2]; the
same ladder with no callback started t=[0, 2, 6]. A reporting hook was deciding
how many attempts a command got.

Anchor the back-off on the end of the attempt rather than on whenever the ladder
gets round to sleeping. The next attempt is due at attempt_end + delay, so what
the ladder spends in between (announcing the previous retry) is spent inside the
back-off instead of being added to it, and the admission check compares that same
wake target against the deadline. Measured on the case above: t=[0, 2, 7], so the
third retry is no longer suppressed; with no callback, or a cheap one, the starts
are unchanged at t=[0, 2, 6]. A retry that the post-sleep recheck cancels is
still never announced (mutation control: restoring the pre-deferral announce site
reddens that check).

Both alternatives were built and measured before choosing this one. Taking the
retry/stop decision before the announcement is inert, t=[0, 2] unchanged: the
pre-sleep check then admits the attempt and the post-sleep recheck cancels it 4 s
later. Queueing the notices until the ladder stops does admit a third attempt,
but it always burns the whole deadline and then pays every callback on top (7.0 s
to 16.1 s for one invocation here), which lets a reporting hook extend the ladder
instead of shortening it.

In-tree behaviour is unchanged: no call site combines `on_retry` with
`retry_deadline`, and the only callback that exists,
DockerImage._warn_pull_retried, costs 0.99 ms per call over a 200-call mean. On
the no-deadline path the gap between attempts becomes max(callback, delay) rather
than callback + delay, which for that callback is under a millisecond.
`proc.kill()` only signals, and nothing reaps the child afterwards, so
`Popen.returncode` stays `None`. This branch added a loop exit that reads it: an
exception raised after `Popen` while the child is still alive can be followed by a
back-off that the post-sleep deadline recheck cancels, and that path returns
`proc.returncode`.

Measured with `Thread.start` raising the way thread exhaustion would, a live
`sleep 120` child, and a deadline the back-off wakes past: master returns 1,
this branch returned `None` and printed
`command failed after 1/4 attempt(s), exit code: None`. Waiting after the kill
returns -9 on the same arm and reaps the child instead of leaving it until the
interpreter exits.
@alexey-milovidov alexey-milovidov self-assigned this Sep 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 13, 2026
Merged via the queue into ClickHouse:master with commit c53f808 Sep 13, 2026
177 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 13, 2026
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 comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). 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 pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants