Skip to content

Deflake 04648_geohashes_in_box_cancellation - #112823

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-flaky-04648-geohash-cancellation
Aug 1, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-flaky-04648-geohash-cancellation

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

04648_geohashes_in_box_cancellation has failed 11 times on master and in pull requests over the last four days, in three distinct ways. All of them come from its two KILL cases on reversed and NaN bounds, plus the fixed millisecond bound the other cases use.

Rows whose box expands to nothing cost about 11ns each, so the row loop a kill has to land in lasts 650ms for the 60M-row block those cases use on a debug build and around 200ms on a release one — and the block cannot be made longer without being made bigger, as it already holds 1.25GiB. Against that window the readiness poll runs curl and then clickhouse-client per iteration, and one fork stall on a loaded runner steps over it: in the report below the killed query lived from 18.394 to 19.005 while the poll slept between its first iteration at 18.233 and its second at 20.251, so KILL was issued 32 seconds after the query had finished (nan kill: query never reached the row loop, then ended with code 0 instead of being cancelled, the dominant mode with 5 of the 11).

Their oracle was unsound as well. It compared how long KILL ... SYNC blocked against the same block run to completion, but that numerator also covers tearing 1.25GiB down, which on a fast release build is most of it — hence nan kill ran 1190ms of a 1436ms block on a build that has the fix.

So the assertion is removed rather than retuned: an interruptible zero-item row loop is not observable from a stateless test at a block size that fits in a CI job. Those boxes stay in the liveness checks, where they exercise counting a row as a work unit at all. The cases that expand a box keep their assertions — such a block runs for ten seconds or more against a one second deadline, so the cancellation lands inside the row loop whatever the load does. Verified against a pre-fix binary: they still fail, by 11x (ran 11423ms past a 1000ms limit) rather than by the 1.2x the zero-item cases had.

The remaining bound was the third failure mode, float64 throw ran 4419ms past a 1000ms limit on a loaded sanitizer build: with a cancellation checkpoint every million items, over three seconds of that was work already started and not yet interruptible. The checkpoint now runs every 100k items — ~1.2MB of geohashes against a clock read — which is what "cancelled promptly" should mean and keeps the measurement an order of magnitude inside the bound.

The test also drops from 47s to 6s and from 1.25GiB peak to a few tens of MB.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8aad759007771032aa94d7f4eee3e18103dd63c3&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29

Related: #112273

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

🤖 Generated with Claude Code

The two `KILL` cases on reversed and NaN bounds raced a window they could not
be given. Rows whose box expands to nothing cost about 11ns each, so the row
loop the kill has to land in lasts 650ms for the 60M-row block the cases use in
a debug build and around 200ms in a release one, and the block cannot be made
longer without being made bigger: it is already 1.25GiB. Against that, the
readiness poll runs `curl` and then `clickhouse-client` per iteration, and a
single fork stall on a loaded runner is enough to step over the whole window.
In the report below the killed query lived from 18.394 to 19.005 while the poll
slept between its first iteration at 18.233 and its second at 20.251, so `KILL`
was finally issued 32 seconds after the query had already finished.

Both cases also compared how long `KILL ... SYNC` blocked against the block run
to completion, and that numerator is not only the remaining loop work: it
includes tearing 1.25GiB down, which on a fast release build is most of it.
Hence `nan kill ran 1190ms of a 1436ms block` on a build that has the fix.

So the assertion is removed rather than retuned: an interruptible zero-item loop
is not observable from a stateless test at a block size that fits in a CI job.
The boxes stay in the liveness checks, which is where they exercise counting a
row as a work unit at all. The cases that expand a box keep their assertions -
one of those blocks runs for ten seconds or more against a one second deadline,
so the cancellation lands inside the row loop whatever the load does, and they
still fail on a build without the fix by 11x rather than by the 1.2x the
zero-item cases had.

The remaining bound was itself the third failure mode, as
`float64 throw ran 4419ms past a 1000ms limit` on a loaded sanitizer build: with
a checkpoint every million items, over three seconds of that was work already
started and not yet interruptible. A checkpoint every 100k items is ~1.2MB of
geohashes against a clock read, which keeps the same measurement an order of
magnitude inside the bound and is what "cancelled promptly" should mean anyway.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8aad759007771032aa94d7f4eee3e18103dd63c3&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29
Related: #112273

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3f0e190]

Summary: ✅


AI Review

Summary

This PR deflakes 04648_geohashes_in_box_cancellation by tightening the in-function cancellation checkpoint and by removing the flaky KILL assertions for reversed and NaN bounds. The runtime change looks reasonable, but the revised shell test weakens coverage for the degenerate/NaN cancellation path enough that I would not merge it as-is.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04648_geohashes_in_box_cancellation.sh:125-128] The replacement "liveness" checks do not actually verify that reversed and NaN rows still count as one cancellation work unit. geohashesInBoxPrepare returns {} for those inputs, so if items_since_check regressed from std::max<UInt64>(1, prepared_args.items_count) back to prepared_args.items_count, these queries would still return the same count()/sum(length()) result and the test would stay green. This drops the only observable regression coverage for the invariant fixed in Make geohashesInBox interruptible while expanding a block of rows #112273.
    Suggested fix: replace these result-only queries with some deterministic observable of the checkpoint path, e.g. a focused unit/stress test that cancels through QueryStatusPtr, or another cancellation oracle that still distinguishes fixed from unfixed code for degenerate boxes.
Final Verdict

Changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 31, 2026
# Degenerate rows cross the same checkpoint once every row counts as a work unit, and must still
# return their documented empty arrays.
# Reversed and NaN bounds return no items at all, so they cross the same checkpoint only because a
# row counts as a work unit on its own, and they must still return their documented empty arrays.

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.

The new "liveness" query here no longer makes the degenerate/NaN cancellation path observable. geohashesInBoxPrepare returns {} for these inputs (src/Functions/GeoHash.cpp:274-281), so if items_since_check regressed back to prepared_args.items_count the query would still produce the same empty-array result and this check would stay green; with no deadline set, crossing the checkpoint has no visible effect. That means this PR drops the only regression coverage for the "count each row as one work unit" invariant from #112273.

If the stateless KILL oracle is too noisy to keep, we still need another observable check here (for example a focused unit/stress test that cancels through QueryStatusPtr) rather than a pure result-value query.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Low importance.

@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.70% +0.00%

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

Full report · Diff report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants