Skip to content

Replace the AggregatingInOrderTransform cancellation test with a failpoint integration test - #114756

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/aggr-in-order-cancel-failpoint-test
Aug 16, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/aggr-in-order-cancel-failpoint-test

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Related: #110104
Related: #107941

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

04512_aggregation_in_order_cancellation.sh guards the per-key-interval cancellation check from
#110104, but asserts on aggregation CPU as a multiple of scan CPU after a shell-issued KILL. It
prints not cancelled in time on master again: 6 such failures on 2026-08-13 (2 on master, 4 on
unrelated PRs), 5 on amd_asan_ubsan, distributed plan, parallel. Eighth rewrite of the assertion.

The oracle prices the window between "rows are read" and "the KILL flips is_cancelled", and two
clickhouse-client startups sit on that path; 04410_primes_source_cancellation.sh:48-49 records
~8 s for one invocation on a loaded sanitizer build. On all five failures that printed the CPU
diagnostics the checkpoint was firing, stopping at 48-75 % of the loop, not 100 %: only the window
grew, and the shell cannot close it, since read progress is published only after the source's
work() returns (ExecutionThreadContext.cpp:57-75).

So this adopts the mechanism LimitByTransform already uses (e20a67394329867 and follow-ups):
a PAUSEABLE_ONCE failpoint on interval 6, after the cancellation check and inside the loop, a
LOG_TEST marker in the existing cancellation branch, and an integration test that pauses there,
kills, resumes and asserts the marker appears exactly once. No timing, no threshold, no free
constant. Exactly once, not merely present: is_cancelled latches, so dropping only the return
prints the marker once per remaining interval (94 here) while every other assertion still passes.
Mid-loop matters for the same reason: a pre-loop pause resumes straight into the first
isCancelled(), staying green with that check hoisted out of the loop, which is what #110104 fixed.

All three mutations (checkpoint deleted, check hoisted, return deleted) redden the new test, the
failpoint still pausing in each so no arm is vacuous. Removing SYSTEM ENABLE FAILPOINT fails
loudly; test_limit_by_transform_kill_query stays green. Hot-path cost is not measurable, and
dropping the 40 M-row fixture removes its max_estimated_execution_time exposure.

04409_skip_index_build_cancellation.sh has a weaker form of the same pattern (bounded
KILL ... SYNC at timeout 10); left unchanged.

…point integration test

04512_aggregation_in_order_cancellation.sh guards the per-key-interval cancellation
check added in ClickHouse#110104, but it asserts on a measured quantity: aggregation CPU as a
multiple of scan CPU, after a shell-issued KILL. It has now been rewritten eight times
and prints "not cancelled in time" on master again (5 failures in 24 h on 2026-08-13,
2 of them on master, all on amd_asan_ubsan / distributed plan / parallel).

The oracle prices the window between "the rows are read" and "the KILL flips
is_cancelled", and two fresh clickhouse-client process startups sit on that critical
path. 04410_primes_source_cancellation.sh:44-49 records the in-tree figure: a single
client invocation alone can take ~8 s on a loaded sanitizer build. The checkpoint was
firing on every failing run, stopping at 52-75 % of the loop rather than 100 %; only
the window grew. The race cannot be closed from the shell either, because read progress
is published after the source's work() returns (ExecutionThreadContext.cpp:57-75), so
nothing shell-visible indicates that the aggregation loop is running.

Adopt the deterministic mechanism LimitByTransform already uses (e20a673, then
d811a21 and 0fa0ea3): a PAUSEABLE_ONCE failpoint on the sixth key
interval, placed after the cancellation check and inside the loop, plus a LOG_TEST
marker in the existing cancellation branch. The new integration test pauses there,
kills the query, resumes, and asserts the marker appears. That assertion is structural
and load-invariant, with no timing, threshold or free constant.

The mid-loop placement is deliberate. A pre-loop pause would resume straight into the
first isCancelled(), so the test would stay green even if that check were hoisted out
of the loop, which is precisely the bug ClickHouse#110104 fixed. Both mutation arms were verified
to redden: deleting the checkpoint, and hoisting it out of the loop.

Deleting the 40 M-row fixture also removes its max_estimated_execution_time exposure on
slow storage, which was a second, independent failure mode of the same test.

The failpoint costs nothing when disabled: pauseFailPoint expands to
if (fiu_fail(name)) [[unlikely]] and sits behind an integer compare, so it is reached at
most once per consume(). Measured over 40 M key intervals, base vs patched interleaved:
11.515 s vs 11.503 s user CPU.

The marker assertion counts lines rather than testing for presence. The marker is
emitted inside the cancellation branch and isCancelled() reads an atomic that stays
true once set, so deleting only the return re-enters the branch on every remaining
iteration: the marker would print once per key interval while the loop still
aggregates to completion. Requiring exactly one line rejects that mutation (94 lines
on the 100-interval fixture) and keeps rejecting a deleted or hoisted check (0 lines),
with no timing term.
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds, 0 open blockers)

An independent reviewer and a second model reviewed this change cold, without the author's
evidence, over two rounds. All findings are resolved; nothing is deferred.

Finding Verdict
❌ The test asserted only that the cancellation marker was present. Because is_cancelled latches, deleting just the return would print the marker once per remaining interval (94 on this fixture) and every assertion would still pass, so the mutation that removes the promptness this test protects was invisible. The deleted 04512 CPU-ratio oracle did catch it. Agreed, fixed. The assertion is now an exact count of 1. Re-verified: 1 with the fix, 0 with the checkpoint deleted or hoisted, 94 with only the return deleted.
⚠️ Is exact equality flake-prone? No, and it is structural rather than empirical. PipelineExecutor::cancel sets finished = true and every executor dispatch loop is gated on !tasks.isFinished(), while work() reaches consume() only while !is_consume_finished && !need_generate - neither of which the cancel-return sets. With one chunk at max_threads = 1 there is a single transform instance, and grep_in_log filters on a fresh per-run query_id. The count is 1 by construction.
💡 Two citations in the description were stale: a line range for the client-startup measurement, and a sentence describing the older presence-only assertion. Both corrected before publication.
💡 04409_skip_index_build_cancellation.sh carries a weaker form of the same pattern. Left unchanged, disclosed in the description. Its bound is a 10 s wall-clock ceiling rather than a work ratio, and 0 of its failures are on master.

Checks re-run independently rather than carried over: the failure counts quoted in the
description were re-measured in the CI database and match; the PR template headers were
re-fetched from master and are byte-identical; the src/ diff adds 14 code lines and 0
comments; git grep finds no remaining reference to the deleted test.

@clickhouse-gh

clickhouse-gh Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ca72e0f]

Summary: ✅


AI Review

Summary

This PR removes the flaky stateless 04512_aggregation_in_order_cancellation.sh test and replaces it with a failpoint-backed integration test for the AggregatingInOrderTransform mid-loop cancellation checkpoint. I did not find a correctness, safety, or coverage issue in the current patch: the new failpoint and LOG_TEST hook follow the existing LimitByTransform pattern, and the replacement test checks the intended invariant without relying on the old timing oracle.

Final Verdict

✅ No findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.10% 79.10% +0.00%

Changed lines: Changed C/C++ lines covered: 14/14 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the defect under fix. Mutation arm 2b puts the source into the exact pre-#110104 shape and the new test then fails on every run, with no timing term. The CI flake itself is a load artifact (client-startup latency) and is dissolved by deleting the timing oracle rather than reproduced.
b Root cause explained? Yes. The deleted test asserted aggregation CPU as a multiple of scan CPU after a shell KILL. Two clickhouse-client startups sit between "rows are read" and "is_cancelled flips"; 04410_primes_source_cancellation.sh:48-49 records ~8 s for one invocation on a loaded sanitizer build. The checkpoint fired on every failing run (52-75 % of the loop, not 100 %); only the window grew. The race is also unsynchronisable from the shell: read progress publishes after the source's work() returns (ExecutionThreadContext.cpp:57-75).
c Fix matches root cause? Yes. It removes the measured quantity entirely instead of retuning it. No widened bound, no no-random-* tag, no dataset reduction on a surviving assertion. Seven previous rounds each swapped one constant or metric.
d Test intent preserved / new tests added? Yes, and strengthened. The old oracle could only observe "the loop stopped early"; the new test asserts the specific checkpoint logged the cancellation exactly once, which also rejects deleting only the return (the branch is re-entered while the flag stays set). Coverage is not dropped: a new integration test replaces the deleted stateless one.
e Both directions demonstrated? Yes, with distinct Build IDs asserted on the running server each time. Fixed: PASS on 5/5 repeats, marker count 1. Arm 2a (checkpoint deleted): FAIL, count 0. Arm 2b (check hoisted out of the loop): FAIL, count 0. Arm 2c (LOG_TEST kept, only return removed): FAIL, count 94. In all three failing arms the failpoint still paused and the query was still cancelled, so no arm is vacuous. Restoring the fix reproduced the fixed arm's Build ID byte for byte. Removing SYSTEM ENABLE FAILPOINT also fails loudly rather than passing silently.
f Fix is general across code paths? Swept all 44 .sh tests containing KILL QUERY. Two further candidates surfaced and were read: 04409_skip_index_build_cancellation.sh carries a weaker form of the same pattern (bounded KILL ... SYNC, 2 hits in 30 days of this class, both PR-only and non-reproducible on rerun) and is disclosed but left alone; 04039_merge_tree_snapshot_teardown_race.sh was refuted (readiness poll, binary reference).
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A: this change adds no input handling. Its one parameter is the interval index (5), reachable because the fixture yields 100 key intervals in a single chunk; an unreachable guard fails loudly on a 60 s timeout rather than passing silently.
h Backward compatible? Yes. No settings, no serialization format, no SettingsChangesHistory.cpp entry, no user-visible behaviour. The failpoint is inert unless explicitly enabled and compiles to nothing when libfiu is disabled.
i Invariants and contracts preserved? Yes. interval_index is a function-local counter incremented on every iteration including the empty-interval case, so it cannot skip past 5 and strand the pause. Existing early-return paths are untouched. The failpoint sits after the cancellation check and before any aggregation-state mutation, so a pause cannot interleave with a half-updated variants. No lock is held across the pause, so it cannot deadlock the executor; the resume completed in all 11 runs.

Session id: cron:clickhouse-impl-slot-4:20260814-031300

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nihalzp @nickitat, could you review this? It replaces the chronically flaky 04512_aggregation_in_order_cancellation.sh (which timed a shell-issued KILL against aggregation CPU) with the failpoint mechanism LimitByTransform already uses: a PAUSEABLE_ONCE failpoint inside the key-interval loop plus an integration test that asserts the cancellation marker is logged exactly once, so there is no timing term left to flake.

@clickhouse-gh

clickhouse-gh Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ca72e0ff5 with master 5c9f28ed5 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 694.55 MiB 691.54 MiB -3.01 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

8 translation units recompiled, 13 s compile time in total, 8 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 89355d8

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.

CI is fully finished on this head and there are no failures to own: 177 leaves, praktika
top-level OK, 0 dropped jobs, 153 success / 24 skipped (every skip carries a reason).

Check / test Reason Owner / fixing PR
(none) - -

Session id: cron:our-pr-ci-monitor:20260814-133000

@PedroTadim

Copy link
Copy Markdown
Member

cc @alexey-milovidov

@alexey-milovidov

Copy link
Copy Markdown
Member

Yes, this test should better be deleted. But I can merge this PR first.

@alexey-milovidov alexey-milovidov self-assigned this Aug 15, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov to be sure I follow up on the right one: this PR already deletes 04512_aggregation_in_order_cancellation.sh, which is the test that is currently red on master (6 failures since 2026-08-13, split between amd_asan_ubsan, distributed plan, parallel and amd_tsan, s3 storage, parallel), so merging as is resolves that.

If you also meant the new tests/integration/test_aggregating_in_order_transform_kill_query that replaces it, say so and I will open a follow-up removing it. That would leave the #110104 checkpoint without a test, which is your call. Either way it does not need to hold this merge.

@clickhouse-gh

clickhouse-gh Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 35 queries analysed

This PR only adds a test-only failpoint, a per-interval counter, and a cancellation-branch log line to the in-order aggregation transform; it changes no query-execution logic and can only add negligible work, never remove it. All 11 flagged results are improvements, so none can be caused by this change, and they have been downgraded to not_sure as run-to-run and co-location variance (the source ran fewer repetitions, and Q23 in particular was highly noisy). The large-delta rows (ClickBench Q23, TPC-H Q7 x8.1 faster and Q8 x2.2 faster) were not locked by the deterministic trust override and are treated the same way. No envelope-suppressed rows were present to reconcile.

clickbench

⚠️ 9 inconclusive

Flagged queries (9 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 13 not_sure 426 343 -19.6% <0.0001 aggregation: The PR only adds a test-only failpoint plus a counter to the in-order aggregation transform; it adds no execution work and cannot produce a -19.6% speedup, so this is run-to-run variance.
⚠️ 14 not_sure 362 323 -10.8% <0.0001 aggregation: This change is purely test instrumentation on the in-order aggregation path and cannot make a query faster, so the -10.8% delta is variance, not a PR effect.
⚠️ 16 not_sure 793 615 -22.4% <0.0001 aggregation: The diff adds only a failpoint and a log line inside a cancellation branch; nothing in the hot path changed, so this -22.4% improvement is run-to-run variance.
⚠️ 17 not_sure 556 453 -18.5% <0.0001 aggregation: No execution work was added or removed by this test-only change, so the -18.5% reading is not attributable to the PR.
⚠️ 18 not_sure 1298 1055 -18.7% <0.0001 aggregation: The PR only wires a test failpoint into the in-order aggregation transform, so a -18.7% speedup here is run-to-run variance rather than a real effect.
⚠️ 23 not_sure 167 73 ×2.3 faster <0.0001 Source measurements were very noisy here, and the PR adds only test instrumentation, so this x2.3 faster reading is not a real PR effect.
⚠️ 31 not_sure 395 346 -12.3% <0.0001 aggregation: A test-only failpoint addition cannot speed up query execution, so the -12.3% delta is run-to-run variance.
⚠️ 33 not_sure 1254 1150 -8.3% <0.0001 aggregation: The diff touches only test instrumentation, not the execution hot path, so this -8.3% improvement is variance.
⚠️ 34 not_sure 1256 1158 -7.8% <0.0001 aggregation: No hot-path code changed; this -7.8% reading is run-to-run variance, not a PR effect.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

⚠️ 2 inconclusive

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 7 not_sure 574 71 ×8.1 faster <0.0001 An x8.1 faster swing cannot come from adding a test failpoint to the in-order aggregation transform; this is co-location or sampling variance, not a PR effect.
⚠️ 8 not_sure 175 80 ×2.2 faster <0.0001 The PR adds only test instrumentation and no execution work, so this x2.2 faster reading is not attributable to the change.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: fec87abe-8906-4fba-a490-fb7196dcf735
  • MIRAI run: f36ab790-f7cd-4ad6-a336-3d8580a4ba98
  • PR check IDs:
    • clickbench_1526624_1786859896
    • clickbench_1526637_1786859896
    • clickbench_1526649_1786859896
    • tpch_adapted_1_official_1526656_1786859896
    • tpch_adapted_1_official_1526680_1786859897
    • tpch_adapted_1_official_1526695_1786859897

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged current master into this branch and resolved the concurrent FailPoint list update; the head is now ca72e0ff5e9b. The flaky stateless 04512_aggregation_in_order_cancellation test remains deleted.

The remaining question from the approved review is whether the new replacement integration test should also be removed. That is a maintainer decision; no further mechanical change is implied by the existing feedback.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 16, 2026
Merged via the queue into ClickHouse:master with commit 2b4c46b Aug 16, 2026
181 checks passed
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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai 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