Skip to content

Remove 04650_replace_cancellation - #114018

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-04650-fast-build-case-bounds
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-04650-fast-build-case-bounds

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

Removes 04650_replace_cancellation, as requested in
#114018 (comment).

The test bounds the elapsed time the server reports when a replace* call is stopped by the query
deadline. That oracle is a timing comparison and nothing can stand in for it: the throw-mode message
in ProcessList.cpp:634 carries no caller identity, so a test cannot distinguish an in-function
checkpoint from a pipeline-level timeout by reading the error. Every case therefore has to be sized
so the function outruns its deadline on the slowest build and stops inside the bound on the fastest.
Holding that band has taken eight follow-up commits and three further pull requests in the eight days
since the test landed in #112483.

This pull request originally re-sized two cases that had drifted out of the band for two different
reasons: one finished legitimately inside its deadline on a warm host, and one left the 5 GiB test
memory profile when its result buffer doubled, with both reported by a single oracle arm as a missing
checkpoint. That change is reverted here in favour of removing the test.

What is lost is the only in-tree timing coverage of cancellation on the replace* dispatch paths.
The checkpoint itself is unchanged and still covered through its other callers:
04822_count_matches_cancellation for countMatches and 04722_count_substrings_cancellation for
countSubstrings* both exercise the same CancellationBudget and makeCancellationCheck with the
same elapsed-bounding oracle. The source added by #112483 is untouched.

After ClickHouse#113031 this test went from 40 failures / 10 PRs / 1 master to 3 / 1 / 0
in the same 60-day window. What remains is two cases whose verdict a fast build
decides, and neither is a cancellation defect.

Case 6 needs only about 690 ms of function work against its 1000 ms deadline, so
on a host with warm pages the query finishes: exception_code = 0 in 7 of 9
attempts recorded in the failing jobs' query_log. Across both outcomes
UserTimeMicroseconds stays constant within 3% while SoftPageFaults swings 16 to
30 times, so what decides the outcome is the cost of zero-filling fresh pages,
i.e. host state, not anything in a pull request diff.

Case 25 grows its result buffer by doubling, so the step past the 2.38 GiB it
needs requests a 4.00 GiB chunk. Live plus requested is 6.13 GiB against the
4.66 GiB left under the 5 GiB test profile, and the query dies of
MEMORY_LIMIT_EXCEEDED in 5 of 12 attempts.

Neither outcome carries TIMEOUT_EXCEEDED or an elapsed number, so both fell to
one catch-all arm printing "no timeout", which reads as a missing in-function
checkpoint and cost a misdirected investigation.

run() gains a seventh parameter, the per-case allowance, defaulting to SLACK_MS
so the other 15 cases compute an identical bound. A per-case deadline alone would
not separate the two sides: bound is deadline plus SLACK_MS, SLACK_MS is global
at 1000, and on a build with the in-function checkpoint disarmed
PipelineExecutor::finalizeExecution() -> checkTimeLimit() still throws a numbered
timeout at total-work time, which run() accepts as "stopped within bound".

Case 6 keeps its fixture because its work is already at the memory ceiling:
CancellationBudget::charge is given the bytes written as well as those read, so
raising the work raises the peak in lockstep and the next doubling step
reproduces case 25's failure. Case 25 drops to 20000 rows, which puts its peak at
1.53 GiB, three times under the cap.

"no timeout" is split into "FAILED WITH CODE n INSTEAD OF THE DEADLINE" and
"FINISHED INSIDE THE DEADLINE". Both are failures against the reference exactly
as "no timeout" was, so no run that passes today can start failing; the gain is
that the next occurrence names its own cause.

Validation: 50 of 50 runs green with randomization enabled, green on ASan with
SCALE = 2 correctly detected, and on a binary whose makeCancellationCheck returns
an empty callback both cases report OVERSHOT at about 4.4 times their bound, so
neither is vacuous. The two-sided band was measured on debug, on an optimized
official master binary and on ASan; the tightest margin is 16%. There is no local
arm_binary, so the fast-arm upper bound is inferred from the failing jobs' own
numbers rather than observed on that flavour, and tsan was not built.

The reference file is unchanged, and the folded-case wall-clock fallback
disclosed on ClickHouse#113034 stays untouched and latent: both cases here are pipeline
cases, so that arm is unreachable for them.
@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 findings raised, 1 accepted as a noted non-blocker)

Two independent reviews were run against this diff before publishing: a cold read of the resulting
code, and a second model given the diff and the PR contract. Both raised the same major point, and it
is refuted below by arithmetic I got wrong the first time.

⚠️ major — the two-sided timing band is not measured on the target arm_binary flavour.
Both cases get sharply tighter bounds (case 6 2000 -> 500, case 25 2000 -> 250 at SCALE = 1),
and neither arm the bounds were derived on is arm_binary. Disagreed, with numbers.
The upper side is not inferred from a proxy at all: it comes from the failing arm_binary jobs'
own query_log (684-733 ms for case 6; ~415 ms for case 25 via measured throughput, 2.27 GiB/s
uncontended locally against 2.3 GiB/s in CI). For the lower side, this test's own CIDB rows over 30
days put arm_binary at p50 33090 ms against amd_debug p50 32860 ms (2716 and 2441 runs), a ratio
of 1.007, and the optimized amd64 binary is strictly faster than debug. So arm_binary sits inside
the pair that was measured at 40 samples per cell, on the same non-sanitizer SCALE = 1 class. Worst
measured headroom is 38% (case 6) and 23% (case 25) against a 15% floor.

⚠️ major — my own first version of that finding predicted a breach on amd_tsan, and it was
wrong.
I had scaled the whole reported figure as if it stretched with the arm. The identity is
elapsed = deadline + quantum, where the quantum is the one uninterruptible result-buffer doubling
still in flight, so the test passes iff quantum < allowance and both terms scale together. Under
that model the sanitizer cells are the safest ones: measured quanta on ASan are 60 ms (case 6) and
75 ms (case 25), below debug's 96 and 116, while the allowance doubles to 600 and 300. A sanitizer
breach needs 3.2x and 2.6x the worst quantum seen on any arm. The prologue mode fails too: breaching
needs 9.5x and 6.9x the debug prologue maximum, amd_tsan runs this test at 2.8x debug, and ASan at
1.6x is green at the identical doubled deadlines. The historical thread-sanitizer notes in this file
are written against fixtures 20x larger than what ships here (400000 rows against 20000), and
case 6's fixture is unchanged.

💡 nit, accepted — run infers a completion from the absence of Code: without consulting the
exit status.
Correct: the client runs inside a command substitution, $? is never captured, and the
script sets neither -e nor pipefail, so an outer timeout 600 kill or a client death with no
numbered exception would be labelled FINISHED INSIDE THE DEADLINE. Not fixed here, deliberately:
neither new string appears in .reference, so such a run still fails the test and only its label
is wrong. It is a diagnosis defect inside a diagnosis improvement, and worth a separate change rather
than a round that alters nothing else.

Stated limits, unchanged from the description: there is no local arm_binary, so the upper bound is
taken from the failing jobs rather than observed on that flavour, and tsan was not built (ASan is the
sanitizer evidence). The folded-case wall-clock fallback stays latent and out of scope, since both
cases here are pipeline cases.

@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. Case 25 reproduces on demand: its query at 50000 rows with no deadline gives Code: 241 ... would use 6.13 GiB (attempt to allocate chunk of 4.00 GiB), maximum: 4.66 GiB, matching the failing jobs verbatim. Case 6 reproduces as a genuine completion (exception_code = 0, 2354 ms of work on debug, 1909-2196 ms optimized).
b Root cause explained? Yes. Case 6 is under-sized: ~690 ms of function work against a 1000 ms deadline, so a warm host finishes it and no timeout was a true statement. Case 25's result buffer doubles, so the step past the 2.38 GiB it needs asks a 4.00 GiB chunk and breaches the 5 GiB test profile. Neither outcome carries TIMEOUT_EXCEEDED or an elapsed number, so both fell to one catch-all arm printing no timeout, which reads as a missing checkpoint.
c Fix matches root cause? Yes. It re-sizes the two fixtures and gives each a bound tight enough to separate a fixed build from an unfixed one. It does not widen BOUND, add a blanket no-random-* tag, or raise max_memory_usage. A deadline-only change would have stayed vacuous, because SLACK_MS is global at 1000 and PipelineExecutor::finalizeExecution() -> checkTimeLimit() reports a numbered timeout at total-work time that the test accepts as stopped within bound.
d Test intent preserved / new tests added? Yes. The deliverable is the test. Both cases still reach the implementations they name: case 6's query is byte-identical, so the plain literal needle still takes the regexp trivial-pattern shortcut into the literal search; case 25 keeps toFixedString(materialize(...)) for its own FixedString entry point and only the row count changes. .reference is unchanged.
e Both directions demonstrated? Yes, with Build IDs asserted per arm via SELECT lower(buildId()). Fixed test on the fixed binary: OK, and OK on ASan. Fixed test on a binary whose makeCancellationCheck returns an empty callback: case 6 OVERSHOT 2186 ms against bound 500, case 25 OVERSHOT 1100 ms against bound 250, so neither is vacuous.
f Fix is general across code paths? Yes. All 17 run cases were audited against the same invariant using the failing jobs' own query_log; cases 6 and 25 are the only carriers. The oracle split additionally fixes the conflation for every case, not just these two: on the unfixed arm cases 5 and 15 printed no timeout before and now name CODE 241.
g Fix generalizes across inputs (params/datatypes/wrappers)? The axis here is build arm, not type wrappers, since no src/ type dispatch is touched. Validated on debug, on an optimized official master binary, and on ASan with SCALE = 2 correctly detected, plus the CI arm_binary figures. The two-sided band holds on every arm, with the tightest margin at 16%.
h Backward compatible? (maintainer-approved exception only) N/A, vacuously: a stateless-test fixture touches no user-visible surface. No SettingsChangesHistory.cpp entry, no format or version change, no feature gate.
i Invariants and contracts preserved? Yes. run's positional contract is extended rather than changed: $7 defaults to SLACK_MS, so the 15 untouched calls compute an identical bound, which the unchanged .reference and a green suite confirm. Both new calls keep $5 empty so they remain pipeline cases and cannot switch onto the folded wall-clock arm.

Additional hygiene: shellcheck -x reports no new findings (3 before, 3 after, set-identical); 50 of 50 runs green with randomization enabled; comment blocks stay within this file's 3-line convention.

Session id: cron:clickhouse-impl-slot-4:20260809-052300

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

cc @antaljanosbenjamin, could you review this? It is test-only: two cases of 04650_replace_cancellation were decided by the build's speed rather than by the cancellation checkpoint, one finishing inside its deadline and one dying of the memory limit, and both fell to a single oracle arm printing no timeout. run now takes a per-case allowance (defaulting to the shared one, so the other 15 cases are untouched) and reports a non-timeout error separately from a genuine completion.

@PedroTadim PedroTadim self-assigned this Aug 9, 2026
@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 9, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@groeneai this test has been flaky a few times, just remove it

@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [846d299]

Summary: ❌

job_name test_name status info comment
Stress test (arm_release) FAIL
Hung check failed, possible deadlock found FAIL cidb

AI Review

Summary

This PR removes 04650_replace_cancellation to get rid of a flaky timeout-based test, and the remaining CI is green. I do not think it is safe to merge as-is, because that deleted script is still the only regression coverage for the replace* cancellation wiring added in FunctionStringReplace, ReplaceStringImpl, and ReplaceRegexpImpl; the surviving countMatches / countSubstrings tests only cover the shared helper, not the replace* paths themselves.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04650_replace_cancellation.sh:1] Removing this file drops the only automated proof that replaceAll, replaceRegexpAll, and replaceRegexpOne still observe query deadlines and KILL QUERY in their own dispatch and fast paths. The remaining tests hit countMatches and countSubstrings, but they never execute the extra materialization and exit checkpoints in src/Functions/FunctionStringReplace.h:71-175, the replace-specific loops in src/Functions/ReplaceStringImpl.h:30-522, or the regexp fallback / JIT paths in src/Functions/ReplaceRegexpImpl.h:147-675. That leaves the source-side fix from #112483 in tree without any regression test that would fail if one of those replace* paths stopped checking cancellation again. Suggested fix: keep a narrower, stable replace* cancellation regression test that still covers at least one replaceAll path and one replaceRegexpAll path, or revert the still-live source-side cancellation changes together with this flaky test.
Final Verdict

Changes requested: removing the flaky test is reasonable, but not without replacing the coverage for the replace* cancellation paths or reverting the fix they were validating.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 9, 2026
The test bounds the elapsed time the server reports when a replace* call
is stopped by the query deadline, so its oracle is a timing comparison and
nothing else can stand in for it: the throw-mode message from
ProcessList.cpp:634 carries no caller identity, so a test cannot tell an
in-function checkpoint from a pipeline-level timeout by reading the error.
Every case therefore has to be sized so the function outruns its deadline
on the slowest build and stops inside the bound on the fastest, and that
band has needed eight follow-up commits and three further pull requests
since the test landed eight days ago.

Two more failure modes had been found on top of that: one case finished
legitimately inside its deadline on a warm host, and another left the 5 GiB
test memory profile when its result buffer doubled, both reported by the
same oracle arm as a missing checkpoint.

Requested by PedroTadim in
ClickHouse#114018 (comment).

The cancellation checkpoint itself, CancellationBudget and
makeCancellationCheck, is unchanged and still covered for countMatches by
04822_count_matches_cancellation.
@groeneai groeneai changed the title Deflake two fast-build cases of 04650_replace_cancellation Remove 04650_replace_cancellation Aug 9, 2026
@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

Done, 846d299 removes the test and reverts the re-sizing this PR started with.

You are right about the history: eight follow-up commits and three further pull requests in the
eight days since it landed. The reason it kept drifting is that its oracle can only be a timing
comparison. The throw-mode message in ProcessList.cpp:634 carries no caller identity, so a test
cannot tell an in-function checkpoint from a pipeline-level timeout by reading the error, and every
case has to be sized to outrun its deadline on the slowest build while stopping inside the bound on
the fastest.

One thing worth recording, since it is what is lost: this was the only in-tree timing coverage of
cancellation on the replace* dispatch paths. The checkpoint itself is unchanged and still exercised
through its other callers, 04822_count_matches_cancellation and
04722_count_substrings_cancellation, which use the same CancellationBudget and the same
elapsed-bounding oracle. The source from #112483 is untouched.

@@ -1,354 +0,0 @@
#!/usr/bin/env bash

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.

Removing this file drops the only regression test that still executes the replace* cancellation wiring added in #112483, while the source-side fix is still present.

The remaining tests only prove the shared helper via countMatches / countSubstrings; they never call FunctionStringReplace::executeImpl, so they do not cover the extra entry and exit checkpoints around constant materialization in src/Functions/FunctionStringReplace.h:71-175, the replaceAll-specific loops and fast paths in src/Functions/ReplaceStringImpl.h:30-522, or the replaceRegexpAll fallback / JIT paths in src/Functions/ReplaceRegexpImpl.h:147-675. After this deletion, a regression in any of those replace* paths will pass CI because there is no other cancellation test for them.

Please keep a narrower replace* cancellation test here, or revert the underlying source change together with this flaky test.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The coverage loss is real and the PR body states it: what goes away is the timing coverage of the replace* dispatch paths.

On the second option, no. The source change from #112483 is untouched here (this PR is 0 added lines and 378 deletions, both files under tests/), and the shared checkpoint it added is still exercised: countMatches and countSubstrings each build a CancellationBudget over makeCancellationCheck (src/Functions/countMatches.cpp:70,87 and src/Functions/CountSubstringsImpl.h:50,151,227), driven by 04822_count_matches_cancellation.sh and 04722_count_substrings_cancellation.sh. makeCancellationCheck is still called from FunctionStringReplace.h:73.

On the first option, a narrower test here reintroduces the defect that caused the removal. Under the default timeout_overflow_mode = throw the in-function checkpoint never reaches its own named message: the lambda calls QueryStatus::checkTimeLimit, which throws Timeout exceeded: elapsed N ms, maximum: M ms from ExecutionSpeedLimits.cpp:137. A pipeline-level check funnels through the same QueryStatus::checkTimeLimit, so the error text is identical. No assertion can distinguish the two by reading the error, which leaves a two-sided timing band as the only possible oracle. That band is what drifted through three follow-up PRs in eight days, and it is why @ PedroTadim asked for the file to be removed.

@clickhouse-gh

clickhouse-gh Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 846d29961 with master 9b6a2d734 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of e2194b4a8; 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 690.65 MiB 687.62 MiB -3.02 MiB (-0.44%)

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

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

Job report

@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 846d299

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
Stress test (arm_release) / Hung check failed, possible deadlock found chronic trunk deadlock, not caused by this PR a fix task is created (investigating at full effort - fixing-PR link to follow on this PR)
Sync n/a CH Inc sync (private, not actionable)

This PR is additions=0, deletions=378, both files under tests/queries/0_stateless/, and touches no
file under src/, so it cannot wedge the server. The signature is trunk-wide: 580 rows across 382
distinct PRs plus 78 master runs in the last 30 days. On my side it is root-caused to a cancelled
mysql() query blocked in mysql_real_connect during query analysis, where mysqlxx::PoolWithFailover
is not cancellation-aware; that is distinct from the Merge/analyzer leaves fixed elsewhere.

Session id: cron:our-pr-ci-monitor:20260809-143000

@PedroTadim

Copy link
Copy Markdown
Member

I am doing this myself

@PedroTadim PedroTadim closed this Aug 9, 2026
@groeneai

groeneai commented Aug 9, 2026

Copy link
Copy Markdown
Collaborator Author

Understood, leaving it with you. #114061 covers 04650 along with the rest of the family, so I am not reopening this or sending a replacement.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the Stress test (arm_release) / Hung check failed, possible deadlock found failure on this PR's CI is now open: #114142

@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.

2 participants