Skip to content

Extract loop-registered function names into the source-derived fuzzer dictionary - #121242

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/fuzz-dict-loop-registered-names
Sep 27, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:groeneai/fuzz-dict-loop-registered-names

Conversation

@groeneai

@groeneai groeneai commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #121214
Related: #115307

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 nightly libFuzzer tests job is red since my #115307 merged: update_dict.sh exits 1 and no
fuzzer target runs. The 2026-09-20 master run recorded 0 fuzzer test rows, against 19 on every
nightly before it
(job log).

generate_source_dict.sh has one pass per registration shape, and the register-call pass requires
a string literal argument. src/Functions/grouping.cpp registers its four specializations in a
range-for over an initializer list and passes the loop variable, so names the binary registers were
never derived from the sources. The coverage check reported exactly those four:
__groupingForCube, __groupingForGroupingSets, __groupingForRollup, __groupingOrdinary.

This adds one pass for that form. The register* call has to be part of the same match: a
name-shaped loop variable alone also matches loops over tag names, backup file names, Enum element
labels and column names. grouping.cpp is not touched; the loop is the idiomatic registration form.

Locally, update_dict.sh against a master binary goes from exit 1 to exit 0 and the dictionary
from 6747 to 6751 tokens: those four names and nothing else. The job runs only in NightlyFuzzers,
so this PR's own CI cannot exercise it.

ci/tests/ is wired into no CI job, so the pytest class this PR first carried could not fail a
check. It is replaced by two checks inside the generator, which runs in the fuzzers build, where
CMakeLists.txt turns a non-zero exit into a FATAL_ERROR, and in the nightly job: the pass has to
extract at least one name, and every name it extracts has to be in the output, so a filter between
the two cannot drop the internal __ names again. Both arms measured: the pass matching nothing, and
the __ filter dropping the internal names, each exited 0 with a short dictionary before and exits 1
now. The unmodified script stays byte-identical at 6751 tokens.


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

Version info

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

groeneai and others added 2 commits September 20, 2026 21:01
… dictionary

src/Functions/grouping.cpp registers its four specializations in a range-for
over an initializer list and passes the loop variable to
factory.registerFunction, so the pass that matches a string literal as the
register* argument never saw __groupingForCube, __groupingForGroupingSets,
__groupingForRollup and __groupingOrdinary. The binary registered four names the
source-derived dictionary did not have, so the coverage check in
tests/fuzz/update_dict.sh exited 1 and the nightly libFuzzer tests job died
before any fuzzer target ran: the 2026-09-20 04:38 UTC master run recorded 0
fuzzer test rows against 19 on every nightly before it.

The gap is the extraction, not the internal-name whitelist. The pass collecting
"__" literals from files that register functions writes a file consumed only as
the awk filter's whitelist, never as a token source, and it already contained
all four names. Seeding it, or seeding dictionaries/old.dict (whose documented
home is names composed at compile time), would not have derived them.

So this adds one pass for the loop form, right after the literal-argument
register-call pass. The register* call reached from the loop header is part of
the match rather than the name-shaped loop variable alone, because that
variable also names sets of tags (TimeSeriesTagsFunctionHelpers.cpp), backup
files (UserDefinedSQLObjectsBackup.cpp), Enum elements (DataTypeFactory.cpp)
and columns (gtest_NestedUtils.cpp). It is the same rule the existing
String-local pass applies. The residual of matching in one regex is that the
register* call has to be the loop body's first statement; the coverage check is
the loud fail-safe for anything the passes miss, which is how this surfaced.

Measured locally with a master debug binary: the generated dictionary goes from
6747 to 6751 tokens, added lines exactly those four names, and the coverage
check from exit 1 to exit 0. The token count is source-derived and does not
depend on the binary; that those four names are the whole gap is what the
failing job's own log shows, with the release binary CI runs. The pass
introduces no new scanned path, so the codegen dictionary's cmake dependency
list is unchanged. grouping.cpp is not touched, since the loop is the idiomatic
registration form.

The test class appended to ci/tests/test_fuzzer_dict_codegen_deps.py runs the
generator and requires the four names in its output, with a control arm running
a copy whose new pattern is rewritten to a keyword no source file holds: that
arm must produce none of the four, and must still produce lcase, whose only
carrier is the neighbouring literal-argument pass.

Co-Authored-By: Claude Opus 5 <[email protected]>
The class pinned membership only: the four __grouping* names present in the
generated dictionary, absent without the new pass. The coverage check in
tests/fuzz/update_dict.sh is one-way (comm -23, binary minus source), so a
source-derived dictionary carrying tokens the binary does not register passes
the nightly job silently, and nothing bounded what else the new pass emits.

Replace the four per-name absence cases with one assertion on the exact
difference between the two arms, which subsumes them in both directions. The
neighbouring TestTheDictionaryTracksAnUnsuffixedCarrier pins its own delta the
same way. Measured: with the pattern's register* clause and the pass's
identifiers_only tail both removed, six unrelated literals reach the
dictionary, the coverage check stays green, the membership cases stay green,
and this assertion fails.

The module docstring scoped the file to the codegen grammar's rebuild
dependencies, while this class is about extraction coverage; it now names both.

Co-Authored-By: Claude Opus 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 Sep 20, 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; 3 gate runs over 3 rounds, 2 findings),
plus my own cold review of the code and its text in each round (9 findings). A further 5 corrections
were to this log itself.

# Sev Finding Verdict Evidence / action
1 ⚠️ The regression test pins membership of the four names, not the exact token delta, so a future widening of the pattern could add junk the one-way coverage check never sees (ci/tests/test_fuzzer_dict_codegen_deps.py) AGREE, fixed The class now asserts that the difference between the two generated dictionaries is exactly the four quoted names, with an empty reverse difference, replacing the per-name absence test it subsumes. Measured live: with the pattern's register* clause and the pass's identifier filter both removed, six unrelated literals reach the dictionary, the coverage check stays green, and this assertion is the only thing that fails
2 ⚠️ The first commit's message said the token delta and the coverage-check flip were measured against a release binary; they were measured with a debug binary AGREE, fixed Reworded to name the binary actually used. The token count is source-derived and independent of the binary; that those four names are the complete gap is what the failing job's own log shows, with the release binary CI runs
3 💡 The draft body kept its Closes: / Related: lines inside the template's HTML comment and referenced the issue only in prose AGREE, fixed Measured: of the 40 most recently merged PRs, 5 declare a relationship and 4 of those put full-URL lines in the visible body. Both lines are now visible above the category header
4 💡 The body made the same release-binary claim AGREE, fixed Reworded, and the claim anchored on the failing job's own log
5 💡 The file's module docstring scoped it to the codegen grammar's rebuild dependencies, while the new class is about extraction coverage AGREE, fixed Docstring widened to cover both subjects. One test comment was rewritten in the same round as a consequence: it described the assertion above it, which finding 1 replaced
6 💡 85 test lines for a 17-line extractor change AGREE, addressed Finding 1's fix was prescribed as a replacement rather than an addition: 6 collected cases instead of 9, asserting strictly more, at the same 62 class lines. Stricter rather than smaller, so the volume itself stands
7 💡 My own carrier enumeration named one carrier the plan did not: the libFuzzer job's cache digest DROPPED No change needed anywhere: ci/defs/job_configs.py already lists tests/fuzz/generate_source_dict.sh in that digest, so the fixed job re-runs instead of taking a cache hit

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Noted and not acted on, each costed: the reverse half of finding 1's assertion cannot fail for any
mutation of that pass (a pure addition into a sort -u union), and the four membership cases are now
subsumed by the delta assertion, but both stay, the first because it makes the delta two-sided, the
second because it names the offending token in the failure output; and finding 5's new docstring
paragraph sits directly above "The comparison is over resolved file paths...", briefly stealing that
sentence's antecedent, which is not worth moving a reviewed tree.

Re-verified independently rather than taken from the author's notes: the new pass matches exactly one
file and yields exactly the four names; the dictionary delta is those four lines and nothing else;
the failing job's log lists the same four, so the gap the fix closes is the complete one; the control
arm's mutation anchor occurs exactly once, so it disables the new pass and not an earlier one; the
generator is deterministic on a fixed tree; the loop-variable claim holds for each of columns, files
and settings (gtest_NestedUtils.cpp, UserDefinedSQLObjectsBackup.cpp, a braced-literal loop over
compression-codec setting names); bash -n and shellcheck clean.

@clickhouse-gh clickhouse-gh Bot closed this Sep 20, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 20, 2026
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [33cfaa3]

Summary: ✅


AI Review

Summary

This PR extends tests/fuzz/generate_source_dict.sh so the source-derived fuzzer dictionary also captures loop-registered internal function names from src/Functions/grouping.cpp, then adds build-time self-checks to make that extractor fail loudly if it stops matching or if a later filter drops the extracted names. I reviewed the current diff, the full modified script, and all prior discussion on the PR, and I did not find a remaining correctness or CI-surface issue in the current version.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 20, 2026
assert len(treatment) == len(control) + 1


class TestLoopRegisteredNamesReachTheDictionary:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test guards nothing at merge. Replace it with a runtime assertion that checks the job consistency where the code runs. Otherwise the fix looks good.

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 c91b3a3: the class is gone and the check is in generate_source_dict.sh, which runs in the fuzzers build, where CMakeLists.txt turns a non-zero exit into a FATAL_ERROR, and in the nightly job.

Two checks, after the dictionary is written:

  • the loop-registration pass has to extract at least one name, so an edit to either half of its pattern (the range-for header, or the register* call reached from it) fails the build instead of quietly shortening the dictionary;
  • every name it extracts has to be in the output, so a filter between the two cannot drop the internal __ names again, which is how update_dict.sh found them missing.

Both arms measured, against a script the checks leave byte-identical at 6751 tokens: the pass matching nothing exited 0 with 6747 tokens before and exits 1 now; the __ filter dropping internal names exited 0 with 6738 tokens and now exits 1, naming __groupingOrdinary. ./src is in the fuzzers build digest, so a change to the registration form re-runs that build rather than cache-hitting it.

One property did not survive the move: the deleted test also pinned the exact token delta, which is what catches a widened pattern adding names the binary does not have. Reproducing that at runtime needs the four expected names written into the generator, and then any new loop-registered function breaks the build, so I left it out; the coverage check in update_dict.sh is binary-minus-source only.

ci/tests/ is wired into no CI job, so the regression class this PR added for
the loop-registered names could not fail a check at merge. Replace it with two
checks inside generate_source_dict.sh, which runs in the fuzzers build, where
CMakeLists.txt turns a non-zero exit into a FATAL_ERROR, and in the nightly
libFuzzer job:

  - the loop-registration pass has to extract at least one name, so an edit to
    either half of its pattern (the range-for header, or the register* call
    reached from it) fails the build instead of quietly shortening the
    dictionary;
  - every name it extracts has to be in the output, so a filter between the two
    cannot drop the internal __ names again, which is how update_dict.sh found
    them missing.

Both arms measured, against a script the checks leave byte-identical (6751
tokens, exit 0):

  - the pass matching nothing: exit 0 and 6747 tokens before, exit 1 now;
  - the __ filter dropping internal names: exit 0 and 6738 tokens before,
    exit 1 now, naming __groupingOrdinary.

Requested in review.
Comment thread tests/fuzz/generate_source_dict.sh Resolved
The check added in the previous commit compared the raw loop matches against the
output, but the dead code filter legitimately drops a name whose only carrier
sits in an #if 0 region, so the generator failed on a tree that is correct.

Reproduced with a source root whose sole carrier is an #if 0 copy of the grouping
loop: exit 1 naming __groupingOrdinary before, exit 0 with no grouping name in
the output now. The same root with the region enabled still yields all four
names, so the arm is not passing because the pass matches nothing there.

Both earlier arms still fail as they should: the pass matching nothing, and the
__ filter dropping the internal names.

Reported in review.
@alexey-milovidov alexey-milovidov self-assigned this Sep 27, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 27, 2026
Merged via the queue into ClickHouse:master with commit 87f442d Sep 27, 2026
176 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 27, 2026
alexey-milovidov pushed a commit to raimannma/ClickHouse that referenced this pull request Oct 30, 2026
…zer dictionary

src/Functions/icebergDateTransforms.cpp (ClickHouse#118583) names each specialization
of its class template with an immediately-invoked lambda:

    static constexpr const char * name = []
    {
        if constexpr (transform == IcebergDateTransform::Year)
            return "icebergYear";
        else if constexpr (transform == IcebergDateTransform::Month)
            return "icebergMonth";
        ...
    }();

The name-constant pass of tests/fuzz/generate_source_dict.sh takes an
initializer up to its first ';', which here ends the lambda's first return
statement, so only icebergYear reached the source-derived dictionary. The
binary also registers icebergMonth, icebergDay and icebergHour, so the
coverage check in tests/fuzz/update_dict.sh exits 1 and the nightly
libFuzzer tests job stops before any fuzzer runs. The 2026-09-28 master run,
which already has ClickHouse#121242, failed on exactly those three names.

The pass now also accepts an immediately-invoked lambda with a brace-free
body, taken up to its closing '}();'. The same alternation goes into the
copy of the pattern that collects aggregate function names for the
combinator expansion, so a lambda-named aggregate function also gets its
<name><combinator> tokens. dictionaries/old.dict is not used: it holds names
composed at compile time, and these are plain literals.

Measured on this tree: the dictionary goes from 6995 to 6998 tokens, the
added lines are exactly those three names and nothing is removed; of the
pass's 1643 matches only the iceberg one changes, and the aggregate copy's
output is unchanged. With a master debug binary the coverage check goes from
exit 1 to exit 0; the failing job's log shows the same 6995 tokens and the
same three names with the release binary CI runs. A lambda body with braces
still falls back to the first ';', and the coverage check names what is
missing, as it did here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-fuzzing Fuzzers: BuzzHouse (the query generator in the client), the AST fuzzer (QueryFuzzer), and the lib... 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-fuzzing Fuzzers: BuzzHouse (the query generator in the client), the AST fuzzer (QueryFuzzer), and the lib... groeneai-origin-request PR origin: a maintainer pinged or directed groeneai manual approve Manual approve required to run CI 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.

libFuzzer tests job fails: 4 __grouping* names missing from source dict

4 participants