Repository navigation
Fix false AST fuzzer oracle mismatch on approx_top_k (re-land) - #120508
alexey-milovidov merged 2 commits into
Conversation
Re-land of ClickHouse#118489, which was reverted by ClickHouse#119957 because its test 05141_oracle_skips_aggregate_aliases was flaky. The revert reason was the test, never the deny-list logic, so master is exposed to the false mismatch again: five occurrences of "AST Fuzzer oracle mismatch: TLP Aggregate" naming approx_top_k since 2026-09-14, two of them on master itself. QueryOracleChecker compares a query's result against a metamorphic rewrite for exact row equality, so it keeps a backstop set of aggregates whose State/Merge path legitimately diverges from direct evaluation. topK and topKWeighted were listed; their space-saving counterparts approx_top_k and approx_top_sum were not, even though QueryFuzzer's aggregate swap list offers approx_top_k for any single-argument aggregate. Which elements survive the bounded counter table, and the counts reported for them, depend on the order values arrive in and on how the partial states merge, so the partitioned rewrite is entitled to disagree with the whole-table reference. Aliases are resolved through AggregateFunctionFactory::getAliasToOrName rather than enumerated, because listing each spelling by hand rots silently and one missing spelling is one false mismatch. Two things differ from ClickHouse#118489. First, the 05141 flake is fixed at its cause. probe() runs the probe query once unfuzzed with the oracle off, purely to read the client's exit status and so tell "this unsafe spelling was skipped" from "this spelling is broken". That invocation redirected nothing, so any server error on it reached the test's stderr, and clickhouse-test fails a test with non-empty stderr regardless of stdout. Exactly one probed aggregate was partial: AnalysisOfVarianceMoments::getFStatistic() throws BAD_ARGUMENTS "There is only one observation in each group" when k == n, which the empty input satisfies with k = n = 0. A degenerate read of the fixture therefore turned the anova gate into a leaked <Error> and failed the test. Both recorded instances are that chain, both identifiable as the unfuzzed gate query by their "(query 1, line 2)" position. The gate's stderr is now discarded, in 05140 as well as 05141, since the two files carry the same probe(). What made the fixture read degenerate is not established, and the fix deliberately does not depend on knowing: a probe's validity gate must not depend on an aggregate's runtime data preconditions. Measured with the fixture INSERT reduced to numbers(0), the pre-revert test reproduces "Reason: having stderror" while this version passes with an empty stderr. The anova probe is dropped rather than repaired because it is the only partial aggregate in the list, and its mechanism class, a raw case-sensitive alias of a deny-listed aggregate, is covered identically by min_by, array_agg, array_concat_agg and medianTDigest. Keeping it would have meant either a UNION ALL shape the oracle is likely to reject outright, which makes the probe vacuous, or a row-count assertion that re-reds the test on the very event the dependence is being removed from. Second, ClickHouse#118489 also removed quantileDeterministic and quantilesDeterministic from the set and added a medianDeterministic(v, 1) positive control that depends on their absence. That measurement does not hold: in the same amd_tsan job as the 05141 failure, master recorded a TLP Aggregate mismatch on "SELECT medianDeterministic(v, 1) FROM oracle_alias_agg", and oracle_alias_agg is 05141's own fixture, so the test was generating master oracle mismatches through its own positive control. Those two entries are left as master has them today. The re-landed alias resolution then rejects every median* spelling of a listed quantile* family, which also makes that control mechanically impossible, so it is removed with the de-listing. The over-rejection risk it covered is already covered by the "safe aliases" control (Bit_And, BIT_OROrNull, BIT_XOR resolving to the associative and commutative groupBitAnd, groupBitOr and groupBitXor), which exercises the raw, combinator-suffixed and mixed-case alias shapes and must stay checkable.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 9 findings, 1 from the gate and 8
On finding 1, for the oracle's owners to rule on rather than for me to decide inside a re-land: the Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260917-042800 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260917-032300 |
|
Workflow [PR], commit [1c1dd6b] Summary: ✅
AI ReviewSummaryThis PR teaches Final Verdict✅ No new findings. LLVM Coverage Report |
Both new tests read `ASTFuzzerOracleChecks`, which all nine oracle paths
increment. Their positive controls therefore proved only that some oracle ran,
not that `checkTLPAggregate` was reachable for the fixture, so every skip probe
could have stayed green with that path out of reach. Add a second positive
control per file reading the dedicated `ASTFuzzerOracleTLPAggregateChecks`
event, as 04658_ast_fuzzer_oracle_tlp_aggregate_counter.sh already does.
The skip probes keep the all-paths counter. The denylist they pin is the screen
shared by all nine oracles, and that counter is measurably the more sensitive
instrument for it: with the screen disabled in a diagnostic build, 90 fuzzed
rounds per spelling gave a per-round detection rate of
spelling all-paths TLP Aggregate only
approx_top_k 51% 40%
approx_top_sum 55% 35%
approx_top_count 54% 40%
array_agg 89% 37%
min_byOrNull 92% 0 of 90
Bit_And, BIT_OROrNull, BIT_XOR 100% 1 of 90
`checkTLPAggregate` skips any aggregate that already carries a combinator, so
`min_byOrNull` and the `BIT_OROrNull` control cannot reach it by construction;
moving them onto the dedicated counter would have retired those assertions
silently. The new controls therefore name combinator-free spellings.
Verified on the reviewed binary (build id 77f68f3884dcadb8): 50 of 50 runs
green, max 2.73s per run. With `checkTLPAggregate` stubbed to return false,
both tests fail on exactly the new line ("TLP Aggregate path never checked")
while every skip probe and both all-paths controls stay green.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1315 translation units recompiled, 6990 s compile time in total, 1315 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.05 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
|
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Stop the AST fuzzer's TLP Aggregate oracle reporting false mismatches on
approx_top_kand on aliasspellings of aggregates it already skips.
Description
QueryOracleCheckerkeeps a backstop set of aggregates whoseState/Mergerewrite legitimatelydiverges from direct evaluation, so the oracle skips them.
topKwas listed; its space-savingcounterparts
approx_top_k/approx_top_sumwere not, and no alias of any member resolved.QueryFuzzeroffersapprox_top_kfor any single-argument aggregate, so the oracle compared resultsentitled to differ.
#118489 fixed that; #119957 reverted it because its test
05141was flaky, not because of thedeny-list. Four such false mismatches have landed since, two on
masteritself. This re-lands#118489 with two differences.
05141no longer depends on a query that can throw.probe()'s validity gate runs one unfuzzedquery purely to read its exit status, but redirected nothing, so a server error on it reached the
test's stderr, which fails the test whatever stdout says.
anovawas the only partial aggregateprobed:
getFStatistic()throwsBAD_ARGUMENTSonce the read yields no more rows than groups, theempty read included, so no fixture rules it out. The gate is now stderr-safe and the
anovaprobe isgone;
min_by,array_agg,array_concat_aggandmedianTDigestcover the same resolution path,and
analysisOfVariancestays listed. Measured with the fixture emptied: the pre-revert test failshaving stderror, this one passes.The
quantileDeterministicde-listing is not re-landed. In the same job as that05141failure,master recorded a mismatch on
medianDeterministic(v, 1)overoracle_alias_agg-05141's ownfixture and positive control. Both entries stay listed; that control is gone.
50 randomized runs of each test are 100/100 green and stderr-clean, and mutation controls for the
listed names, the alias lookup, its per-stage placement and the flake each redden. Both
historical
05141failures show a degenerate fixture read unders3 storage, sequential; that causeis not established and this change no longer depends on it.
Requested by @ alexey-milovidov on
#104076 and
#107108.
Report for
10c12dba.Workflow [PR]
Sync PR [sync-upstream/pr/120508]