Skip to content

Revert "Revert "Correct nightly coverage selection and share PR test manifests"" - #122111

Merged
fm4v merged 6 commits into
masterfrom
revert-122110-revert-118223-nightly-coverage-test-selection
Sep 26, 2026
Merged

fm4v merged 6 commits into
masterfrom
revert-122110-revert-118223-nightly-coverage-test-selection

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Related: #118223
Related: #122110
Related: #122067

This re-lands #118223 (precise-coverage test selection inside each targeted stateless job), which was reverted in #122110, together with fixes for the reason of the revert.

Why it was reverted

Targeted stateless jobs failed with Failed to load test selection: CIDB query failed ... Read timed out (read timeout=60), for example in #122067 (job log). Stateless tests (amd_asan_ubsan, db disk, distributed plan, targeted) is a core blocking job, so each such failure skipped the rest of the PR pipeline.

In CIDB, 190 of the 199 Failed to load test selection errors between the merge and the revert came from the coverage snapshot query in Targeting.coverage_snapshots. It computed uniqExact(test_name) over the whole 14-day window of checks_coverage_lines: 3.5 billion rows and 57 GB (test_name is 288 of the table's 304 GiB), about 6 s on an idle server. Every targeted job of every PR ran it, and the failures clustered at 2026-09-24 18:00-20:00 and 2026-09-25 02:00-04:00 UTC, when the per-test coverage export inserts about 240 million rows. Under that load all five 60 s attempts timed out.

Changes on top of the reverted PR

  • Snapshot lookup (load_snapshots in coverage_selection.py): first the distinct check_start_time values of the window (only that column is read, about 0.3 s), then the exported tests are counted for five timestamps per query, filtered by the primary key, newest first, until every shard has coverage_run_count healthy snapshots. At six cutoffs on live CIDB data the result is identical to the old query, with 6-10 GB of test_name read instead of 57 GB and 1.4-2.3 s instead of about 6 s.
  • The snapshot queries use use_query_cache = 1 (TTL 1 h): they only read settled exports, so all jobs and PRs get the same result. A repeated lookup reads 0 rows. They also get a 180 s timeout per attempt instead of 60 s (CIDB.query accepts a timeout).
  • If a CIDB request of the selection still times out on every attempt (new CIDBTimeoutError), the targeted job ends SKIPPED instead of ERROR, so it no longer skips the jobs that wait for the core blocking jobs. It adds a workflow warning and the comment CIDB timeout in test selection, rerun to test, and it is not cached. The PR summary table now also lists skipped jobs that carry a comment, so the skip is visible. Other selection failures remain errors.
  • test_selection_smoke runs in a targeted job only when the PR changes the selection code (Targeting.SELECTION_SOURCES), not in every PR.
  • Removed unused code: keyword matching (_extract_domain_keywords), the shadow rankings (three extra rank_candidates calls per job whose output nothing read), the expanded targeted matrix that was built and discarded because expanded_targeted_matrix was off, the entry-count experiments, and the offline replay tool evaluate_test_selection.py. Production ranking and the generated workflows are unchanged.

Validation

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):

...


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

Version info

  • Merged into: 26.10.1.741-master (included in 26.10 and later)

@clickhouse-gh

clickhouse-gh Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2c4057e]

Summary: ✅


AI Review

Summary

This revert-of-revert re-enables coverage-based targeted selection for PR stateless jobs and adds nightly/export smokes plus selection manifests. The query optimization itself looks reasonable, but the current head still has multiple CI-correctness gaps: targeted stateless results are still cacheable on inputs the digest cannot represent, mixed CIDB failures can be downgraded to SKIPPED, and several change classes still escape the validation they are supposed to trigger.

Findings
❌ Blockers
  • [ci/jobs/functional_tests.py:862-897] Targeted stateless jobs still publish ordinary cache-success records even though the selected test list now depends on the PR diff, selection_cutoff, run_attempt, and live CIDB state. Praktika's shared cache key is still just (job name, digest), so one PR can reuse another PR's green targeted result without recomputing its own selection. Make targeted stateless jobs uncached (digest_config = None) or force every targeted exit path to set do_not_cache=True.
  • [ci/praktika/cidb.py:353-363] CIDBTimeoutError is raised whenever the last retry timed out, even if earlier retries failed for different reasons. A sequence like ConnectionError, ConnectionError, ReadTimeout is therefore converted into the "safe to skip" path in functional_tests.py, which downgrades a mixed CIDB failure to SKIPPED and lets dependent PR jobs proceed. Track all_timed_out across retries and raise CIDBTimeoutError only when every failed attempt was a client-side timeout.
⚠️ Majors
  • [ci/defs/job_configs.py:2171-2189] The PR sanitizer matrix no longer contains a plain amd_tsan stateless lane. The generated list now keeps only Stateless tests (amd_tsan, s3 storage, targeted), so ordinary TSan regressions that reproduce only outside the S3 setup lose all PR-level signal. Keep a plain amd_tsan, targeted variant in functional_tests_pr_jobs, or justify replacing the default TSan environment with the S3 one.
  • [ci/jobs/functional_tests.py:862-908] A PR that changes only the targeted-check harness or selector code can still make every targeted stateless job skip without running clickhouse-test: get_changed_tests is empty for ci/-only changes, there is no fallback smoke list anymore, and the job exits SKIPPED on an empty selection. That leaves targeted-mode changes in functional_tests.py and the selector stack unexercised by the very jobs meant to validate them. Restore a small deterministic smoke list for targeted or harness changes, or otherwise guarantee that a targeted PR job executes at least one real test when its own pipeline changes.
  • [ci/jobs/scripts/find_tests.py:97-104; ci/defs/job_configs.py:185-196; ci/jobs/scripts/workflow_hooks/filter_job.py:121-123] The selector's real inputs are still wired incompletely. SELECTION_SOURCES omits the Info and environment carriers that feed run_attempt and workflow_start_time, the stateless digest still omits test_selection_smoke.py and ci/praktika/_environment.py, and the coverage-pipeline skip list still omits test_selection_config.py. Those gaps let selection-semantic changes skip the smoke, reuse cached targeted results, or skip nightly coverage jobs as "unchanged". Add every selection-contract input to the smoke trigger, targeted digest, and coverage-pipeline path list.
  • [ci/jobs/scripts/find_tests.py:727-737; ci/jobs/scripts/find_tests.py:766-773] Brand-new source files still parse as old-file line 0 / hunk range (0, 0). The resulting coverage predicate becomes line_end >= 0 AND line_start <= 0, which can never match the 1-based coverage stored in CIDB, so a PR that only adds a new src/ / programs/ / base/ file gets no precise coverage candidates. Clamp -0,0 hunks to the added new-line range, or at least to line 1, before building the candidate query.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: make targeted stateless jobs non-cacheable on PR-local selection inputs, fix CIDBTimeoutError so only all-timeout retry sequences are skipped, and close the remaining coverage gaps in targeted validation (plain amd_tsan, CI-only harness changes, hidden selector inputs, and new-file diff mapping).

LLVM Coverage Report

Measured on commit 2c4057e.

Metric Baseline Current Δ
Lines 88.20% 88.10% -0.10%
Functions 91.80% 91.70% -0.10%
Branches 79.50% 79.40% -0.10%

Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage).

Newly covered: +187 lines in 53 files (-123 lines lost coverage) · Details

Full report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 24, 2026
@clickhouse-gh
clickhouse-gh Bot requested review from leshikus and maxknv September 24, 2026 22:19
Comment thread ci/defs/job_configs.py
if job.parameter.startswith(
(
"amd_asan_ubsan, db disk, distributed plan,",
"amd_tsan, s3 storage,",

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.

This narrows the PR TSan matrix down to the s3 storage configuration only. Before the revert, the selected-test lanes still kept both the plain amd_tsan jobs and the amd_tsan, s3 storage jobs; after functional_tests_pr_jobs filters out every sanitizer lane below, the default TSan functional environment disappears from PR CI entirely and only the S3-flavored job remains.

That is a real coverage loss: regressions that reproduce only in the ordinary TSan setup now get no PR-level TSan signal unless they happen to be covered by the separate changed-test flaky check. Please keep the plain amd_tsan configuration in stateless_tests_sanitizer_pr_jobs as well, or explain why the s3 storage lane is intended to replace it completely.

)
print(f"[selected tests] {len(tests)} tests to run: {tests}")

if not tests:

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.

With the old selected-tests path gone, this branch now trusts the selector to always return at least one real test. But Targeting.get_changed_tests only maps files under tests/queries/0_stateless, so a PR that changes only the targeted-check harness itself (ci/jobs/functional_tests.py, find_tests.py, coverage_selection.py, etc. — including this one) produces changed=[], coverage_lines=[], and usually previously_failed=[] on the first attempt.

In that case we hit this SKIPPED exit and the only PR sanitizer lanes that exercise targeted mode never actually run clickhouse-test on the very selector/harness changes they are supposed to validate. The old STATELESS_HARNESS_SMOKE_TESTS fallback existed exactly to avoid that blind spot. Please restore a small deterministic smoke list for harness/selector changes, or otherwise guarantee that targeted jobs execute at least one real test when their own pipeline changes.

@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Sep 24, 2026
The snapshot query counted `uniqExact(test_name)` over the whole 14-day window of `checks_coverage_lines`: 3.5 billion rows and 57 GB, about 6 s on an idle server. Every targeted stateless job of every PR runs it, so while the per-test coverage export was inserting (2026-09-24 18:00-20:00 and 2026-09-25 02:00-04:00 UTC) it exceeded the 60 s timeout on all five attempts. 190 of the 199 "Failed to load test selection" errors since the selector was merged were this query, and as `Stateless tests (amd_asan_ubsan, db disk, distributed plan, targeted)` is a core blocking job, each of them skipped the rest of the PR pipeline. This is why #118223 was reverted in #122110.

Now the distinct `check_start_time` values of the window are listed first (only that column is read, about 0.3 s), and exported tests are counted for the newest three timestamps at a time, filtered by the primary key, until every shard has `coverage_run_count` healthy snapshots. On live CIDB data the result is identical to the old query at every cutoff tried, and it reads 6-10 GB of `test_name` instead of 57 GB, in 1.4-2.3 s instead of about 6 s.

Example failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/122067/925c788e633f3e3fd2f31f3cd68b916ceb728a3e/pr/stateless_tests_arm_asan_ubsan_targeted/job.log (#122067)
Count exported tests for five timestamps per query, give the snapshot queries a 180 s timeout instead of the default 60 s, and enable the query cache for them: they only read settled exports, so every job and pull request gets the same result. On live CIDB data a repeated lookup reads 0 rows and the result is unchanged.

If a CIDB request of the test selection still times out on every attempt, the targeted stateless job is now `SKIPPED` instead of `ERROR`, so it no longer skips the jobs waiting for the core blocking jobs. It adds a workflow warning and a comment, and is not cached, so a rerun or the next commit selects again. Other selection failures remain errors. `CIDB` raises the new `CIDBTimeoutError` for this case, and the PR summary table now also lists skipped jobs that carry a comment, so such a skip is visible instead of silently green.
@@ -1990,9 +857,9 @@ def _parse_diff_lines(diff_text: str) -> list:
old_line += 1
elif line.startswith("+"):
changed.add((current_file, old_line)) # insertion point in old file

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.

For a brand-new source file hunk (@@ -0,0 +... @@), old_line is 0 here and _parse_diff_hunk_ranges also records (0, 0). build_candidate_query later turns that into line_end >= 0 AND line_start <= 0, but stored coverage is 1-based, so a PR that only adds a new src/ / programs/ / base/ file produces no precise coverage candidates at all.

Because this PR removed the old broad fallback, targeted selection can now end up empty (or only run unrelated stale failures) for brand-new production code. Please special-case -0,0 hunks to map to the added new-line range, or at least clamp new-file additions to line 1 before building the coverage predicate.

Comment thread ci/praktika/cidb.py

print(f"WARNING: CIDB {error} - attempt {retry}/{retries}")
if retry >= retries:
if timed_out:

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.

CIDBTimeoutError is documented and consumed as "every attempt timed out", but timed_out here only reflects the last retry. A sequence like ConnectionError, ConnectionError, ReadTimeout now raises CIDBTimeoutError, and functional_tests.py converts that mixed CIDB failure into SKIPPED instead of ERROR, letting downstream PR jobs proceed.

Please accumulate an all_timed_out flag across retries and raise CIDBTimeoutError only when every failed attempt was a client-side timeout.

Comment thread ci/defs/job_configs.py
# `find_tests.py` selects the targeted tests from CIDB and reads
# `Info`, so both modules decide which tests this job runs.
"./ci/praktika/cidb.py",
"./ci/praktika/info.py",

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.

Targeted stateless jobs now always execute python3 -m ci.jobs.scripts.test_selection_smoke, and the rerun-cutoff path in find_tests.py depends on Info.run_attempt / workflow_start_time, which are populated in ci/praktika/_environment.py. Neither file is covered by this digest.

That means a PR that only changes test_selection_smoke.py or _environment.py can reuse a cached targeted result and never exercise the selector path it actually modified. Please add both files to common_ft_job_config.digest_config.include_paths.

"ci/jobs/scripts/job_hooks/llvm_coverage_hook.py",
# Exports per-test coverage and runs the post-export selector smoke.
"ci/jobs/scripts/functional_tests/export_coverage.py",
"ci/jobs/scripts/coverage_selection.py",

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.

coverage_selection.py imports SELECTION_CONFIG directly, and the nightly/export smoke path uses that module too. A PR that only changes ci/jobs/scripts/test_selection_config.py still makes _has_coverage_pipeline_changes return false here, so the whole amd_llvm_coverage* / LLVM Coverage family is skipped as "coverage identical to master" even though the selector thresholds and timeouts it runs with have changed.

Please add test_selection_config.py (and any other selector-contract inputs that must rerun coverage jobs) to _COVERAGE_PIPELINE_PATHS.

The targeted stateless jobs ran `test_selection_smoke` before every selection. It checks the selection code, not the pull request, so it only needs to run when a pull request changes that code: `Targeting.SELECTION_SOURCES`. If the changed files are unknown it still runs.
"ci/jobs/scripts/test_selection_config.py",
"ci/jobs/scripts/test_selection_manifest.py",
"ci/jobs/scripts/test_selection_smoke.py",
"ci/praktika/cidb.py",

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.

SELECTION_SOURCES is the contract for "changes that must run test_selection_smoke before targeted selection", but selection_code_changed, get_changed_tests, and selection_cutoff all read through Info, and this PR adds new Info.workflow_start_time / Info.run_attempt carriers without listing ci/praktika/info.py here.

A future PR that changes only those proxies will rerun the selector with different semantics but skip the smoke, so the per-attempt cutoff invariant can regress silently. Please include ci/praktika/info.py here as well (and, if _environment.py remains an independent selection input, the carrier that feeds it too).

Nothing read the results of these, so they only cost code and CPU in every targeted job:

- `_extract_domain_keywords` and the `semantic_keyword_matches` it filled in.
- The `shadow` rankings, three extra `rank_candidates` calls per job for the entry-count experiments.
- The expanded targeted matrix: it was built and then discarded, because `expanded_targeted_matrix` was off. Removes `targeted_matrix` and `rollout_targeted_jobs`. The generated workflows are unchanged.
- `_stored_path`, which had no callers.
- The offline replay tool `evaluate_test_selection.py`, which no CI job ran, and with it the entry-count experiments in `rank_candidates` (`entry_mode`, `entry_count_bonus_bound`), which only it and the shadow rankings used. Production scoring was `entry_mode="disabled"` and does not change.
results=results,
)
skipped.set_comment("CIDB timeout in test selection, rerun to test")
skipped.complete_job(do_not_cache=True)

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.

Only the CIDB-timeout skip is marked do_not_cache=True here, but the normal targeted path still publishes an ordinary cache-success record. That is not a safe cache key anymore: the selected test list now depends on the PR diff, selection_cutoff() / run attempt, and CIDB failure history, while Praktika still reuses this job purely by repository-file digest.

The result is that once one PR produces a green Stateless tests (..., targeted) record, another PR with the same repo digest can reuse it from the shared cache and skip its own targeted execution entirely. Please make targeted stateless jobs uncached (digest_config = None) or force do_not_cache=True for every targeted exit, not only the timeout case.

…t-118223-nightly-coverage-test-selection

# Conflicts:
#	ci/defs/job_configs.py
#	ci/jobs/scripts/find_tests.py
@clickhouse-gh clickhouse-gh Bot added pr-ci and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Sep 25, 2026
@fm4v
fm4v added this pull request to the merge queue Sep 26, 2026
Merged via the queue into master with commit 84275a6 Sep 26, 2026
174 checks passed
@fm4v
fm4v deleted the revert-122110-revert-118223-nightly-coverage-test-selection branch September 26, 2026 07:01
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 26, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 27, 2026
…est-selector

Master re-landed ClickHouse#118223 (74c90e9, ClickHouse#122111), which restores
Targeting.selection_test_name and ci/jobs/scripts/test_selection_smoke.py and
drops DIRECT_CALL_MAX_DEPTH:

- ci/jobs/scripts/find_tests.py: selection_pattern builds on
  selection_test_name again, as before the revert, instead of repeating its
  normalization. DIRECT_CALL_MAX_DEPTH stays removed.
- ci/jobs/scripts/test_selection_smoke.py: the two selector checks are back.
  The targeted job runs this suite when find_tests.py changes.

Re-validated on the merged tree: the smoke suite passes 16/16 and each selector
check fails under its mutation; every one of the 15,806 stateless test sources
is selected alone by its selector from every name shape a producer emits,
through the real run_tests command line, bash and the tests/clickhouse-test
matcher.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
middas-0706 pushed a commit to middas-0706/ClickHouse that referenced this pull request Nov 24, 2026
…ted job

ClickHouse#122111 made the targeted stateless and integration jobs SKIP instead of
ERROR when a test-selection CIDB request times out on every attempt
(`CIDBTimeoutError`). The first selection read, the strict previously-failed
lookup in `Targeting.get_previously_failed_tests_with_info`, re-wrapped any
exception as a plain `RuntimeError`, so a timeout there lost its class
before reaching either `except CIDBTimeoutError` handler and the shard
still ERRORed ("Failed to load test selection" in the stateless job, an
uncaught exception in the integration job). On a `pr-bugfix` PR that drops
`Bugfix validation` and fails `Finish Workflow / Post Hooks`.

Re-raise `CIDBTimeoutError` unchanged in strict mode. Every other failure
(a refused connection, an answered non-OK response) stays wrapped and keeps
failing the job, as ClickHouse#114730 intends. Best-effort mode is unchanged.

CIDB shows 3 such errors, all on 2026-09-24/25 during the CIDB overload
ClickHouse#122111 targets (PRs ClickHouse#118823, ClickHouse#117436, ClickHouse#114865).

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

comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). 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