Skip to content

Do not report progress of server-side AST fuzzer queries to the client - #124526

Merged
PedroTadim merged 7 commits into
ClickHouse:masterfrom
groeneai:ast-fuzzer-no-client-progress
Oct 16, 2026
Merged

PedroTadim merged 7 commits into
ClickHouse:masterfrom
groeneai:ast-fuzzer-no-client-progress

Conversation

@groeneai

@groeneai groeneai commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Description

Fixes Logical error: 'Cannot finalize buffer after cancellation.' (STID 2341-2d32) in Stress test (arm_debug), e.g. PR #113776. No related open issue found.

Root cause: the server-side AST fuzzer builds each fuzzed query's context with Context::createCopy of the seed query's context, so it inherits the progress callback that HTTPHandler installed on the seed: fuzzed queries add their rows to the seed's X-ClickHouse-Summary and write X-ClickHouse-Progress headers to the seed client's socket. In CI the client was gone: a header write failed, WriteBufferFromHTTPServerResponse::onProgress cancelled the seed's response, the fuzz loop swallowed the error, and the seed's finalize() hit the cancelled buffer.

Change: reset the progress and file-progress callbacks on the fuzz context, next to resetInputCallbacks(), and do not fuzz secondary queries: their context also holds the callbacks the initiator installed (e.g. the read-task callback of a cluster function). Collaborative workers were already skipped; the initiator still fuzzes the client's query.

The cancel_http_readonly_queries_on_client_close peer check ran inside that progress callback, so HTTPHandler now also stores it in the query context (Context::setClientConnectedCallback). The fuzz loop polls it before each fuzzed query and from the executor cancel callback, and the fuzz context gets a progress callback that only throws once the client is gone, which also stops the ast_fuzzer_oracle sub-queries; QueryOracleChecker propagates that cancellation.

Validation: the new test checks that SELECT number FROM numbers(10) with ast_fuzzer_runs=10 reports read_rows 10 in the summary and the progress headers (master 20/20 fail, fix 50/50 pass). A client disconnecting after the first progress header aborted a master debug server 3 of 4 times, 0 of 25 with the fix. With readonly=2 and a client closing during fuzzing, the seed stops within 0.13 s (master with ast_fuzzer_oracle=1: 5.3-7.6 s).

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/124526]

Version info

  • Merged into: 26.11.1.50-master (included in 26.11 and later)

The fuzz context is a `Context::createCopy` of the seed query's context, so
it inherited the progress callback that `HTTPHandler` installed on the seed:
every fuzzed query added its rows to the seed's `X-ClickHouse-Summary` and,
with `send_progress_in_http_headers=1`, wrote `X-ClickHouse-Progress` headers
to the seed client's socket.

When the client was already gone (end of a stress run), a fuzzed header write
failed, `WriteBufferFromHTTPServerResponse::onProgress` cancelled the seed's
response and rethrew, the fuzz loop swallowed the exception, and the seed's
`finalize()` then hit the cancelled buffer: `Logical error: 'Cannot finalize
buffer after cancellation.'` (STID 2341-2d32), Stress test (arm_debug).

Reset the progress and file-progress callbacks on the fuzz context, next to
the existing `resetInputCallbacks()`, the same way the fuzzer already detaches
the seed's ProcessList entry and transaction.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet labels Oct 8, 2026
@groeneai

groeneai commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 findings) plus my own review (1 nit).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test stays green if the fuzzer runs no queries (no positive control) DISAGREE With no fuzzed queries nothing can leak, so green is correct. With fuzzing and the leak present the test fails: master 20/20, fix with only setProgressCallback({}) removed 10/10.
2 ⚠️ Removing setFileProgressCallback({}) is not detected by the test DISAGREE True (that mutation passes 10/10), but HTTP never installs a file-progress callback, so the line cannot affect this abort; on TCP it only feeds the client's progress counters. Same operation as the tested line on its sibling field.
3 💡 The TCP interactive cancel callback is still inherited by fuzzed queries DISAGREE Kept on purpose: it only reads Cancel for the seed and sends protocol-legal progress packets; TCPHandler checks isCanceled() before writing.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261008-000600

@clickhouse-gh

clickhouse-gh Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ccdfc2b]

Summary: ✅


AI Review

Summary

The PR isolates server-side AST fuzzer progress from the seed client's response, preserves HTTP disconnect cancellation during fuzzing and oracle checks, and skips secondary queries that inherit transport callbacks. Review of ccdfc2b964e4de0555ff52a1ddf218c1b6991f46 found no outstanding actionable issues; the previous cancellation findings are addressed.

Missing context / blind spots
  • ⚠️ Current-head CI is still running, with stateless and TSan stress results pending. No local ClickHouse executable or build is available, so runtime evidence comes from the regression test and the author's documented before/after measurements. Completed current-head CI would close this validation gap.
Final Verdict

Status: ✅ Approve. No new inline findings. Current-head CI should finish successfully before merge.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 8, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. label Oct 8, 2026
@PedroTadim PedroTadim self-assigned this Oct 8, 2026
@PedroTadim
PedroTadim enabled auto-merge October 8, 2026 16:07
@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit ccdfc2b964e4de0555ff52a1ddf218c1b6991f46 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception; stopped retrying after the 1250 s read budget).

See the job log for details.

Comment thread src/Interpreters/executeQuery.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator Author

The AI review is right: clearing the progress callback also drops the cancel_http_readonly_queries_on_client_close check for the fuzz loop, because HTTPHandler runs that check inside the same callback chain. Measured with readonly=2, ast_fuzzer_runs=300 and a client that closes the socket 0.3 s in: master kills the seed query after 28-42 fuzzed queries (3 runs), this PR runs all 300. With the client connected, or with the setting off, both run all 300.

The loop stays bounded by the seed's max_execution_time and the 30 s per-mutation cap, and the setting is off by default. Keeping the check without the progress writes needs a separate client-liveness callback in Context, set by HTTPHandler and polled by the fuzz loop. @PedroTadim should I add that here, or keep the PR as is?

@PedroTadim
PedroTadim disabled auto-merge October 12, 2026 10:02
@PedroTadim

Copy link
Copy Markdown
Member

@groeneai add to this PR

Fuzz contexts no longer inherit the client's progress callback, and that
callback chain is also where `cancel_http_readonly_queries_on_client_close`
polls the HTTP peer. Without it a client that disconnects during fuzzing no
longer stops the fuzz loop.

`HTTPHandler` now also stores its peer check in the query context
(`Context::setClientConnectedCallback`), and the fuzz loop polls it before
each fuzzed query and from the fuzzed query's executor cancel callback, which
are the points where the seed's KILL is checked.

Measured with `readonly=2`, `ast_fuzzer_runs=300`, client closes at 0.3 s:
the loop stops after 33-53 fuzzed queries (master: 28-42, previous commit:
300). With the client connected or the setting off, all 300 run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Done in 13277f4: HTTPHandler also stores the peer check in the query context (Context::setClientConnectedCallback), and the fuzz loop polls it before each fuzzed query and from the fuzzed query's executor cancel callback. Same measurement as above: with the client closing at 0.3 s the loop now stops after 33-53 fuzzed queries (master: 28-42); with the client connected or the setting off, all 300 run.

Comment thread src/Interpreters/executeQuery.cpp Resolved
The oracle's sub-queries run on copies of the fuzz context, which has no
progress callback and does not carry the client-liveness callback, so a
disconnected client's oracle phase ran to the end. Give the fuzz context a
progress callback that only throws `QUERY_WAS_CANCELLED_BY_CLIENT` once the
client is gone; every query on a copy of it now stops at its next progress.

Oracle mode, `readonly=2`, `cancel_http_readonly_queries_on_client_close=1`,
client closes at 3 s: the seed stops 0.02-0.13 s after the close (previous
commit: 2.6-5.4 s, master: 5.3-7.6 s). With the client connected or the
setting off nothing changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fuzz context's progress callback throws QUERY_WAS_CANCELLED_BY_CLIENT
when the client is gone, but QueryOracleChecker swallowed it like any
other oracle execution error, so every remaining oracle of the current
candidate still started and failed at its first progress tick. Propagate
it from run_oracle and from the DQP variant guard, so the oracle phase
stops at once and the fuzz loop exits at its next client check.

Measured on a 20M-row DISTINCT seed with ast_fuzzer_oracle=1, readonly=2,
cancel_http_readonly_queries_on_client_close=1, client closing at
2..11 s: before, 1-3 remaining oracles started after the close in 7 of 7
runs still fuzzing; after, 0 in 8 of 8. With the setting off, or the
client connected, the oracles still run in full.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim

Copy link
Copy Markdown
Member

@groeneai 🕵️ The progress fix looks right to me. The same ContextData copy also hands the fuzz context the rest of the seed's per-query callbacks: next_task_callback, merge_tree_read_task_callback, merge_tree_all_ranges_callback and block_marshalling_callback (Context.cpp, copy constructor). executeASTFuzzerQueries only skips parallel-replicas followers (collaborate_with_initiator), so it still runs on other secondary queries.

From reading the code (not run): on a worker of s3Cluster / icebergCluster and similar, the fuzzed queries keep the initiator's read-task callback. A fuzzed variant of the worker's read would pull files from the shared task iterator while other workers are still reading. The fuzzer discards its results, so the initiator's query silently misses those files.

This is the same kind of inheritance this PR fixes for progress. Could the fuzz context drop all of them in one place, e.g. a Context::resetQueryCallbacks() next to resetInputCallbacks() that clears every per-query callback the client or the initiator installs? The other option would be to skip fuzzing on secondary queries.

A secondary query's context holds the callbacks its initiator's connection
installed for it (the read-task callback of a cluster function, block
marshalling, the merge tree read callbacks), and `Context::createCopy` hands
all of them to the fuzz context, so a fuzzed copy on a shard can reach back
into the initiator's query, e.g. by requesting a read task when the fuzzer
puts a cluster function into it. Collaborative workers were already skipped;
skip every secondary query in the same place instead of clearing the callbacks
one by one. Clearing them would not be enough: a fuzzed copy on a shard still
runs as a secondary query, so a fuzzed cluster function there would hit the
`LOGICAL_ERROR` in `getClusterFunctionReadTaskCallback()`.

The initiator still fuzzes the client's query. The skip is counted in the new
`ASTFuzzerSkippedSecondaryQuery` profile event.

Measured with `SELECT sum(number) FROM remote('127.0.0.1:<port>', numbers(1000))
SETTINGS ast_fuzzer_runs = 100, prefer_localhost_replica = 0`, 40 seeds: master
ran 88950 fuzzed queries (its shard fuzzes the seed's shard query, and the
fuzzer does not strip `ast_fuzzer_runs` from a copy's `SETTINGS`, so the shard
queries of fuzzed copies are fuzzed too), this change ran 4000 = 40 x 100, all
on the initiator. All 80 results were correct.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

Checked. The s3Cluster / icebergCluster worker case is already covered: an initiator with a task iterator sets collaborate_with_initiator on its workers (RemoteQueryExecutor.cpp, = extension.has_value()), so they return at the existing check before any copy is made. Measured with a fileCluster read of 20 files and ast_fuzzer_runs = 20: 10/10 results complete, no worker query fuzzed.

Other secondary queries were still fuzzed, so I took the second option in ccdfc2b: executeASTFuzzerQueries now returns for every secondary query (counted in ASTFuzzerSkippedSecondaryQuery). I preferred it over a resetQueryCallbacks() because a fuzzed copy on a shard still runs as a secondary query, so with the read-task callback cleared, a fuzzed cluster function there would hit the LOGICAL_ERROR in getClusterFunctionReadTaskCallback(). On initial queries the remaining inherited callbacks are not reached: they are only read on secondary or collaborative contexts.

With remote('127.0.0.1:<port>', numbers(1000)), prefer_localhost_replica = 0, ast_fuzzer_runs = 100 and 40 seeds, master ran 88950 fuzzed queries and this change 4000, all on the initiator; all results were correct on both.

@PedroTadim
PedroTadim added this pull request to the merge queue Oct 16, 2026
Merged via the queue into ClickHouse:master with commit 3cad7bd Oct 16, 2026
178 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 16, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 11, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 11, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 12, 2026
Backport #124526 to 26.10: Do not report progress of server-side AST fuzzer queries to the client
groeneai pushed a commit to groeneai/ClickHouse that referenced this pull request Nov 12, 2026
leshikus pushed a commit that referenced this pull request Nov 13, 2026
JingYanchao pushed a commit to JingYanchao/ClickHouse that referenced this pull request Nov 16, 2026
The test asserts that a repeated INSERT ... SELECT with the same
insert_deduplication_token is deduplicated. The dedup block id depends on
how the source read is chunked, so both inserts must produce the same
chunks; the test pins the query-level read shape but not parallel
replicas, which the ParallelReplicas jobs enable server-side.

With a small randomized index_granularity (15 on ClickHouse#94017) the 20000-row
source has 1333 marks. On s3-backed parts the replicas read it in 13 or 14
requests depending on timing, and when the two inserts make a different
number of requests the chunks differ and the repeat is appended (40000
instead of 20000). Measured locally: 21 of 21 failing pairs had different
request counts, 16 of 16 deduplicated pairs had equal ones; a different
mark split alone does not break deduplication (local disk: 173 requests
per insert, 0 of 400 runs failing). In the automatic parallel replicas
runs of ClickHouse#120438 the first insert runs single-node and the second on
parallel replicas, so those draws fail every rerun.

CI: ClickHouse#94017 arm_binary ParallelReplicas s3 (22/53 reruns), ClickHouse#120438
amd_debug and arm_binary ParallelReplicas s3 (94/94, 50/50), ClickHouse#124526
arm_binary ParallelReplicas s3 (38/38). No master failure.

Same fix as 05080_dedup_hash_lazy_replicated_column in ClickHouse#123943: skipped
in the ParallelReplicas jobs, enable_parallel_replicas = 0 elsewhere.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 comp-query-execution Runtime execution pipeline, processors, vectorized operators, resource management during execution. groeneai-origin-oranjeai PR origin: delegated from the OranjeAI sibling fleet pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants