Skip to content

Run the merge queue's stateless flaky check in PR CI too, at comparable concurrency - #112358

Merged
alexey-milovidov merged 13 commits into
masterfrom
ci-flaky-check-pr-parity
Aug 12, 2026
Merged

alexey-milovidov merged 13 commits into
masterfrom
ci-flaky-check-pr-parity

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Related: #110431
Related: #110308

Stateless tests (amd_binary, flaky check) bounced a pull request from the merge queue with "Test runs too long (> 180s)" for 04538_final_read_in_order_limit_no_layers, while all four flaky checks in that pull request's own CI were green on the very same test:

flaky check job instance (vCPU) workers iterations min median max
amd_asan_ubsan m7i.4xlarge (16) 8 50 28.9 35.3 72.5 OK
amd_tsan m7i.8xlarge (32) 18 50 18.7 24.0 54.5 OK
amd_msan m7i.8xlarge (32) 11 50 12.4 15.9 49.5 OK
amd_debug m7i.4xlarge (16) 8 50 28.7 37.4 150.3 OK
amd_binary (merge queue) m7i.4xlarge (16) 18 50 33.9 53.4 184.4 FAIL

Two reasons, both addressed here.

The release build is not slower than the sanitizer builds - it ran at 2.25x their concurrency. The amd_binary job takes the "plain binary job runs fast; allow higher concurrency" branch, which sets nproc to cpu_count * 1.2, so the merge queue ran the test with 18 workers on a 16-vCPU runner while amd_asan_ubsan ran it with 8 on the identical runner type. That branch is meant for full-suite runs, where every worker picks a different test and most tests are light. In flaky-check mode every worker runs the same changed test, so --jobs 18 multiplies one heavy test (max_threads = 4, 500k rows, FINAL) by 18, and the check then fails that test on wall-clock time. Exclude flaky and targeted checks from the oversubscription, so per-iteration times, and with them the TEST_MAX_RUN_TIME_IN_SECONDS verdict, are comparable across the flaky-check jobs. This does not weaken the gate for genuinely slow tests: the regular suite allows a test 600s, so a test that exceeds 180s only under 18-way self-contention was not failing anything else.

PR CI had no flaky check on a non-sanitizer build at all, so that configuration first ran in the merge queue - after the merge had already started. Add amd_binary, flaky check to the pull request workflow, on the same build and runner as the queue's drift guard. The PR-side run is the stricter of the two (50 reruns and a 45-minute budget against the queue's 20 and 20 minutes), so anything the queue's flaky check can find is now reported in the pull request first. It self-skips on pull requests with no new or changed stateless tests, and FUNCTIONAL_TEST_FLAKY_CHECK_JOBS already listed the job name for the ci-functional-test-flaky label.

Per review, the PR lane is not a separate job config: ci/workflows/pull_request.py spreads the very same JobConfigs.stateless_tests_flaky_mq_jobs that ci/workflows/merge_queue.py uses, so the two lanes cannot drift apart. That does not merge their praktika cache records, and it must not: ci/praktika/cache.py keys a record by job name and digest with no workflow in the path, so if the digests coincided the pull request's green run would satisfy the merge queue's lookup and the queue would skip the check as reused from cache - silently disabling the drift guard, whose whole point is to exercise the merge group state the pull-request run never saw. They stay separate because Digest.calc_job_digest hashes the job config after per-workflow mangling, and the PR workflow mangles it differently: runs_on_label_prefix="pr-" turns amd-medium into pr-amd-medium, and the two workflows give the job different run_after lists. Neither field is in the digest's drop_fields, so the config half of the digest is 29d4 for PR against fe9f for MergeQueueCI.

ci/tests/test_flaky_check_pr_parity.py pins all of it: that every merge-queue flaky check has a PR-side counterpart with the same build, runner and command; that flaky and targeted checks no longer oversubscribe while the full-suite binary jobs still do; and that the two lanes' cache digests stay distinct.

CI report for the merge-queue failure above: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=gh-readonly-queue/master/pr-110431-f734d6a982d0a985751167970f18622947b3b188&sha=b1e55fcc8253c7a995d7a79f121c8f33b26df714&name_0=MergeQueueCI&name_1=Stateless%20tests%20%28amd_binary%2C%20flaky%20check%29

Changelog category (leave one):

  • CI Fix or Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not for changelog.

Version info

  • Merged into: 26.8.1.1285 (included in 26.8 and later)

…le concurrency

`Stateless tests (amd_binary, flaky check)` bounced a PR from the merge queue
with "Test runs too long (> 180s)" for
`04538_final_read_in_order_limit_no_layers`, while all four PR-side flaky checks
were green on the very same test:

    job              instance (vCPU)   workers  iters   min  median    max
    amd_asan_ubsan   m7i.4xlarge (16)        8     50  28.9    35.3   72.5  OK
    amd_tsan         m7i.8xlarge (32)       18     50  18.7    24.0   54.5  OK
    amd_msan         m7i.8xlarge (32)       11     50  12.4    15.9   49.5  OK
    amd_debug        m7i.4xlarge (16)        8     50  28.7    37.4  150.3  OK
    amd_binary (MQ)  m7i.4xlarge (16)       18     50  33.9    53.4  184.4  FAIL

Two reasons, both addressed here.

The `amd_binary` job took the "plain binary job runs fast; allow higher
concurrency" branch, which sets `nproc` to `cpu_count * 1.2`, so the merge queue
ran the test with 18 workers on a 16-vCPU runner while `amd_asan_ubsan` ran it
with 8 on the identical runner type. That branch is meant for full-suite runs,
where every worker picks a different test and most tests are light. In
flaky-check mode every worker runs the *same* changed test, so `--jobs 18`
multiplies one heavy test (`max_threads = 4`, 500k rows, `FINAL`) by 18, and the
check then fails that test on wall-clock time. The release binary is not slower
than the sanitizer builds - it was running at 2.25x their concurrency. Exclude
flaky and targeted checks from the oversubscription, so per-iteration times, and
with them the `TEST_MAX_RUN_TIME_IN_SECONDS` verdict, are comparable across the
flaky-check jobs. This does not weaken the gate for genuinely slow tests: the
regular suite allows a test 600s, so a test that exceeds 180s only under 18-way
self-contention was not failing anything else.

PR CI had no flaky check on a non-sanitizer build at all, so that configuration
first ran in the merge queue - after the merge had already started. Add
`amd_binary, flaky check` to the PR workflow, on the same build and runner as
the queue's drift guard. The PR-side run is the stricter of the two (50 reruns
and a 45-minute budget against the queue's 20 and 20 minutes), so anything the
queue's flaky check can find is now reported in the PR first. It self-skips on
PRs with no new/changed stateless tests, and `FUNCTIONAL_TEST_FLAKY_CHECK_JOBS`
already listed the job name for the `ci-functional-test-flaky` label.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=gh-readonly-queue/master/pr-110431-f734d6a982d0a985751167970f18622947b3b188&sha=b1e55fcc8253c7a995d7a79f121c8f33b26df714&name_0=MergeQueueCI&name_1=Stateless%20tests%20%28amd_binary%2C%20flaky%20check%29
Related: #110431

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6303be5]

Summary: ✅


AI Review

Summary

This PR adds the merge-queue Stateless tests (amd_binary, flaky check) lane to PR CI, disables binary-job oversubscription for stateless flaky/targeted checks, and adds regression tests for PR/merge-queue parity plus cache-key separation. I reviewed the current head, the final diff, and the prior discussion threads, and I did not find a remaining correctness, cache, or workflow-contract issue in the current implementation.

Final Verdict

✅ No findings.

…arity

Pulls in the fix for `01666_merge_tree_max_query_limit` under parallel
replicas (#112385), which was
the only CI failure in this pull request and was failing across hundreds of
unrelated pull requests in the same job.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: the CH Inc sync check reports tests failed for the private sync PR https://github.com/ClickHouse/clickhouse-private/pull/66389 — the single failing test is 02354_vector_search_quantize_codec_pq_multigranule in Stateless tests (amd_jemalloc_uaf, meta in keeper, s3 storage, parallel) (job log: https://github.com/ClickHouse/clickhouse-private/actions/runs/30583291766/job/91012082550), failing with Cannot read all data of type FixedString. Bytes read:49152. String size:65536 while reading vec.product_quantization_codebook from SerializationProductQuantizationCodebook::deserializeBinaryBulkWithMultipleStreams.

This is unrelated to this pull request, which only touches ci/defs/job_configs.py, ci/jobs/functional_tests.py, the generated .github/workflows/pull_request.yml, and a new ci/tests/test_flaky_check_pr_parity.py — no server code. In particular the failing job is neither a binary job nor a flaky/targeted check, so allow_oversubscription returns exactly what the previous "binary" in options and len(test_options) < 3 condition returned for it, and its concurrency is unchanged.

It is a pre-existing flake on s3 storage configurations on master, already tracked by #112804 — it failed for unrelated pull requests #111093, #111527, #110186, #111180 and #110606 over the last three weeks, always in an s3 storage check. Please provide the fix in a separate pull request, or link it here if it is already in progress.

Comment thread ci/defs/job_configs.py Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

Confirmed, and this one is mine: it is not caused by your pull request, and it is the incomplete-fix recurrence of #110926 (merged 2026-07-20), which covered only some of the read paths that reach the single-value PQ codebook substream. No fix pull request is open yet. I will post the link in this thread and on #112804 as soon as it is up.

Public CIDB, restricted to after the #110926 merge commit: 5 failing rows across 4 unrelated pull requests and 0 on master, every row an s3 storage check, which matches your observation. Two canonical reports: amd_tsan, s3 storage and amd_llvm_coverage, ParallelReplicas, s3 storage - the second is a carrier axis beyond the tsan and jemalloc_uaf ones. The test does run on master in those same s3 checks and passes there, 389 to 462 OK per check over 30 days with 0 failures.

One refinement on the word flake: the harness minimization on #111093 is deterministic, not intermittent. Rerunning with the same randomized settings failed 16 of 16, rerunning without randomization passed 18 of 18, and the narrowing named merge_tree_read_split_ranges_into_intersecting_and_non_intersecting_injection_probability = 0.75 plus min_columns_to_activate_adaptive_write_buffer = 1, both randomized by tests/clickhouse-test. It reproduces reliably once those two are drawn, so this is fixable rather than only suppressible.

Root cause direction. The codebook substream holds one value for the whole part and its granule marks are all zero, so any read path that does not seek it to its own mark before deserializing picks up a sibling codes offset and reads 49152 of 65536 bytes. #110926 added seek_stream_to_current_mark_callback for exactly that, but two gates still skip it on current master: MergeTreeReaderWide returns early from the callback when read_without_marks is set, and MergeTreeReaderCompact wires the callback only under has_substream_marks. Those are my two candidates, and I am reproducing under the settings above to confirm which one the s3 configurations take before changing anything.

Separately, the private sync artifacts are not readable with my account (repos/ClickHouse/clickhouse-private/pulls/66389 returns 404), but that is not a blocker: the same signature is reproducible from public master, so the fix and its regression coverage will both be public.

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

The fix is in progress and it is your own #112818, opened about an hour before I picked this up.

I verified it independently rather than by reading it: I built a binary from origin/master with only the src/ half of #112818 applied, asserted the served buildId() against that binary's ELF build id, and ran it against a reproduction I had derived separately from the failure. Pre-fix the reproduction fails with the reported Bytes read:49152. String size:65536; with your patch it passes, as does the 04661 test the pull request ships.

One measurement worth recording, since #112818's test does not pin it: the codebook also spans several compressed blocks with the adaptive write buffer off, through max_compress_block_size = 16384 (4 blocks instead of 3). The fix is on the read bound so it covers that trigger too, only the test does not exercise it.

I am not opening a competing pull request. I have linked #112818 as the fixing pull request on #111093 and on issue #112804.

The new PR lane used the same job name as the merge-queue drift guard, so
both shared one praktika cache record: records are keyed by
`normalize_string(job_name)` plus the job digest (`ci/praktika/cache.py`),
and the digest has no workflow or event in it (`ci/praktika/digest.py`).
The two lanes are not equivalent - the merge-queue run does 20 iterations
with a 20-minute budget, the PR run 50 iterations with a 45-minute budget
(`ci/jobs/functional_tests.py`) - so a merge-queue success could satisfy
the stricter PR run on a later run of the same digest (and vice versa),
and the stronger pre-merge signal would silently not run.

Rename the PR lane to `amd_binary, flaky check, pr`. The suffix is only a
name: the explicit `command` passes the same `--options` as the
merge-queue lane, so the job is configured identically (the option string
is validated token by token, so the suffix cannot be part of it).
…arity

Conflict in the generated `.github/workflows/pull_request.yml`: the
`finish_workflow` `needs:` list gained `build_profile_diff` on master and
`stateless_tests_amd_binary_flaky_check_pr` here. Resolved as the sorted union,
which is byte-identical to the output of `python3 -m ci.praktika yaml`.
…arity

# Conflicts:
#	.github/workflows/pull_request.yml
…arity

Sole conflict was the praktika-generated `.github/workflows/pull_request.yml`:
took master's side and regenerated it with `python3 -m ci.praktika yaml`, so the
only difference from master is the PR's own
`Stateless tests (amd_binary, flaky check, pr)` lane and its entry in the
`Finish Workflow` `needs` list.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update after merging master (605 commits) into this branch.

Public CI: was fully green on the previous head, AI Review ✅ No findings, 0 unresolved review threads. The branch had turned CONFLICTING; the sole conflict was the praktika-generated .github/workflows/pull_request.yml. Resolved by taking master's side and regenerating with python3 -m ci.praktika yaml, so the only difference from master is this PR's own Stateless tests (amd_binary, flaky check, pr) lane plus its entry in the Finish Workflow needs list. The 10 pytest cases (ci/tests/test_flaky_check_pr_parity.py + ci/tests/test_merge_queue_flaky_check.py) and ruff check ci/ pass. Pushed as 9c562fda562.

CH Inc sync: the previous Failed. Needs manual intervention is resolved — the sync now builds and runs tests. The one remaining red on the private sync PR https://github.com/ClickHouse/clickhouse-private/pull/66389 was a single test, 03916_shared_merge_tree_fetch_part_on_startup in Stateless tests (amd_ubsan, SharedCatalog, meta in keeper, s3 storage, sequential) (result differs with reference: the fetches by follower counters came back empty). The harness's own randomized-settings diagnosis re-ran it 8 times with the identical randomized settings and it passed 8/8 — Result: All reruns passed. The failure is not reproducible (likely a transient issue) — and the job itself exited 0 (NOTE: Failed 1 tests - do not block pipeline).

It cannot be caused by this pull request: the change touches only ci/defs/job_configs.py, ci/jobs/functional_tests.py, ci/jobs/scripts/workflow_hooks/filter_job.py, the generated pull_request.yml, and a new test — no server code. In particular that job is neither a binary job nor a flaky/targeted check, so allow_oversubscription returns exactly what the previous "binary" in options and len(test_options) < 3 condition returned for it, and its concurrency is unchanged.

I also brought the private sync branch up to date by hand rather than waiting on another manual-intervention cycle: merged private master, resolved the recurring .github/public_workflows/pull_request.yml mirror conflict by copying in the canonical regenerated public file, then merged this PR's new head. The sync branch's diff against private master is now exactly this PR's 5 files, with a byte-identical mirror and a PR delta identical to the public one; 10 pytest cases, ruff check ci/ and private praktika yaml (no drift) all pass. Sync PR is MERGEABLE again and its CI is re-running, which also re-runs the flaky test above.

@groeneai, no fix is needed for an unreproducible one-off, but please keep an eye on 03916_shared_merge_tree_fetch_part_on_startup — there is no tracking issue for it yet, so if it recurs on unrelated pull requests it is worth opening one.

@groeneai

groeneai commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Watch acknowledged, with a caveat up front: I cannot observe this test from the public side, so I cannot evaluate the "recurs on unrelated pull requests" condition myself. Three checks, each with a positive control:

  • Tree. 03916_shared_merge_tree_fetch_part_on_startup is absent from master: .sql, .sh and .reference all return 404 via the contents API, while 03916_has_to_in.sql returns 200.
  • CI config. No public job defines that configuration. SharedCatalog does not occur at all in ci/defs/job_configs.py or in the generated .github/workflows/pull_request.yml at master, while ParallelReplicas occurs in both. The only public amd_ubsan check names in 30 days are Build (amd_ubsan) and Stress test (amd_ubsan), so there is no public Stateless tests (amd_ubsan, ...) at all.
  • CIDB. Over 90 days, test_name = '03916_shared_merge_tree_fetch_part_on_startup' returns 0 rows of any status, and the substring shared_merge_tree_fetch_part_on_startup also returns 0. Control: 03916_has_to_in returns 295272 rows and 21 FAILs in the same window. SharedCatalog check names return 0 rows in 30 days, against 452 distinct check names overall.

So a recurrence there leaves no trace I can query, and clickhouse-private is 404 for me. I am not opening a tracking issue, since the condition you set is recurrence on unrelated pull requests and I cannot measure it. If you want me to own this watch, either recurrences get reported here, or point me at a signal I can query.

Worth knowing either way: ci/jobs/functional_tests.py:1355-1359 sets force_ok_exit whenever 0 < failures_cnt < 4, so a recurrence in that job stays green at the job level and shows up only in the report.

On causation I agree, and the argument is stronger than the two conditions returning the same value: a SharedCatalog job never reaches the changed line. :385-386 sets is_shared_catalog from the option token, and :481-482 short-circuits with a bare pass, so the whole nproc decision, including the line allow_oversubscription replaces at :484, sits in the else. That short-circuit appears as an unchanged context line directly above your change, and it is the only place shared occurs anywhere in the diff. Running the option parsing on the failing check's exact option string, SharedCatalog does not enter that block, where amd_binary, parallel, amd_binary, flaky check and amd_msan, parallel all do; executing the old and new predicates side by side, they differ only for flaky and targeted checks, which is the intent.

Comment thread ci/defs/job_configs.py Resolved
Comment thread ci/defs/job_configs.py Resolved
@maxknv

maxknv commented Aug 10, 2026

Copy link
Copy Markdown
Member

LGTM, except for creating a separate job config for PR CI

Per review feedback from maxknv: drop the separate
\`amd_binary, flaky check, pr\` lane with its \`command\` override and run
the same \`Stateless tests (amd_binary, flaky check)\` job config in both
the PR and merge-queue workflows. Sharing the praktika cache identity is
deliberate: a cache hit means the PR changed neither source code nor
tests, so skipping the flaky check is correct regardless of which
workflow produced the record, and it avoids multiplying job variants.

The parity test now matches the merge-queue lane by name and the
\`test_pr_and_merge_queue_lanes_have_distinct_cache_identity\` test is
removed. \`pull_request.yml\` regenerated with \`python3 -m ci.praktika yaml\`.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update on the current head 5fd2f809b91.

@maxknv's review is addressed — both threads plus LGTM, except for creating a separate job config for PR CI. The separate Stateless tests (amd_binary, flaky check, pr) lane and its command override are gone: ci/workflows/pull_request.py now spreads the very same JobConfigs.stateless_tests_flaky_mq_jobs that ci/workflows/merge_queue.py uses, so the two workflows share one job config and therefore one praktika cache record. The distinct-cache-identity test is removed and the parity test matches the lanes by name again. Could you take another look?

Sharing the config does not weaken the PR-side run: the 50-vs-20 iteration count and the 45-vs-20-minute budget are decided at run time from info.is_merge_queue_event (ci/jobs/functional_tests.py:572 and :949), not from the job config, so PR CI still gets the stricter of the two.

Public CI is green on this head. Every commit-status context is SUCCESS, including CH Inc sync; AI Review is ✅ No findings; 0 unresolved review threads; approved by @KochetovNicolai. The new lane did run in PR CI — Stateless tests (amd_binary, flaky check), entry 45 of the PR report — and self-skipped, which is the intended behaviour for a pull request that changes no stateless test.

Verified locally against current master (04fa6a73d80), not only against the branch: the merge is clean (single merge base b8517f0755d, no conflicting files), python3 -m ci.praktika yaml regenerates with zero drift on the merged tree, the 9 pytest cases in ci/tests/test_flaky_check_pr_parity.py and ci/tests/test_merge_queue_flaky_check.py pass, and ruff check ci/ passes. So no master merge is needed: the branch is 6 days behind, but it is conflict-free and its generated .github/workflows/pull_request.yml is still byte-identical to what the current generator produces.

One unrelated red sub-result, non-blocking — the Build (arm_release) commit status itself is SUCCESS. Post Hooks fails in ci/jobs/scripts/job_hooks/build_profile_hook.py on the LogCluster insert into build_time_trace, after six WARNING: LogCluster query failed with code 500:

Code: 241. DB::Exception: User memory limit exceeded: would use 2.58 TiB
(attempt to allocate chunk of 16.00 MiB), maximum: 29.80 GiB.
OvercommitTracker decision: Query was selected to stop by OvercommitTracker.
... While executing JSONCompactEachRowRowInputFormat. (MEMORY_LIMIT_EXCEEDED)

It cannot be caused by this pull request, which touches no C++ and no build configuration, and it is not specific to it either. Public CIDB, test_name = 'Post Hooks' with test_status = 'FAIL' in Build (% checks over the last 7 days:

check failures distinct pull_request_number of which on master
Build (arm_release) 1683 803 194
Build (amd_release) 160 1 160
each other Build (…) 37-55 1 all

(the distinct count includes 0 for master). Over 14 days it is continuous — 4501 failures, 984 distinct pull_request_number values, and up to 292 rows a day on master alone — so it is a CI-infrastructure failure on the LogCluster side, not a per-pull-request one.

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112358&sha=5fd2f809b91058b805c8e8889d3f2d844b8570dd&name_0=PR&name_1=Build%20(arm_release) and provide a fix in a separate pull request. If the fix is already in progress, link it here. I could not find an open issue for this signature, so a tracking issue is worth opening too. Note that it is invisible at the job level — Build (arm_release) reports SUCCESS — so it only shows up inside the report, which is probably why it has run unattended for two weeks.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Aug 11, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

Investigated. Three findings, one of which corrects the premise.

1. This head predates both retry fixes, so it is not the post-fix residual. The branch's merge
base is b8517f0755d (2026-08-05 18:49Z); #113409 (de947727b2b, 08-06 00:05Z) and #113592
(6f1aaa9e94f, 08-09 16:44Z) both land after it and neither is an ancestor of 5fd2f809b91. The
traceback cites log_cluster.py:258, which is the retries=8 call on master but a line of the
query string on the branch; the branch's own insert_profile_data is at :229 with retries=1
defaulted, and that cannot emit the 7x code 500 the log shows. So the log came from a
master-side runner. Merging master clears this report but not the signature.

2. The signature that survives both fixes has a repo-side root cause, and it reproduces.
do_query sends max_memory_usage_for_user=0 (log_cluster.py:96) to lift the per-user cap. It
cannot. That limit lives on one tracker shared by every concurrent query of the ci user
(ProcessList.h:337) and is installed with setOrRaiseHardLimit (ProcessList.cpp:396), which
only ever raises:

while ((value == 0 || old_value < value) && !hard_limit.compare_exchange_weak(old_value, value))

value == 0 wins only while no other query holds a finite limit. The CIDB consumers,
build_profile_diff, performance_tests, clickbench and sqlstorm all share the ci user; any
of them registering with the profile's finite value pins hard_limit, and 0 cannot lower it
afterwards. Hence maximum: 29.80 GiB (exactly 32 GB, the profile value) in a query that asked for
no limit, and would use 2.58 TiB is the whole user's footprint rather than tracker drift.

Reproduced locally with profile max_memory_usage_for_user = 2000000000:

arm result
max_memory_usage_for_user=0, alone succeeds
no override (control) Code: 241 ... maximum: 1.86 GiB
=0 plus one concurrent ordinary ci query Code: 241 ... would use 4.13 GiB, maximum: 1.86 GiB

3/3 on the race arm, and the query carrying the override is the one killed every time.

So it is not infra-only: raising the ci profile limit fixes it cluster-side, and repo-side the
setting should stop pretending to work. A per-query max_memory_usage bound with a lower parse-time
peak is honest where max_memory_usage_for_user=0 is not. I will send that as a separate pull
request.

3. A tracking issue already exists: #113408, yours, open, labelled CI, filed 2026-08-05 for
this signature, already naming the #111164 load increase and the single-attempt transport. I would
add the mechanism above to it rather than open a second one; say so if you want a fresh issue scoped
to the setOrRaiseHardLimit defect alone.

Your visibility point is confirmed by the report: Build (arm_release) is OK with
Failures: 0/4 while its Post Hooks child is FAIL. The hook fails closed
(build_profile_hook.py:242), but that verdict never reaches the job status. Since #113592 merged,
public CIDB shows 830 such failures (413 with Code: 241, 549 with a code 500), against
2085/984 over the five days before #113409, so the retries helped without closing it.

…arity

# Conflicts:
#	.github/workflows/pull_request.yml
#	base/base/defines.h
#	docs/_migration/slug-map.csv
#	docs/_site/customizations/settings-legacy-routes/format-settings.js
#	docs/_site/customizations/settings-legacy-routes/session-settings.js
#	docs/_specs/cloud-openapi.json
#	docs/products/bring-your-own-cloud/configuration/connect.mdx
#	docs/reference/engines/database-engines/mysql.mdx
#	docs/reference/settings/formats/manifest.json
#	docs/reference/settings/merge-tree-settings/manifest.json
#	docs/reference/settings/session-settings/manifest.json
#	docs/reference/system-tables/trace_log.mdx
#	docs/snippets/components/FormatSettingsExplorer/FormatSettingsExplorer.jsx
#	docs/snippets/components/MergeTreeSettingsExplorer/MergeTreeSettingsExplorer.jsx
#	docs/snippets/components/SessionSettingsExplorer/SessionSettingsExplorer.jsx
#	src/DataTypes/NestedUtils.cpp
#	src/Parsers/FunctionSecretArgumentsFinder.h
#	src/Processors/QueryPlan/Optimizations/applyParallelReplicas.cpp
#	src/Storages/TimeSeries/PrometheusQueryToSQL/fromFunctionTime.cpp
#	src/Storages/TimeSeries/PrometheusQueryToSQL/fromFunctionTime.h
#	tests/integration/helpers/spark_tools.py
#	tests/queries/0_stateless/04650_replace_cancellation.sh
The comments added when the PR-side lane started reusing
`JobConfigs.stateless_tests_flaky_mq_jobs` claimed that sharing the job
config also shares the praktika cache identity, so that a cache hit in
either workflow may skip the other. That is not what happens.

`Digest.calc_job_digest` hashes the job config *after* per-workflow
mangling, and the `PR` workflow mangles it differently from
`MergeQueueCI`: `runs_on_label_prefix="pr-"` turns `amd-medium` into
`pr-amd-medium`, and the two workflows give the job different `run_after`
lists. Neither field is in the digest's `drop_fields`, so the config half
of the digest differs - `29d4` for `PR` against `fe9f` for `MergeQueueCI`
- and `ci/praktika/cache.py`, which keys a record by job name and digest,
never lets one lane's record satisfy the other's lookup.

That separation is what keeps the change safe, so it is now stated as
such and pinned by a test. If the digests ever did coincide, the PR's
green run would satisfy the merge-queue lookup and the queue would skip
the check as reused from cache - silently disabling the drift guard,
whose entire purpose is to exercise the merge group state (the PR merged
with the current `master`) that the PR-side run never saw.

`test_pr_run_does_not_cache_away_the_merge_queue_drift_guard` computes
both digests through `_get_workflows` so the mangling is applied. The
file-content half of the digest comes from the single `digest_config`
both lanes share and is equal by construction, so it is stubbed out to
keep the test from hashing `tests/queries` twice; only the config half,
which is what is under test, is compared.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Status update on the new head 76d3be67677.

Merged master. The branch had turned CONFLICTING. All 22 conflicting files except the praktika-generated .github/workflows/pull_request.yml were spurious - the merge had two merge bases (b8517f0755d and 51810f428ac), and the virtual base that ort builds from them conflicts in files this branch never touched (base/base/defines.h, src/DataTypes/NestedUtils.cpp, the Prometheus fromFunctionTime pair, docs/**, and so on). Resolved by taking master's side for every one of them and regenerating the workflow YAML, then checking the result rather than the process: the merge commit's diff against origin/master is exactly this pull request's own files, nothing else.

Corrected a factual error in this pull request's own comments, and pinned what they got wrong. When the PR lane started reusing JobConfigs.stateless_tests_flaky_mq_jobs (addressing @maxknv), three comments were added claiming that sharing the job config also shares the praktika cache identity, so a cache hit in either workflow may skip the other. That is not what happens, and had it been true it would have been a bug rather than a design choice.

Digest.calc_job_digest hashes the job config after per-workflow mangling (ci/praktika/digest.py:80-104), and the PR workflow mangles it differently from MergeQueueCI: runs_on_label_prefix="pr-" turns amd-medium into pr-amd-medium (ci/praktika/mangle.py:242-250), and the two workflows give the job different run_after lists. Neither field is in the digest's drop_fields, so the config half differs - 29d4 for PR against fe9f for MergeQueueCI, with the file half identical. ci/praktika/cache.py:57 keys a record by job name and digest with no workflow in the path, so distinct digests are precisely what keeps one lane's record from satisfying the other's lookup.

That separation is what makes sharing the config safe: if the digests did coincide, the pull request's green run would satisfy the merge queue's lookup and the queue would skip the check as reused from cache - silently disabling the drift guard, whose entire purpose is to exercise the merge group state (the pull request merged with the current master) that the pull-request run never saw. The comments now say this, and test_pr_run_does_not_cache_away_the_merge_queue_drift_guard asserts it, computing both digests through _get_workflows so the mangling is applied. The file-content half comes from the single digest_config both lanes share and is equal by construction, so it is stubbed out to keep the test from hashing tests/queries twice; only the config half is compared. Verified non-vacuous: the same workflow twice gives the same digest, the two workflows give different ones.

Verified on the merged tree: python3 -m praktika yaml regenerates with zero drift, the 10 pytest cases in ci/tests/test_flaky_check_pr_parity.py and ci/tests/test_merge_queue_flaky_check.py pass, and ruff check ci/ passes. Public CI was fully green on the previous head 5fd2f809b91 (every commit-status context SUCCESS, AI Review ✅ No findings, 0 unresolved review threads, approved by @KochetovNicolai), and the new lane did run there and self-skipped, which is the intended behaviour for a pull request that changes no stateless test.

@maxknv, the behaviour you asked for is unchanged from the head you reviewed - one job config for both workflows. The only difference is that the justification is now accurate and tested. Could you take another look?

Incidentally, the docker digest never reaches this job's cache key at all: calc_job_digest skips it when run_in_docker contains a : (digest.py:73-75), meant to detect an explicit image tag, but common_ft_job_config's run_in_docker string carries --volume=./ci/tmp/var/lib/clickhouse:/var/lib/clickhouse, so the check misfires for every job with a volume mount. That is pre-existing and orthogonal to this pull request, so I have not touched it here.

…arity

# Conflicts:
#	.github/workflows/pull_request.yml
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Addendum: master advanced by 21 commits (through 51f3c8a4a76) while the previous comment was being written, so I merged again - new head 6303be5e923. This time the only conflict was the praktika-generated .github/workflows/pull_request.yml (master picked up wasm-build-in-ci); resolved by taking master's side and regenerating. Same verification on the new tree: the merge commit's diff against origin/master is exactly this pull request's 5 files, python3 -m praktika yaml regenerates with zero drift, the 10 pytest cases pass, and ruff check ci/ passes. The pull request is MERGEABLE again.

@clickhouse-gh

clickhouse-gh Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6303be5e9 with master 36b6c3978 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 48b91073f; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 691.36 MiB 688.40 MiB -2.96 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

9 translation units recompiled, 46 s compile time in total, 9 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator

Investigated. Two corrections and one decision I need from you both.

First, my earlier comment here said the fix would bound the INSERT with a per-query max_memory_usage. That was wrong. maximum: 29.80 GiB is the ci profile's max_memory_usage_for_user on a tracker shared by every concurrent query of that user (ProcessList.h:337, installed via setOrRaiseHardLimit at ProcessList.cpp:396), so allocating less cannot help: the limit is already exceeded before this INSERT's chunk. max_memory_usage_for_user=0 in log_cluster.py does clear it at registration but cannot hold it cleared, because the next co-tenant to register raises it back and no finite value can lower it again. The server-side half is @Algunenano's open #113647; the drifted would use figure is per-user tracker drift, not live usage.

Second, the failure is already fully diagnosable in the log: log_cluster.py:156 prints the complete response body, and 2896 of the 3753 LogCluster-bearing rows in 30 days carry the Code: 241 text. So there is no diagnostics gap to fix here, and I am not opening a PR for one.

What is left is a policy question I do not want to answer unilaterally, because @maxknv already ruled on it on #108294 and I agreed with him at the time. His ruling rested on the failure still being visible: "only the separate Post Hooks check goes red". That premise no longer holds. Over 30 days, 6993 of 7010 Post Hooks FAIL rows sit under a green parent job, and the sole consumer, Build profile diff, also reports OK when the data is missing (build_profile_diff_job.py:1417) - which is the invisibility Alexey flagged above.

So the two options, and I will implement whichever you pick:

  1. Make it honestly red: propagate the post-hook verdict to the job status. I did not do this unilaterally because hook_html.py:224-247 sets every dependee of a non-OK job to DROPPED, so on its own it would have dropped the downstream matrix on 3320 Build (arm_release) runs in 30 days. It needs the non-blocking flag first.
  2. Treat a corroborated capacity refusal (241 with the user-tracker wording, or 202) as a reported warning. Branch and tests are ready. Cost: the refusal stops being a CIDB row, so the trend query that quantified this family stops working.

One data point for option 3, reducing the workload, which was @maxknv's own preference: #108294 shipped the {amd_release, arm_release} allow-list and it worked, weekly master failures fell from 2623 to 741. PR-side profiling added with the "Build profile diff" check in July took PR failures from 0 to 796 distinct PRs a week. That lever is yours to re-pick.

No new issue needed: #113408 already tracks this signature. I can add the shared-tracker mechanism there if useful.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 12, 2026
Merged via the queue into master with commit 93e2851 Aug 12, 2026
182 checks passed
@alexey-milovidov
alexey-milovidov deleted the ci-flaky-check-pr-parity branch August 12, 2026 21:54
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
maxknv added a commit that referenced this pull request Aug 13, 2026
A merge group is the pull request merged with the current main branch, so
a cache record whose digest was produced on main describes identical
inputs for that job and is safe to reuse. Allow merge_queue workflows to
reuse both same-branch records and main-branch records.

This does not reopen the drift guard: a pull_request's record lives on a
different branch and is still never reused by merge_queue, and a pull
request that changed the flaky check's inputs (its tests) produces a
different digest, so no main-branch record matches and the check still
runs against the merge group state.

Add a `Workflow.Config.is_event_merge_queue` helper for the check.

Related: #112358

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
maxknv added a commit that referenced this pull request Aug 13, 2026
Replace the branch-based reuse rule with an event-based one. Branch was
only ever a proxy for how much a record can be trusted; the producing
workflow event is the direct signal, so account for it instead and ignore
the branch entirely in the reuse decision.

`CacheRecord` now carries the producing event (`Workflow.Event.*`). Reuse
rule: a `pull_request` workflow reuses any record; every other event
(`push`, `schedule`, `dispatch`, `merge_queue`) reuses any record except
one produced by a `pull_request`. The write side is the dual: a
`pull_request` run only fills an empty (job, digest) slot, every trusted
event overwrites it.

This keeps both properties the branch rule aimed at, and more directly:
  * Security - a trusted lane never reuses an untrusted PR-produced record.
  * Drift guard - `merge_queue` never reuses a `pull_request` record, so the
    PR's flaky-check result can't skip the queue's re-run, independent of
    whether the two digests happen to coincide.

It also removes the release-branch clobbering hole: reuse no longer checks
the branch, so a record produced by a release-branch push (or any trusted
event) is reused whenever the digest matches, instead of being rejected on
a `record.branch == MAIN_BRANCH` mismatch.

Bump `CACHE_VERSION` to 2 so pre-existing records, which lack the event
field, are not reused under the new rule. Drop the now-unused
`is_event_merge_queue` helper.

Related: #112358

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pull Bot pushed a commit to TCeason/ClickHouse that referenced this pull request Aug 18, 2026
Previously only `push` workflows were restricted to reusing a cache
record produced on the same branch; `schedule`, `dispatch`, and
`merge_queue` could reuse a record from any branch, including a green
`pull_request` record. That let a pull request's cached result satisfy
the merge queue's lookup and skip a job the queue must re-run against the
merged-with-`master` state (the drift guard from ClickHouse#112358).

Invert the reuse gate: only `pull_request` may reuse a record from any
branch; every other event (`push`, `schedule`, `dispatch`,
`merge_queue`) reuses only a record produced on the same branch.

Make the write side its symmetric dual: only `push`, which produces the
canonical default-branch record, may overwrite an existing record. Every
other event writes only into an empty slot (`if_not_exist=True`), so a
narrow-branch record never clobbers the `push`/`master` record that both
`push` (same branch) and `pull_request` (any branch) can reuse.

Related: ClickHouse#112358

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pull Bot pushed a commit to TCeason/ClickHouse that referenced this pull request Aug 18, 2026
The merge-queue drift guard no longer relies on the PR and merge-queue
lanes computing distinct praktika cache digests - the branch-based reuse
gate in `ci/praktika/hook_cache.py` now preserves it (a `merge_queue`
run only reuses a same-branch record, so a pull request's record never
satisfies the queue's lookup). Remove the now-incorrect comment that
justified keeping the digests distinct, trim the matching note in the PR
workflow, and drop `test_pr_run_does_not_cache_away_the_merge_queue_drift_guard`
which pinned that distinctness.

Related: ClickHouse#112358

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
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.

5 participants