Skip to content

Keep the huge max_streams_to_max_threads_ratio of test 04842 out of the AST fuzzer - #123125

Merged
PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/bound-read-sources-by-max-threads-ceiling
Oct 1, 2026
Merged

PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/bound-read-sources-by-max-threads-ceiling

Conversation

@groeneai

@groeneai groeneai commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #110936

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

The AST fuzzer runs the test corpus in one session, so SET max_streams_to_max_threads_ratio = 288230376151711744 in 04842_merge_num_streams_marks_overflow stayed in effect for every later query. Under it the server-side fuzzer turned numbers_mt(1048576) into numbers_mt(9223372036854775807), and the server was OOM-killed while building one source per block. Failing master job: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=6b601838b5c7526a500254219a92542f852d5e55&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29

The ratio is now passed in the SETTINGS clause of the four queries that need it; 04842 was the only test that set it for the whole session. Both fuzzers keep a query's SETTINGS in its fuzzed copies, so these queries set ast_fuzzer_runs = 0 for the server-side one, like 02920, 03714 and 04141, and the test is now a shell test, because the client-side one reads only .sql files (measured on the old file: 10 server-side and 48 client-side fuzzed queries with the 2^58 ratio, 8 of the latter joining numbers_mt). The SQL and the reference are unchanged, and the four queries still run with 2^58 (checked in system.query_log).


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

Version info

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

@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 30, 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; 2 rounds, 2 findings then 0) plus my own review (3 nits).

# Sev Finding Verdict Evidence / action
1 ⚠️ The icebergS3 rows could be rewritten to icebergS3Cluster in the ParallelReplicas job DISAGREE FROM (EXPLAIN ...) is lowered to viewExplain(...), so the query has two table functions and the analyzer disables parallel_replicas_for_cluster_engines; 05059 (same shape over url()) passes 4921/4921 in that job
2 ⚠️ No test row reaches the Delta Lake change-feed clamp AGREE, fixed @ 854bac3 control and bound rows over the public hits Delta table; reverting only that clamp flips only that row
3 ⚠️ No test row reaches the urlCluster worker clamp DISAGREE the worker read is not in the initiator's EXPLAIN, and an executing row would run 256 x cores worker sources; verified manually (unfixed debug server aborts with std::length_error in pipes.reserve, fixed returns the result)
4 💡 ReadFromMergeTree and clampClusterFunctionNumStreams still spell 256 * getNumberOfCPUCoresToUse() AGREE, fixed @ 854bac3 both use getMaxThreadsMaxValue
5 💡 The S3 rows make the whole test no-fasttest, no-msan noted, not changed one test file per change; every other stateless job runs all rows

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20260930-181511

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: SELECT DISTINCT 1 FROM numbers_mt(9223372036854775807) SETTINGS max_threads = 4, max_streams_to_max_threads_ratio = 2.8823037615171174e17, max_execution_time = 5 in clickhouse local with a 3G server cap is OOM-killed in a 6 GiB cgroup in ~6 s on every run.
b Root cause explained? The planner requests max_threads * ratio streams; these reads create one source per requested stream while the pipeline is built, with no data bound, no cancellation point and mostly untracked allocations.
c Fix matches root cause? Yes: the request is bounded where it becomes sources, by the ceiling max_threads already has (as ReadFromMergeTree does).
d Test intent preserved / new tests added? New 05296 test: control and bound row per read; removing the clamp at any one site flips exactly that site's rows (every site except the urlCluster worker, whose read is not in the initiator's EXPLAIN; covered by the repro).
e Both directions demonstrated? Yes: unfixed binary is OOM-killed or aborts on every read (a urlCluster worker aborts the server); fixed returns or hits the memory limit gracefully. Test fails on the unfixed server (9 bound rows), passes on the fixed one, randomized runs all OK.
f Fix is general across code paths? All reads with the pattern are fixed: numbers_mt (both paths), zeros_mt, fuzzQuery, FuzzJSON, filesystem, system.detached_parts, object storage with an unknown key count, the urlCluster worker, the Delta Lake change feed.
g Fix generalizes across inputs (params/datatypes/wrappers)? Requests below the ceiling are unchanged (control rows), requests above are clamped (bound rows); no data-type path involved.
h Backward compatible? (maintainer-approved exception only) Yes: no setting or format change; only requests above 256 x cores produce fewer sources, with the same results.
i Invariants and contracts preserved? The bound is applied at construction or before the first use of num_streams, so every later use (clone, stride, LIMIT reduction) sees one value; the post-read resize still uses the unbounded request.

Session id: cron:clickhouse-impl-slot-4:20260930-175800

@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a0c746c]

Summary: ✅


AI Review

Summary

This PR turns 04842_merge_num_streams_marks_overflow into a shell test, keeps the huge max_streams_to_max_threads_ratio inline on the four statements that need it, and adds ast_fuzzer_runs = 0 so the server-side AST fuzzer no longer replays them. I checked the current diff, the prior discussion, and the actual AST-fuzzer corpus selectors: the client-side collectors only index *.sql files, while the remaining in-test statements now opt out of server-side AST fuzzing. That closes the original OOM trigger without changing the test's checked SQL behavior, and I do not see a remaining correctness or test-harness issue in the current version.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. labels Sep 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 7d968fa4a with master 60cba6ce6 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 94e6e7323; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

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

Job report

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai how max_streams_to_max_threads_ratio = 1e12 was generated?

@groeneai

groeneai commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

It was not generated: I picked 1e12 by hand for the released-version repro in the description. It only has to make max_threads * ratio exceed the number of blocks in numbers_mt(1000000000000000) (1e15 / 65409, about 1.5e10), so that every block becomes its own source.

The ratio in the failing master job was 2^58, and no fuzzer invented that one either. The AST fuzzer client replayed SET max_streams_to_max_threads_ratio = 288230376151711744 from 04842_merge_num_streams_marks_overflow.sql:14 (line 4946868 of fuzzer.log). The setting stayed in the session until the end (it is in the final Changed settings dump), and the server-side fuzzer then mutated numbers_mt(1048576) into numbers_mt(9223372036854775807) under it (server.log, query d18bdd09-359f-4928-94f3-716b95bde7d5).

Artifacts: https://s3.amazonaws.com/clickhouse-test-reports/REFs/master/6b601838b5c7526a500254219a92542f852d5e55/masterci/ast_fuzzer_amd_release_oracle/

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai then you should fix the test, please refractor this PR.

The AST fuzzer runs the test corpus in one session, so the session
`SET max_streams_to_max_threads_ratio = 288230376151711744` in 04842 stayed in
effect for every later query. Under it the server-side fuzzer turned
`numbers_mt(1048576)` into `numbers_mt(9223372036854775807)`, and the server was
OOM-killed while building one source per block:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=6b601838b5c7526a500254219a92542f852d5e55&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29

Pass the ratio in the SETTINGS clause of the four queries that need it. 04842
was the only test that set it for the whole session.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai
groeneai force-pushed the groeneai/bound-read-sources-by-max-threads-ceiling branch from 7d968fa to ca94d59 Compare October 1, 2026 10:00
@groeneai groeneai changed the title Bound the number of sources a read creates by the max_threads ceiling Pass the huge max_streams_to_max_threads_ratio of test 04842 per query, not for the session Oct 1, 2026
@groeneai

groeneai commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

Done in ca94d59: the PR is now only the test change. 04842 passes the ratio in the SETTINGS clause of its four queries instead of a session SET (it was the only test that set it for the whole session), so the AST fuzzer no longer keeps it for later queries. The engine clamp and 05296 are dropped; the previous version is 7d968fa.

@groeneai
groeneai removed the request for review from antaljanosbenjamin October 1, 2026 10:01
@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). and removed pr-bugfix Pull request with bugfix, not backported by default comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. labels Oct 1, 2026
The server-side AST fuzzer clones the executed query with its SETTINGS
clause and strips only the row/time/memory/block limits, so every fuzzed
copy of the four 04842 queries still ran with
`max_streams_to_max_threads_ratio = 288230376151711744`. Some of those
copies read `numbers_mt(1048576)` through an added JOIN or ARRAY JOIN,
one literal mutation away from the `numbers_mt(9223372036854775807)` read
that got the server OOM-killed on master.

Disable the server-side fuzzer on these queries with `ast_fuzzer_runs = 0`,
like 02920, 03714 and 04141 do.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The client-side AST fuzzer reads every `*.sql` file of `0_stateless`
(`run-fuzzer.sh`, and the targeted corpus in `ast_fuzzer_job.py`), and
fuzzes each SELECT 1000 times with its inline `SETTINGS` kept. A fuzzed
copy of a 04842 query can join a table function collected from another
corpus query, such as `numbers_mt(...)`, and run it with
`max_streams_to_max_threads_ratio = 2^58`, which is how the master AST
fuzzer OOM started. `FuzzLoop.cpp` has no per-query opt-out, so the
test becomes a shell test, which neither client-side corpus reads. The
SQL is unchanged: the ratio stays per query and `ast_fuzzer_runs = 0`
stays, because the stress test's server-side fuzzer still sees the
queries of shell tests.

Failing master job:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=6b601838b5c7526a500254219a92542f852d5e55&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_release%2C%20oracle%29

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai changed the title Pass the huge max_streams_to_max_threads_ratio of test 04842 per query, not for the session Keep the huge max_streams_to_max_threads_ratio of test 04842 out of the AST fuzzer Oct 1, 2026
@PedroTadim
PedroTadim enabled auto-merge October 1, 2026 18:25
@PedroTadim
PedroTadim added this pull request to the merge queue Oct 1, 2026
Merged via the queue into ClickHouse:master with commit 016a75c Oct 1, 2026
149 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 1, 2026
robinld pushed a commit to robinld/ClickHouse that referenced this pull request Oct 4, 2026
A nested SETTINGS clause is applied to the query node's own context after
`clampToSettingsConstraints` and `doSettingsSanityCheckClamp`, and the
Planner of that node runs on that context. The aggregation block of
`Planner::buildPlanForQueryNode` re-applied `query_node.getSettingsChanges()`
as written on top of a copy of those settings, which undid both: a subquery
with `SETTINGS max_threads = 1000000000, max_threads_min_free_memory_per_thread = 0`
made `AggregatingStep` resize the pipeline to 1e9 ports and OOM-killed the
server (found by the targeted AST fuzzer on ClickHouse#123125), and a `MAX` or
`readonly` constraint on `max_threads` did not bound the aggregation.

The re-application came with ClickHouse#114690 for a Fast test failure of 04836 that a
later test change fixed; the node context already carries the nested
`make_distributed_plan`, so the values are taken from it as they are.
The only thing the raw clause still contributed is the `changed` flag of a
nested `group_by_overflow_mode` whose value equals the inherited one:
`SettingsConstraints::checkOrClamp` drops such a change, and
`getTrivialGroupByLimit` reads the flag to keep a user's explicit `throw`. So
that flag is set when the node's clause names the setting; nothing else on
this path reads a `changed` flag.

Test: the nested `max_threads` still reaches the aggregation, a clause dropped
under `readonly` no longer does (fails without the fix), and an explicit
nested `group_by_overflow_mode = 'throw'` equal to the default still throws
(fails without the flag).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. and removed comp-testing Test content only (no production code). labels Nov 22, 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-mergetree MergeTree* family: parts, merges, primary index, column statistics, background data transformation. groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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