Repository navigation
Bound the docker buildx retry ladder by wall clock, not by the timeout divisor - #117578
Conversation
…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.
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,
Severity: blocker / warn / nit. DISAGREE verdicts carry recorded evidence and are terminal Also noticed and deliberately not raised, all pre-existing or unreachable from any caller: a Session id: cron:clickhouse-review-slot-49:20260901-192000 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20260901-171600 |
|
Workflow [PR], commit [e1f4156] Summary: ✅ AI ReviewSummaryThis PR splits the Findings
Final VerdictChanges requested: keep the existing |
|
cc @maxknv @leshikus, could you review this? |
`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.
| 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
_announceis inert. Taking the decision on a clock snapshot captured before the flush, so the callback cannot influence it at all, still givest=[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.
There was a problem hiding this comment.
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.
Changelog category (leave one):
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 imagegave no verdict forhead-distroless-amd64or its library image test:docker.ioreturned500 Internal Server Errorfor theubuntu:22.04manifest twice, twoseconds apart. The ladder matched, then exhausted its budget:
the two ladder lines from that job.log
BUILDX_RETRIESwas both the ladder's attempt cap and the divisor sizing each invocation'stimeout, so one number budgeted two classes whose costs differ by three orders ofmagnitude; #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 thebuildx_timeoutdivisor, andBUILDX_RETRY_DEADLINE= 30 is the wall clock past which no attempt starts. So the per-invocationtimeoutis unchanged, and the deadline holds the expensive class at 2 attempts. Oneinvocation's worst case grows by 28s: at most 15 * 28 = 420s per job against a
BUILDX_JOB_RESERVEof 3600s. Whether the job cap should move is a separate question:#113869 (comment)
Second, independent:
test_docker_libraryselected images by suffix alone, so a failed build wastested anyway and reported
image does not exist!, the second red row.At
retry_deadline=Nonethe printed transcript is byte-identical; replaying the captured stderrgives
2/2 attempt(s)before and4/4after. The apt ladder keeps its 2 attempts; six retry loopsoutside
Shell.runare untouched. Unchanged from master:Shell.runmatches any stderr line, so apermanent 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
26.9.1.1344(included in26.9and later)