Skip to content

Fix the AST fuzzer aborting on a degenerate predicate such as and() - #112139

Merged
PedroTadim merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-queryfuzzer-degenerate-logical-predicate
Jul 28, 2026
Merged

PedroTadim merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-queryfuzzer-degenerate-logical-predicate

Conversation

@groeneai

@groeneai groeneai commented Jul 27, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #112014
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112014&sha=ecda8174cacd8b3ea74e244c0c1231390fcef152&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29

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 aborts itself when it mutates a query containing a zero-argument logical call such as
and():

Logical error: '!predicates.empty()'.
src/Common/QueryFuzzer.cpp:3919  DB::QueryFuzzer::permutePredicateClause(const ASTPtr &, int)
src/Common/QueryFuzzer.cpp:3991  DB::QueryFuzzer::addOrReplacePredicate(ASTSelectQuery *, ASTSelectQuery::Expression)
src/Common/QueryFuzzer.cpp:3656  DB::QueryFuzzer::fuzz(vector<ASTPtr> &)

Root cause. permutePredicateClause accepts any node named and/or/xor and delegates the
flattening to extractPredicates with op == func->name. Because the name matches op,
extractPredicates took its first branch — iterate func->arguments->children and return — which
appends nothing when that list is empty. Control returned with an empty predicates list and the
chassert fired. and() is a parseable AST (Function and (children 1) / ExpressionList with zero
children); it is only rejected later by the analyzer, so the fuzzer aborts while mutating, long
before execution.

An empty extraction from a fuzzer input is a legitimate input, not an invariant violation, so this
fixes the flattening function rather than guarding its caller: extractPredicates treats a
degenerate logical call as an opaque leaf, and the chassert is removed.

The early return in permutePredicateClause also closes an unbounded-recursion path. A node with a
null arguments fails the func->name == op && func->arguments guard and falls through to the
branch that calls permutePredicateClause on that very same node; the early return breaks the
cycle. It is load-bearing rather than defensive: with it removed, driving an
ASTFunction{name = "and", arguments = nullptr} through permutePredicateClause segfaults on a
stack overflow. The shape itself is hardening — the parser always attaches an ExpressionList, so I
could not exhibit it from SQL; the plausible route is the function-name swap in fuzz, which picks
from {"and", "or", "xor"} without checking arguments.

This is a bug in the fuzzing tool, not in query execution. QueryFuzzer is reached only from the
client --query-fuzzer-runs loop, the server-side ast_fuzzer_runs setting, and
fuzzQuery/StorageFuzzQuery — there is no production query path. The impact is that the fuzzing
session is lost and a red check plus a CI database failure row are produced on an unrelated pull
request. Only builds with chassert enabled are affected.

Reproducer (deterministic, fuzzQuery with an explicit seed):

SELECT * FROM fuzzQuery('SELECT 1 FROM numbers(10) WHERE and()', 2000, 8) LIMIT 200 FORMAT Null;

Before the fix this aborts the server with the stack above; after it, it completes. The new test
04651_fuzzer_degenerate_logical_predicate drives a degenerate node into permutePredicateClause
through three different callers — addOrReplacePredicate, the recursive call inside
extractPredicates, and the JOIN ON path — and all four of its statements abort on an unpatched
binary. The fix is in the shared callee, so the fourth call site (fuzzMandatoryPredicate, reached
from lightweight DELETE/UPDATE and ALTER predicates) is covered by construction even though no
statement targets it. The pre-existing fuzzQuery tests (03031, 03834, 04141, 04202) and the
QueryFuzzer unit tests were re-run because the fix changes fuzzer output for degenerate inputs; all
pass with no reference changes.

On the coverage that test provides: removing both guards makes all four of its statements abort, so
it pins the defect and the fix as a whole. It does not isolate the two guards individually — with the
chassert gone, dropping either one alone degrades output silently (a dropped operand, or an
and(and()) self-wrap) rather than aborting, and FuzzQuerySource::createColumn falls back to
emitting the unfuzzed base query, so an inert fuzzer still returns rows. A unit test covering each
guard separately was dropped from this pull request at the reviewer's request.

One merge-order note: the new early return calls the existing tryNegateNextPredicate, which
#111406 renames to fuzzPredicate. The two branches
merge with no textual conflict, but the merged result would not compile, because that guard would hold
the only remaining call to the old name. Whichever lands second needs the one-line rename there;
nothing else overlaps, and that pull request changes neither extractPredicates nor the assertion.

No related open issue found.

Version info

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

groeneai and others added 2 commits July 27, 2026 10:57
`QueryFuzzer::permutePredicateClause` delegates the flattening of an AND/OR/XOR
tree to `extractPredicates` with `op` set to the node's own name. Because the
name matched `op`, `extractPredicates` took its first branch, iterated
`func->arguments->children` and returned, appending nothing when that list is
empty. Control returned with an empty `predicates` list and tripped
`chassert(!predicates.empty())`, aborting the server.

A bare `and()` is a parseable AST (`Function and (children 1) / ExpressionList`
with zero children) and is only rejected later by the analyzer, so the fuzzer
aborts while mutating the query, long before execution. Such a node reaches the
fuzzer from the input corpus, so an empty extraction is a legitimate input
rather than an invariant violation: `extractPredicates` now keeps a degenerate
logical call as an opaque leaf and the assertion is removed.

The same condition also removes an unbounded mutual recursion. When `arguments`
is null the old guard `func->name == op && func->arguments` fell through to the
branch that calls `permutePredicateClause` on the very same node. The parser
always attaches an `ExpressionList`, so that path is hardening rather than an
observed crash; the plausible route is the function-name swap in `fuzz`, which
picks from `{"and", "or", "xor"}` without checking `arguments`.

`QueryFuzzer` is reached only from the client `--query-fuzzer-runs` loop, the
server-side `ast_fuzzer_runs` setting and `fuzzQuery`/`StorageFuzzQuery`, so no
production query path is affected. The cost of the abort is a lost fuzzing
session plus a red check and a CI database failure row on an unrelated pull
request.

The new test drives the three distinct callers of `permutePredicateClause` that
a degenerate node can reach, using `fuzzQuery` with explicit seeds so each case
is deterministic; every statement aborts on an unpatched binary.

Co-Authored-By: Claude Opus 5 <[email protected]>
Follow-up to the previous commit on this branch, which stopped the AST fuzzer from
aborting on a degenerate logical call such as `and()`. That commit's stateless test
asserts only that `fuzzQuery` returns rows, and `FuzzQuerySource::createColumn` falls
back to emitting the unfuzzed base query, so an inert fuzzer still satisfies it. The
abort oracle it provides does pin the removal of `chassert(!predicates.empty())`, but
neither of the two guards that make the empty extraction impossible was pinned: dropping
the degenerate-leaf `predicates.emplace_back(node)` in `extractPredicates`, or the
degenerate early return in `permutePredicateClause`, left the suite green.

`src/Common/tests/gtest_query_fuzzer_degenerate_predicate.cpp` calls the two private
helpers directly, so each guard has its own assertion and no dependence on the fuzzer's
random draw. `extractPredicates` must contribute exactly one opaque leaf for a degenerate
node, and the same for a logical `ASTFunction` whose `arguments` is null (the shape that
used to recurse on itself); `permutePredicateClause` must return that node unchanged, or
`not` of it, never a fresh logical call wrapping it. Reverting either guard fails exactly
the assertions for that guard and no others; reverting both fails all three. The
gtest fixtures reach the helpers through the in-tree friend-class idiom, as
`LRUFileCachePriority` and `TemporaryDataOnDisk` already do.

The stateless test loses its `no-llvm-coverage` tag. Its rationale was that `fuzzQuery`
drives the process-global `QueryFuzzer` whose accumulated state varies run-to-run, which
is true of the scalar `fuzzQuery` function and of `03834_fuzz_query_function`, but not of
the table function used here: `FuzzQuerySource` owns a per-source `QueryFuzzer` seeded
from its `random_seed` argument, and `getGlobalASTFuzzer` has no caller under
`src/Storages` or `src/TableFunctions`. The output is byte-identical across repeated runs
and across an intervening load of 500 global-fuzzer calls, so there is nothing
non-deterministic to skip. `04141_fuzz_query_max_query_length` is the same-form
precedent and carries `no-fasttest` only. The remaining `no-fasttest` is load-bearing for
a different reason, now stated in the test: fast builds are `NDEBUG` without sanitizers,
so `chassert` expands to `(void)sizeof(...)` and the statements would pass vacuously.

The comment on the new `extractPredicates` branch said extraction from a degenerate node
"yields nothing" three lines above the code that appends a leaf. It now says the call
contributes exactly one opaque leaf, which is the reason the extraction can no longer
come back empty.

The previous commit message described the test as covering every caller of
`permutePredicateClause` a degenerate node can reach. That is not right: there are four
call sites, the test drives a degenerate node through three of them, and the fourth,
`fuzzMandatoryPredicate`, is covered by construction because the fix is in the shared
callee.

The failure was observed on an unrelated pull request, ClickHouse#112014, whose diff is two `ci/`
Python files. It is linked below as the source of the CI report only, not as the cause.

Related: ClickHouse#112014
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112014&sha=ecda8174cacd8b3ea74e244c0c1231390fcef152&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review — 2 rounds, 10 findings, 9 AGREE / 0 DISAGREE (click to expand)

Before opening this pull request I ran two rounds of independent review: a cold read of the
resulting code by a reviewer that had not written it, plus a second model reviewing the same diff
against the in-repo review checklist and the intended description. Round 1 sent the change back for
a fix round; round 2 came back clean and is what is published here.

Per-round counts, derived from the review ledgers: round 1 — 7 findings (3 from the second model,
4 from the cold read), 5 AGREE and 1 dropped as self-fixed, all four AGREEd blockers/majors
implemented in the fix round; round 2 — 4 findings, all from the cold read, the second model
returned 0.

Round 1 — sent back (❌ = fixed before publication)

❌ The stateless test could not see either guard. FuzzQuerySource::createColumn falls back to
emitting the unfuzzed base query, so count() > 0 is satisfied by a completely inert fuzzer.
Measured: deleting the degenerate-leaf append in extractPredicates, or the degenerate early
return in permutePredicateClause, left the whole suite green — only the chassert removal was
pinned. Fixed by adding src/Common/tests/gtest_query_fuzzer_degenerate_predicate.cpp, which calls
both private helpers directly with a fixed seed, one assertion per guard. The proposed alternatives
were rejected on evidence: seed-specific formatted-AST assertions are churn, and an absolute "the
fuzzer never emits and(and())" invariant is false, since the fixed build legitimately produces 333
such occurrences from real operand lists.

❌ The no-llvm-coverage rationale was wrong for this form. It claimed fuzzQuery drives the
process-global QueryFuzzer. That is true of the scalar function, but FuzzQuerySource owns a
per-source fuzzer seeded from its random_seed argument, and getGlobalASTFuzzer has no caller
under src/Storages or src/TableFunctions. Verified empirically as well: byte-identical output
across repeated runs and across 500 intervening global-fuzzer calls. The tag was dropped, and the
remaining no-fasttest now states the reason that is actually load-bearing — fast builds are
NDEBUG without sanitizers, so chassert expands to (void)sizeof(...) and the statements would
pass vacuously.

❌ The commit message omitted the CI report URL and the link to the pull request where the failure
was observed
, which the repository instructions require; added in the new commit, since amending
is not allowed here.

❌ An in-code comment contradicted the line below it — it said extracting from a degenerate node
"yields nothing" three lines above the code that appends a leaf. Reworded.

❌ An exhaustiveness claim was too strong — "the three distinct callers" understated the four
call sites of permutePredicateClause. The description and the commit message now say four exist,
the test drives three, and fuzzMandatoryPredicate is covered by construction because the fix is in
the shared callee.

Round 2 — clean, published

The second model returned 0 findings, having read every changed function, traced every caller and
fuzzer entry path, and run the three new unit tests.

The cold read produced 4 findings, none of them in the shipped code:

❌ Merge order against #111406. The new early return calls the existing
tryNegateNextPredicate, which that pull request renames to fuzzPredicate. The branches merge
with no textual conflict, but the merged tree would not compile, because that guard would hold the
only remaining call to the old name. This is now stated in the description with the one-line remedy.
Worth noting that the two changes are otherwise independent: #111406 changes neither
extractPredicates nor the assertion, and merging it against master produces the same zero
conflicts, so this branch introduces none of its own.

❌ The description did not name the unit test, which is the only oracle for either guard and 103
of the 154 added lines. Added.

⚠️ Two nits on the new unit test, recorded and not fixed, since neither affects behaviour and both
would cost another build and review round: an unused <Parsers/ASTExpressionList.h> include (the
type is named only in comments), and a comment that says the negation branch is taken "in almost
every run" when the fixture seeds pcg64(1) and the draw is therefore deterministic. The clause the
test actually relies on — that its assertions accept both outcomes — is correct.

Verified clean

The restructure is behaviour-preserving for every non-degenerate input: op is provably always one
of and/or/xor, so hoisting the name test above the name == op test cannot change which
branch a non-degenerate node takes. The unbounded-recursion claim is real — neither function calls
checkIterationLimit, so that path is a stack overflow rather than a caught TOO_DEEP_RECURSION.
The null-arguments shape is correctly labelled hardening: the parser always attaches an
ExpressionList, and the two parsers that do clear it produce index types and backup names, never a
predicate. Test-liveness was re-read from the raw mutation logs rather than from a summary, and the
tag scanners in tests/clickhouse-test were re-run against the committed file to confirm the added
comment prose changes no skip status.

Session id: cron:clickhouse-review-slot-9:20260727-142300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT * FROM fuzzQuery('SELECT 1 FROM numbers(10) WHERE and()', 2000, 8) LIMIT 200 FORMAT Null; through clickhouse local --logger.console=1 --logger.level=none aborts with RC=134 and Logical error: '!predicates.empty()', matching the CI stack frame for frame. Measured 9/9 aborts over the test's statements x 3 repeats on an unpatched binary. The new gtest QueryFuzzer.ExtractPredicatesKeepsDegenerateLeaf reproduces the same condition with no RNG dependence at all.
b Root cause explained? Yes. permutePredicateClause delegates flattening to extractPredicates with op == func->name; because the name matched op, extractPredicates took its first branch, iterated func->arguments->children and returned, appending nothing for a zero-child list. Control returned with an empty predicates and the chassert fired. and() parses as Function and (children 1) / ExpressionList with no children and is rejected only later by the analyzer, so the fuzzer aborts while mutating.
c Fix matches root cause? Yes. The missing case is added in extractPredicates, the single function that decides what is a flattenable operand, and the chassert is deleted because an empty extraction from a fuzzer input is a legitimate input. Rejected alternatives: a guard in the caller only (leaves the unbounded-recursion path and keeps the false invariant), downgrading the chassert to a log (would feed an empty list into makeASTFunction), and a producer-side guard (the degenerate node arrives from the input corpus, so it would close no observed carrier).
d Test intent preserved / new tests added? Yes. No existing test is weakened. 04651_fuzzer_degenerate_logical_predicate adds four statements, each pinning a distinct caller of permutePredicateClause and each shown to abort on an unpatched binary, and src/Common/tests/gtest_query_fuzzer_degenerate_predicate.cpp adds three assertions that call the two changed helpers directly. The gtest exists because the stateless statements assert only that rows come back, and FuzzQuerySource::createColumn falls back to emitting the unfuzzed base query, so they pin the chassert removal but neither of the two guards.
e Both directions demonstrated? Yes, per carrier and per guard. Unpatched: statement 1 RC=134 at addOrReplacePredicate, statements 2 and 3 at the recursive call inside extractPredicates, statement 4 at the JOIN ON path; patched RC=0 with .reference matched byte for byte. Per guard, three mutants x three assertions: dropping the degenerate-leaf append fails the two extractPredicates assertions only, dropping the permutePredicateClause early return fails the permute assertion only, dropping both fails all three. Both mutation series restore the source md5 exactly and rebuild to the recorded Build ID.
f Fix is general across code paths? Yes. permutePredicateClause has four call sites plus its definition, all funnelling into one extractPredicates; the test drives a degenerate node through three of them, and the fourth, fuzzMandatoryPredicate, is covered by construction because the fix is in the shared callee. The two logical-name conditions in the file are precisely the two the fix touches, so no per-call-site guard is needed. The other assertions in QueryFuzzer.cpp guard unrelated invariants and are untouched, as are the two already-resolved sibling defects in the same file.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes for the axis that exists here. and, or and xor are handled by the same two conditions the fix sits inside, so all three degenerate spellings are covered symmetrically; nested (and(and())), mixed (and(and(), materialize(1))) and JOIN ON and() shapes were all exercised. The null-arguments shape, which SQL cannot produce, is now covered by the gtest that builds the ASTFunction programmatically. Verified non-carriers: one-argument logical calls (one child is appended, so the list is non-empty) and not(and()) (the outer name is not logical). No type-wrapper axis applies to an AST mutator.
h Backward compatible? (maintainer-approved exception only) Yes, trivially. Fuzzing-only tool: no settings, no serialization, no format change, no SettingsChangesHistory.cpp entry. QueryFuzzer is reached only from the client --query-fuzzer-runs loop, the server-side ast_fuzzer_runs setting, and fuzzQuery/StorageFuzzQuery, so there is no production query path. The header change adds three forward declarations and three friend declarations for the gtest fixtures, following the existing LRUFileCachePriority and TemporaryDataOnDisk idiom.
i Invariants and contracts preserved? Yes. The new invariant is that extractPredicates appends at least one element for any node it is called on and never recurses on the node it was given; it is asserted by the gtest rather than by a chassert, since the lesson of this site is that a legitimate input was modelled as an invariant. permutePredicateClause still returns a non-null ASTPtr on the new early-return path via tryNegateNextPredicate, and makeASTFunction is no longer reachable with an empty argument vector. No locks, ownership or error paths are involved.

Session id: cron:clickhouse-impl-slot-44:20260727-130300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @PedroTadim @qoega — could you review this? A zero-argument logical call such as and() reaches QueryFuzzer::permutePredicateClause, whose extractPredicates flattens an empty argument list into nothing and then trips chassert(!predicates.empty()), so the fuzzer aborts itself on an input the corpus can legitimately produce; the same guard also let a logical node with a null argument list recurse on itself. The fix adds the degenerate-leaf case in the shared flattening callee and drops the assertion, and a new unit test pins each of the two guards separately, since the stateless statements alone cannot see them.

@PedroTadim PedroTadim self-assigned this Jul 27, 2026
Comment thread src/Common/QueryFuzzer.h Outdated
@@ -16,6 +16,12 @@
#include <Common/randomSeed.h>


/// Fixtures of src/Common/tests/gtest_query_fuzzer_degenerate_predicate.cpp, which drives the
/// private predicate helpers directly.
class QueryFuzzer_ExtractPredicatesKeepsDegenerateLeaf_Test;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@groeneai you don't need the gtest, leave the stateless test only

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in feb92ee -- the gtest and the friend declarations are gone, so src/Common/QueryFuzzer.h is byte-identical to master again, and 04651_fuzzer_degenerate_logical_predicate is the only test.

One thing worth recording, since it is the coverage the gtest was carrying. The stateless test does pin the defect as a whole: with both guards removed the mutated QueryFuzzer.cpp is byte-identical to master's, and all four statements abort. What it cannot do is isolate the two guards individually. With the chassert gone, dropping either one alone degrades output silently instead of aborting -- dropping the early return rebuilds and() as and(and()), dropping the opaque-leaf append collapses and(and()) back to and() -- and FuzzQuerySource::createColumn emits the unfuzzed base query on its fallback path, so count() > 0 holds either way. I measured that: with the assert deleted, dropping either guard leaves all four statements at rc=0.

That is fine by me if it is fine by you -- it is your code and a unit test for a fuzzer internal is a reasonable thing not to want. If you would rather keep some of it, the two cheaper options are a single gtest assertion instead of three, or leaving it as is and accepting that a future refactor of either guard will not be caught by a test. Happy either way; no need to reply if you are content with the current state.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jul 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9176dfe]

Summary: ✅


AI Review

Summary

This PR hardens QueryFuzzer against degenerate logical predicates such as and() by keeping empty logical calls as opaque leaves during extraction and by short-circuiting permutation when the logical node has no operands. I reviewed the current diff, the existing discussion, the touched callers in QueryFuzzer.cpp, and the current green CI state, and I did not find a remaining correctness, safety, or evidence gap that still warrants a review comment.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 27, 2026
Comment thread src/Common/QueryFuzzer.cpp Outdated
@@ -3885,17 +3885,25 @@ void QueryFuzzer::extractPredicates(const ASTPtr & node, ASTs & predicates, cons
{
if (const auto * func = node->as<ASTFunction>())
{
if (func->name == op && func->arguments)
if (func->name == "and" || func->name == "or" || func->name == "xor")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@groeneai please keep if (func->name == op && func->arguments) just add the if (!func->arguments || func->arguments->children.empty()) check

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in feb92ee -- if (func->name == op && func->arguments) is back exactly as it was, with the empty-list check nested inside it.

Your literal suggestion works as written, and it is worth saying why, because the null half now lands somewhere else. With the outer condition restored, a node whose arguments is null fails that condition and falls through to the and/or/xor branch below, which calls permutePredicateClause on the same node -- and the early return there catches it, so the recursion is broken one hop deeper than in my previous version rather than not at all. I checked that the early return really is what closes it: remove it, drive an ASTFunction{name = "and", arguments = nullptr} through permutePredicateClause, and it segfaults on a stack overflow. So inside extractPredicates the plain func->arguments->children.empty() you asked for is sufficient, and I dropped the !func->arguments || disjunct there as redundant.

Re-verified after the change: all four statements of the stateless test abort on a pristine master build and pass here, 50/50 randomized runs pass, and 03031, 03834, 04141, 04202 plus the existing QueryFuzzer unit tests are green with no reference changes.

groeneai added 2 commits July 27, 2026 17:07
Follow-up to the review on ClickHouse#112139.

- `extractPredicates` keeps its original `if (func->name == op && func->arguments)`
  condition; the degenerate-argument-list check is nested inside it rather than
  restructuring the branch order.
- Removed `src/Common/tests/gtest_query_fuzzer_degenerate_predicate.cpp` and the
  friend declarations it needed, so `src/Common/QueryFuzzer.h` is untouched again.
  `04651_fuzzer_degenerate_logical_predicate` is the only test now.

With the outer condition restored, a node whose `arguments` is null no longer reaches
the degenerate branch in `extractPredicates`; it falls through to the call into
`permutePredicateClause`, whose own early return breaks the recursion there. Verified
by removing that early return and driving an `ASTFunction{name = "and", arguments =
nullptr}` through it: stack overflow, SIGSEGV.

All four statements of the stateless test still abort on a pristine master build and
pass here. Removing both guards reproduces master exactly (the mutated file is
byte-identical to master's). 50/50 randomized runs of the new test pass, as do
`03031_table_function_fuzzquery`, `03834_fuzz_query_function`,
`04141_fuzz_query_max_query_length`, `04202_storage_fuzzquery_engine` and the
existing `QueryFuzzer` unit tests.

Related: ClickHouse#112014
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112014&sha=ecda8174cacd8b3ea74e244c0c1231390fcef152&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29
Four statements cover three distinct callers, not one each: seeds 7 and 35 both
reach the recursive `extractPredicates` path.
@PedroTadim
PedroTadim enabled auto-merge July 27, 2026 18:57
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — feb92ee

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (amd_debug) / Logical error: Inconsistent KeyCondition behavior (STID 5182-2f27) the debug-only exact-range consistency check in MergeTreeDataSelectExecutor::markRangesFromPKRange. fatal.log gives the aborting statement as SELECT count() FROM t_big WHERE (g = toUInt128(5)) AND (945 = r) SETTINGS use_lightweight_primary_key_index_analysis = 0 (fuzzed from 04612_reverse_key_index_analysis.sql), i.e. the widening-cast atom class where matchesExactContinuousRange treated a non-monotonic wider-type comparison as an exact continuous range #109023 (mine, merged 2026-07-27 20:50 UTC), merged master @ 9176dfe811d7 to pick it up. The tested build was the merge into master tip be5aa85e3e72, which predates that merge, so the fix was absent from the binary that aborted
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) / Logical error: Got read request from replica 1 for unknown stream ... (STID 5217-505b), and the Server died row it caused the ParallelReplicasReadingCoordinator unknown-stream abort. clickhouse-server.err.log names the aborting query SELECT count() FROM mv WHERE id = 999999999 over an .inner_id.<uuid> materialized-view inner table. Trunk bug: 103 rows across 90 unrelated PRs plus 7 master hits in 30d #111689 (mine, open)
Stateless tests (amd_tsan, s3 storage, parallel, 3/3) / 04367_distributed_plan_merge_scatter_multishard real hang, not timeout flakiness: an unbounded condition-variable wait in local execution of distributed plans that needs the max_threads 1 randomization draw plus scheduling luck, so the runner's own Runs: 24, Failed: 0 rerun verdict is corroboration rather than evidence of transience #111762 (external, open)

None of the three is caused by this PR's diff, which changes src/Common/QueryFuzzer.cpp plus its
own new 04651 stateless test. The AST fuzzer is disabled in the stress harness
(ast_fuzzer_runs=0, ci/jobs/scripts/stress/stress.py:339) and is not used at all by the
stateless jobs, so the fuzzer code path cannot reach primary-key index analysis, the
parallel-replicas coordinator, or the scatter-exchange hang.

Session id: cron:our-pr-ci-monitor:20260728-023000

@PedroTadim
PedroTadim added this pull request to the merge queue Jul 28, 2026
Merged via the queue into ClickHouse:master with commit 0f2975d Jul 28, 2026
178 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 28, 2026
scanhex12 pushed a commit to scanhex12/ClickHouse that referenced this pull request Jul 29, 2026
Follow-up to the review on ClickHouse#112139.

- `extractPredicates` keeps its original `if (func->name == op && func->arguments)`
  condition; the degenerate-argument-list check is nested inside it rather than
  restructuring the branch order.
- Removed `src/Common/tests/gtest_query_fuzzer_degenerate_predicate.cpp` and the
  friend declarations it needed, so `src/Common/QueryFuzzer.h` is untouched again.
  `04651_fuzzer_degenerate_logical_predicate` is the only test now.

With the outer condition restored, a node whose `arguments` is null no longer reaches
the degenerate branch in `extractPredicates`; it falls through to the call into
`permutePredicateClause`, whose own early return breaks the recursion there. Verified
by removing that early return and driving an `ASTFunction{name = "and", arguments =
nullptr}` through it: stack overflow, SIGSEGV.

All four statements of the stateless test still abort on a pristine master build and
pass here. Removing both guards reproduces master exactly (the mutated file is
byte-identical to master's). 50/50 randomized runs of the new test pass, as do
`03031_table_function_fuzzquery`, `03834_fuzz_query_function`,
`04141_fuzz_query_max_query_length`, `04202_storage_fuzzquery_engine` and the
existing `QueryFuzzer` unit tests.

Related: ClickHouse#112014
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112014&sha=ecda8174cacd8b3ea74e244c0c1231390fcef152&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29
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 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