Skip to content

Make the remembered verdict of 05324_adaptive_aggregator_disable_thaw independent of how numbers_mt splits rows - #128084

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-05324-adaptive-aggregator-disable-thaw
Nov 6, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-flaky-05324-adaptive-aggregator-disable-thaw

Conversation

@groeneai

@groeneai groeneai commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #123531

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

05324_adaptive_aggregator_disable_thaw failed 3 times in 30 days on unrelated PRs, always with Remembered verdict 1 0 1 1 instead of 1 1 1 1: amd_debug, arm_binary, amd_debug, s3 storage.

The second run of the last cell was not refused the adaptive aggregator. The verdict that the first run stores is a vote of threads: it needs half of the producers whose tables froze to be repeat-dominated (Aggregator::adaptiveStagingVerdict). numbers_mt(2000000) gives its 4 streams blocks from one shared cursor and there is no resize before the aggregation, so under load one thread can read most of the 245 blocks. That thread thaws, but the other threads froze on a few blocks, have too little staged evidence to count as repeat-dominated, and outvote it.

The last cell now runs on two threads. Of two producers, the one that reads at least half of the input always thaws, and its vote alone is half of the frozen producers, so the verdict is positive for any split. The counters of the other cells need only one thread to thaw or stage records, which holds for any split, so they keep four threads.

Validation: with a local patch (not in this PR) that gives one block to every stream but the first in the first numbers_mt query, the old cell prints 1 0 1 1 20/20 (the trace shows a 1975424/8192/8192/8192 split, one thaw, and a stored verdict of false) and the new one 1 1 1 1 20/20. Without hash-table statistics, or with the verdict forced to false, the new cell fails, so the assertion is still live. 100 direct runs and 50 runs each with and without -j 8 pass.


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

Version info

  • Merged into: 26.11.1.1531-master (included in 26.11 and later)

… independent of how numbers_mt splits rows

The last cell expects its first run to store a positive staging verdict so
that the second run is refused the adaptive aggregator. That verdict is a
vote of threads: `Aggregator::adaptiveStagingVerdict` needs half of the
producers whose tables froze to be repeat-dominated, and a producer is
repeat-dominated only if it thawed or, still frozen, staged at least 65536
records that repeat past the bound.

`numbers_mt(2000000)` gives its 4 streams 8192-row blocks from one shared
cursor, and `system.numbers` reads are treated as evenly distributed, so
there is no resize before the aggregation: each producer gets exactly the
blocks its source grabbed. Under load one thread can read most of the 245
blocks. It thaws, but the other three froze on a block or a few and vote
"not dominated", so the stored verdict is false, the second run freezes and
thaws again and the cell prints `1 0 1 1`, as in all three CI failures.

Run the last cell on two threads. The producer that reads at least half of
the input (1000000 rows over 20000 keys) always thaws, and its vote alone is
half of the frozen producers, so the verdict is positive for any split,
including 2000000/0. Two streams keep the cell on the adaptive path. The
other cells only assert that some thread thawed or staged records, which
holds for any split, and keep four threads.

With a local patch that gives one block to every stream but the first in
the first numbers_mt query of the process, the old cell printed `1 0 1 1` in
20 of 20 runs (run 1 split 1975424/8192/8192/8192, one thaw, verdict
`adaptive_staging_repeat_dominated=false`) and the new one `1 1 1 1` in 20 of
20; the whole old test failed 10 of 10 with the CI diff and the new one
passed 10 of 10. Without hash-table statistics, or with the verdict forced
to false, the new cell prints 0 in column 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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; 0 findings), plus my own cold review of the diff (0 findings).

No findings to adjudicate. Checked: the stored verdict is 2 * repeat_dominated_producers >= frozen_producers, so with two producers the one that reads at least half of the input decides it for any split (including 2000000/0); two streams keep the cell on the adaptive path; the other cells' counters need only one thread to thaw or stage records; no other test relies on a four-thread numbers_mt vote.

Session id: cron:clickhouse-review-slot-8:20261028-190800

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A local patch (not in the PR) makes the first numbers_mt query give one block to every stream but the first: the old cell prints 1 0 1 1 20/20, the whole old test fails 10/10 with the CI diff.
b Root cause explained? The stored verdict is a vote of threads (half of the frozen producers must be repeat-dominated). numbers_mt lets one thread read most blocks; it thaws, the other frozen threads lack the staged evidence and outvote it, so run 2 is not refused.
c Fix matches root cause? Yes. With two producers the one that reads at least half of the input always thaws and wins the vote, for any split. No bound widened, no tag, no randomization disabled.
d Test intent preserved / new tests added? Yes. All four columns keep their meaning; column 2 still fails without hash-table statistics and with the verdict forced to false. Test-only fix.
e Both directions demonstrated? Yes. Same forced split: old cell 1 0 1 1 20/20, new cell 1 1 1 1 20/20; whole test FAIL 10/10 vs OK 10/10.
f Fix is general across code paths? Yes. The other cells assert only that some thread thawed or staged (holds for any 4-way split); the sibling verdict tests already read four numbers(offset, N) branches.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes for this cell: the guarantee holds for every 2-way split, including 2000000/0. Types/wrappers N/A (test-only).
h Backward compatible? (maintainer-approved exception only) N/A, test-only change.
i Invariants and contracts preserved? Yes. Run 1 freezes and thaws, run 2 is refused, run 3 freezes with the thaw disabled and records no verdict, run 4 is refused; two streams keep the adaptive path enabled.

Session id: cron:clickhouse-impl-slot-5:20261028-180400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nihalzp, could you review this and add the can be tested label so CI runs? The last cell of 05324_adaptive_aggregator_disable_thaw now runs on two threads, because with four numbers_mt streams one thread can read most blocks and get outvoted by threads that froze on too little staged evidence, so the second run was not refused.

@clickhouse-gh

clickhouse-gh Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c2b42e2]

Summary: ✅


AI Review

Summary

The PR stabilizes 05324_adaptive_aggregator_disable_thaw by running its remembered-verdict cell with two threads. This makes a thawed producer sufficient for the stored verdict under uneven numbers_mt input splits while preserving all four assertions. No actionable findings. The reported deterministic reproduction and 50 passing debug flaky-check runs provide adequate evidence for this test-only change.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Oct 28, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 616d6f3

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
Fast test (arm_darwin) / 05397_clickhouse_local_locked_path_untouched not from this PR (its diff changes only 05324): the test holds the status lock with flock(1), which macOS does not have, so the second clickhouse local never starts. It fails on every arm_darwin run since it landed (44 PRs in 14 days) #128088 (mine, open; its own Fast test (arm_darwin) passed)
Stateless tests (arm_binary, parallel) / 05055_format_schema_source_query_background_access flaky, not from this PR: session_timezone Africa/Khartoum puts the session date ahead of the server date, so the text_log filter misses the row (69 PRs in 14 days). The tested merge tree predates the fix #127797 (mine, merged)
Mergeable Check, PR praktika rollups of the rows above #128088, #127797 (the owners of the rows above)

The changed test passed all five stateless flaky check builds, and CH Inc sync is green. The earlier Config Workflow failures were the attempts before the can be tested label.

Session id: cron:our-pr-ci-monitor:20261029-000003

@alexey-milovidov alexey-milovidov self-assigned this Nov 6, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Nov 6, 2026
Merged via the queue into ClickHouse:master with commit b8b277d Nov 6, 2026
186 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 Nov 6, 2026
@clickhouse-gh clickhouse-gh Bot added comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). 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

blocker This issue / pr blocks a new release can be tested Allows running workflows for external contributors comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). 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