Skip to content

CI: wait for a CI database query slot instead of failing the test-selection step - #120928

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-cidb-queue-wait-test-selection
Sep 19, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:ci-cidb-queue-wait-test-selection

Conversation

@groeneai

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

Not required (CI-only change).

Description

Related: #114417 (the request to investigate this if it recurred; it did on 2026-09-18). Job log: https://github.com/ClickHouse/ClickHouse/actions/jobs/105539654847

What breaks. A Stateless tests (..., selected tests) job dies before running a single test, with Failed to select tests: Failed to get previously failed tests required for test selection. I measured 8 such deaths on 6 days across 6 PRs; 4, including both on 09-18, are the CI database answering HTTP 500 Code: 202 ... Too many simultaneous queries. Maximum: 1000.

Root cause. queue_max_wait_ms defaults to 0, and it is honoured by exactly the 202 branch this hits (ProcessList.cpp:183-193, the max_size branch): at 0 the server throws at once, at a positive value it waits for an admission slot. praktika never sends it, so every request asks to be rejected rather than queued, and the client spends its 5 retries in 31 s re-asking a saturated server. strict=True on a selected tests run makes that fatal. I am not touching that fail-closed policy; it is deliberate (#114730).

Change (2 files, 5 lines). _post_with_retries sends queue_max_wait_ms at half the caller's timeout (30000 ms for queries, 10000 for inserts), covering query, insert_rows and check. The selected-tests error handler also renders traceback.format_exc(): today it prints only the outer fixed string, so 1 of the 8 occurrences has no diagnostic.

Validation. With max_concurrent_queries=1 and the only slot held, SELECT 1 gives 500 Code: 202; with queue_max_wait_ms=30000 it gives 200 after a 4.01 s wait, the holder's remaining time; with queue_max_wait_ms=1, 500 again. Both hunks also have negative-control seam assertions; the end-to-end gate is this PR's own CI, since every job inserts to CIDB through the changed helper.

Scope. This is the client-side half only; the server-side lever on that cluster is your call. I can add a unit test if the CI Tests runner returns.

The 8 measured occurrences (from job logs, not CIDB)
date PR check cause in the job log
08-20 114417 amd_asan_ubsan, distributed plan, parallel, selected tests CIDB HTTP 500 Code: 202
08-20 114417 amd_asan_ubsan, db disk, distributed plan, sequential, selected tests CIDB HTTP 500 Code: 202
08-21 115441 amd_tsan, s3 storage, parallel, selected tests aws: [ERROR] ... (NoCredentials)
08-28 103478 amd_asan_ubsan, db disk, distributed plan, sequential, selected tests none logged
08-28 115546 amd_tsan, sequential, selected tests aws: [ERROR] ... (NoCredentials)
09-06 111895 amd_tsan, s3 storage, parallel, selected tests nothing at all
09-18 107074 amd_asan_ubsan, distributed plan, parallel, selected tests CIDB HTTP 500 Code: 202
09-18 107074 amd_asan_ubsan, db disk, distributed plan, sequential, selected tests CIDB HTTP 500 Code: 202

One infra cause produced 3 red checks on 09-18, and two Bugfix validation jobs were dropped behind them.

Only 4 have a row in default.checks: on 2026-09-18 the jobs' own result insert also hit Code: 202, so they left no row. Breadth for this family has to come from job logs or the check-runs API.

Not addressed, deliberately: the secret-fetch variant (2 of the 8) died with the move of secret.py to boto3, so I added nothing for a mechanism that no longer exists, and the traceback makes the remaining unattributable occurrence nameable rather than fixed. cidb_cluster.py is a second HTTP client that fails soft by design, so it is untouched; extending the same parameter to its 4 call sites is a mechanical follow-up if you want it.

#115436 (merged 2026-08-20) added the current backoff and is an ancestor of the 2026-09-18 failing head, so it is not this failure's owner.


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

Version info

  • Merged into: 26.10.1.145 (included in 26.10 and later)

…ection step

A `Stateless tests (..., selected tests)` job dies before running a single test
with `Failed to select tests: Failed to get previously failed tests required for
test selection`. Eight such job deaths were measured over six days on six PRs
between 2026-08-20 and 2026-09-18; four of them, including both on 2026-09-18,
are the CI database answering HTTP 500 `Code: 202. DB::Exception: Too many
simultaneous queries. Maximum: 1000`.

`queue_max_wait_ms` defaults to 0, and it is honoured by exactly the 202 branch
these requests hit: `ProcessList.cpp:183-193`, the `max_size`
(`max_concurrent_queries`) branch. At 0 the server throws immediately; at a
positive value it logs "Too many simultaneous queries, will wait N ms." and waits
on `have_space` for an admission slot, throwing only if the wait expires. The
sibling 202 branches carry different messages ("for all users", "for user X",
"insert/select queries", "for table X"), so the attribution is exact. praktika
never sends the setting, so every CI database request asks to be rejected rather
than queued, and `_post_with_retries` then spends its five attempts in 31 s
re-asking a saturated server. Because a `selected tests` run passes
`include_changed_tests=True`, `find_tests.py` has `strict=True` and converts that
into an ERROR result with zero tests run.

Send `queue_max_wait_ms` at half the caller's own timeout (30000 ms for queries,
10000 ms for inserts and the smoke test) from the single shared helper, so the
server waits for a slot instead of rejecting, and without issuing another request
to an already saturated server. This covers `query`, `insert_rows` and `check`.
The fail-closed selection policy itself is deliberate and is left untouched.

Separately, the selected-tests error handler rendered only `str()` of the outer
exception, whose message is a fixed string, so the preserved `__cause__` chain
was never shown. One of the eight occurrences (2026-09-06) therefore carries no
diagnostic at all and cannot be attributed today. Render `traceback.format_exc()`
as well; that handler catches every selection leg, and `Result.info` reaches all
three places a human looks: the job log, the HTML report and the CI database.

Validated on a server with `max_concurrent_queries=1` and the only slot held:
plain `SELECT 1` returns 500 `Code: 202` in 0.06 s; with
`queue_max_wait_ms=30000` it returns 200 after a 4.01 s wait, the holder's
remaining time, and the server logs "will wait 30000 ms."; with
`queue_max_wait_ms=1` it returns 500 again, which isolates the wait duration as
the causal variable. Seam assertions cover both hunks, each with a patch-revert
negative control.

Related: ClickHouse#114417

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 18, 2026
@groeneai

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

Pre-publication review by an independent model (engine: codex; 0 findings;
bounded: 1 full pass + 1 fix round + 1 delta recheck). The two rows below come from my own
cold read of the diff, which ran before the gate and before I read the implementation notes.

# Sev Finding Verdict Evidence / action
1 💡 cidb_cluster.py is a second HTTP client to the same CI database (same connection secret) whose four request sites keep the fail-fast behaviour this change removes from cidb.py; its one fatal path is assert cidb_cluster.is_ready() (ci/jobs/functional_tests.py:631) AGREE, not fixed here Out of this change's scope and unmeasured: none of the 8 occurrences I collected came through that client, and it fails soft elsewhere by design. Offered in the description as a mechanical follow-up.
2 💡 On a saturated CI database the worst case lengthens: about 31 s to 180 s for a query, 6 s to 36 s for an insert, on every job's result insert rather than only the selection step AGREE, no text change The mechanism and both values (30000 / 10000 ms) are already in the description, and the commit message states that one waiting request replaces five immediate re-asks of a saturated server.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Checks behind the verdict, for the record: the error string Too many simultaneous queries. Maximum: N
has exactly one emitter (ProcessList.cpp:190-192) and that is the only branch honouring
queue_max_wait_ms, so the attribution is exact; the setting has no second-order effect on workload
admission, which uses workload_admission_timeout_ms; have_space.wait_for releases the process-list
mutex while waiting; the commit-status description is byte-identical because it is the first line of
Result.info and the traceback is appended after a newline; and the added server log line cannot be
injected into a response body, because over HTTP the log queue is attached only when a framing format
is enabled and praktika never sets one.

Session id: cron:clickhouse-review-slot-9:20260918-221700

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. With max_concurrent_queries=1 and the only admission slot held, SELECT 1 returns 500 Code: 202 ... Too many simultaneous queries in 0.06 s, every time, on an unmodified binary. The diagnostic half reproduces deterministically too: the current handler renders only the outer fixed string. Nothing here is probabilistic.
b Root cause explained? Yes. queue_max_wait_ms defaults to 0, and that setting is honoured by exactly the 202 branch this hits (ProcessList.cpp:183-193, the max_size branch): at 0 the server throws at once, at a positive value it waits on have_space for a slot. praktika never sends it, so the request asks to be rejected rather than queued; the client then burns 5 retries in 31 s re-asking a saturated server, and strict=True on a selected tests run turns that into ERROR with 0 tests run.
c Fix matches root cause? Yes. It changes the one input that selects between "throw" and "wait" in the measured branch. Retry counts, timeouts, the fail-closed selection policy (deliberate, #114730) and test-selection semantics are all untouched. Raising retries, widening the backoff, and degrading the selection were considered and rejected; the first two re-ask a saturated server more often, the third reports success having tested less.
d Test intent preserved / new tests added? Preserved: no test is modified or weakened, and the second hunk only adds text on an already-fatal path. No committed test, deliberately, because ci/tests/ is not run by anything today (the CI Tests job was deleted in #115650) and ci/praktika/ has no other Python harness. Validation is the four experiments below plus this PR's own CI. I can add a unit test if that runner returns.
e Both directions demonstrated? Yes, three times. Real server: 500 without the setting, 200 with queue_max_wait_ms=30000 after a 4.01 s wait, and 500 again with queue_max_wait_ms=1 as a negative control isolating the wait duration. Seam probe: 7 assertions flip from pass to fail when the diff is patch-reverted, while every "unchanged behaviour" assertion keeps passing. Rendering probe: the underlying Code: 202 is absent before and present after.
f Fix is general across code paths? Yes. The change sits in the single shared helper, so query (the failing path), insert_rows (every job's result insert, whose failure is why this family leaves no CIDB row) and check (the Config Workflow probe) are all covered, each asserted. The coverage-query selection leg is also a CI database query, so it is covered as well. cidb_cluster.py is a separate client that fails soft by design and is deliberately untouched, as noted in the description.
g Fix generalizes across inputs? Yes. The value is derived from the caller's own timeout rather than hardcoded (60 s to 30000 ms, 20 s to 10000 ms), and the assertions compare against the settings constants, so a future timeout change cannot silently desync it. The arithmetic is integral for int and float timeouts. Type wrappers are not applicable: this is one integer URL parameter, not a data path. A timeout of 0 would yield 0, which is exactly today's behaviour.
h Backward compatible? Yes. No default changed, no setting added or renamed, no format or schema change, so SettingsChangesHistory.cpp is not involved. queue_max_wait_ms is a plain query-level setting that has existed since 2019. Below the concurrency limit behaviour is identical; at the limit the request waits instead of failing. Reverting is one line.
i Invariants and contracts preserved? Yes. The helper's contract (return the first OK response, else raise after retries attempts) is pinned in both directions by assertions on the success count and the exhaustion count. The caller's params dict is copied, not written through, so no request can leak a setting into another. Server side, the waiting path is the pre-existing bounded have_space.wait_for under the ProcessList mutex, with the 202 throw still the backstop when the wait expires. The second hunk only builds a string after the ERROR status is already decided, so it cannot change any status or control flow.

Session id: cron:clickhouse-impl-slot-41:20260918-214800

@clickhouse-gh

clickhouse-gh Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2cf44dc]

Summary: ✅


AI Review

Summary

This PR teaches the shared CIDB HTTP helper to send queue_max_wait_ms so CI database requests wait for a free max_concurrent_queries slot instead of failing immediately, and it appends the full traceback when selected-test discovery fails. I traced the changed helper through all current callers (query, insert_rows, and check) and through the selected-tests path in find_tests.py / functional_tests.py; I did not find a current correctness, compatibility, or reporting-contract issue in the patch.

Final Verdict

✅ No actionable findings.

LLVM Coverage Report

⚠️ No coverage measurement for commit 2cf44dc: incomplete coverage measurement: 16 of 21 shard profiles are missing: LLVM_COVERAGE_FILE_ft_2.profdata, LLVM_COVERAGE_FILE_ft_3.profdata, LLVM_COVERAGE_FILE_ft_s3_async_sequential.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_parallel_2.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_parallel_3.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_sequential_1.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_sequential_2.profdata, LLVM_COVERAGE_FILE_ft_s3_sequential.profdata, LLVM_COVERAGE_FILE_it_1.profdata, LLVM_COVERAGE_FILE_it_2.profdata, LLVM_COVERAGE_FILE_it_3.profdata, LLVM_COVERAGE_FILE_it_4.profdata, LLVM_COVERAGE_FILE_it_5.profdata, LLVM_COVERAGE_FILE_it_6.profdata, LLVM_COVERAGE_FILE_it_7.profdata, LLVM_COVERAGE_FILE_it_8.profdata.

@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 19, 2026
Merged via the queue into ClickHouse:master with commit 12bfa4e Sep 19, 2026
177 of 349 checks passed
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai manual approve Manual approve required to run CI pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants