Repository navigation
CI: bound the "Build profile diff" CI logs cluster reads by the job's wall clock - #121849
Conversation
… wall clock `Build profile diff` is SIGKILLed at its 1800 s job timeout while retrying CI logs cluster reads, so it reds a pull request for an outage of an unrelated shared service and reports no reason at all. LogCluster.select bounds a read by attempt count only (retries=8, timeout=60, plus a 5+10+...+40 = 180 s backoff, so about 684 s worst case for one read, and requests' timeout bounds one socket read rather than the request, so a trickling connection was measured at 185 s for a single attempt). It is never bounded by wall clock, while build_profile_diff_job.py issues 16 db.query reads inside a job whose timeout is 1800 s. Three degraded reads exhaust the window, praktika SIGTERM/SIGKILLs the process, and select never returns and never raises: Db.query cannot propagate, main()'s except LogClusterUnavailable never runs, and the green report_cluster_unavailable completion added in ClickHouse#121048 is unreachable in exactly the window it was written for. The kill also skips update_comment, leaving the comparison comment of an earlier commit of the same pull request in place as if it were the current one. Observed on PR ClickHouse#96662 at head 72541f0, which already contains ClickHouse#121048 and ClickHouse#121393: 18 requests.exceptions.ReadTimeout, zero "LogCluster not ready", and the job killed exactly 1800 s after its process started with no Result at all. Reads were succeeding in between, so the job was crawling at about 420 s per read rather than blocked, which is why the budget is shared across the job's reads instead of applied to each one. A LogCluster instance now takes an optional read budget (default None, so every other caller is unchanged) and select gains one guard at the top of its retry loop, on a spent budget AND a POST already attempted. Both conditions are load-bearing rather than conveniences, for the same reason: the post-loop discriminator is defined by what the attempts did, so any read that leaves the loop having attempted no POST classifies as LogClusterNotReady (red) even though the cluster was answering. Exempting attempt 0 covers the read that starts after the deadline; requiring post_attempted covers the read whose first readiness probe fails transiently, which would otherwise break at the second iteration with nothing attempted. So the budget stops POST retries only, and the readiness schedule, which exists because is_ready fails during the same pressure spikes as the query itself, always keeps its full count. The added cost is bounded and paid at most once per job: a read that never becomes ready spends 8 probes plus the 180 s backoff, about 204 s, and then ends the job. No new green path appears, LogClusterNotReady stays red and TRANSIENT_EXCEPTION_CODES is untouched, so both the rule that only "the cluster never answered" is green and ClickHouse#121393's narrowing that keeps 159 and 209 hard continue to hold. The number is derived from the job's own configured timeout via Info().job_config, following stateful_prep_step_timeout in ci/jobs/functional_tests.py, minus a fixed reserve of 550 s, so 1250 s at the current timeout=1800. The reserve is fixed rather than a fraction because every component of it is independent of the timeout: interpreter startup before the first read, one in-flight POST overrunning its 60 s socket timeout, one already-started backoff, and the reporting tail. The docker image pull is not charged to it, because job.timeout only starts with the job process. Applied to the ClickHouse#96662 timeline the read raises at about 13:21:20 instead, 8.5 minutes before the kill, and the check completes green with the reason and a refreshed comment. The failed-attempt spacing there (65/70/75/80/86/90 s, the 60 s socket timeout plus 5*(retry+1)) identifies the 13:20:43 failure as the seventh attempt of that read, so the guard is next reached after its 35 s backoff; 13:23:14 is the first attempt of the following read, which the change never reaches. Validated against a local HTTP stub over three runs with identical classifications, with a control on the pre-change file that matches wherever no budget is passed, with assertions on the derivation keyed on the real JobConfigs.build_profile_diff_job.timeout, and with a case that pins the readiness behaviour: a spent budget plus one transient probe failure returns the body, while the same case without the post_attempted condition raises LogClusterNotReady. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex) plus an independent cold review,
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20260923-182400 |
|
Workflow [PR], commit [1616b90] Summary: ✅
AI ReviewSummaryThis PR adds a shared wall-clock budget to the Final Verdict
LLVM Coverage Report |
leshikus
left a comment
There was a problem hiding this comment.
Generally looks good, please fix two minor issues with the budget computation
| if info.is_local_run: | ||
| return None | ||
| job_config = info.job_config | ||
| job_timeout = ( |
There was a problem hiding this comment.
for a particular job the timeout should be in one particular place, no need to have the complex construct here
There was a problem hiding this comment.
Done in 2540a78. It now reads JobConfigs.build_profile_diff_job.timeout, the one place the timeout is defined, which is the shape ci/jobs/docker_server.py already uses for JobConfigs.docker_server.timeout. That removes the Mapping/getattr pair, the RuntimeError branch it needed, and the collections.abc.Mapping import: 10 lines added for 15 removed, and a malformed JOB_CONFIG can no longer fail the check.
One deliberate detail: the import is inside the function, not at module scope. ci.defs.job_configs needs a bare praktika, which the documented local run (python3 -m ci.jobs.build_profile_diff_job --local, PYTHONPATH = repo root) resolves only through the sys.path entry ci/praktika/__init__.py adds on import. At module scope in alphabetical position it raises ModuleNotFoundError: No module named 'praktika', both there and under the runner's own PYTHONPATH=. job environment. Happy to move it up if you would rather the local run carry ./ci on the path.
| raise RuntimeError( | ||
| f"Cannot derive the CI logs cluster read budget: job timeout is [{job_timeout!r}]" | ||
| ) | ||
| return max(1, int(job_timeout) - CLUSTER_READ_RESERVE_SECONDS) |
There was a problem hiding this comment.
cluster_read_budget == 1 looks a bit strange; better assert CLUSTER_READ_RESERVE_SECONDS * 2 < int(job_timeout)
There was a problem hiding this comment.
Done in 2540a78: the max(1, ...) floor is gone, replaced by assert CLUSTER_READ_RESERVE_SECONDS * 2 < job_timeout. It holds for this job (550 * 2 = 1100 < 1800) and the budget is unchanged at 1250 s.
I also made it a real check rather than a claim: reserves of 900, 1800 and 5000 each trip the assertion while the shipped 550 does not.
Review feedback on ClickHouse#121849: for a particular job the timeout should be in one particular place, and the read-budget derivation did not need a construct that copes with two runtime shapes of `info.job_config`. `cluster_read_budget_seconds` now reads `JobConfigs.build_profile_diff_job.timeout`, the single place that timeout is defined (ci/defs/job_configs.py:2134). That is the shape ci/jobs/docker_server.py already uses for `JobConfigs.docker_server.timeout`, and it removes the Mapping/getattr pair, the `RuntimeError` branch that pair needed, and the now unused `from collections.abc import Mapping`. The `max(1, ...)` floor is replaced by the asked-for assertion `CLUSTER_READ_RESERVE_SECONDS * 2 < job_timeout`, so a reserve that would swallow the read window fails loudly instead of silently degenerating to a 1 s budget (one attempt per read, no retries). It holds for the configured job: 550 * 2 = 1100 < 1800. The budget itself is unchanged at 1250 s. `ci.defs.job_configs` is imported inside the function rather than at module scope because it needs a bare `praktika`, which the documented local run (`python3 -m ci.jobs.build_profile_diff_job --local`, PYTHONPATH = repo root) resolves only through the sys.path entry `ci/praktika/__init__.py` adds when it is imported. A module-scope import in alphabetical position was measured to break both that run and the praktika runner's own `PYTHONPATH=.` job environment with `ModuleNotFoundError: No module named 'praktika'`. Net effect on the job: 10 added lines for 15 removed, and a malformed or absent `JOB_CONFIG` can no longer fail the check. Validation: the derivation cells now assert that the budget comes from the job definition alone (four bogus `info.job_config` values are ignored rather than raising), with a negative control in which reserves of 900, 1800 and 5000 each trip the new assertion while the shipped 550 does not. 13 assertions x 3 runs, byte-identical output. The select and readiness cells are unchanged and still pass; log_cluster.py is not touched by this commit.
…dule The AI review of 2540a78 observed that the read budget is only consulted when `retry and post_attempted`, so the readiness schedule of a read that has not reached its POST yet runs outside it. That is right, and the reserve comment understated it: it named "one already-started backoff (<= 40 s)" where the read in flight can still pay its whole readiness schedule. Measured against a local HTTP peer, a refusing probe costs 0.00 s, so that schedule is its backoff: 180.0 s over the full 8 retries. With one POST overrunning its own socket timeout (the 185 s already named in the comment) the reserve has to absorb <= 365 s of its 550 s, which it does. No behaviour change: both hunks are comments, and the parsed trees are identical to 2540a78. The review also asked to bound the readiness path by wall clock. A check between retries cannot do that, because it cannot interrupt a request already in flight: `requests` bounds each socket operation, not the transfer, so a peer that keeps dribbling outlasts any timeout. Measured, a `SELECT 1` probe answered in 20 chunks 0.5 s apart takes 11.5 s at timeout=3, while a peer that goes silent is cut at 3.0 s; the same law is where the 185 s POST figure comes from. The variant that does cut the readiness schedule was measured in the first fix round and rejected: it classifies a single transient probe failure as LogClusterNotReady while the cluster is answering reads, reddening the check for an outage that is not happening.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes9 object files changed (+43.16 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline. |
Related: #120462
Related: #121048
Related: #121393
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not required: CI-only change.
Description
Build profile diffis SIGKILLed at its 1800 s job timeout while retrying CI logs cluster reads, so it reds a pull request for an outage of an unrelated shared service and reports no reason at all.Failing job, on a head that already contains #121048 and #121393: https://github.com/ClickHouse/ClickHouse/actions/runs/35808880819/job/107189818308 (PR #96662, head
72541f0db997).18
requests.exceptions.ReadTimeouts, zeroLogCluster not ready, with noResult.LogCluster.selectbounds a read by attempt count only (retries=8, timeout=60plus 180 s of backoff, about 684 s per read), never by wall clock, while this job issues 16 reads insidetimeout=1800. Three degraded reads exhaust the window, so the runner kills the process beforeselectcan raise, and #121048's greenreport_cluster_unavailablepath is unreachable in exactly the window it was written for. The kill also skipsupdate_comment, leaving an earlier commit's comparison on the pull request as if it were current.A
LogClusternow takes one shared read budget, and a spent budget is a second stop condition forselect's POST retries. Attempt 0 of every read is always made, so every exit stays classified by what the attempts did: no new green path,LogClusterNotReadystays red,TRANSIENT_EXCEPTION_CODESis untouched. The budget is the job's owntimeoutfromci/defs/job_configs.pyminus a named reserve, so 1250 s today, and an assertion rejects a reserve that would leave no usable window.On that timeline the read raises at about 13:21:20, 8.5 minutes before the kill, and the check completes green with the reason and a refreshed comment.
Measured on the 40 longest runs of the last day: 36 already report
nothing compared, 2 are the kill class above, 1 delivered a comparison the budget would cut.Validation, other retry loops, residuals
Local HTTP stub, three runs, identical classifications:
LogClusterUnavailablenaming the budget, 2 attempts, 21.0 sLogClusterNotReady(red) in bothLogClusterQueryErroron attempt 1LogClusterUnavailable, reached soonerThe same cases against the pre-change file are identical wherever no budget is passed, so the default is unchanged for every other
LogClusteruser. The derivation is asserted against the realJobConfigs.build_profile_diff_job.timeouttoo, so it follows a retunedtimeout=on its own.Other retry loops that could cross a job timeout, and why they are untouched:
do_query(the INSERT path): reached only from a praktika post hook, which runs with no timeout, and it returns False while its callers assert, so an exhausted upload fails loudly. The budgeted instance isreadonly=True, whichdo_queryasserts against.is_ready: one POST withtimeout=3, already bounded.gh apimaster walk: 60 pages x 120 s worst case inside the same 1800 s, but zero observed occurrences and ~21 fast pages measured. Truncating it is not a fail-close stop: a short non-empty chain silently narrows the baseline candidate set rather than reporting none was found, so that is the check owner's decision.Residuals: a read that still succeeds, slowly or after readiness retries, is never cut, so the kill stays reachable; greening that would widen the green path past "the cluster never answered", so I did not. A job-level watchdog would cover every overrun, but its colour would have to stay red, since a slow query of this job's own SQL is a finding about this run.
Workflow [PR]
Sync PR [sync-upstream/pr/121849]
Version info
26.10.1.624-master(included in26.10and later)