Repository navigation
Do not fail the AST fuzzer job on a server-survived memory limit - #109590
PedroTadim merged 6 commits into
Conversation
A fuzzed query can push the server over its memory cap. The memory tracker rejects the allocation with Code 241 (MEMORY_LIMIT_EXCEEDED) and the server stays alive; clickhouse-client returns the server error code as its exit status, so the fuzzer exits 241 with server_died=0 and a clean server shutdown. run-fuzzer.sh's liveness loop already treats a 241 as "server alive, busy", but ast_fuzzer_job.py had no matching branch: fuzzer_exit_code 241 fell into the catch-all else and turned the whole job into a bogus ERROR "Client failure". Classify a server-survived 241 (server_died=0 and MEMORY_LIMIT_EXCEEDED present in the fuzzer log) as OK. A genuine unbounded-memory bug crashes the server instead and is still caught via server_died / OOM-in-dmesg. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260707-004100 |
|
cc @alexey-milovidov — could you review this? It makes the AST fuzzer job classifier consistent with run-fuzzer.sh's liveness loop: a server-survived Code 241 (MEMORY_LIMIT_EXCEEDED, server stays alive) is no longer reported as a job ERROR. |
|
Workflow [PR], commit [11c387f] Summary: ✅ AI ReviewSummaryThis PR makes Final Verdict✅ No actionable findings. |
Co-Authored-By: Claude Opus 4.8 <[email protected]>
The benign path swallowed any fuzzer exit 241 as long as some MEMORY_LIMIT_EXCEEDED text appeared in fuzzer.log. But clickhouse-client itself can raise 241 under --max_memory_usage_in_client (see tests/queries/0_stateless/02003_memory_limit_in_client.sh) and mainEntryClickHouseClient returns that code verbatim, so an escaped client/harness 241 was also reported OK, masking a real regression. Require server-origin evidence: match the transmitted-exception signature 'Received from ... MEMORY_LIMIT_EXCEEDED' (SERVER_MLE_SIGNATURE). A client-side 241 prints 'Code: 241. ...' with no 'Received from' prefix and is no longer swallowed. Test updated with client-vs-server cases. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
@clickhouse-gh[bot] good catch — the Fixed in e7277e2: the benign path now keys off a server-origin signature instead of any MLE text.
Demonstration (both directions): Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-3:20260708-082000 |
CI finish ledger — e7277e2Every failure below has a fixing PR owner. Only
Session id: cron:our-pr-ci-monitor:20260708-110000 |
CI finish ledger — e7277e2Every failure below has an owner (fixing PR or full-effort fix task). Only
Session id: cron:our-pr-ci-monitor:20260708-113000 |
| elif _is_benign_memory_limit( | ||
| server_died, | ||
| fuzzer_exit_code, | ||
| Shell.check(f"rg --text -q '{SERVER_MLE_SIGNATURE}' {fuzzer_log}"), |
There was a problem hiding this comment.
@groeneai shouldn't this check from the last queries sent by the fuzzer?
There was a problem hiding this comment.
Good catch, you are right. Fixed in 3979bde.
The AST fuzzer swallows a query-side server MEMORY_LIMIT_EXCEEDED and keeps running (Client::processASTFuzzerStep in programs/client/FuzzLoop.cpp resets the exception and returns true), so a 30-minute fuzzer.log accumulates many recovered Received from ... (MEMORY_LIMIT_EXCEEDED) lines that did NOT terminate the run. Only the terminal exception the swallow does not cover (e.g. the TCPHandler::receiveHello handshake path from the original failing log) sets the 241 exit. The old whole-log grep could match a stale earlier server MLE while the actual exit-241 came from something else (e.g. a client-side 241), masking a real regression.
The benign check now scans only the last queries the fuzzer ran: _fuzzer_log_tail_has_server_mle matches SERVER_MLE_SIGNATURE against the fuzzer.log tail (last 50 lines) instead of the whole log.
Pre-PR validation gate (click to expand)
| # | Check | Result |
|---|---|---|
| a | Deterministic repro? | Yes. ci/tests/test_ast_fuzzer_memory_limit.py::test_tail_ignores_stale_server_mle_before_tail: a log with a stale early server MLE + 200 later lines is classified NOT benign; the old whole-log grep returned True on the same input. |
| b | Root cause explained? | The fuzzer recovers from query-side server MLEs and continues, so fuzzer.log holds many non-terminal server MLE lines. A whole-log grep matches any of them, so a stale earlier server MLE could swallow a terminal client/harness 241 that exit-241 actually came from. |
| c | Fix matches root cause? | Yes. Evidence is now scoped to the log tail (the fuzzer's last queries), tying the benign 241 to its terminal cause. |
| d | Test intent preserved / new tests? | Yes. Kept the server-origin-signature and server-survived-241 cases; added 4 tail-scoping tests (terminal server MLE benign; stale-early server MLE NOT benign; terminal client 241 NOT benign; empty log). |
| e | Both directions? | Yes. Stale-early + terminal client 241: OLD whole-log = True (wrongly benign), NEW tail = False. Terminal server 241: NEW tail = True (benign preserved). |
| f | General, not narrow? | N/A (CI-script classification fix, not a code bug). |
| g | Generalizes across inputs? | N/A. |
| h | Backward compatible? | N/A (CI job classification only). |
| i | Invariants preserved? | Yes. _is_benign_memory_limit still gates on server_died==0 AND exit==241 AND server-origin evidence; only the evidence source narrowed from whole-log to tail. |
Session id: cron:clickhouse-worker-slot-0:20260714-160800
There was a problem hiding this comment.
3979bde still does not key this off the terminal query. In ci/jobs/ast_fuzzer_job.py:71-72 _fuzzer_log_tail_has_server_mle only searches the last 50 lines, so a recovered server-side MEMORY_LIMIT_EXCEEDED from step N can still sit in that window while the actual exit-241 from step N+1 is client-side. I reproduced that against the current helper with a log containing one swallowed server MLE, 15 stack-frame lines, then a later Code: 241. DB::Exception: Client memory limit exceeded; _fuzzer_log_tail_has_server_mle returned True, so run_fuzz_job would still classify the run as OK. This still needs to anchor on the last query block / last Dump of fuzzed AST: section rather than an arbitrary tail window.
There was a problem hiding this comment.
Fixed in 6d86f07. Replaced the fixed 50-line tail with terminal-query-block anchoring: _terminal_query_block() returns the text after the last Dump of fuzzed AST: marker (printed by programs/client/FuzzLoop.cpp:341 before each step executes), and _fuzzer_log_terminal_block_has_server_mle() searches only that block. A server-side MLE swallowed on step N sits inside step N's block, before the last dump marker, so it can no longer count as evidence for a terminal 241 from step N+1. Your exact reproduction (swallowed server MLE + 15 frames + later client-side Code: 241) now returns False and is covered by test_terminal_block_reproduction_from_review. When no dump marker is present (a startup/handshake 241 before any fuzz step) the read tail is treated as the terminal region, so the original TCPHandler::receiveHello false positive stays classified benign.
Pre-PR validation gate (click to expand)
| # | Question | Answer |
|---|---|---|
| a | Deterministic repro? | Yes. test_terminal_block_reproduction_from_review reconstructs the exact log shape you gave (swallowed server MLE, 15 stack frames, terminal client-side Code: 241) and asserts it is NOT benign. |
| b | Root cause explained? | The AST fuzzer swallows query-side server MEMORY_LIMIT_EXCEEDED and keeps running (Client::processASTFuzzerStep), so recovered Received from ... (MEMORY_LIMIT_EXCEEDED) lines from earlier steps stay in the log. A fixed 50-line/64 KiB window can straddle two steps, letting an earlier swallowed server MLE and a later client-side 241 share the window, so the run was wrongly classified OK. |
| c | Fix matches root cause? | Yes. The search is scoped to the terminal step (text after the last Dump of fuzzed AST:) — the only step whose outcome sets the exit code — instead of a size-based window that can cross step boundaries. |
| d | Test intent preserved / new tests added? | Yes. Kept the server-survived-241 -> OK case; added terminal-block tests: server MLE after last dump -> benign, earlier-step server MLE -> not benign, the reviewer repro -> not benign, terminal client-side 241 -> not benign, no-dump-marker startup 241 -> benign, empty log -> False. 12/12 pass. |
| e | Demonstrated in both directions? | Yes. Reviewer repro: old 50-line tail matches (wrongly benign) -> True; new terminal-block -> False. Terminal server-241 -> new terminal-block True (benign preserved). |
| f | Fix is general, not a narrow patch? | Anchoring on the terminal query block covers any earlier-step swallowed limit, not just the 15-frame gap in the repro; the bounded read (256 KiB) stays inside the terminal block by construction. |
| g | Generalizes across inputs? | N/A (CI-script log-classification fix, no ClickHouse code path / datatype surface). |
| h | Backward compatible? | N/A (CI job classification only; no settings, formats, or user-visible behavior). |
| i | Invariants/contracts preserved? | Yes. _is_benign_memory_limit still requires server_died == 0 and fuzzer_exit_code == 241; the only change is tightening the third condition from a fixed tail window to the terminal block. |
Session id: cron:clickhouse-worker-slot-10:20260716-103900
The fuzzer swallows query-side server MEMORY_LIMIT_EXCEEDED and keeps running (Client::processASTFuzzerStep), so a 30-min fuzzer.log holds many recovered server MLE lines that did not terminate the run. A whole-log grep could match a stale one and wrongly classify a terminal client/harness 241 as OK. Scan only the tail so the benign 241 is attributed to its actual terminal cause. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ry block A fixed 50-line tail can hold a swallowed server-side MEMORY_LIMIT_EXCEEDED from step N together with a terminal client-side 241 from step N+1 when only a few stack frames separate them, so the whole run would still be classified OK and mask a real client/harness regression. Scope the server-MLE search to the text after the last 'Dump of fuzzed AST:' marker (the terminal step whose outcome sets the exit code) instead of a fixed-size tail window. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Head branch was pushed to by a user without write access
…marker Extend the benign-Code-241 classifier so it fires on the real PR ClickHouse#109006 log, which two independent gaps caused it to miss, and harden the terminal-cause check. 1. Signature. SERVER_MLE_SIGNATURE required "Received from" and the enum "MEMORY_LIMIT_EXCEEDED" on one line, but a real server-transmitted limit prints the prose "(total) memory limit exceeded" on the "Received from" line and the enum on a separate line, so it matched nothing. Match either the enum or the prose form; the "Received from" prefix keeps it server-origin, so a client-side --max_memory_usage_in_client 241 is still not treated benign. 2. Terminal-block anchor. The block was anchored on the last "Dump of fuzzed AST:" marker, which is printed to stdout. run-fuzzer.sh merges the streams with "> fuzzer.log 2>&1"; stdout is block-buffered when redirected, so the terminal step's dump is flushed at process exit AFTER its own unbuffered stderr exception, and the last dump marker is a trailing re-dump past the evidence. Anchor on the last "Fuzzing step N out of M" marker instead (stderr, causally ordered). No marker (a startup/handshake 241 before any step, or BuzzHouse) falls back to the read tail, as before. 3. Terminal-cause ordering. The terminal block can still hold a server limit the run recovered from earlier followed by a later client/harness 241 -- a recovered query limit then a client-side reconnect/handshake 241 within a step, or the same across a markerless BuzzHouse/startup tail. Treat it as benign only when no client-origin 241 line (a "Code: 241" line with no "Received from" prefix) appears after the last server-origin MLE, so a later client/harness 241 still surfaces while an earlier recovered client 241 does not veto a genuinely terminal server limit. The terminal-step invariant from earlier review rounds is preserved: a swallowed earlier-step query MLE cannot mask a later client 241, both because it sits before the terminal step's "Fuzzing step" marker and because a client 241 after the last server MLE now vetoes the benign classification. Regression tests: a prose-form signature case, a fixture built from the real log's shape (prose MLE + trailing buffered dump), and ordering cases (a later client 241 is not benign in both the marker and no-marker forms; a terminal server limit after an earlier recovered client 241 is benign); the prior invariant tests are kept. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings across 1 full pass + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-0:20260721-071501 |
|
Extended the benign-241 classifier to cover the real #109006 log shape (@ 11c387f). Two gaps, plus a hardening: (1) the server-MLE signature only matched the enum Verified end-to-end against the real #109006 Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-0:20260721-071501 |
|
cc @PedroTadim — this addresses the terminal-query concern you raised: the classifier now anchors the terminal block on the stderr |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
A fuzzed query can push the server over its memory cap. The memory tracker rejects the allocation with
Code 241 (MEMORY_LIMIT_EXCEEDED)and the server stays alive.clickhouse-clientreturns the server error code as its exit status, so the fuzzer process exits 241 withserver_died=0and a clean server shutdown.run-fuzzer.sh's post-fuzz liveness loop already treats a 241 as "server alive, busy", butci/jobs/ast_fuzzer_job.pyhad no matching branch:fuzzer_exit_code == 241fell into the catch-allelseand turned the whole job into a bogusERROR("Client failure").This makes the Python classifier consistent with the shell loop: a server-survived 241 (
server_died == 0andMEMORY_LIMIT_EXCEEDEDpresent in the fuzzer log) is classifiedOK. A genuine unbounded-memory bug crashes the server instead and is still caught viaserver_died/ OOM-in-dmesg, so this does not mask real findings.Adds
ci/tests/test_ast_fuzzer_memory_limit.pycovering: server-survived 241 -> OK; 241 without log evidence -> not benign; dead server -> not benign; non-241 client failure -> not benign.CI report showing the failure this addresses (AST fuzzer (amd_debug), server RSS 44.56 GiB > 44.46 GiB cap, Code 241 on
SET send_logs_level='fatal'atTCPHandler::receiveHello): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=107236&sha=0c14f334914a3654b21050598ac4def93be109d6&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29