Skip to content

Run a stateless flaky check in the merge queue - #110308

Merged
alexey-milovidov merged 5 commits into
masterfrom
mq-flaky-check
Jul 15, 2026
Merged

alexey-milovidov merged 5 commits into
masterfrom
mq-flaky-check

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Related: #108548
Related: #110260
Related: #108511

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

A PR's green CI describes the master of its last run, not of its merge. #108548 merged on 2026-07-13 with CI last run on 07-01; on 07-03 master merged #108511, which added materialize_statistics_on_insert to the settings randomizer in tests/clickhouse-test. The PR's new test 02346_text_index_bug108519_qcc_skip_index then failed on master whenever the randomized setting was drawn (~40% of runs) and kept master red for ~7 hours until #110260 pinned auto_statistics_types at the table level. The flaky check would have caught this with near certainty — it just last ran against a master that did not have the randomizer yet.

The merge queue already builds the exact merged state (Build (amd_binary)) but ran no stateless tests on it. This PR adds Stateless tests (amd_binary, flaky check) to MergeQueueCI: it reruns the PR's new/changed stateless tests on the merge group state (the PR merged with the current master), so a semantic conflict with post-CI master changes bounces the PR from the queue instead of breaking master. The job self-skips when the PR changes no tests, so non-test PRs pay nothing.

Details:

  • Merge-queue runs use a reduced budget: rerun_count 20 instead of 50 and a 20-minute instead of 45-minute time limit, since the PR CI already ran the full flaky check and this rerun is a drift guard. A randomized setting drawn with probability 0.4 per run escapes 20 iterations with probability 0.6^20 ≈ 4e-5. --sequential-test-runs scales along, as it is derived from rerun_count.
  • Changed-file detection in merge-queue runs now uses the linked PR's paginated files list: PR_NUMBER is 0 in a merge_group event (only LINKED_PR_NUMBER is parsed from the queue ref), and the previously used commits API caps a merge commit's file list at 300 entries.
  • The changed-files fetch in store_data.py now fails closed in merge-queue runs (as it already did for PR runs), so a persistent GitHub API failure cannot silently turn the flaky check into a skip. Master/release workflows keep the tolerant behavior.
  • .github/workflows/merge_queue.yml is regenerated with praktika yaml.

A SKIPPED result (no tests to run) counts as success for the merge-ready status, same as in PR CI.

Version info

  • Merged into: 26.7.1.967 (included in 26.7 and later)

A PR's green CI describes the master of its last run, not of its merge.
PR #108548 merged on 2026-07-13 with CI last run on 07-01; on 07-03
master merged #108511, which added materialize_statistics_on_insert to
the settings randomizer in tests/clickhouse-test. The PR's new test
02346_text_index_bug108519_qcc_skip_index then failed on master whenever
the randomized setting was drawn (~40% of runs) and kept master red for
~7 hours until #110260 pinned auto_statistics_types at the table level.

The merge queue already builds the exact merged state (Build
(amd_binary)) but ran no stateless tests on it. Add "Stateless tests
(amd_binary, flaky check)" to MergeQueueCI: it reruns the PR's
new/changed stateless tests on the merge group state (the PR merged with
the current master), so a semantic conflict with post-CI master changes
bounces the PR from the queue instead of breaking master. The job
self-skips when the PR changes no tests.

Merge-queue runs use a reduced budget (20 iterations / 20 min instead of
50 iterations / 45 min): the PR CI already ran the full flaky check, and
a randomized setting drawn with probability 0.4 per run escapes 20
iterations with probability 0.6^20 ~= 4e-5.

Changed-file detection in merge-queue runs now uses the linked PR's
paginated files list (PR_NUMBER is 0 there, and the commits API caps a
merge commit's file list at 300 entries), and the changed-files fetch
fails closed in merge-queue runs so a GitHub API failure cannot silently
skip the check.

Incident: #108548
Follow-up fix it required: #110260

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [66dfd5d]

Summary: ✅


AI Review

Summary

This PR adds a merge-queue stateless flaky check that reruns PR-touched stateless tests on the merge-group state, tightens merge-queue changed-file discovery, and bounds the merge-queue flaky-check runtime. High-level verdict: the main workflow wiring looks reasonable, but one remaining selector gap still lets the new drift guard self-skip on realistic stateless-fixture-only changes, so the advertised coverage is not complete yet.

Findings

⚠️ Majors

  • [ci/jobs/scripts/find_tests.py:119-131] The new fixture mapping only handles auxiliary stateless files whose basename starts with a five-digit test prefix. Many existing tests/queries/0_stateless assets do not follow that convention. A concrete current-tree example is tests/queries/0_stateless/data_mysql_dump/dump1.sql: 02286_mysql_dump_input_format.sh consumes it, but _tests_owning_data_file returns [] for that path and Targeting.get_changed_tests therefore yields no selected tests, so should_skip_merge_queue_job still skips the merge-queue drift guard on a fixture-only PR. Suggested fix: when a changed path under tests/queries/0_stateless/ cannot be mapped to a concrete test, treat it as “coverage needed” rather than “nothing to rerun” by keeping the job enabled and/or falling back to a broader stateless rerun.
Tests

⚠️ Add a focused regression test for a non-prefixed auxiliary file such as tests/queries/0_stateless/data_mysql_dump/dump1.sql or tests/queries/0_stateless/helpers/protobuf_length_delimited_encoder.py, and assert that the merge-queue selector does not return [] for that class of change.

Final Verdict

Status: ⚠️ Request changes

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 13, 2026
Comment thread ci/workflows/merge_queue.py Resolved
Comment thread ci/praktika/gh.py Resolved
Comment thread ci/jobs/functional_tests.py Resolved
alexey-milovidov and others added 3 commits July 14, 2026 05:54
…umber

In `GH.get_changed_files`, a merge-queue run with an unparseable merge group
head ref left `linked_pr_number` at 0, so the code fell through to
`repos/{repo}/commits/{sha}`, whose file list is capped at 300 entries. On a
large PR that can silently drop changed test files and turn the merge-queue
flaky check into a false green.

A merge-queue entry always corresponds to exactly one PR, so a missing linked
PR number is a real fault, not a skip condition. Fail closed (raise) on a
strict call instead of falling back to the capped commits API; the tolerant
non-strict path is preserved for master/release-style callers.

AI review: #110308

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…xhausts its budget

The flaky-check time budget was computed as
`max(FLAKY_CHECK_TIME_LIMIT - elapsed, 0)`, but `run_tests` interprets
`global_time_limit == 0` as "pass no `--global_time_limit`" - i.e. no cap at
all, and no outer `Shell.run` timeout either. Once setup consumes the whole
budget (more likely under the tighter 20-minute merge-queue limit) the run
becomes unbounded, defeating the latency bound the reduced budget exists to
enforce.

Floor the budget at a small positive value (60s) so a positive
`--global_time_limit` is always passed and the run stays bounded, mirroring the
existing targeted-check floor.

AI review: #110308

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…on-test PRs

The `SKIPPED` exit in `functional_tests.py` happens only after the job has been
scheduled, restored `CH_AMD_BINARY`, and entered the stateless-test container,
so a source-only PR still paid that startup cost even though there were no
stateless tests to rerun - breaking the "non-test PRs pay nothing" contract.

Add a minimal `workflow_filter_hooks` entry (`should_skip_merge_queue_job`) to
`MergeQueueCI` that filters the flaky check at config time when the PR changes
no stateless tests, so such a PR never schedules the runner. The hook is the
merge-queue counterpart to the `flaky` branch of `should_skip_job`, kept
deliberately minimal so it can never skip the build/style/fast-test jobs the
queue always needs. Its skip condition matches the in-job selection (both use
`Targeting.get_changed_tests`), so the config-time skip and the early exit never
disagree. A filtered job reports `SKIPPED`, which already counts as success for
the merge-ready status.

AI review: #110308

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Addressed the three AI-review majors (each as its own commit, with unit tests):

  • ci/workflows/merge_queue.py — config-time skip. Added a minimal workflow_filter_hooks entry (should_skip_merge_queue_job) to MergeQueueCI that filters the stateless flaky check at config time when the PR changes no stateless tests, so a source-only PR never schedules the runner or restores CH_AMD_BINARY. The hook is the merge-queue counterpart to the flaky branch of should_skip_job, kept deliberately minimal so it cannot skip the build/style/fast-test jobs the queue always needs; its skip condition mirrors the in-job selection (both use Targeting.get_changed_tests), and a filtered job reports SKIPPED (already counts as success for merge-ready). No YAML change: the flaky-check job's generated if already gates on cache_success_base64, which the filter populates.
  • ci/praktika/gh.py — fail closed on a missing linked PR number. A merge-queue run with an unparseable head ref no longer falls back to the 300-entry-capped commits API; a strict call now raises, since a merge-queue entry always corresponds to exactly one PR. The tolerant non-strict path is preserved for master/release callers.
  • ci/jobs/functional_tests.py — bounded run. Floored the flaky-check budget at 60s so a positive --global_time_limit is always passed; run_tests treats 0 as "no cap", which would make the run unbounded once setup consumed the whole budget.

Tests: ci/tests/test_gh.py (fail-close / linked-PR paths) and ci/tests/test_merge_queue_flaky_check.py (config-time skip + budget floor). ruff check clean.


targeter = Targeting(info=_info_cache)
targeter.job_type = Targeting.STATELESS_JOB_TYPE
if not targeter.get_changed_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.

Targeting.get_changed_tests() is narrower than "all changed stateless tests": it only returns paths it can map back to a concrete root-level test name. That means a PR that changes an auxiliary fixture under tests/queries/0_stateless/ can still be treated as "no changed tests" here.

For example, tests/queries/0_stateless/data_parquet/02716_data.parquet is consumed by tests/queries/0_stateless/02716_parquet_invalid_date32.sh, but get_changed_tests() ignores that path entirely, so this hook filters the merge-queue flaky check out. The job then goes green without ever rerunning the modified test surface on the merge-group state, which reintroduces a false-green path for the exact drift this PR is meant to catch.

Please either teach the targeting logic to map helper/data-file changes back to their owning stateless tests, or conservatively keep the merge-queue flaky check enabled whenever a changed path under tests/queries/0_stateless/ cannot be resolved to a concrete test name.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 66dfd5d by mapping auxiliary fixtures back to their owning test(s) in Targeting.get_changed_tests — the shared selector both the config-time skip and the in-job selection use, so they stay in sync.

Fixtures carry the owning test's five-digit prefix by convention, so the prefix narrows the candidates to the NNNNN_* tests at the suite root (a handful of files, never the whole suite). Among those, the ones whose body references the fixture by name are preferred, with a conservative fallback to all prefix siblings when the reference is built dynamically. Only real tests are emitted, so a fixture-only PR reruns the affected surface without ever fabricating a zero-match pattern (which would make clickhouse-test exit 1, the failure mode PR #104097 fixed).

Your exact example now resolves: data_parquet/02716_data.parquet → 02716_parquet_invalid_date32. Covered by new tests in ci/tests/test_find_tests.py (subdirectory fixture, root-level orphan, unmappable fixture, and the end-to-end get_changed_tests path). As a side effect this also fixes a latent gap where four-digit-prefixed root tests (4060_*, 4061_*) were skipped by the old \d{5} regex.

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 is still reproducible for auxiliary stateless files that do not carry a five-digit test prefix.

_tests_owning_data_file returns [] immediately when os.path.basename(fpath) does not match r"(\d{5})" in ci/jobs/scripts/find_tests.py:129-131, so a fixture-only diff like tests/queries/0_stateless/data_mysql_dump/dump1.sql still produces no selected tests. 02286_mysql_dump_input_format.sh consumes that file at tests/queries/0_stateless/02286_mysql_dump_input_format.sh:8-24, but the current tree still makes Targeting.get_changed_tests return [] for a diff containing only data_mysql_dump/dump1.sql, which means should_skip_merge_queue_job keeps skipping the merge-queue drift guard for that PR shape.

The fix still needs a conservative path for unmappable files under tests/queries/0_stateless/ (for example, keep the job enabled and fall back to a broader rerun) instead of treating them as “nothing to rerun”.

The merge-queue flaky check (and the regular flaky check it is built on)
selected tests via `Targeting.get_changed_tests`, which only mapped a changed
path back to a test when the path was itself a test source or a supporting
file with a same-named sibling test. A data fixture consumed by a test — either
a root-level orphan like `02995_settings_26_4_1.tsv` or, worse, one nested in a
subdirectory like `data_parquet/02716_data.parquet` (which the old
`\d{5}`-after-prefix regex did not even consider) — resolved to no test. A PR
that changed only such a fixture was therefore treated as "no changed tests",
so `should_skip_merge_queue_job` skipped the drift guard and the merge group
never reran the affected test surface: a false green for the exact drift this
check exists to catch.

Map auxiliary fixtures back to their owning test(s). Fixtures carry the owning
test's five-digit prefix by convention, so the prefix narrows the candidates to
the `NNNNN_*` tests at the suite root (a handful of files, never the whole
suite); among those, prefer the ones whose body actually references the fixture
by name, and fall back to all prefix siblings only when the reference is
constructed dynamically. Only real tests are emitted, so a run never fabricates
a zero-match pattern (which would make `clickhouse-test` exit 1, the failure
mode `PR #104097` fixed). Because both the config-time skip and the in-job
selection call `get_changed_tests`, they stay in sync automatically.

As a side effect this also fixes a latent gap: root-level tests with a
four-digit prefix (`4060_*`, `4061_*`), which the old `\d{5}` regex skipped, are
now selected.

Tests: `ci/tests/test_find_tests.py` covers the subdirectory fixture, the
root-level orphan, unmappable fixtures, and the end-to-end `get_changed_tests`
path.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Addressed the remaining AI-review Major (fixture-only changes could false-green the drift guard), commit 66dfd5dfc8b, with unit tests.

ci/jobs/scripts/find_tests.py — resolve data fixtures to their owning tests. Targeting.get_changed_tests previously selected a test only when a changed path was itself a test source or a supporting file with a same-named sibling. A data fixture consumed by a test — a root-level orphan (02995_settings_26_4_1.tsv) or, worse, one nested in a subdirectory (data_parquet/02716_data.parquet, which the old \d{5}-after-prefix regex did not even consider) — mapped to no test, so a PR changing only such a fixture looked like "no changed tests" and should_skip_merge_queue_job skipped the merge-group rerun entirely.

Now every changed path under tests/queries/0_stateless/ is routed through resolution: a root-level test/supporting file keeps its existing precise mapping, and anything else is mapped back to the test(s) that own it. Fixtures carry the owning test's five-digit prefix by convention, so the prefix narrows the candidates to the NNNNN_* tests at the suite root (a handful of files, never the whole suite); among those, the tests whose body references the fixture by name are preferred, with a conservative fallback to all prefix siblings when the reference is built dynamically. Only real tests are emitted, so a run never fabricates a zero-match pattern (which would make clickhouse-test exit 1, the failure mode PR #104097 fixed). Because both the config-time skip and the in-job selection call get_changed_tests, they stay in sync automatically.

The reviewer's example now resolves: data_parquet/02716_data.parquet → 02716_parquet_invalid_date32. As a side effect this also closes a latent gap — four-digit-prefixed root tests (4060_*, 4061_*) that the old \d{5} regex skipped are now selected.

Tests: ci/tests/test_find_tests.py adds the subdirectory fixture, the root-level orphan, unmappable fixtures (no prefix / no matching test), and an end-to-end get_changed_tests case. All ci unit tests pass; ruff check clean.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, let's try.

@alexey-milovidov alexey-milovidov self-assigned this Jul 15, 2026
@alexey-milovidov
alexey-milovidov merged commit 67bff81 into master Jul 15, 2026
174 of 175 checks passed
@alexey-milovidov
alexey-milovidov deleted the mq-flaky-check branch July 15, 2026 01:04
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 15, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…umber

In `GH.get_changed_files`, a merge-queue run with an unparseable merge group
head ref left `linked_pr_number` at 0, so the code fell through to
`repos/{repo}/commits/{sha}`, whose file list is capped at 300 entries. On a
large PR that can silently drop changed test files and turn the merge-queue
flaky check into a false green.

A merge-queue entry always corresponds to exactly one PR, so a missing linked
PR number is a real fault, not a skip condition. Fail closed (raise) on a
strict call instead of falling back to the capped commits API; the tolerant
non-strict path is preserved for master/release-style callers.

AI review: ClickHouse#110308

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…xhausts its budget

The flaky-check time budget was computed as
`max(FLAKY_CHECK_TIME_LIMIT - elapsed, 0)`, but `run_tests` interprets
`global_time_limit == 0` as "pass no `--global_time_limit`" - i.e. no cap at
all, and no outer `Shell.run` timeout either. Once setup consumes the whole
budget (more likely under the tighter 20-minute merge-queue limit) the run
becomes unbounded, defeating the latency bound the reduced budget exists to
enforce.

Floor the budget at a small positive value (60s) so a positive
`--global_time_limit` is always passed and the run stays bounded, mirroring the
existing targeted-check floor.

AI review: ClickHouse#110308

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…on-test PRs

The `SKIPPED` exit in `functional_tests.py` happens only after the job has been
scheduled, restored `CH_AMD_BINARY`, and entered the stateless-test container,
so a source-only PR still paid that startup cost even though there were no
stateless tests to rerun - breaking the "non-test PRs pay nothing" contract.

Add a minimal `workflow_filter_hooks` entry (`should_skip_merge_queue_job`) to
`MergeQueueCI` that filters the flaky check at config time when the PR changes
no stateless tests, so such a PR never schedules the runner. The hook is the
merge-queue counterpart to the `flaky` branch of `should_skip_job`, kept
deliberately minimal so it can never skip the build/style/fast-test jobs the
queue always needs. Its skip condition matches the in-job selection (both use
`Targeting.get_changed_tests`), so the config-time skip and the early exit never
disagree. A filtered job reports `SKIPPED`, which already counts as success for
the merge-ready status.

AI review: ClickHouse#110308

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Run a stateless flaky check in the merge queue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants