Skip to content

Fix flaky test 05097_adaptive_aggregator_heap_state_valve_memory - #124289

Merged
nihalzp merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-05097-shared-table-line
Oct 7, 2026
Merged

nihalzp merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-05097-shared-table-line

Conversation

@groeneai

@groeneai groeneai commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #123673
Related: #117880

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

05097_adaptive_aggregator_heap_state_valve_memory printed the shared table was written at the part bound 0 in Stateless tests (arm_binary, parallel) on #123673, a FileLog-only PR. Every other line held. That is 1 failure in about 131k runs since the test landed in #117880, and 0 on master.

The line asserts an optional path. A pressure sweep's claim that reaches a part goes to a producer-local table. Only a smaller tail is drained into the shared table, and AdaptiveAggregationSharedTableSpills counts that table when it reaches the part bound. When the query's memory falls below the spill threshold (max_bytes_before_external_group_by) between crossings, the backlog has grown past a part at every sweep. Every claim then goes producer-local, and the shared table never reaches the bound. That is the designed routing. Whether a run ends up there depends on where its memory floor sits against the threshold. With the test's own query at a 45 MB threshold (limit 450 MB), 40 of 80 runs read 0, all with exact totals and every other claim held.

This PR removes the line and its reference and rewrites the header sentence about it.

The tail detach the line witnessed is still caught: with it deleted from drainStagedChunksBatchUnderMemoryPressure, 04650, 05059, 05076, 05099 and 05100 fail in 5 of 5 runs (Code: 241, or a spill counter at 0). Without the deletion they pass 5 of 5. What is given up: no test asserts AdaptiveAggregationSharedTableSpills any more, so this heap-state shape is no longer proven to take the shared-table path; that would need another shape or a new observable.

Validation: the new test matches its reference on debug, ASan and amd_binary; --test-runs 50 -j 50 50/50 OK; 0/400 diffs under the SIGPROF thread fuzzer.

Note: #123531 deletes this test as part of an aggregator rewrite.

🤖 Generated with Claude Code


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

Version info

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

The line `the shared table was written at the part bound` asserted an
optional path of the pressure valve. A sweep's claim that reaches a part
goes to a producer-local table, and only a tail smaller than a part is
drained into the shared table, which `AdaptiveAggregationSharedTableSpills`
counts when it reaches the part bound. When the query's memory falls below
`max_bytes_before_external_group_by` between crossings, the backlog has
grown past a part at every sweep, every claim goes producer-local, and the
shared table only gets the finish drain's remainder, below the bound. The
counter then stays 0 with exact results and every other claim intact.

Which regime a run settles in depends on where its memory floor sits
against the threshold. With the test's own query, one fresh
clickhouse-local per run: 0 in 15 of 50 runs at a 40 MB threshold and in
43 of 80 (re-measured: 40 of 80) at 45 MB, while 20 MB gave a minimum of 3
over 2,250 runs, including the SIGPROF thread fuzzer. CI hit the zero once
in about 131k runs, on `Stateless tests (arm_binary, parallel)`.

Remove the line and its reference, and say in the header why the path is
not asserted. The tail detach stays covered: deleting it from
`drainStagedChunksBatchUnderMemoryPressure` fails 04650, 05059, 05076,
05099 and 05100 in every run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Oct 6, 2026
@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding), plus my own review of the same tree (2 nits).

# Sev Finding Verdict Evidence / action
1 ⚠️ Removing the only AdaptiveAggregationSharedTableSpills assertion leaves the shared-table path without coverage DISAGREE Deleting the tail detach still fails 04650, 05059, 05076, 05099, 05100 in 25 of 25 runs (control: 25 of 25 pass); the 10x max_memory_usage cell, which stays, guards the accounting. Residual stated in the description: nothing now shows this shape reaches the shared table's write.
2 💡 Description did not say what the removal gives up AGREE, fixed in the description one sentence added
3 💡 Header comment simplifies the regime condition noted, not blocking the description states it precisely

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-11:20261006-171100

@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? The test's own query at a 45 MB threshold (450 MB limit) reads AdaptiveAggregationSharedTableSpills = 0 in 40 of 80 runs on the base amd_binary, each with exact totals; the CI schedule at 20 MB did not recur in 2,250 local runs.
b Root cause explained? A claim that reaches a part goes producer-local; when memory dips below the threshold between crossings every claim does, so the shared table never reaches the bound (designed routing).
c Fix matches root cause? The line asserts an optional engine path, not a result, so it is removed. No bound is widened and nothing is retried.
d Test intent preserved / new tests added? All correctness claims stay (exact totals, 10x memory cell, external, valve, freeze, drain > 500000, no thaw/stand-down); the tail detach deletion still fails 04650, 05059, 05076, 05099, 05100 5/5.
e Both directions demonstrated? Old line: 0 in 40/80 at 45 MB, 10/10 with the tail detach deleted. New test: 20/20 on debug, ASan, amd_binary; 50/50 --test-runs 50 -j 50; 400/400 under the SIGPROF fuzzer.
f Fix is general across code paths? N/A (test-only). No other test reads AdaptiveAggregationSharedTableSpills.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only).
h Backward compatible? (maintainer-approved exception only) N/A (no source or settings change).
i Invariants and contracts preserved? N/A for source. The counters are still read in the test's own clickhouse-local process.

Session id: cron:clickhouse-impl-slot-4:20261006-155600

@clickhouse-gh

clickhouse-gh Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3189d14]

Summary: ✅


AI Review

Summary

This PR removes the flaky AdaptiveAggregationSharedTableSpills assertion from 05097_adaptive_aggregator_heap_state_valve_memory. That addresses the immediate intermittency, but it also removes the only direct check of the shared-tail spill path, so the test no longer proves the shared-table accounting route described in the header still works.

Findings
  • ⚠️ Majors
    • [tests/queries/0_stateless/05097_adaptive_aggregator_heap_state_valve_memory.sh:24] Removing the AdaptiveAggregationSharedTableSpills assertion drops the only direct coverage of the shared-tail spill path. That path accounts memory through shared.early_drain_tracked_bytes and sharedDrainTableBytes in src/Interpreters/AdaptiveAggregationKernels.cpp:2025 and src/Interpreters/AdaptiveAggregationKernels.cpp:2048, while producer-local drains correct the reservation through a different code path in src/Interpreters/AdaptiveAggregationKernels.cpp:2099. After this change the test still passes whenever every pressure claim routes producer-local, so a regression in the shared-table spill trigger or accounting can slip through unnoticed.
    • Suggested fix: reshape this workload so it deterministically reaches the shared-table spill path again, or add a small dedicated stateless test that asserts that path through another stable observable.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required action: restore deterministic coverage of the shared-table spill path instead of deleting the only direct assertion for it.

# spill. The thresholds are pinned because the runner randomizes them, and `max_memory_usage` is the
# cell that encodes the claim: ten times the threshold the query asked to spill at.
# table, so the shape usually covers that table's path to disk as well as the producer-local one.
# That is not asserted: when the backlog has grown past a part at every crossing, every batch goes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fixes the flake, but it also drops the only direct check of the shared-tail spill path. The remaining assertions still prove that pressure drains happened, yet they no longer prove that the shared residue ever crossed the part bound. That matters because the shared path accounts memory through shared.early_drain_tracked_bytes / sharedDrainTableBytes in src/Interpreters/AdaptiveAggregationKernels.cpp, while producer-local drains correct their reservation through a different code path. After this change, a regression in the shared-table spill trigger or accounting can pass unnoticed whenever every pressure claim routes producer-local.

Can we keep a deterministic assertion for the shared-table path here, or add a tiny dedicated stateless test that exercises it directly?

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 6, 2026
@nihalzp nihalzp self-assigned this Oct 7, 2026
@nihalzp
nihalzp added this pull request to the merge queue Oct 7, 2026
Merged via the queue into ClickHouse:master with commit 8c4cf25 Oct 7, 2026
149 of 150 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 7, 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

can be tested Allows running workflows for external contributors comp-aggregation GROUP BY / aggregation framework (hash tables, spilling, external aggregation). groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect 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