Repository navigation
Conversation
`clickhouse-client --chime N` is documented to alert on success and on error,
but on the error path it fired only sometimes.
The gate read `ProgressIndication::elapsedSeconds()`, which prefers the
server-reported `elapsed_ns` and falls back to the client's stopwatch only when
that value is exactly 0. The server puts `elapsed_ns` on the wire in
`TCPHandler::sendProgress`: in-loop sends are throttled by `interactive_delay`,
and the two unconditional final sends sit after the pulling loop, which a
throwing query skips via `catch (...) { executor.cancel(); throw; }`. The outer
exception handler sends logs and the exception, never progress. A failing query
therefore keeps whatever partial delta arrived before the throw, and because a
non-zero server value overrides the client's correct wall clock, the threshold
comparison used that partial figure.
Measured with `SELECT throwIf(sleep(1.5) = 0, 'expected error')` (true wait
1.5s), reading the client's own belief through `--time`: the success path
reports 1.503, the error path 1.406 at the default `interactive_delay`, and
0.802 at `interactive_delay=800000`, which is below a 1 second threshold and so
emits no bell. `clickhouse-local` never sets `elapsed_ns`, so it always used the
client stopwatch and was unaffected.
Add `ProgressIndication::clientElapsedSeconds()` and use it at the chime gate
only. `elapsedSeconds()` and its other consumers (the `Elapsed:` line, `--time`,
progress-bar ETA and CPU-rate math) deliberately keep preferring the server
figure, which excludes client-side round-trip and is what those rates are
computed against.
This also removes the intermittent case-11 failure of
04312_client_chime_on_slow_query_92718, which recurred 8 times on unrelated
branches after ClickHouse#109001, all on sanitizer lanes. That PR made the elapsed time
deterministic; it did not make delivery of that time deterministic, which is why
the symptom survived it. The stale comment claiming the arm's determinism
follows from the nesting alone is corrected in cases 4 and 11, and case 9's
comment no longer quotes the gate's C++ expression.
Case 11 pins `interactive_delay` in its own client invocation. At the default
cadence the partial elapsed value that reaches the client on the error path is
close enough to the threshold that the arm only failed under an unlucky draw, so
it did not reliably exercise the contract it covers; pinned, it reaches that
state on every run. The oracle is unchanged, the reference file is unchanged, and
a control that differs only in dropping the pin passes on the same pre-fix
binary, which is what attributes the failure to the arming.
Validation: the test fails 6 of 6 runs before this change with exactly the CI
diff line and passes 50 of 50 after with default randomization, plus 20 of 20
under heavy machine load, and 04625_client_chime_config stays green.
Sub-threshold, `--chime 0` and non-TTY arms all stay silent while a positive
control emits the bell, so the chime is not simply always emitted.
Internal second-model review (3 rounds, 9 findings, all resolved)An independent model reviewed this change across three rounds. Findings and verdicts:
Final round: 0 findings. Known limitation, not fixed here: |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-review-slot-8:20260824-010200 |
|
Workflow [PR], commit [0deec4c] Summary: ❌
AI ReviewSummaryThe live PR diff at Final Verdict✅ No new actionable findings in the current PR diff. |
|
cc @azat @serxa, could you review this? The |
| if (chime_threshold_seconds > 0 | ||
| && stderr_is_a_tty | ||
| && progress_indication.elapsedSeconds() >= static_cast<double>(chime_threshold_seconds)) | ||
| && progress_indication.clientElapsedSeconds() >= static_cast<double>(chime_threshold_seconds)) |
There was a problem hiding this comment.
Switching the chime gate to clientElapsedSeconds() here makes the client disagree with its own elapsed reporting on failing queries. Elapsed: a few lines above, and --time in non-interactive mode, still read progress_indication.elapsedSeconds(), which stays stuck on the last partial elapsed_ns packet when the server throws before the final progress update. That means clickhouse-client --chime 1 --time can now print something like 0.802 / Elapsed: 0.802 sec. and still ring the bell for crossing the 1-second threshold. Since --chime is documented in terms of the query's runtime, users now get two contradictory answers from the same invocation. I think the end-of-query user-facing elapsed value on the error path needs to use the same clock as the chime threshold, or the chime gate needs to stay aligned with the displayed elapsed.
There was a problem hiding this comment.
Confirmed, and the PR body already notes it: "Not fixed here: --time and Elapsed: under-report on the error path for the same reason."
Measured on both builds, error path, --chime 1 --time --interactive_delay 800000, 3 runs each:
| build | --time prints |
BEL |
|---|---|---|
master, Build ID ffc68c79 |
0.802 | absent |
this PR, Build ID 1b5ae298 |
0.802 | present |
Negative control --chime 0 on this PR: BEL absent. At the default interactive_delay both builds print 1.406 and both ring, so the two only diverge in the window where the partial figure sits below the threshold.
So the divergence is real, but the query ran for 1.5 seconds and --chime is documented as firing "after running for at least N seconds". The bell is the output this PR makes correct; 0.802 is the wrong one, and it is equally wrong on master. Aligning the gate to the displayed elapsed would restore the missing bell, which is the defect this PR exists to fix.
Putting Elapsed: and --time on the client clock is worth doing, but as a separate change: getElapsedNanoseconds() also feeds the ETA and CPU-rate math and output_format->setStartTime, which want the server figure when one is available. I am not widening this PR to cover them.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 units23 translation units recompiled, 159 s compile time in total, 23 of them have a recent master baseline. |
|
Superseded by #117179 (merged 2026-08-31T15:27:02Z, Verified on
That is this pull request's entire source change, so it carries nothing CIDB confirms the flake is retired: 4444 recorded runs of This can be closed. |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
clickhouse-client --chime Nnot emitting the terminal bell when a long-running query ends in an error. The threshold is now measured on the client's own clock instead of the server-reported elapsed time, which a failing query does not deliver.Description
--chime Nis documented to alert "on success and on error", but on the error path it firedonly sometimes. The gate read
ProgressIndication::elapsedSeconds(), which prefers the server-reportedelapsed_nsand only falls back to the client's stopwatch at exactly0. The server putselapsed_nson the wire inTCPHandler::sendProgress: in-loop sends are throttled byinteractive_delay, and the two unconditional final sends happen after the pulling loop, which athrowing query skips. The exception handler sends logs and the exception, never progress. A failing
query therefore keeps whatever partial delta arrived before the throw, and that small non-zero value
overrides the wall clock. Measured on
SELECT throwIf(sleep(1.5) = 0, 'expected error')via--time: 1.503 on the success path against 0.802 on the error path atinteractive_delay=800000,below a 1-second threshold.
clickhouse-localnever setselapsed_nsand was not affected.The fix adds
clientElapsedSeconds()and uses it at the chime gate only.elapsedSeconds()and itsother consumers (
Elapsed:,--time, ETA and CPU-rate math) are unchanged, since they want theserver figure when available. No setting and no protocol change. The client clock is never below the
server's elapsed time, so anything that chimed before still chimes; a query within round-trip
distance of the threshold can now chime where it did not.
This also fixes the intermittent
04312_client_chime_on_slow_query_92718case-11 failure (8occurrences on unrelated branches since #109001 merged, all sanitizer lanes). Case 11 now pins
interactive_delayso it reaches that state on every run instead of under an unlucky cadence: itthen fails 6/6 before this change with exactly the CI diff line, and passes 50/50 after.
Sub-threshold,
--chime 0and non-TTY arms confirm the chime is not always emitted.Not fixed here:
--timeandElapsed:under-report on the error path for the same reason.Related: #92718
Workflow [PR]
Sync PR [sync-upstream/pr/116033]