Skip to content

Concentrate the arrayFold cancellation fixtures of 04752 in one row - #114039

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-04752-arrayfold-fixture-shape
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-04752-arrayfold-fixture-shape

Conversation

@groeneai

@groeneai groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator

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 two arrayFold arms of 04752_persisted_expression_cancellation sat about twice their bound
rather than four times below it, and one reported OVERSHOT 4258ms past a 1000ms limit on
Stateless tests (amd_debug, sequential). Surfaced by @ alexey-milovidov on #109454; no related open
issue exists. This is not the grep oracle of #113943, which cannot affect it: the failing assertion
is the duration oracle, and the two PRs touch disjoint lines of the file.

arrayFold's cancellation checkpoints sit in its per-slice fold loop, but the selector loop and
scatter ahead of them are O(total elements) and effectively uninterruptible. The old fixture spread
1.8e8 elements evenly over 60000 rows, so the arm paid about 2.9s of prologue before the deadline
could be observed, against a 4000ms bound, and crossed it on a slower runner.

Concentrating the same fold in one row (range(if(k = 0, 400000, 1))) leaves the interruptible work
intact, since the fold loop runs max_array_size times over all rows regardless of individual array
lengths, while the prologue drops by the same factor. No bound is widened, no tag is added, the
oracle and .reference are untouched, and peak memory drops from 2.01 GiB to 1.56 GiB. Both arms are
changed: the one that has not fired yet had the identical margin.

Validated on a debug build matching amd_debug: 50/50 runs pass, .reference matches byte for byte,
and the arms stop at 1040-1161ms worst case, a 3.45x margin. With the engine fix of #113456 reverted
on a separately built binary they still redden, at about 14.8s against the old 5.7s, so the oracle
discriminates more sharply than before rather than less.

arrayFold's prologue remains effectively uninterruptible, so a fold over a very large evenly shaped
argument still observes the deadline late. The query is cancelled, only later, and that is left as is.

The two arrayFold arms of 04752_persisted_expression_cancellation sat about
twice their bound rather than four times below it, and arrayfold_orderby
reported OVERSHOT 4258ms past a 1000ms limit on Stateless tests
(amd_debug, sequential).

arrayFold's cancellation checkpoints are in its per-slice fold loop, and in a
selector loop that checks only every 0xFFFFF elements; the scatter between them
carries none. Both pre-fold phases are O(total array elements), so with the
argument spread evenly over 60000 rows the arm ran about 2.9s of
uninterruptible prologue before the deadline could be observed. Measured on one
debug binary: 2947ms and 2767ms fixed against 5672ms and 5792ms with the
per-call status resolution of 37a532b reverted, a margin of 1.78x
against a 4000ms bound, where every other arm of the test has 8x to 52x and
stops near 1100ms.

The fold loop iterates all rows on every slice whatever the individual array
lengths are, so concentrating the same number of elements in one row keeps the
interruptible work while the prologue drops by the same factor. With
range(if(k = 0, 400000, 1)) the arms stop at 1040ms to 1161ms worst case over
50 runs, a 3.45x margin, and still overshoot to about 14.8s with that commit
reverted, so the oracle discriminates more sharply than before. Peak memory
falls from 2.01 GiB to 1.56 GiB.

Both arms are changed rather than only the one that fired: arrayfold_partition
had the same 1.78x margin and had not crossed the bound only by luck. No bound
is widened, no tag is added, the token oracle and the reference file are
untouched, and BOUND is left alone so the kill arms that share it are
unaffected.

arrayFold's prologue remains effectively uninterruptible, so a fold over a very
large evenly shaped argument still observes the deadline late. The query is
cancelled, only later than the deadline, and that is left as it is here.
@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

An independent reviewer read the change cold, then a second model re-reviewed the full diff. No blockers or majors were raised by either. Verdicts below.

# Severity Finding Verdict
1 💡 nit A maintainer handle was used in the description as attribution rather than as a request for attention, which notifies for nothing. Agreed, fixed before publishing.
2 💡 nit The description ran slightly over the concision budget. Agreed, condensed.
3 💡 nit The new fixture comment calls the selector loop "effectively uninterruptible", but it does carry a checkpoint every 0xFFFFF elements (172 firings on the old fixture), unlike scatter, which carries none. Disagreed. "Effectively" is accurate at a 1048575-element stride, and the claim the comment carries, that both pre-fold phases are O(total elements) so the deadline cannot be observed until the prologue completes, is correct.

Checks that mattered here, and what they found:

  • Does the test still fail without the fix? Yes. With the arrayFold part of Resolve the query status per call in functions that check for cancellation #113456 reverted on a separately built binary (build IDs asserted against readelf -n on both arms), the reshaped test fails and the reported diff is exactly the two arrayFold lines. The fixed:unfixed margin moves from 1.78x to about 14.2x, so the oracle discriminates more sharply than before, not less.
  • Is the randomized 50 run doing the discriminating? No, and it is not claimed to. Under default randomization the old fixture also reads about 1004ms, so 50 green randomized runs would look the same before and after. The discriminating measurements are the non-randomized A/B and the two binaries; the 50 run covers regression only.
  • Is anything else weakened? No. BOUND is untouched, so the KILL arms sharing it are unaffected; the token oracle is untouched, since Fix flaky 04752_persisted_expression_cancellation oracle #113943 owns it; no tag is added and the reference file is byte-identical.
  • Are there other carriers? No stateless test other than this one pairs arrayFold with a cancellation or duration oracle, and the sibling cancellation-latency tests that share this bound idiom contain no arrayFold arm. Within this test both arrayFold arms are reshaped, not only the one that fired.

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. On a debug build (CMAKE_BUILD_TYPE=Debug, no sanitizer, no coverage, so SCALE=1 and BOUND=4000 as in the failing job) the arms take 2947ms and 2767ms every run under --no-random-settings; 12 isolated repeats gave 2265-2984ms, median 2814ms. The bound-crossing itself needs a slower runner, so the deterministic oracle is the reverted-engine binary below, where the arms land ~3.7x over the bound on every run.
b Root cause explained? Yes. arrayFold's cancellation checkpoints are in the per-slice fold loop (arrayFold.cpp:249) and the selector loop (:197, which checks only every 0xFFFFF elements); the scatter at :227-228 has no checkpoint at all. Both pre-fold phases are O(total elements). The old fixture spread 1.8e8 elements evenly over 60000 rows, so ~2.9s of uninterruptible prologue ran before the deadline could be observed, leaving a 1.78x fixed:unfixed margin against a 4000ms bound where every other arm has 8x-52x.
c Fix matches root cause? Yes. It moves the cost out of the uninterruptible prologue into the checkpointed fold loop by concentrating the elements in one row. No bound is widened, no no-random-* tag is added, no data is merely reduced, and the oracle and .reference are untouched.
d Test intent preserved / new tests added? Preserved and strengthened. The arms assert prompt cancellation against the same 4000ms bound, with the same labels and the same .reference; the margin improves from 1.78x to ~14.2x. The deliverable is the test itself, so no new test is added.
e Both directions demonstrated? Yes, on two separately built binaries with readelf -n asserted equal to SELECT lower(buildId()). Pristine HEAD (f5ff25a5b201): passes, arms at 1040-1161ms. Engine fix of #113456 reverted in arrayFold.cpp only, spliced byte-exactly against 37a532be655467d^ (8142121465a4): runner FAILS, and the reported diff is exactly the two arrayfold lines, OVERSHOT 14994ms and OVERSHOT 14752ms. Old fixture on the same mutant: 5672/5792ms.
f Fix is general across code paths? Yes. Both arrayFold arms are changed, arrayfold_partition and arrayfold_orderby, not only the one that fired: the partition arm had the identical margin (5792 vs 2879) and had not fired only by luck. The kill_case pair and kill_geohash share BOUND and stay untouched precisely because BOUND is not moved. The three sibling cancellation tests have no arrayFold arm and are out of scope.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for type wrappers: this is a shell test fixture, not a code path. The applicable matrix is the settings matrix, and the test passes both randomized and --no-random-settings, plus 50 randomized runs.
h Backward compatible? (maintainer-approved exception only) N/A. Test-only: no settings, no SettingsChangesHistory.cpp, no serialization change, no user-visible behavior.
i Invariants and contracts preserved? Yes. The source table src_i is unchanged, so every other arm reading it (sleep_partition, sleep_orderby, the direct baseline) is byte-identical, and all 13 other arms were confirmed unchanged across the 50-run. The argument stays column-dependent, which the file documents as load-bearing since a constant argument would be folded once. Peak memory drops from 2.01 GiB to 1.56 GiB.

Validation: 50/50 runs pass with randomization on (--test-runs 50 --long-test-runs-ratio 1.0), .reference matches byte for byte on all 38 lines, and the worst case across the whole 50-run is 1161ms for arrayfold_orderby and 1127ms for arrayfold_partition, a 3.45x margin under the bound. The slowest arm in the suite is now kill_h3containment_orderby at 1233ms; previously it was arrayfold_orderby at 2947ms.

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

cc @Algunenano, could you review this? It is test-only: the two arrayFold arms of 04752 sat at only 1.78x their cancellation bound because arrayFold's selector loop and scatter run before its first usable checkpoint and are O(total array elements), so concentrating the same fold in one row moves the cost into the checkpointed fold loop without widening any bound.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0e92957]


AI Review

Summary

This PR reshapes the two arrayFold fixture arms in 04752_persisted_expression_cancellation so the expensive uninterruptible arrayFold prologue no longer dominates the fixed path before the first usable cancellation check. I checked the diff against the current arrayFold implementation and the surrounding test contract, and I did not find any unresolved correctness, coverage, or CI-stability issues in the updated fixture.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 9, 2026
@PedroTadim

Copy link
Copy Markdown
Member

I am removing the test myself

@PedroTadim PedroTadim closed this Aug 9, 2026
@groeneai groeneai added the groeneai-origin-request PR origin: a maintainer pinged or directed groeneai label Aug 19, 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 groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants