Skip to content

Pin ast_fuzzer_runs = 0 in 04870_distinct_merge_over_distributed - #115839

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:pin-ast-fuzzer-runs-04870
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:pin-ast-fuzzer-runs-04870

Conversation

@groeneai

@groeneai groeneai commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Description

Related: #115455
Related: #113242
Related: #114677

Stress test (*) jobs abort with Logical error: 'Equal values are not contiguous within the range assumed to be sorted' at DistinctSortedStreamTransform.cpp:184: 87 times across 78
unrelated pull requests since 04870 was merged on 2026-08-17, against 5 in the 20 days before,
and it is still firing today.

The engine defect is old and is not what I change here. The stress profile sets
ast_fuzzer_runs = 5 and ast_fuzzer_any_query = true
(tests/docker_scripts/stress_tests.lib), so the server-side AST fuzzer re-runs mutated copies of
every statement of every stateless test, CREATE included. In 04870 it retypes the fixture's
Merge parent and substitutes the clone into a SELECT, and a Merge parent whose column type
differs from its child's is the precondition for the assertion. My test is the amplifier, and this
PR removes only that. The defect itself is #113242, still open.

The change is one statement, SET ast_fuzzer_runs = 0;, pinning the setting to its own declared
default. It weakens nothing: all seven arms still run and still assert, and the .reference file
is unchanged. Nine stateless tests already pin it, several for this same reason. It is file-level
rather than per-query because the chain needs both a fuzzed CREATE, to mint the clone, and a
fuzzed SELECT, to substitute it in. -- Tags: no-stress is not an option, clickhouse-test
rejects it.

Validation, one debug binary differing only in the test file: with the fuzzer armed the unpinned
test fails 6 of 30 runs and the pinned test passes 30 of 30. I also reproduced the abort on a
hand-built mistyped fixture, with a stack matching CI. 50 randomized runs, and 50 with the fuzzer
armed, pass.


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

…stributed

The stress profile sets ast_fuzzer_runs = 5 and ast_fuzzer_any_query = true
(tests/docker_scripts/stress_tests.lib), so the server-side AST fuzzer re-runs
mutated copies of every statement of every stateless test, CREATE included. In
this test it retypes the Merge parent's column and substitutes the retyped clone
into a SELECT. A Merge parent whose column type differs from its child's is the
precondition for the sort-order defect behind
'Equal values are not contiguous within the range assumed to be sorted' at
DistinctSortedStreamTransform.cpp, so every stress run manufactures it.

That is 24 stress aborts across 22 unrelated pull requests in the last 24 hours,
and 87 since this test was merged on 2026-08-17, against 5 in the 20 days
before. The engine defect itself is old and is not addressed here; ClickHouse#113242 owns
it. This change removes the amplification only.

Pinning ast_fuzzer_runs to its own declared default weakens no assertion: all
seven arms still run and still assert, and the reference file is unchanged. The
pin is file-level rather than per-query because the chain needs both a fuzzed
CREATE, to mint the mistyped clone, and a fuzzed SELECT, to substitute it in, so
pinning only the SELECTs would cut one link of two. Nine stateless tests already
pin this setting, two of them for this same reason. The no-stress tag is not an
option, clickhouse-test rejects it.

Validated on one debug binary differing only in the test file: with the fuzzer
armed the unpinned test fails 6 of 30 runs and the pinned test passes 30 of 30,
with fuzzed queries for this test dropping from 4650 to 150. The abort was also
reproduced locally on a hand-built mistyped fixture with a stack matching CI.
50 randomized runs, and 50 more with the fuzzer armed, pass.

Co-Authored-By: Claude Fable 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Aug 21, 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; 1 finding; bounded: 1 full pass).
I also ran my own cold review of the resulting diff before reading the implementation notes, which
raised 2 further nits, both self-refuted below. No blocker and no major in either pass.

# Sev Finding Verdict Evidence / action
1 💡 The added comment implies every parent/child type mismatch breaks sort order (04870_distinct_merge_over_distributed.sql:15-16) AGREE, not fixed Right, and worth stating precisely: an order-preserving widening such as Int32 to Int64 keeps the child's rows in the parent's declared order. The precondition is an order-breaking conversion, which is what #113242 is named for. The case the fuzzer manufactures here, an Int128 parent over a String child, is order-breaking, so the comment is imprecise rather than wrong and the pin it justifies is unaffected. Left as is to keep the diff at one statement; noted here instead.
2 💡 The 5-line comment outnumbers the 1 added code line DISAGREE Test files are exempt from the comment-length budget, and the in-tree precedent for this exact pin is a 5-line block in 02920_rename_column_of_skip_indices.sql and a 5-line block in 03714_base32_base58_short_string.sql. The comment states the mechanism a future reader needs in order not to delete the pin.
3 💡 "Nine stateless tests already pin it, several for this same reason" understates the count sharing the stress-fuzzer rationale DROPPED Re-counted: 9 files pin the setting and 4 of them (02920, 03714, 04653, 04654) carry a stress-fuzzer rationale. The body's wording is already non-committal, so nothing to correct.

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

Independently re-derived during review, rather than taken from the implementation notes: the
num_runs == 0 short-circuit at src/Interpreters/executeQuery.cpp:3387 fires before
ast_fuzzer_any_query is read, so that setting needs no separate pin; ast_fuzzer_runs is
Session scope and a .sql test runs as one clickhouse-client --multiquery session, so the
file-level SET covers the CREATEs that a per-query SETTINGS could not; each fuzzed query
executes on a copied context that is itself pinned to 0 (:3511), and the ASTSetQuery fuzz
handler only mutates values and order, so the one fuzzed SET cannot raise the test's own value
or mint a mistyped clone. Carrier enumeration was redone from scratch: of the 32 stateless tests
combining ENGINE = Merge( with Distributed(, exactly one also uses
optimize_distinct_in_order, and it is this test.

One residual, disclosed and not chased: #113242's regression test covers Int64, UInt64,
Int32 and Nullable targets but no wide integer, so the Int128 route measured here is
uncovered by it. That belongs to #113242, not to this PR.

Session id: cron:clickhouse-review-slot-9:20260821-181000

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The abort is deterministic on a hand-built mistyped fixture (a Merge parent declared Int128 over a String Distributed child, then the test's first DISTINCT query), one command. The natural armed path is deterministic in aggregate: 6/30 failures without the pin vs 0/30 with it, plus the ASTFuzzerQueries counter delta.
b Root cause explained? Yes. Two chains, kept apart. The engine defect: ReadFromMerge pushes a sort into a Merge child across an order-breaking cast, so rows arrive sorted by the child's type while the plan claims the parent's type, and DistinctSortedStreamTransform (adjacent-duplicates only) trips its contiguity assertion. The amplification, which is what this PR removes: the stress profile sets ast_fuzzer_runs = 5 + ast_fuzzer_any_query = true (tests/docker_scripts/stress_tests.lib:190-191), so the server-side fuzzer re-runs mutated copies of every statement including CREATE, retypes the Merge parent and substitutes the clone into a SELECT, manufacturing the precondition on every stress run.
c Fix matches root cause? Yes, for the amplification it targets. Pinning ast_fuzzer_runs = 0 removes exactly the mechanism in (b) and nothing else. It is deliberately not a fix for the engine defect, which is #113242, and the PR body says so plainly. This is the established in-tree remedy for a stress fuzzer that mutates a test's own fixture into something pathological: nine stateless tests pin the setting, two of them for that reason (02920_rename_column_of_skip_indices, 03714_base32_base58_short_string).
d Test intent preserved / new tests added? Yes. All seven arms still run and still assert their results; the .reference file is byte-unchanged and the unfuzzed run passes. No new test is added because the deliverable IS a test change. Coverage of the engine defect is untouched: it lives in #113242 and its own regression test.
e Both directions demonstrated? Yes, on one debug binary (Build-ID bda920830ec56d54a64c7afd6e85775ed4023e3e, asserted against SELECT lower(buildId())) differing only in the test file, with the same armed command. Without the pin: 24/30 passed, 6/30 failed, 4650 fuzzed queries. With the pin: 30/30 passed, 150 fuzzed queries. The ASTFuzzerQueries positive control moved 155 without the pin and 0 (per test, in query_log) with it.
f Fix is general across code paths? Yes. Re-ran the carrier grep on the base: only this test combines Merge + Distributed + optimize_distinct_in_order. The one broader candidate, 04104_56208_merge_distributed_merge_chain.sql, is correctly excluded: single shard, DISTINCT on the virtual _table column rather than an ordered key, no optimize_distinct_in_order, and zero CIDB occurrences of this assertion in 30 days. The DISTINCT ON arm exercising LimitBySortedStreamTransform shares the adjacency assumption and is covered by the same file-level SET.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A as an input matrix: this pins one session setting to its own declared default, with no data path to vary. What did need checking is scope, and it holds: ast_fuzzer_runs is Session-scope, so the file-level SET covers every later statement in the test's session, verified for both enable_analyzer = 0 and = 1 arms.
h Backward compatible? (maintainer-approved exception only) Yes, vacuously. No src/ change, no default change, no serialization change, so no SettingsChangesHistory.cpp entry is needed: ast_fuzzer_runs already exists (src/Core/Settings.cpp, history entry present) and its default is already 0. The test pins the setting to the value it already has outside stress.
i Invariants and contracts preserved? Yes. Nothing in src/ changes, so no function precondition, data-structure invariant or concurrency contract is touched. The test's own invariant, that its fixture keeps the types it declares so the DISTINCT arms measure what they claim, is strengthened. One measured residual, disclosed: the SET statement itself is still fuzzed once before the new value applies, so the global counter moves by 5 per run. Probes confirm this is bounded to that single statement (SET alone: delta 5; SET plus two selects: still 5; three selects without the SET: 15) and it cannot mint a mistyped clone (0 %__fuzz% tables after the armed pinned runs, and 0 tables created by a fuzzed SET in a fresh database).

Session id: cron:clickhouse-impl-slot-40:20260821-173200 (implementation); cron:clickhouse-review-slot-9:20260821-181000 (review)

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [68b414d]

Summary: ✅


AI Review

Summary

This PR pins ast_fuzzer_runs = 0 at the top of 04870_distinct_merge_over_distributed so the stress profile no longer lets the server-side AST fuzzer mutate the test's own CREATE/SELECT chain into the known Merge-over-Distributed order-breaking scenario from #113242. I traced the runner/session semantics and the AST-fuzzer behavior around ASTSetQuery, and I did not find a material correctness, coverage, or metadata issue in the current patch.

Final Verdict

✅ No findings.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @tavplubix, could you review this? It is a test-only change: the stress profile arms the server-side AST fuzzer for every statement, which retypes this test's Merge parent over its Distributed child and manufactures the order-breaking cast behind an assertion that has now aborted 87 stress runs across 78 pull requests, so the test pins ast_fuzzer_runs = 0 without weakening any of its arms.

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 68b414d28 with master 7e1c82b83 (stripped binary size, per-symbol sizes and ThinLTO time; 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 704.51 MiB 701.49 MiB -3.02 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

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

Job report

@qoega

qoega commented Sep 3, 2026

Copy link
Copy Markdown
Member

This PR does not fix CI. Not merging

@qoega qoega closed this Sep 3, 2026
@qoega qoega self-assigned this Sep 3, 2026
@groeneai

groeneai commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

Agreed, and I am not reopening or re-pushing this.

Measured why you are right. #113242, the root-cause fix, merged 2026-08-30T16:33:24Z. On Stress test%, for the whole assertion message, CIDB gives 148 hits / 130 PRs / 7 true-master over the 13.1 days before that merge (2026-08-17 11:44 to 08-30 15:04), against 11 hits / 11 PRs / 1 true-master over the 3.4 days after (08-30 16:41 to 09-03 02:00). Part of that remainder is still pre-fix trees, since CIDB timestamps the run and not the tree.

The part that is genuinely post-fix is exactly what a fuzzer pin must not absorb. The one post-fix true-master hit is master f3a460fe04c9, Stress test (arm_tsan) at 2026-09-01 20:16:44, and #113242 is in that tree (behind_by=0 from its merge commit, and conversionPreservesOrder occurs in src/Storages/StorageMerge.cpp at that sha but not at my PR head). Its carrier is 04870 itself (log_comment in the fatal dump and in query_log), where the fuzzer minted

CREATE TABLE dist_distinct__fuzz_3 (`s` BFloat16) ENGINE = Distributed('test_cluster_two_shards_localhost', currentDatabase(), 't_distinct', rand())

over t_distinct (s String), then aborted on SELECT DISTINCT s FROM dist_distinct__fuzz_3 ORDER BY s with optimize_distinct_in_order = 1.

That is the StorageDistributed carrier of the mechanism, not the Merge one #113242 repaired: a Distributed table whose declared column type differs from its source's without preserving order takes its order promise from the stage, so the cast lands above the shard's sort. It needs no fuzzer, and the non-DISTINCT arms of the same mismatch return a wrong ORDER BY rather than an assertion. I reported it with the mechanism and four measured-dead designs at #112940 (comment), where it is waiting on a design decision. Pinning ast_fuzzer_runs = 0 here would have removed that signal instead of fixing it.

The separate PR I promised on #112951 was this one, so I am recording the outcome here rather than reviving that closed thread.

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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants