Repository navigation
Conversation
get_gh_api retried 5 times with a fixed 3 second sleep. Its only special branches are a 403 carrying "rate limit exceeded" and a 404, so everything else including 5xx shared one generic tail: 4 x 3 s = a 12 second window, which any longer GitHub blip exhausts. That reddened Upgrade check (*) in its setup phase, before any ClickHouse binary started, so the failure said nothing about the PR under test. 9 occurrences over 45 days across 9 distinct PRs, 0 on master. ClickHouse#107916 gave the asset download in this file a capped exponential backoff and introduced DOWNLOAD_RETRY_MAX_BACKOFF for that purpose, but left get_gh_api, the metadata fetch that runs first in the same call chain, using the fixed sleep. Give that shared tail the same capped exponential backoff, scoped to the statuses that are transient by definition: 5xx, 429 and transport errors such as the read timeout that opened the reported failure. At the default sleep the failing window grows from 12 to 45 seconds. Every 4xx keeps its behaviour byte for byte, including both auth failover branches. Distinguishing a transient 403 (GitHub's secondary rate limit, or abuse detection) from a terminal one would require matching a response body, and the existing predicate provably misses both of those messages, so reclassifying 4xx would trade this starvation for a subtler one. The multiplier is the caller-supplied sleep rather than a literal, so the pr_info.py call sites that pass RETRY_SLEEP = 0 keep sleeping not at all. The retry log is promoted to a warning naming the attempt, the retry count and the delay, so the next occurrence is triageable from job.log alone. Add ci/tests/test_get_gh_api_retries.py, which drives the real function against scripted responses without sleeping: 4 of its rows fail before this change and all 13 pass after. Each row pins one invariant, including the 4xx budgets, the 403 and 404 failovers, the zero-sleep callers and the backoff cap. Co-Authored-By: Claude Fable 5 <[email protected]>
The cap test asserted only max(sleeps) == DOWNLOAD_RETRY_MAX_BACKOFF and an upper bound on every sleep, which says nothing about the growth before saturation. An implementation that applies the cap immediately whenever retries exceeds DOWNLOAD_RETRIES_COUNT yields nine 60-second sleeps and satisfies both assertions, so it survived the whole suite: every other row uses the default retries and cannot see it. Asserting the exact sequence kills that mutant while the retained max(...) line keeps the literal values tied to the named constant, so retuning the constant still fails loudly instead of drifting. Also shorten the 4xx-exclusion comment to three lines. The argument about which 403 bodies the rate-limit predicate misses is already in the PR description; only the scope statement needs to sit at the call site. No production behaviour changes: stripping comments from both revisions of build_download_helper.py gives identical files. Co-Authored-By: Claude Fable 5 <[email protected]>
Attempt 1 of the reported production failure was a read timeout, but the only transport row raised requests.ConnectionError, and ReadTimeout inherits Timeout -> RequestException rather than ConnectionError. A change that kept the growing backoff for connection resets while dropping it for read timeouts therefore passed the whole suite, so the test could not see a regression on the scenario the change exists for. Parameterize that row over both classes by threading the exception class through the harness instead of a bool. Patch only requests.get on the real module rather than replacing bdh.requests with a namespace exposing get, HTTPError and ConnectionError. With the namespace in place, any future handler naming another requests attribute raises AttributeError inside the function under test, which reports a behavioural regression as an unrelated crash. Measured on a handler added for requests.Timeout: the namespace form fails with "assert 'AttributeError' == 'APIException'", the single-symbol form with "assert [3, 3, 3, 3] == [3, 6, 12, 24]". monkeypatch restores the attribute per test, and ci/tests/test_download_build_with_progress.py already patches a single symbol this way. tests/ci/build_download_helper.py is unchanged.
Two oracles in the new suite could not observe a regression in the behaviour they guard, so a change violating the stated contract would have stayed green. Row 8 passed a preset token for all five of its cases. With the token already set, the failover guard is short-circuited by `not token_is_set` alone, so the 403 body predicate was never load-bearing: widening it to every 403 kept the attempt count and the sleep sequence identical and the whole suite passed. The preset only changes the outcome for the 404 case, so the four cases where it is inert now run without it and additionally assert that no auth header was ever added; the 404 case keeps the preset in a row of its own. Row 1 asserted the exponential sequence for 504 only, and row 3 for 503, so narrowing the predicate from `>= 500` to `in (503, 504)` also passed. Row 1 is now parameterized over the boundaries of the contract: 500, 502, 503, 504, 599. Verified in both directions against the two mutants: each is fully green on the previous suite and fails on this one, on the new assertion and on the sleeps sequence respectively. No other mutant's failure set shrank. Co-Authored-By: Claude Fable 5 <[email protected]>
A bare 429 is the one status that is both a 4xx and newly eligible for the growing backoff, so it must get the backoff and must not get the 403/404 auth failover. The row pinned only the first half: widening the failover predicate to cover 429 grants it a robot token and an extra attempt, yet the counter reset re-warms the backoff from the base sleep, so the four recorded sleeps are unchanged and the row still passed. Bind the attempt count and the observed auth headers so the second half is guarded too. The module docstring also claimed every 4xx keeps its existing behaviour two bullets after stating that 429 gets the new backoff. Name the exception. Co-Authored-By: Claude Fable 5 <[email protected]>
The retry test drove ten distinct statuses, and 499 was not among them. Nothing adjacent to the threshold was covered from the 4xx side, so lowering the predicate to `status_code >= 499` produced a byte-identical sleep sequence for every status the suite exercised and survived the whole run, while quietly giving HTTP 499 the exponential window [3, 6, 12, 24] in place of [3, 3, 3, 3]. The published promise is that every other 4xx keeps its current behaviour exactly, so the whole 4xx range is contract and the range needs a guard next to the threshold, not only above it. Row 8a gains one 499 parameter; the assertions, the rows around it and the helper are unchanged. No 400 case: 400 sits in the same equivalence class as the already-covered 401 and 422, so its sleep sequence is identical under both the shipped predicate and the lowered-threshold mutant, and it kills nothing 401 does not already kill. Co-Authored-By: Claude Fable 5 <[email protected]>
Two gaps in the guard added earlier in this branch.
The retry log line is the only trace a CI operator gets of a transient GitHub
API failure, since the job's stdout is the sole place it appears. The diff
raises it to a warning and adds the attempt number and the delay, but nothing
observed any of that: all 19 cases passed with the line reverted to the old
`logger.info("Exception '%s' while getting, retry %i", ...)`. A new case pins
the level and the two fields the message promises. Verified in both directions:
reverting the block to the old one-liner reddens exactly that case (no WARNING
records at all), and keeping the warning while dropping the attempt and delay
reddens it too. The twelve recorded policy mutants are unaffected, so no
existing case lost a killer.
`CI Tests` digested `./ci`, `./tests/clickhouse-test` and
`./tests/queries/shell_config.sh`, but not the helper the new guard loads by
relative path. So a future PR touching only `tests/ci/build_download_helper.py`
was filtered out as unaffected, and its digest was byte-identical, hence an S3
cache hit: the assertions would never execute. 9 of the last 15 master commits
to that helper touched zero files under `ci/`, including the previous change to
this very retry code. Adding the single file flips affectedness for it while
leaving `tests/ci/pr_info.py` and `docs/` unaffected, and makes the digest move
when the helper changes; including the whole directory would have added 42
files and rerun the job for 11 of the last 200 master commits.
`tests/ci/build_download_helper.py` is unchanged by this commit.
Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model review (click to expand)An independent model reviewed each revision cold against the code on disk. Every finding was ❌ Vacuous cap oracle (fixed). Asserting only ❌ Read timeouts uncovered (fixed). The transport row raised only ❌ Unfaithful test double (fixed). Replacing the whole ❌ The 4xx row could not see its own predicate widen (fixed). It preset a token for every case, ❌ The ❌ The 429 row could not see the failover widen to 429 (fixed). It asserted sleeps but discarded ❌ Nothing observed the promised retry diagnostic (fixed). Reverting the new ❌ The new guard would not have run when its subject changed (fixed).
💡 Noted, not blocking. Three other Twelve policy mutants plus two for the diagnostic; no mutant's kill set shrank as rows were added. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-review-slot-9:20260802-023001 |
|
cc @leshikus, could you review this? |
leshikus
left a comment
There was a problem hiding this comment.
The change of retry policy is not in changed files, only the tests present
|
The retry policy change is in
Likely what you looked at: of the seven commits on the branch, the policy is in the first two ( |
|
|
|
I checked whether the failing call can reach
If the objection is that the policy should not live in a I can do that split if you want the constants out of |
|
Why not to add a gh_api request wrapper to gh.py? in this case you can put the retry policy in there |
|
That works, and it corrects me: I said praktika is not importable on that path, and that was too strong. I had only tested a bare One property has to survive the move. Plan, unless you want it differently:
The 8 call sites in |
ci/praktika/gh.py drifted since this branch's base and is now touched by this change, so the merge happens before the edit.
The capped exponential backoff added earlier in this branch lived in tests/ci/build_download_helper.py. A timeout/retry policy for GitHub HTTP reads is framework knowledge that every praktika job can reuse, so it moves to ci/praktika/gh.py as GH.api_get, and get_gh_api becomes a thin shim over it. The split follows what can move: the policy is generic, while the robot-token failover cannot leave tests/ci because get_robot_token imports boto3 and PyGithub at module level. The shim therefore keeps its signature, its APIException, and the failover, driving the latter through an on_http_error callback so the attempt budget still restarts exactly once when a token is acquired. Behaviour is unchanged for all eight production call sites. gh.py had no HTTP client before this (0 requests calls, 11 Shell calls), so it gains a top level import requests; gh_auth.py already imports it unguarded and runner.py already imports gh_auth, and requests is praktika's one core dependency in ci/praktika/pyproject.toml. api_get raises RuntimeError on exhaustion rather than returning an empty value like get_output_with_retries, because a caller cannot tell an empty result from a failed read. The shim translates that to APIException, which report.py catches to fall back to a run URL instead of failing the job. API_GET_RETRIES_COUNT is deliberately separate from Settings.MAX_RETRIES_GH: the latter bounds gh CLI invocations, which need a token even for a public read, so the two paths have different failure classes. Two hazards the tests pin. ci/praktika/gh.py is importable under two module names that are distinct module objects (praktika/__init__.py appends ci/ to sys.path), so the shim and the tests both use the dotted ci.praktika.gh form; patching the other form leaves the production path unpatched and reaching the network. And the sys.path root is derived with realpath, not abspath, because get_previous_release_tag.py is invoked through a /usr/bin symlink where abspath yields "/". Tests split accordingly: policy cases drive GH.api_get, failover and error-class cases drive the shim, plus new cases for the error translation and for raising on exhaustion.
tests/docker_scripts/upgrade_runner.sh:30 captures the stdout of get_previous_release_tag.py into a shell variable and splices it unquoted into `git clone --branch=$previous_release_tag`. That script prints the tag on stdout and resolves it through get_gh_api, so the retry warning shared the stream with the tag: as soon as a read was retried the variable held the WARNING lines too and the clone was invoked with `--branch=WARNING:`. The retry path is exactly the path this branch makes reachable, so it turned a rare hard failure on a GitHub blip into a corrupted setup on the same trigger. Measured with a scripted 504,504,200 through the real get_gh_api: the captured stdout was two WARNING lines followed by the tag, and is now the tag alone. The test row that pinned this diagnostic asserted it on stdout, which made the polluting stream the contract and let all 27 cases pass green with the corruption present. It now asserts stderr and also asserts that stdout carries no WARNING, so an echo-to-both regression still reddens, and a new case pins the shell-capture contract directly. Separately, an on_http_error callback returning True reset the attempt budget before the sleep block with nothing bounding how many times it could. The in-tree shim is safe because its token latch fires once, but the hook is documented as an extension point, so a caller taking that at face value got a sleepless loop against api.github.com: an always-true callback issued over 200 requests with zero sleeps. Resets are now capped at API_GET_MAX_BUDGET_RESETS = 1, which reproduces the shim's existing behaviour exactly, and past the allowance the status is handled as an ordinary error. The same probe now issues 6 requests and raises. The local `import sys` in the __main__ block became redundant once sys was imported at module level, and was removed; pylint findings on the file go from 18 to 13 with no new messages.
Internal second-model review — 8 rounds, 2 residual test-liveness gaps (click to expand)An independent model reviewed each revision cold. Every accepted finding was reproduced by Equivalence, measured. I drove the pre-change ❌ Fixed during the branch. The retry diagnostic went to stdout, which
Both are test-liveness only, and both arrived at my internal round cap, so this publishes 💡 Corrected in the description here: the case count read 27 where the suite collects 29, One concern of my own, dismissed: the new unguarded |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20260811-095900 |
|
Done, as you suggested: the retry policy is now The failover has to stay in I checked the relocation is behaviour-preserving rather than assuming it: driving the old |
Two test-liveness gaps disclosed at the previous round cap, both now closed and each verified by a mutation that reddens only the new row. The fake transport recorded a single boolean per attempt, so nothing proved that caller options survive the shim's extra hop into `GH.api_get`. It now snapshots every request. `test_caller_request_options_survive_delegation` asserts the two live shapes -- `params` plus `timeout` from `get_previous_release_tag.py`, the `Accept` header from `pr_info.py` -- and `test_failover_sends_the_fetched_token` asserts the installed value is `Bearer fetched-token`, not merely that an `Authorization` key appeared. Dropping `**kwargs` from the delegation reddens the first; installing an empty bearer reddens the second, while the pre-existing failover rows stay green, which is what made them blind to it. `test_budget_resets_are_bounded` derived both its expected count and its ceiling from `API_GET_MAX_BUDGET_RESETS`, so raising the constant moved the goalposts with it. The bound is now a literal, and changing the constant to 2 reddens the row. Dropped the `realpath` comment in the download helper: it attributed the path requirement to a `/usr/bin` symlink, but `upgrade_runner.sh` symlinks only the two entry scripts and this module is imported from its repository path, where `abspath` and `realpath` agree. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112205&sha=66f93bffd6aa9d3b6f038bf7a6b59ac02a5b3f10&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 PR: ClickHouse#112205
The job this fixes was filtered out by its own change. `upgrade_test_jobs` digested the two entry scripts but not `tests/ci/build_download_helper.py`, which both import at module level, nor `ci/praktika/gh.py`, which the helper now imports for the retry policy. Measured against `Job.is_affected_by` with the four changed paths: `Upgrade check (amd_release)` read False before, True after, and still False for an unrelated `src/` change. Strengthened the delegation oracle, which observed only the first successful request: it now drives the shim through two retries with `sleep=0` and asserts the params, timeout and `Accept` header on every attempt, plus the forwarded sleep sequence. The failover row asserts the same across the budget restart. Dropping `sleep=sleep` from the delegation reddens it, and so does clearing an option after a failure. Corrected the `api_get` docstring formula to `sleep * 2 ** (attempt - 1)`: attempt 1 uses exponent zero, which is what the pinned `[3, 6, 12, 24]` sequence shows. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112205&sha=66f93bffd6aa9d3b6f038bf7a6b59ac02a5b3f10&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 PR: ClickHouse#112205
The failover row passed only `params` and inspected headers on the first authenticated request, so losing an option, the bearer or the caller's sleep on a later post-reset attempt stayed invisible. It now drives the persistent `404` with the shapes the callers actually use (`sleep=0`, `params`, the diff `Accept` header, `timeout=10`) and asserts all of them, plus the sleep sequence, on every attempt after the reset. Clearing an option at the reset reddens it, and so does dropping the bearer from the third attempt onward, while the pre-existing failover rows stay green. Corrected two comments that said `report.py` falls back to the run URL after catching `APIException`: `GITHUB_JOB_ID` swallows it by default, so `GITHUB_JOB_URL` returns an empty string without entering that branch. The invariant the test pins is only that the class stays catchable at the existing caller boundary. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112205&sha=66f93bffd6aa9d3b6f038bf7a6b59ac02a5b3f10&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 PR: ClickHouse#112205
|
Rebased on master (the conflict was one The merge surfaced a real gap: Also closed the two test-liveness gaps left at the previous round cap. The suite recorded Each is backed by a mutation that reddens only the new row: dropping |
|
Workflow [PR], commit [a2f2fbb] Summary: ✅ AI ReviewSummaryThe PR centralizes GitHub API read retries in Final VerdictStatus: ✅ Approve. |
|
I read
Threading a callable through it would also bypass everything it exists for: the Your point about the duplication is right, though the closest copies are inside |
|
Hi @leshikus, gentle ping - the open question is whether the shared backoff helper for |
…retry-v2 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…retry-v2 Resolves the conflict with ClickHouse#119166 in ci/praktika/gh.py: GH.api_get stays in place before do_command_with_retries, which keeps master's new strict parameter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
No CI job runs `ci/tests` since the `CI Tests` job was removed, and changes to the CI infrastructure ship without tests of that infrastructure. The 31 scripted-response cases were run locally against this tree instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`get_previous_release_tag` reads page 1 of the GitHub releases list and, since ClickHouse#115228, refuses a page shorter than the 100 releases it asks for, because choosing from or walking past a degraded page gave stale baselines. It refused after a single request, though. GitHub sometimes answers that request with HTTP 200 and `[]`, which `get_gh_api` returns as a success (it retries only on HTTP errors), so one degraded answer killed the job: on 2026-10-22, 14:58-15:32 UTC, `Upgrade check (amd_release)` ended after about a minute with `Unknown job error` on 5 unrelated PRs. Probing the same URL returned `[]` on 4 of 19 requests, each followed by a full page within 10-22 s; answers carry `cache-control: s-maxage=60`, and one empty answer came from the edge cache. Retry a short first page up to 4 times, 60 s apart, so the cached answer has expired before the next request, then raise the same `ReleaseNotFoundException` as before. A full page still costs one request and no wait. HTTP 5xx on the same request is left to ClickHouse#112974. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Retry GitHub API reads with a capped exponential backoff instead of a fixed delay, so the
Upgrade checkrides out a longer transient5xxor429fromapi.github.comduring setup instead of failing on a routine blip. The policy now lives inpraktikaasGH.api_get.Description
Related: #112205
Upgrade check (*)fails in setup (Download script failed) on a transient5xxfrom theGitHub releases API.
get_previous_release_tag.pyresolves it throughget_gh_api,which retried 5 times with a fixed 3 s sleep, so
retriesbounded the attempt countbut not the time window: a 12 s budget, which a routine blip outlasts. On PR #112205 a read
timeout at 10:06:15 was followed by four
504retries 3 s apart, exhausted at 10:06:27.Report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112205&sha=66f93bffd6aa9d3b6f038bf7a6b59ac02a5b3f10&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29
The delay now grows as
sleep * 2 ** (attempt - 1), capped at 60 s, for the classestransient by definition: every
5xx,429, and transport errors, giving a 45 s defaultwindow. Terminal statuses keep the flat sleep, and the growth base is the caller's own
sleep, so thepr_info.pysites passingRETRY_SLEEP = 0still get none. An outage thatoutlasts the whole budget still raises.
Per review the policy lives in
ci/praktika/gh.pyasGH.api_get, reusable by any praktikajob, with
get_gh_apia thin shim over it. The failover has to stay inci/toolsbecauseget_robot_tokenimportsboto3and PyGithub at module level, so the shim keeps itssignature, its
APIExceptionand the failover, driving the latter through anon_http_errorcallback that restarts the budget exactly once. All eight call sites areunaffected.
The
Upgrade checkdigest now also listsbuild_download_helper.pyandgh.py, which itsentry scripts import: without them the job filter read this very change as unaffected.
Validated locally, since changes to the CI code ship without tests of it: 31 scripted-response
cases across both layers, each checked against a deliberate mutation of its subject, plus a
live
get_previous_release_tagrun.Workflow [PR]
Sync PR [sync-upstream/pr/112974]