Skip to content

CI: bound each docker buildx invocation in the Docker image jobs - #113869

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:ci-bound-docker-buildx-timeout
Aug 21, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:ci-bound-docker-buildx-timeout

Conversation

@groeneai

@groeneai groeneai commented Aug 7, 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

Docker server image and Docker keeper image wedged with no output for about five hours, then died
on the praktika 18000s job cap: four times on 2026-08-05 on four unrelated PRs, producing no image and
no usable log. No related open issue found. The stall is inside apt-get update.

apt cannot bound it: Acquire::http::Timeout is an inactivity timeout, not a wall-clock one.
Measured locally, a mirror trickling a byte per second runs unbounded past a 700s cap, and
Acquire::Retries=5 does not change that. The failing jobs show that shape.

And the retry configured here could never run: both call sites pass retries and retry_errors, but
Result.from_commands_run never forwards a timeout, so a command that never returns is never
retried. All four logs show zero Retryable error lines.

Both invocations are now wrapped in GNU timeout, so an expiry is retried while a real build error
still fails fast.

The bound starts at 2700s, above the slowest healthy single attempt over 90 days (1819.1s). A fixed
bound would not bound the job: main() loops over os variants and tags, so the invocation count is
not fixed, and nine successful builds at 2700s exceed the cap alone. Each invocation instead gets what
remains of the cap after a 3600s reserve, divided by the retry count: the scheduled shape's worst case
is then 16334s against 18000s. That division is also why the retry count drops from 5 to 2: five
attempts fit only up to a 255s bound, seven times below the slowest healthy attempt, where two
attempts leave 881s above it. Being one count for all of Shell.run's tokens, it applies to the
registry and mirror signatures too.

ci/tests/test_docker_buildx_timeout.py pins that arithmetic against the job's own cap, and the
sentinels arming a real retry by attempt count rather than membership.

Validation (click to expand)

An expiry is recognised on 124, and on the escalated 137 only when timeout logged its own KILL
diagnostic, so an OOM or an external kill is not mistaken for one: the same discrimination
clickhouse_proc.py makes with _TIMEOUT_KILL_DIAG, with LC_ALL=C pinning that translated string.
Acquire::Retries is deliberately not re-added to the published Dockerfiles, which would revert
7cb4072. The git clone of docker-library/official-images stays unbounded: not the apt
layer, never observed wedging.

Retry behaviour through the real Shell.run at the shipped count of 2:

arm rc attempts verdict
expiry, child honours SIGTERM 124 2 retried
expiry, child ignores SIGTERM (escalated) 137 2 retried
succeeds 0 1 no retry
real error exit 7 7 1 fails fast
bare 137 (kill -9) 137 1 no retry

The last two are the discriminating controls. Replacing the KILL diagnostic with a string timeout
never prints drops the second arm to one attempt, proving the token is read rather than merely present
in a list. Quoting is pinned against an unwrapped baseline: the brace group reproduces every argument
byte-for-byte, while bash -c returns rc=0 and truncates a --build-arg.

The worst case walks main()'s own loop, allowing a wedge in every variant/tag group rather than one
per job, since nothing breaks between groups; it is exact by construction, merging combinations that
reach the same elapsed. Restoring five retries, or cutting the reserve to 600s, reddens it at 18510s
and 18246s. One extra os variant stays green at 17180s, since a shrinking deadline absorbs it, while
thirty redden it. A separate arm pins the single tag both scheduled commands request: unreachable
--tag-type release would build four tags and not fit (23948s). Twenty-four of twenty-six
mutations redden a named arm; the other two are controls.


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

Version info

  • Merged into: 26.8.1.1880 (included in 26.8 and later)
  • Backported to: 26.7.7.33

groeneai and others added 2 commits August 7, 2026 14:37
`Docker server image` and `Docker keeper image` wedged with no output for
about five hours and then died on the praktika 18000s job cap, four times on
2026-08-05 across four unrelated PRs, producing no image and no usable log.
The stall is inside `apt-get update` against the in-region Ubuntu mirror.

apt cannot bound it. `Acquire::http::Timeout` is an inactivity timeout, not a
wall-clock one: measured against a local mirror, one that never answers lets
`apt-get update` return in 248s, but one trickling a byte per second was still
running at a 700s cap, and `Acquire::Retries=5` does not change that. The
failing jobs show the trickling shape, their throughput decaying to about 6
kB/s in the last logged fetches. Re-adding `Acquire::Retries` to the published
Dockerfiles is also not an option: 7cb4072 deliberately removed it.

The retry configured here could never run either. Both call sites already pass
`retries` and `retry_errors`, but `Result.from_commands_run` never forwards a
`timeout` to `Shell.run`, so a command that never returns is never retried.
All four job logs contain zero `Retryable error` lines.

Wrap both invocations in GNU `timeout` and let the existing retry machinery
act on the expiry. An expiry is recognised on 124 via an echoed sentinel, and
on the escalated 137 only when `timeout` logged its own KILL diagnostic, so an
OOM or an external kill is not mistaken for one; this is the discrimination
`clickhouse_proc.py` already makes with `_TIMEOUT_KILL_DIAG`, and `LC_ALL=C`
pins that translated string. Both sentinels go to stderr, which is the only
stream `Shell.run` matches against. A real build error still fails fast with
its own status.

The wrapper is a brace group rather than `bash -c`, because the buildx command
already contains single-quoted arguments: the `bash -c` form returns rc 0
while silently truncating a space-bearing `--build-arg` at the space, so the
exit code is not the oracle for it and the argv is pinned instead.

A single per-invocation constant would not bound the job. `main()` loops over
the os variants and tags, each running one build per architecture plus a push,
so the invocation count is not fixed, and nine successful builds at 2700s
exceed the cap on their own. Each invocation therefore gets what remains of
the cap after a 3600s reserve, divided by the retry count, which bounds the
job by construction for any variant count: the scheduled shape's worst case is
16334s against 18000s, and the envelope holds to four os variants at one tag.
A passed deadline is clamped to 60s rather than 0, since `timeout 0` runs the
command unbounded. The starting bound of 2700s is above the slowest healthy
single attempt over 90 days (1819.1s; one job was green on a single 1748.1s
attempt).

Lowering `BUILDX_RETRIES` from 5 to 2 is what makes that arithmetic fit, and
it applies to the registry and mirror signatures the constant already covered
as well, since `Shell.run` takes one retry count for all of its retry tokens.
At five attempts the largest bound that fits is 255s, seven times below the
slowest healthy attempt, so five attempts would kill passing builds rather
than wedged ones.

`ci/tests/test_docker_buildx_timeout.py` pins what would otherwise fail
silently: that arithmetic against `JobConfigs.docker_server.timeout` rather
than a hardcoded cap, both call sites still passing `retries` and
`retry_errors`, the sentinels arming a real retry, the argv surviving the
wrapper, and a bare 137 not being read as an expiry. Two arms drive the
shipped code rather than its source text, because a substring assertion cannot
see either regression: one runs `build_and_push_image` and reads the bound back
out of every command it produces, so reverting the call sites to a fixed bound
is caught, and one drives `with_timeout` itself through `Shell.run`, so a
non-positive kill delay is caught. A zeroed delay never escalates, which leaves
a build that ignores SIGTERM running to completion and then retried on the 124
sentinel. The retry arms assert the
attempt count through the real `Shell.run`, not membership in
`BUILDX_RETRY_ERRORS`: that list is built from the sentinel constants, so a
membership assertion stays true even for a token `timeout` never emits.
Replacing the KILL diagnostic with such a string drops that arm from two
attempts to one.

The worst case walks `main()`'s own loop, which has no break and no `is_ok()`
gate between variant/tag groups, so it allows a wedge in every group rather
than one per job; the early returns inside `build_and_push_image` end only
their own group. Each invocation gets all three fates `Shell.run` admits, not
two: succeeding first try, wedging on every attempt, and expiring some number
of times before a later attempt succeeds. The third is the expensive one,
costing nearly as much as a wedge while leaving the rest of the group to run,
and omitting it understates the scheduled shape by 1210s. It is exact by
construction: group cost is a pure function of the elapsed time on entry and
the per-invocation fates, so traces reaching the same elapsed are merged
instead of enumerated. Restoring five retries takes the four-variant push
shape to 23490s, and cutting the reserve to 600s takes the scheduled shape to
18972s; both fail. A separate arm pins the single tag
both scheduled job commands request, since `--tag-type release` would build
four tags and does not fit; that shape is not reachable from any scheduled job.
main() is the only production caller of build_and_push_image, and it was the
only thing supplying the stopwatch and the job cap. Both parameters were
optional, and buildx_timeout returns the fixed BUILDX_TIMEOUT whenever
job_timeout is falsy, so dropping those two keyword arguments silently reverted
every invocation to a fixed 2700s bound with the whole test suite green: the
scheduled shape then prices at 50058s against the 18000s job cap, up from
16334s. Make both parameters required so that omission is a TypeError rather
than a silent downgrade, and pin main()'s call site with an AST assertion, since
a signature can be relaxed again. The existing arm that drives
build_and_push_image supplies both arguments itself, so it pins the two inner
call sites but structurally cannot see main().

The scope premise for that envelope asserted the textual presence of
`--tag-type head` in the scheduled commands. argparse resolves a repeated option
to its last occurrence, so appending `--tag-type release` left the assertion
green while the job built four tags, a shape priced at 23948s. Resolve the
commands through the shipped parse_args instead and assert the effective value.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai

groeneai commented Aug 7, 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; 9 gated rounds, 2 on the approach
and 7 on the code, raising 17 findings for $42.35). Verdicts below are for the final round;
earlier rounds' AGREEd findings are already fixed in the commits.

# Sev Finding Verdict Evidence / action
1 ⚠️ The main() wiring test asserts keyword names only, so writing job_timeout=0 at the call site keeps it green while selecting the fixed 2700s fallback (ci/tests/test_docker_buildx_timeout.py:451) AGREE, not fixed Reproduced: that one-token edit leaves all 22 arms green, and the model then prices the scheduled shape at 50058s against the 18000s cap. Narrower than it reads: dropping the arguments is now a TypeError, buildx_timeout has two call sites and both forward the parameter, and no production path yields a falsy cap (both job configs are 18000, the Job.Config default is 5 * 3600, and the only set_timeout caller is an unrelated job). So this is a test-strength gap against a deliberate hand-edit, not a live regression. One line closes it: assert the keyword values are ast.Name loads, since a literal 0 is ast.Constant.
2 💡 The retry count drops from 5 to 2, which also halves the budget for the registry and mirror signatures AGREE, disclosed Arithmetically forced, not chosen: the largest per-invocation bound that fits the cap is 255s at 5 attempts, 422s at 4 and 1094s at 3, all below the slowest healthy attempt (1819.1s); the kill-after overhead alone at 5 attempts is 5400s. Two attempts is the only count compatible with a bound above a healthy build. Stated in the description.
3 💡 Two commands in this job stay unbounded: the official-images clone and each run.sh AGREE, out of scope Both run only on the non-push path after every build has finished, and neither is the apt layer. That path's worst case is 15488s of 18000s, leaving 2512s inside the reserve. No occurrence of the job-cap signature in that phase over 90 days.
4 💡 ci/jobs/release_job.py:772 runs an unbounded docker buildx build over the same Dockerfiles AGREE, out of scope Same class, and it would need its own envelope, so it is left for a separate change under one concern per PR. The release workflow is manually dispatched and no release check carries the job-cap signature over 90 days.

Severity: ❌ blocker / ⚠️ major / 💡 nit. Finding 1 was raised in three consecutive rounds and is
recorded rather than overridden: the review round budget for this change is exhausted, so it is
published with the measurement above instead of a further round. Nothing in it affects the
shipped behaviour, only how strongly a future edit is caught.

Checked independently of the author's notes, before reading them: the budget arithmetic was
re-derived by executing the shipped buildx_timeout and the test's own worst-case walk; the
timeout semantics were measured in isolated shells under GNU coreutils 9.4 (expiry 124 with the
sentinel on stderr, TERM-ignoring child 137 with the KILL diagnostic, success and a genuine
exit 7 and a bare kill -9 each with neither sentinel, and timeout 0 running unbounded, which
is what makes the floor load-bearing); the brace group's argv was compared byte-for-byte against
an unwrapped baseline; the new ci.defs.job_configs import was confirmed cycle-free and working
under the PYTHONPATH CI sets; and every number in the description was re-derived, including the
four job-cap failures on 2026-08-05 across four unrelated pull requests.

Session id: cron:clickhouse-review-slot-11:20260807-175212

@groeneai

groeneai commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, for the mechanism this changes. probe/native.sh trickle:1 <port> 700 reproduces the unbounded apt-get update 2 of 2 against passing controls (a mirror that never answers returns in 248s by default and 168s with Timeout=20; one trickling a byte per second is still running at the 700s cap). The unreachable-retry half reproduces through the real praktika Shell.run. A CI reproduction of the job wedge needs a stalling upstream mirror and was deliberately not attempted.
b Root cause explained? Yes. Acquire::http::Timeout is an inactivity timeout, not a wall-clock one, so a mirror that keeps trickling bytes is never bounded by it; and Result.from_commands_run never forwards a timeout to Shell.run, so the retries and retry_errors these call sites already pass could never be reached. One stalled fetch therefore consumed the whole 18000s job cap, and all four job logs contain zero Retryable error lines.
c Fix matches root cause? Yes. It adds the missing wall-clock bound at the call site that already owns the retry contract, and makes the expiry match that contract. A single per-invocation constant would not have bounded the job, since main() loops over os variants and tags and the invocation count is not fixed, so the bound is derived from the job's own configured cap instead. That derivation is priced against main()'s real control flow, which has no break and no is_ok() gate between variant/tag groups and so admits one wedge per group rather than one per job, and against all three fates Shell.run admits per invocation, including the expensive one where some attempts expire before a later one succeeds and the rest of the group still runs: the scheduled shape's worst case is 16334s against the imported 18000s cap. Fitting it also required lowering the retry count from 5 to 2, which applies to the registry and mirror signatures the constant already covered, since Shell.run takes one retry count per call. No bound is widened, no check disabled, no workload reduced.
d Test intent preserved / new tests added? Yes. Nothing is weakened: a real build error still fails fast on the first attempt. ci/tests/test_docker_buildx_timeout.py holds 22 tests, scheduled by ci_tests on every PR since its digest includes ./ci, and pins what would otherwise fail silently: the whole-job worst case against JobConfigs.docker_server.timeout (imported, never hardcoded), the single tag both scheduled commands request, which is the premise scoping that worst case, the sentinels arming a real retry, the argv surviving the wrapper, and a bare 137 not being read as an expiry. Two arms drive the shipped code rather than its source text, because a substring assertion cannot see either regression: one runs build_and_push_image and reads the bound back out of every command it produces, so reverting the call sites to a fixed bound is caught, and one drives with_timeout itself through Shell.run, so a wrapper that stops emitting --kill-after is caught. Two further arms close the frame the first of those cannot reach, since it supplies the budget context itself: sw and job_timeout carry no defaults, asserted through inspect.signature, and main()'s supply of both is asserted on its call site by AST rather than by counting a substring. The tag-scope premise is likewise resolved through the shipped parse_args rather than matched, since argparse takes the last occurrence of a repeated option. It runs in about 27s with no docker and no network; the shipped --kill-after=120 is asserted at the string level, including that it is positive, rather than waited out, while the escalation path itself is exercised with the delay patched down to seconds.
e Both directions demonstrated? Yes. Without a bound: apt-get update still running at the 700s cap, and zero retry lines in all four job logs. With it: the expiry is bounded and retried on both 124 and the escalated 137, at the shipped retry count of 2, measured through the real Shell.run (2 / 1 / 2 / 1 / 1 / 1 / 2 attempts across the six arms that drive it, one of which drives the shipped wrapper itself). The retry is asserted by attempt count rather than by list membership, because BUILDX_RETRY_ERRORS is built from the sentinel constants and a membership assertion stays true even for a token timeout never emits: replacing the KILL diagnostic with such a string drops that arm from 2 attempts to 1. Of twenty-six source mutations, twenty-four redden a named arm; the two that do not are deliberate controls, one of them a fourth os variant that genuinely fits under a shrinking deadline. Restoring the retry count to 5 takes the four-variant push shape to 23490s, and cutting the reserve to 600s takes the scheduled shape to 18972s; both fail. Cutting the reserve to 1250s is the arm's own anti-vacuity check: it takes the scheduled shape to 18378s and fails, where a model that priced only success-first-try and terminal-wedge reported 17474s and passed. Unwiring both call sites from the stopwatch, which every substring assertion still accepts, is reported as a bound of 2700 where 1350 is required; zeroing the kill delay is reported as a non-positive delay. Dropping the two keyword arguments from main() is reported as the stopwatch not being passed, while every other arm including that one stays green, which is the asymmetry showing the two frames are covered separately; restoring their defaults is reported as a default silently selecting a fixed bound, and the two together reproduce the all-green fixed-bound state that priced the scheduled shape at 50058s. Appending a second --tag-type release rather than replacing the first is reported as resolving to 'release', the mutation the substring form accepted.
f Fix is general across code paths? Yes. Every command-running site in the file was enumerated: both docker buildx invocations are bounded, and each remaining site has a stated disposition (docker login, the git clone of docker-library/official-images which already carries retries=3, the official-images smoke test, and two local commands with no network). The sibling Docker keeper image job is covered by construction, since both jobs run this same script and their configured caps are equal, and all four Dockerfiles are covered because the bound is on the builder invocation rather than on any one Dockerfile.
g Fix generalizes across inputs? Yes, for the inputs that exist here: both exit codes of an expiry (124 and the escalated 137), a bare 137 that is not an expiry, a real non-zero error, and success. On the budget axis the bound is checked at a fresh job, mid-job, at the deadline and past it, because timeout 0 runs the command unbounded and an over-budget job must never compute zero. Quoting matters more than datatypes in a shell wrapper, so the real quoting shape is pinned byte for byte, including a single-quoted value containing a space. No datatype axis exists, since there is no src/ change.
h Backward compatible? Yes, trivially. CI-only file: no setting, no SettingsChangesHistory entry, no format change, and no change to any shipped image's content.
i Invariants and contracts preserved? Yes. with_timeout returns a shell command string, which is exactly what from_commands_run(command=...) expects, and exit $rc preserves the child's exit status on every path, so is_ok() and the existing early returns behave identically for real failures. The per-invocation bound is always positive, so no path can produce an unbounded timeout 0. The brace group leaves the argument list byte for byte unchanged, which is the invariant the bash -c form violates. No concurrency or data-structure invariant is involved.

Session id: cron:clickhouse-impl-slot-40:20260807-142000

@groeneai

groeneai commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator Author

cc @Felixoid @leshikus, could you review this? Docker server image and Docker keeper image wedged inside apt-get update and died on the 18000s job cap four times on 2026-08-05, because apt's Acquire::http::Timeout is an inactivity timeout and the retry already configured for these builds could never fire on a command that never returns, so each docker buildx invocation is now wrapped in GNU timeout with a deadline that shrinks to keep the whole job inside its own cap.

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [88f5a3d]

Summary: ✅


AI Review

Summary

This PR wraps the two docker buildx invocations in ci/jobs/docker_server.py with GNU timeout, derives each bound from the remaining job budget, and adds a focused regression suite around the retry and budgeting behavior. The retry plumbing itself looks coherent, but one important proof obligation is still open: the new “whole job fits under the cap” claim is stronger than what the test and model actually cover.

Findings

⚠️ Majors

  • [ci/tests/test_docker_buildx_timeout.py:251] The new envelope test claims to prove that the whole Docker server image / Docker keeper image job stays inside its Praktika timeout, but it only models the build_and_push_image loop. main() still performs docker_login() before that loop on push jobs, test_docker_library() after it on non-push jobs, and check_server_readme() on both paths. That means a long but successful sequence of bounded buildx calls can still run out the 18000 s job cap without violating this test or the associated comments/docstrings.
    Suggested fix: either extend the envelope/proof to include the non-buildx phases, or narrow the production/test comments so they claim only that the buildx portion is bounded.
Final Verdict

Changes requested: the timeout wrapper looks reasonable, but the end-to-end “whole job stays inside the cap” guarantee is not proven by the current model.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 21, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

This has escalated sharply since the PR was opened, so it is worth re-stating the case with fresh data.

A new occurrence today: Docker server image on #114262 wedged for 4 h 42 min inside apt-get update and died on the 18000 s cap.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=114262&sha=3bc0f3932012909c99d782a157575594847cebbf&name_0=PR&name_1=Docker%20server%20image

The last output before five hours of silence is the same shape described above:

[2026-08-21 08:23:49] #10 4.114 Ign:4 http://us-east-1.ec2.ports.ubuntu.com/ubuntu-ports jammy-security InRelease
[2026-08-21 13:06:05] WARNING: Timeout exceeded [18000] for [92870]

Counting the 5 h job timeouts of Docker server image and Docker keeper image in CIDB over 180 days (check_status='error' AND check_duration_ms > 15000000 AND test_name=''):

Day Timeouts of which on master
2026-03-04 2 0
2026-05-17 1 0
2026-06-17 1 0
2026-06-19 1 0
2026-07-03 1 0
2026-08-05 4 0
2026-08-18 1 0
2026-08-19 8 0
2026-08-20 16 0
2026-08-21 18 4

43 of the 53 occurrences are in the last four days, and master is now affected. Each one burns five hours of a runner and produces no image and no per-image result at all: the job writes a single empty CIDB row with check_duration_ms = 18001666.

I checked five of the recent wedges (#114262, #114596, #115074, #78927 and master f4143cf04e4d8cb7c1eeb99dbc074c3ae8139798) and they all stall in apt-get update against us-east-1.ec2.ports.ubuntu.com, i.e. the arm64 ports mirror, with no further output. Same root cause in every case.

Two things I verified independently while triaging that failure:

  • Shell.run does have a timeout parameter, so plumbing it through Result.from_commands_run looks like the smaller change. It would bound the wedge but never retry it: _check_timeout announces the expiry on stdout, while retry_errors is matched against stderr only. That is what makes the timeout wrapper's stderr sentinels necessary rather than merely convenient.

  • Retry behaviour through the real Shell.run at the shipped count of 2, with a 3 s bound:

    arm rc attempts elapsed
    hang, child honours SIGTERM 124 2, on ERROR: docker buildx timed out 8.2 s
    hang, child ignores SIGTERM 137 2, on sending signal KILL to command 248.6 s
    real error exit 7 7 1, fails fast 0.1 s
    succeeds 0 1 0.1 s

    The second arm costs BUILDX_TIMEOUT_KILL_AFTER per attempt, as intended.

One interaction to decide before either lands, since both touch the same region of build_and_push_image and conflict textually: #115726 rebuilds against Canonical when an image exhausts its retries on an apt download failure. Its trigger is is_apt_mirror_failure, matching Failed to fetch / Unable to fetch some archives / Some index files failed to download. A bounded wedge prints none of those — it prints the timeout sentinel — so with both changes in, a hung mirror is bounded to about 90 minutes instead of five hours but still reds the check, because the Canonical rebuild is not reached. Treating a timeout expiry as an apt-mirror failure for the purpose of that second attempt would turn this failure mode from bounded into recoverable. Happy to fold that in here, or leave it to whichever PR merges second.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 21, 2026
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 21, 2026
Comment thread ci/tests/test_docker_buildx_timeout.py Resolved
@alexey-milovidov alexey-milovidov self-assigned this Aug 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 88f5a3dd8 with master 5391ee5b1 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 342d96b5c; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 704.50 MiB 701.48 MiB -3.02 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

The AST guard collected only `kw.arg`, so it stayed green for
`job_timeout=0` and for `sw=Utils.Stopwatch()`. Both restore the fixed
2700s bound while spelling the keywords: a falsy cap makes
`buildx_timeout` return early, and a fresh stopwatch reports zero
elapsed, so the deadline stops shrinking across invocations and the
job-envelope guarantee disappears.

Assert each value is the live `ast.Name` load instead. Measured against
the shipped module: `job_timeout=0` and `sw=Utils.Stopwatch()` each
redden this arm and left the whole suite green before this change;
dropping both keywords still reddens it; annotating the call site
without changing the bindings leaves all 22 arms green.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Thanks - agreed on folding it in here, and your stdout/stderr point matches what I measure.

One correction before it lands: the expiry has two sentinels, not one. timeout only
prints ERROR: docker buildx timed out on rc 124, i.e. when the child honours SIGTERM.
A child that ignores it escalates to SIGKILL and the only evidence is
sending signal KILL to command on rc 137. Measured through the real
Result.from_commands_run, reading the Result.info that is_apt_mirror_failure would see:

arm rc timed out in info signal KILL in info
wedge, child honours SIGTERM 124 yes no
wedge, child ignores SIGTERM 137 no yes
real Failed to fetch (control) 100 no no
success (control) 0 no no

So APT_MIRROR_ERRORS needs both BUILDX_TIMEOUT_MESSAGE and BUILDX_TIMEOUT_KILL_DIAG.
With only the first, the SIGKILL wedge stays bounded-but-red, which is the shape that reds
Docker server image when buildkit does not die on the first signal.

The envelope has room for the extra attempt. Worst case over every choice of which
invocation wedges terminally, for the scheduled shape (3 os variants, --tag-type head,
9 invocations), with the bound recomputed from the shipped buildx_timeout:

  • today: 14790 s
  • with the Canonical rebuild reachable on an expiry: 14970 s, 3030 s under the 18000 s cap

and it is recoverable rather than merely bounded: when the in-region retries are exhausted
at 5949 s the Canonical attempt still gets the full 2700 s bound, above the 1819.1 s
slowest healthy attempt.

Happy to fold it in here. I have not done so yet since #115726 is yours and still open - if
you would rather keep the two changes separate, adding both sentinels to APT_MIRROR_ERRORS
there is the same one-line change and avoids the textual conflict in build_and_push_image.
Say which you prefer and I will push it.

Separately, I pushed 88f5a3d for the AI review's point on the main() wiring guard: it
collected only kw.arg, so job_timeout=0 and sw=Utils.Stopwatch() both kept it green
while restoring the fixed 2700 s bound. It now asserts each value is the live ast.Name
load. Both of those mutations redden it, dropping the keywords still reddens it, and
annotating the call site without changing the bindings leaves all 22 arms green.

return max(reachable)


def test_the_whole_job_worst_case_fits_inside_the_jobs_own_cap():

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.

test_the_whole_job_worst_case_fits_inside_the_jobs_own_cap currently only models the build_and_push_image loop, but main() still does real work outside that loop: docker_login() on the push path, then test_docker_library() on the non-push path, and check_server_readme() on both paths. So this arm proves that the bounded buildx portion fits under the cap, not that the whole job does.

With the shipped helper, the build loop still leaves only about 2512 s of slack on PR jobs and 1666 s on push jobs, so an expensive tail phase can still hit the 18000 s Praktika timeout while this test stays green. Can we either include those extra phases in the envelope, or narrow the code/comments/tests to claim only that the buildx portion is bounded?

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.

Agreed, and narrowed rather than widened, in ddc3d64.

The arm is now test_the_build_loops_worst_case_fits_inside_the_jobs_own_cap and claims only
the loop. docker_login is not part of the tail, though: it runs before the loop, so the
stopwatch each deadline is derived from has already charged it. That leaves
test_docker_library and check_server_readme, and your 2512 s / 1666 s reproduce exactly.

Widening the envelope to include them would put an unbounded quantity inside an arm that
asserts a bound, so instead the slack is pinned as its own arm: it requires ten times the
slowest tail ever observed. Measured end to end, from the loop's last build to process exit
so the official-images clone and README.sh are inside the interval, over 60 whole jobs:
max 120.5 s, p50 67.5 s. The constant is 133 s, the larger figure from a 296-job sample, and
1330 s fits in 1666 s.

The two arms are not redundant: dropping the reserve to 2900 s leaves the envelope arm green
and reds the new one. Raising the constant to 134 stays green, to 167 reds.

Chasing this also turned up a real one next door, fixed in the same push. buildx_timeout
returned the unshrunk 2700 s bound when the cap was falsy, so zeroing both cap assignments in
main() left the whole suite green while the scheduled push shape modelled 50058 s against
18000 s. A missing cap is now refused, and the oracles that were counting textual prefixes
(retries=BUILDX_RETRIES + 1, retry_errors=BUILDX_RETRY_ERRORS[:-2], and a cap read from
an unrelated job's config) now compare the whole expression.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 21, 2026
Merged via the queue into ClickHouse:master with commit 08da345 Aug 21, 2026
178 checks passed
@groeneai

Copy link
Copy Markdown
Collaborator Author

Following up on this PR's own retry machinery, because #115726 changed a quantity it depends on.

build_and_push_image now wraps each per-arch buildx invocation in a 2-mirror loop, so one logical
build can run two retry ladders. buildx_timeout() still divides the remaining job budget by the
attempts within one ladder, so the per-invocation bound no longer prices a whole build.

Walking main()'s own loop structure at master's configuration (BUILDX_RETRIES = 2, no deadline,
BUILDX_JOB_RESERVE = 3600, 2 mirrors, 1 tag, --os default of 3, and push=True as MasterCI sets
it at docker_server.py:600-607):

shape worst case 18000s cap
3 variants, no push (PR CI) 17660s ok
3 variants, push (MasterCI) 18386s over by 386s
4 variants, no push 18988s over by 988s

Two things make this hard to see:

  • _worst_case_job_seconds derives per_group = len(ARCH) + (1 if push else 0)
    (tests/test_docker_buildx_timeout.py:256), a constant with no way to observe the mirror loop, so
    the shipped cap test reports ok.
  • BUILDX_JOB_RESERVE is not a floor. A group runs up to five invocations, each bounded by
    (remaining - reserve) / BUILDX_EXPENSIVE_ATTEMPTS, so later invocations spend the reserve. At one
    mirror the shipped model already exceeds cap - reserve by up to 2780s, before Rebuild against Canonical when the in-region apt mirror is broken #115726.

I looked for a way to bring this back inside the cap and could not find one that holds. Every
per-invocation scheme either drops the bound below the 1819.1s slowest healthy attempt that
test_a_healthy_first_build_still_gets_the_full_bound pins, or leaves a reachable shape over cap.
The reachable MasterCI topology is 13 invocations; at 2 * (1819.1 + 120) + 30 each, honouring that
floor everywhere needs 54407s against an 18000s cap, so at most 3 of 13 invocations can carry a
healthy-sized bound.

A caller-level budget check does not work either, and for a reason worth recording: main() runs an
unbounded tail after the buildx work - a git clone at :493, the docker-library run.sh per image
at :499-513, and check_server_readme at :546. None of it is bounded or modelled, and
praktika/runner.py:516-563 is the actual whole-job timeout authority (it already records an ERROR
result tagged TIMEOUT with a log tail). So no buildx-level model can establish a whole-job
invariant.

That leaves three directions, and choosing between them is a call for whoever owns the mirror loop:

  1. Give each architecture one expensive budget shared across its mirror ladders, and reprice.
  2. Bound the untimed tail first, which is what would make a whole-job model possible at all.
  3. Raise JobConfigs.docker_server.timeout (shared with docker_keeper).

I am not proposing a patch for this, and I have not touched the mirror loop. Separately, the
docker library image test row selects images by architecture suffix alone
(test_docker_library, :479-482) without checking Result.is_ok(), so a build that failed is
still handed to the image test and fails again with image does not exist! - both rows red for one
cause. That one is small and I am happy to send it if useful.

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 5, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 5, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 5, 2026
Backport #113869 to 26.7: CI: bound each docker buildx invocation in the Docker image jobs
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 7, 2026
pull Bot pushed a commit to admariner/ClickHouse that referenced this pull request Sep 13, 2026
…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]>
superdiaodiao pushed a commit to superdiaodiao/ClickHouse that referenced this pull request Oct 1, 2026
`BUILDX_RETRIES = 2` gives a `docker buildx` command in the Docker server and keeper
image jobs one retry after a 2 s back-off, so a Docker Hub error that clears within
seconds still fails the leg. On master 6b60183 (2026-09-30) the
`head-distroless-arm64` keeper image built, and pushing it got `unexpected status from
POST request to https://auth.docker.io/token: 500 Internal Server Error` twice, 3 s
apart, so that image was not published:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=6b601838b5c7526a500254219a92542f852d5e55&name_0=MasterCI&name_1=Docker%20keeper%20image

The count was 5 until ClickHouse#113869 lowered it to 2 while adding the per-invocation
`timeout`. `buildx_timeout` divides the job's remaining budget by `BUILDX_RETRIES`, so
with 5 an invocation whose every attempt expires still ends inside the job's reserve,
and the per-attempt bound stays at 2700 s for the first 900 s of the job. A fast
registry failure now gets 30 s of back-off (2, 4, 8, 16 s) instead of 2 s.

Suggested in ClickHouse#121298 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
superdiaodiao pushed a commit to superdiaodiao/ClickHouse that referenced this pull request Oct 1, 2026
…instead of retrying it

The `timeout` sentinels `ERROR: docker buildx timed out` and `sending signal KILL to command`
were appended to `BUILDX_RETRY_ERRORS` by ClickHouse#113869, so an attempt killed by `with_timeout`
was retried on the same apt mirror. With `BUILDX_RETRIES = 5` a mirror that stalls every
attempt would hold one leg for up to 5 x (2700 + 120) s + 30 s = 14130 s before
`should_try_next_mirror` rebuilds against Canonical, whose attempts are then bounded by
`buildx_timeout` at its 60 s floor.

`should_try_next_mirror` already treats an expiry as a mirror failure (`is_buildx_timeout`),
so a same-mirror retry is not needed: an expired attempt now matches no retry token, the
invocation stops after one bound, and the unchanged mirror loop rebuilds against Canonical.
A stalled mirror costs one bound (2820 s), and the Canonical rebuild keeps a per-attempt
bound of 2316 s.

Measured on all September 2026 job logs of `Docker keeper image` and `Docker server image`
on master-based trees (20,140 jobs, 127,519 legs): 146 expiries, every one on the in-region
mirror's `docker buildx build`, and in each the timeout sentinel was the only retry token
that matched. 0 expiries on Canonical and 0 on the `imagetools create` push, the two places
that lose their same-mirror retry. The Canonical rebuild succeeded for 152 of 152 legs
(p50 242 s), faster than a same-mirror success after an expiry (p50 426 s).

On master 1d6237c the keeper `head-distroless-arm64` build expired (12:11:13 to
12:56:13), its same-mirror retry failed with `Failed to fetch` at 12:57:07, and no rebuild
against Canonical followed, so the check failed:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=1d6237ce14bd733c01641a182aa34e5938eaeff9&name_0=MasterCI&name_1=Docker%20keeper%20image

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.3-must-backport v26.6-must-backport v26.7-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants