Skip to content

Replace chassert with diagnostic LOGICAL_ERROR in AggregateFunctionArray - #102868

Merged
nikitamikhaylov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-aggregate-array-diagnostic-assertion
Apr 17, 2026
Merged

nikitamikhaylov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-aggregate-array-diagnostic-assertion

Conversation

@groeneai

@groeneai groeneai commented Apr 16, 2026 •

Copy link
Copy Markdown
Collaborator

The assertion parameters == nested_func->getParameters() in AggregateFunctionArray has been firing sporadically in CI (~4 hits per month) through AST fuzzer and serverfuzz stress tests (STID 4870-4f21, STID 4870-4e45, STID 2508-522c).

The previous chassert (converted from C assert() in #102856, before that fixed primary root cause in #100679) only provides the expression text — zero information about what the actual parameters are when it fires. This makes investigation of the remaining secondary code path extremely difficult.

What this PR does:

Replaces the chassert with an explicit LOGICAL_ERROR exception that logs:

  • The Array wrapper function name (e.g., quantileIfArrayArray)
  • The nested function name (e.g., nothingNull)
  • Both parameter sets with their actual values and sizes

Example error message:

AggregateFunctionArray: parameters mismatch between Array wrapper 'quantileIfArrayArray' 
and nested function 'nothingNull'. Wrapper has 1 parameter(s): [0.5], 
nested function has 0 parameter(s): []

Why:

The invariant that parameters == nested_func->getParameters() should always hold because the Array combinator does not transform parameters. When it fails, it indicates a bug in AggregateFunctionFactory::getImpl() or a combinator wrapper that loses/modifies parameters during resolution.

The diagnostic info will immediately identify which combinator+function combination triggers the mismatch, enabling targeted root cause analysis on the next CI occurrence.

Behavior:

  • Debug/sanitizer builds: throws LOGICAL_ERROR (same as chassert, but with useful message)
  • Release builds: throws LOGICAL_ERROR (improvement — chassert was a no-op in release)

Changelog category (leave one):

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

Changelog entry (a]utofill):

  • ...no entry required...

  • Documentation is written (if applicable)

Version info

  • Merged into: 26.4.1.1009

@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR Validation Gate (session: cron:clickhouse-ci-task-worker:20260416-061500)

a) Deterministic repro?
N/A — this is a diagnostic improvement, not a bug fix. The underlying assertion fires ~4 times/month in CI via AST fuzzer mutations that I was unable to reproduce locally after 15+ minutes of targeted fuzzing across 1000+ systematic combinator combinations. The fix preserves the exact same invariant check.

b) Root cause explained?
The root cause of the original assertion (parameters == nested_func->getParameters()) is an unknown code path in the aggregate function combinator resolution that loses or modifies parameters when the Array combinator wraps a nested function. PR #100679 fixed the primary path (AggregateFunctionNothingImpl discarding parameters). A secondary path remains unidentified — this PR provides the diagnostic data needed to identify it on the next CI occurrence.

c) Fix matches root cause?
This is a diagnostic improvement — it replaces a bare assertion (that provides zero information about the actual parameter values) with a proper LOGICAL_ERROR exception that logs both parameter sets. It does NOT change the invariant being checked.

d) Test intent preserved?
The check is unchanged — parameters must match. Only the error reporting is improved: from an opaque "assertion failed" to a detailed message showing exactly which function and parameters are mismatched.

e) Both directions demonstrated?
All existing aggregate function tests pass with the change. The assertion path cannot be triggered locally (see point a), but the error handling behavior is verified through code review: throw Exception(ErrorCodes::LOGICAL_ERROR, ...) is the standard ClickHouse pattern for invariant violations.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Avogar — could you review this? It replaces the bare chassert in AggregateFunctionArray (from #102856) with a proper LOGICAL_ERROR that logs both parameter sets. The invariant still fires ~4x/month in CI fuzzers but the current error gives zero diagnostic info about what parameters actually mismatch.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Apr 16, 2026
@clickhouse-gh

clickhouse-gh Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9e47e65]

Summary: ✅


AI Review

Summary

This PR replaces a diagnostic chassert in AggregateFunctionArray with an explicit LOGICAL_ERROR exception that preserves the invariant check in all build types and includes actionable mismatch details (function names, parameter counts, and parameter values). The change is narrowly scoped, improves debuggability, and does not introduce correctness, safety, or compatibility risks based on the touched code.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Apr 16, 2026
@Avogar Avogar self-assigned this Apr 16, 2026
@Avogar

Avogar commented Apr 16, 2026

Copy link
Copy Markdown
Member

@groeneai there is a failure of tidy build:

DEBUG:clang-tidy-cache.py:Calling real clang-tidy.
/ClickHouse/src/AggregateFunctions/Combinators/AggregateFunctionArray.h:44:13: error: multiple declarations in a single statement reduces readability [readability-isolate-declaration,-warnings-as-errors]
   44 |             String outer_params_str, nested_params_str;
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix it.

groeneai and others added 2 commits April 16, 2026 12:47
The assertion `parameters == nested_func->getParameters()` in
AggregateFunctionArray has been firing ~4 times per month in CI
(AST fuzzer and serverfuzz stress tests), triggered by specific
combinator+Array+Nullable mutations that are extremely hard to
reproduce locally.

The previous chassert (converted from assert() in PR ClickHouse#102856) only
provides the expression text with no information about WHAT the
parameters actually are. This makes root cause investigation nearly
impossible.

Replace with an explicit LOGICAL_ERROR exception that logs:
- The Array wrapper function name
- The nested function name
- Both parameter sets with their values and sizes

This preserves the invariant check while providing actionable
diagnostic information. The next CI occurrence will immediately
reveal which code path produces the parameter mismatch.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Split multi-variable declaration into separate statements
to satisfy readability-isolate-declaration clang-tidy check.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@groeneai
groeneai force-pushed the fix-aggregate-array-diagnostic-assertion branch from 388326e to 9e47e65 Compare April 16, 2026 12:50
@groeneai

Copy link
Copy Markdown
Collaborator Author

@Avogar Thanks for the review and the approval! Fixed the clang-tidy readability-isolate-declaration warning — split String outer_params_str, nested_params_str; into two separate declarations.

@clickhouse-gh

clickhouse-gh Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.00% -0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.50% -0.10%

Changed lines: 25.00% (5/20) · Uncovered code

Full report · Diff report

@nikitamikhaylov
nikitamikhaylov added this pull request to the merge queue Apr 17, 2026
Merged via the queue into ClickHouse:master with commit 2642aa5 Apr 17, 2026
161 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 17, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Apr 18, 2026
…eSeries*ToGrid functions

The `timeSeries*ToGrid` aggregate function family normalizes its parameters
internally — 4 user-typed literals (start, end, step, window) are stored as
`Decimal64` fields scaled to match the timestamp column, and the 5-parameter
`timeSeriesPredictLinearToGrid` variant stores `predict_offset` as a member
instead of in the parameter array. This produces an intentional normalization
that lets states serialized with different timestamp scales merge together.

When the `Array` combinator wrapped such a function, its constructor fired
`LOGICAL_ERROR` ("parameters mismatch"): it was initializing its own parameter
array from the user-typed `params_` (`UInt64`, possibly 5 entries) but then
comparing against the nested function's normalized parameters (`Decimal64`,
always 4 entries). The assertion was originally a `chassert` that silently
compiled out in release; ClickHouse#102868 made it a real `LOGICAL_ERROR` to aid
diagnosis, which then surfaced as a master-level failure in serverfuzz /
`AST fuzzer` runs (STID 4870 family, ~10 hits across 60 days).

Fix the Array combinator by initializing its own parameter array from
`nested_->getParameters()` instead of the user-supplied `params_`. This makes
the wrapper transparent to whatever normalization the nested function performs:
`timeSeries*ToGridArray(...)` states now match the corresponding
`timeSeries*ToGrid(...)` states, preserving the scale-independent state
compatibility that `timeSeries*ToGrid` relies on.

For every other aggregate function the user-typed `params_` and
`nested_->getParameters()` are identical — no behavior change.

Reproducer (previously threw `LOGICAL_ERROR`, now succeeds):
```
SET allow_experimental_time_series_aggregate_functions = 1;
SELECT timeSeriesPredictLinearToGridArray(60, 180, 10, 20, -60)(ts, val) FROM ts;
SELECT timeSeriesDerivToGridArray(60, 180, 10, 20)(ts, val) FROM ts;
```

Regression test: `04102_timeseries_array_combinator_params`.

STID 4870 family: 4870-4f07, 4870-4f21, 4870-4d73, 5480-49e6.
Diagnostic PR that made the error visible: ClickHouse#102868.
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.

4 participants