Skip to content

Collect the full diagnostics when a stateless job fails during setup - #117294

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:collect-diagnostics-on-stateless-setup-failure
Sep 3, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:collect-diagnostics-on-stateless-setup-failure

Conversation

@groeneai

@groeneai groeneai commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #110321 (comment)
Related: #115585

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):

A stateless job that fails during setup now uploads the same diagnostics as one that fails during tests.

Description

Stateless tests (amd_tsan, flaky check) on #110321 failed before any test ran:
prepare_stateful_data hit its per-statement bound on
INSERT INTO test.hits_s3 SELECT * FROM test.hits
(report).
Its diagnostics were then discarded. @ alexey-milovidov asked me for a separate PR.

functional_tests.py assigns test_result only inside the test stage, so a setup failure
leaves it None, test_run_failed reads False, and prepare_logs runs with all=False -
dropping cores, system-table dumps, the SeaweedFS log, dmesg and Keeper logs, for exactly
the runs that cannot explain themselves. Here job.log logs send TRAP signal to generate core file and Collect logs in the same second. The shape covers 45+ stateless runs in 30 days.
#115585 got such a job to reach Collect logs; this makes it collect.

Four changes, all under ci/:

  • capture gdb -batch -ex 'thread apply all backtrace' into the log directory when a prep
    statement hits its bound; skipped on ASan lanes, where the attach disables LeakSanitizer;
  • require timeout's own TERM diagnostic before trusting exit 124, which is also the
    error code INCORRECT_ELEMENT_OF_SET;
  • count a setup failure as a failure in the artifact-collection predicate;
  • run dmesg in the full-collection path, where nothing did: a setup failure gains
    dmesg.log, and a run whose OOM check already graded one gains dmesg.at-collect.log
    beside it, because start clears the buffer per server generation.

Green runs are unchanged.

This does not fix the hang; it makes the next occurrence diagnosable. Also not
fixed: the fatal-log scan still skips setup failures; a failure before start dumps an
uncleared ring buffer; stop_server still waits 10 s after SIGTRAP, so a core may not
survive; the gdb attach is argued from container flags, not measured in-container; ASan lanes
get no stacks. #109745 edits the same function without overlap.

The hang this PR does not fix

Measured from the job's own clickhouse-server.log. The INSERT
(22411ddf-da0f-4f93-90b6-c4a06af00f93) progresses normally for 35.4 s, writing blocks and
completing S3 uploads at 8.00 GiB of tracked memory against an 85.25 GiB cap. Then the server
emits nothing at all for 62.0 min, from any of the 186 threads that had ever logged, and the
last line of the log is an unfinished SystemLog (system.query_metric_log): Flushing system log. Of 18 system logs, only metric_log and query_metric_log have an unmatched
Flushing. --max_execution_time 1800 never fired, so the query threads were blocked rather
than slow; SYSTEM FLUSH LOGS afterwards returned Code: 209 SOCKET_TIMEOUT after the full
300 s receive timeout; SIGTERM was ignored for 300 s. TERM landed at exactly +3150 s, the
bound from #115585, to the second.

Truncation is ruled out: the file ends on a complete line at 3.43 MB with no .zst sibling,
and jobs at the same commit uploaded 59.7 MB and 9.96 MB logs spanning their full durations.
Same-commit, same-binary controls for the identical statement: amd_tsan parallel 133 s,
amd_tsan sequential 277 s, amd_asan_ubsan flaky check 789 s, against >3150 s here.

A merely slow INSERT logs continuously. A server that answers no new query is globally
blocked, and naming the mechanism needs a thread stack, which no occurrence has produced -
7 in 90 days, none with a core or a fatal.log. That is what this PR adds.


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

`functional_tests.py` assigns `test_result` only inside the test stage, so a
setup failure leaves it `None`. `test_run_failed` is derived from it alone, reads
`False`, and `prepare_logs` runs with `all=False`: core dumps, system-table dumps,
the object-storage service log, dmesg and the Keeper logs are discarded for
exactly the runs that have no test results to explain themselves with.

Found while investigating a `Stateless tests (amd_tsan, flaky check)` failure on
2def28a, where `prepare_stateful_data` hit its per-statement bound on
`INSERT INTO test.hits_s3 SELECT * FROM test.hits`. That job's `result.json` has
three children (`Install ClickHouse`, `Start ClickHouse Server`, `Collect logs`,
`Failures: 1/3`), and its `job.log` records `send TRAP signal to generate core
file` and `Collect logs` in the same second: the harness asked the kernel for a
core with the core, system-table, object-storage-log, dmesg and coordination
branches all switched off. Whether a core survived the ten-second wait that
follows the `SIGTRAP` cannot be told from what was uploaded, which is itself the
problem. Of the 403s an earlier investigation saw, `dmesg.log` is the one fully
explained by this defect. In CIDB over 30 days that three-child shape covers 58
job-level rows of `Stateless tests (...)` lanes, across 28 commits and 19 of those
lanes, at least 45 of them in lanes that do collect logs.

Four changes:

- Capture an external all-thread backtrace when a prep statement hits its bound.
  Both in-process routes are dead for the case that needs them: the `SIGTRAP` in
  `stop_server` produced no log output at all, and `SYSTEM FLUSH LOGS` returned
  `Code: 209 SOCKET_TIMEOUT`, so `system.stack_trace` is unreachable. Meanwhile
  the wedged server stayed alive and unexamined for ten minutes between the prep
  returning and teardown starting. `STACK_CAPTURE_TIMEOUT_S` is 300s, derived
  from measurement rather than guessed: on the failing job's own TSan binary
  (build id 66b21ff2c033) a capture took 16.7s idle over 203 threads, 20.5s and
  20.6s loaded over 347 threads, and 13.5s for the literal command emitted here
  over 381 threads, resolving 1874 `DB::` frames of which 1280 carried
  `at ./src/...` file and line. `tests/docker_scripts/stress_tests.lib` allows
  1800s for the identical command, so 300s is the conservative end. Two
  consecutive attaches during an insert left the server serving and the insert
  completed, so the capture does not disturb what it inspects.

- Skip that capture on ASan builds, where attaching a debugger disables
  LeakSanitizer. `tests/clickhouse-test` already applies this policy in
  `print_c_stacktraces` and its message is reused verbatim so the same wording
  appears in `job.log`. The test matches `"ubsan"` as well as `"asan"` so that a
  build name carrying `ubsan` without `asan` (which this repository's defs do not
  produce, though `functional_tests.py:55` and
  `src/Core/tests/gtest_protocol_packet_to_string.cpp:23` both refer to private
  `amd_ubsan` and `arm_ubsan` lanes) is skipped rather than captured. No build
  type in the tree changes behaviour, since both in-tree `ubsan` names already
  contain `asan`. `arm_fuzzers` is also built with
  `SANITIZE=address` and matches neither, but it is consumed only by
  `libFuzzer tests`, which never runs `functional_tests.py`; a branch for it would
  be dead code.

- Require `timeout`'s own TERM diagnostic before treating exit 124 as an expiry.
  124 is also the ClickHouse error code `INCORRECT_ELEMENT_OF_SET`, which the
  client returns from `main`, so the code alone does not distinguish a bound
  firing from a server exception. This mirrors the existing treatment of 137. The
  needle deliberately contains no quotes: the real diagnostic quotes the command
  name with U+2018/U+2019 under a UTF-8 locale, so a needle written with ASCII
  quotes would silently never match. The predicate reads the whole prep log rather
  than the fifteen-line tail the error message uses. `Shell.run` streams stdout and
  stderr into one file, so the diagnostic and the ERR trap are the last lines
  written and a tail normally holds them, as it did here; reading the whole log
  removes the dependence on that ordering. The tail itself is sliced with
  `io.StringIO(text).readlines()`, which is exactly what the previous
  `f.readlines()` produced, rather than `str.splitlines`, which also breaks on
  `\x0b`, `\x0c`, `\x1c`-`\x1e`, U+0085 and U+2028 and would have altered the
  recorded message.

- Produce `dmesg.log` in the full-collection path. Its only other producer is the
  OOM check, which needs test results to grade, so a setup failure never wrote
  the file that the collection list then looked for. Where that check has already
  run, its graded file is left untouched and the current buffer is written beside
  it as `dmesg.at-collect.log`, because `start` clears the ring buffer for each
  server generation: declining to capture would upload an earlier generation's
  buffer, and overwriting would leave the graded `OOM in dmesg` row disagreeing
  with the uploaded bytes. A setup failure that never reached `start` gets an
  uncleared buffer, so its dump can include lines from earlier on the host;
  nothing grades it, because the fatal scan needs test results. A `dmesg` that
  fails leaves an empty file behind, because the shell creates the redirect
  target first, so that file is removed and a warning printed rather than
  uploaded as an empty dump that reads as "no OOM".

The capture is written under `log_dir` as `stateful-prep-stacks-<pid>.log`, which
is uploaded on every collection and matches none of the `clickhouse-server*.log`,
`clickhouse-server*.err.log` or `stderr*.log` globs that
`check_fatal_messages_in_logs` greps for `<Fatal>` and sanitizer text, so a
backtrace cannot become a false blocker. `gdb` exits 0 even when an attach is
refused, so its stderr is redirected into the same file and the artifact explains
its own emptiness; `Shell.check` cannot raise, so a missing or unattachable `gdb`
leaves the job's outcome unchanged.

This does not fix the hang underneath the reported failure. That server logged
normally for 35.4s of the insert, then emitted nothing for 62.0 minutes from any
of the 186 threads that had ever logged, never raised `max_execution_time`,
answered no new query, and ignored SIGTERM for 300s. Naming the mechanism needs a
thread stack, and none of the seven occurrences in 90 days produced one, or a core,
or a `fatal.log`. An earlier revision of this work instead bracketed the fixture
load with `SYSTEM STOP/START THREAD FUZZER`; that was withdrawn after measurement,
because the fuzzer accounts for 1.76x against a failure of more than 23.7x, its
pthread wrappers are compiled out under TSan, and five arms including one at five
times the CI fuzzer strength all completed with continuous logging. Perturbing the
timing of the thing being diagnosed could also have made the only occurrences
available disappear.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110321&sha=2def28ac1fbdc8166d4e6c37c00ab830b4248148&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29
Related: ClickHouse#110321

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Aug 31, 2026
@groeneai

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

Pre-publication review of this change: my own cold review of the resulting code plus an
independent model pass (engine: codex), repeated each fix round. Every finding below was
either fixed before publication or is recorded here with its refutation.

# Sev Finding Verdict Evidence / action
1 ⚠️ The commit message claimed the failing job's recorded fifteen-line tail held no timeout diagnostic, and a source comment claimed the diagnostic precedes the last statement's output AGREE, fixed Both false. The praktika logger stamps every line of a multi-line message, so the tail reads as its first line under grep; the recorded tail is 15 lines and its 14th IS the TERM diagnostic. Shell.run streams stdout and stderr into one file, so the diagnostic is written last, not first. Comment deleted, wording corrected, and the validation arm built on the wrong string replaced
2 ⚠️ The LeakSanitizer guard fails open on an ASan build whose name lacks asan (ci/jobs/scripts/clickhouse_proc.py) AGREE, fixed ci/jobs/functional_tests.py:55 documents a private amd_ubsan ASan+UBSan lane; that name does not match asan, so a debugger would have been attached to an ASan build. The predicate now also matches ubsan: a no-op for every build type in the tree (both in-tree ubsan names already contain asan) and fail-closed for the others
3 💡 The justification for that guard over-reached, asserting no build carries ubsan without ASan AGREE, fixed The tree holds both a supporting source (functional_tests.py:55) and a contradicting one (docs/.../continuous-integration.mdx:187 lists Build (amd_ubsan) as a UBSan build beside a separate amd_asan), so the absolute is not settleable from public data. The code is correct on every branch either way; only the claim was wrong, and it now states what is checkable
4 ⚠️ A bugfix-validation re-preparation failure could upload the previous build type's dmesg.log AGREE, fixed start clears the ring buffer per server generation and the earlier fatal scan leaves a graded dmesg.log behind, so the no-overwrite guard published the wrong generation's buffer. The graded file is now kept and the current buffer captured beside it
5 ⚠️ The new setup-failure collection can attach diagnostics and encrypted cores belonging to a previous CI job DISAGREE Raised twice, and refuted by measurement both times it was acted on. The premise is that ci/tmp survives between jobs because it is gitignored and ci/praktika/runner.py:167 runs git clean -ffd without -x. Both citations are true; the conclusion is not, because git clean is not what clears ci/tmp. The generated workflow does, one step earlier: every praktika run step is preceded in its own job block by an unconditional rm -rf ./ci/tmp. Parsing all 32 workflow files: 537 run steps, 0 unwiped, and 0 jobs with a second run step that could inherit leftovers. Control: deleting that one line from the stateless_tests_amd_tsan_flaky_check block yields exactly 1 violation at that job, so the zero is a real negative. clickhouse_proc.py:26 puts temp_dir inside ci/tmp, so every surface named is covered by the wipe
6 ⚠️ The ring buffer, unlike ci/tmp, is host state, and a comment claimed a provenance guarantee that a setup failure before start does not have AGREE, fixed The residual of #5 that the wipe does not cover. functional_tests.py:1019-1021 can fail before CH.start() at :1022, so dmesg --clear (clickhouse_proc.py:349-351, inside start) never runs, yet the dump at :854-864 still happens. Nothing grades it: the only grader is reached via check_fatal_messages_in_logs, gated at functional_tests.py:1485 on a non-None test result, so no false OOM in dmesg verdict is reachable. Fixed as a comment stating the scoping in both directions, plus a disclosure in the description and the commit message. Clearing the buffer earlier was rejected (it destroys pre-job host history, needs privilege the sibling call takes with sudo, and no local test can back it); suppressing the dump was rejected (it removes the artifact on the one path this change exists to serve)
7 ⚠️ The description understated the change's blast radius on the ordinary test-failure path AGREE, fixed Every failing stateless job, not only a setup failure, now also gains a dmesg.at-collect.log, since the OOM check has already written dmesg.log by then. The description named only the setup-failure gain and the bullet named the wrong filename for the common case
8 ⚠️ The commit message listed gdb.log among the artifacts this defect discarded AGREE, fixed No stateless path has ever written that name: it belongs to tests/docker_scripts/stress_tests.lib and the fuzzer script, so it is absent regardless of this defect. Removed
9 ⚠️ The commit message asserted a core file existed and was discarded AGREE, fixed Only the request is provable. stop_server follows the SIGTRAP with a ten-second wait and then a SIGKILL, which aborts a dump in progress, and that SIGTRAP produced no server log output at all. Reworded to the provable claim, with the ten-second wait listed as a limitation
10 ⚠️ The commit message's CIDB counts did not reproduce as written AGREE, fixed The unrestricted 30-day query returns 1053 rows over 51 checks, dominated by Fast test and the build jobs; the quoted 58 rows over 19 checks needs the restriction to Stateless tests lanes, which is now stated
11 ⚠️ The diagnostics contract has no visible live regression evidence DISAGREE The check is a two-module A/B: the pristine copy of clickhouse_proc.py is loaded beside the modified one and exactly one of five arms is asserted to flip, so it does fail with the previous predicate. The capture itself was forced on the failing job's own TSan binary against a real s3_cache disk (1874 resolved frames), the ASan skip is driven over every reachable build type with a negative control, and absent gdb, a dead pid and all-pids-zero are covered. The one element genuinely missing is a live in-container run, which the description states as a limitation
12 💡 The tail slice changed its line-splitting alphabet, so the recorded error string was not guaranteed unchanged AGREE, fixed splitlines splits on more separators than a text-mode readlines; the faithful form is used now
13 💡 An unavailable dmesg left a zero-byte artifact that reads as "no OOM" AGREE, fixed The write is gated on its exit code, mirroring the existing OOM check
14 💡 A comment justified the predicate by contrast with an alternative I could not construct AGREE, fixed res starts true, its outer assignments are all is_ok() (which accepts SKIPPED), and the res writes inside the start closure bind that closure's own local, so the contrast does not hold. Removed from the source comment in an earlier round and, in the last round, from the commit message as well - relocating a false claim does not fix it
15 💡 Measurements and refuted alternatives sat in source comments AGREE, fixed Moved to the commit message, where the numbers already were
16 ⚠️ The false contrast above survived in the commit message after being deleted from the comment AGREE, fixed The earlier round's evidence said two things - that the clause belonged in the commit message under the repository's comment rule, and that it asserted a run that cannot be constructed. Only the first was acted on, so a deletion became a promotion into permanent history, where a later commit cannot correct it. Deleted outright, with no replacement justification
17 💡 INCORRECT_ELEMENT_OF_SET was not written as inline code in a comment AGREE, fixed .claude/CLAUDE.md:7 requires literal ClickHouse names in comments and commit messages to be wrapped in inline code, and that rule predates this branch. The same comment already backticked timeout and the commit message already backticked this identifier, so the comment was the only inconsistency; a sweep of every added line plus the whole commit message found this one site
18 💡 A failed dmesg in the pre-existing OOM check still leaves a zero-byte dmesg.log that collection uploads DISAGREE Real, and pre-existing rather than introduced here: the previous code appended the same empty file unconditionally, so this change never worsens it, and where the collection-time dmesg succeeds it strictly improves the artifact set by adding a real dump beside the empty one. No verdict can be affected, because that check returns no result at all when its own dmesg fails. The branch is also not taken in these jobs, which run privileged as root. Fixing the other producer would be a defensive change in an unrelated function on a path CI does not reach; disclosed here instead
19 ⚠️ The commit message carried no CI provenance URL AGREE, fixed .claude/CLAUDE.md:169 requires that a supplied CI report URL go into the commit message, and that a link carrying PR=... be accompanied by a link to that pull request. Both conditions applied here and the message held no URL at all. An earlier round declined this on the ground that no rule placed them there, which was wrong about the same file that round quoted for finding 17. Report URL and pull-request link added
20 ⚠️ The Related: lines sat inside the template's HTML comment, so the rendered description carried no relationship line AGREE, fixed An earlier round declined this because upstream PULL_REQUEST_TEMPLATE.md puts them there. But the repository rule asks for them "on its own line in the pull request description" and says GitHub renders and auto-closes from them, neither of which happens inside a comment. The concern behind not editing the template is the ### headers that CI parses; the parsers (pr_labels_and_category.get_category, pr_body_check.check_changelog_entry) are line scanners keyed on those headers and indifferent to the comment. Both lines now render, once each
21 💡 A comment called 300 s the wall-clock cap of one backtrace capture AGREE, fixed The same invocation passes --kill-after=60, so timeout signals TERM at 300 s and escalates to KILL at 360 s: the real bound is 360 s. Reworded to name the TERM deadline; the grace period is already documented on the constant two lines above
22 💡 The repaired predicate widens collection for an Install ClickHouse failure too, not only a Start ClickHouse Server one Noted, not blocking Correct and intended: an install failure is a setup failure. The widened work is bounded by machinery that already runs for every test failure - dump_system_tables bounds each of its ten dumps with timeout --verbose --signal=TERM --kill-after=60 600 - and prepare_logs degrades its own exceptions into a workflow warning, so nothing new can fail a job. Recorded here rather than fixed

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by a fix round are auto-dropped.

The final round found nothing: my own full-scope cold re-derivation of the diff (23
verifications) and the independent pass both returned zero findings on the published tree.
The decisive check was liveness rather than style - the failing job's own job.log carries
both exit 124 and the literal needle sending signal TERM to command, in its genuine
U+2018-quoted form, on a lane where the ASan skip does not apply, with the server still
holding its socket for the following 300 s. So the new capture fires on the exact failure it
was written for, and the deliberately quote-free needle is load-bearing: an ASCII-quoted one
would have matched nothing, silently, forever.

Session id: cron:clickhouse-review-slot-9:20260831-083300

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 31, 2026
@clickhouse-gh clickhouse-gh Bot closed this Aug 31, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 31, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. PYTHONPATH=.:./ci python3 tmp/v_checks.py (throwaway, not committed) - 118 checks, 0 failures. The bug is the predicate itself: test_result=None, res=False reads as "nothing failed". No server, no timing, exit-code asserted.
b Root cause explained? functional_tests.py assigns test_result only inside if res and JobStages.TEST in stages:. A setup failure sets res=False, so test_result stays None, test_run_failed = bool(test_result) and not test_result.is_ok() is False, and prepare_logs(all=False) discards everything under if all: - cores, system tables, the object-storage log, dmesg, Keeper logs. On the reported job job.log records send TRAP signal to generate core file and Collect logs in the same second, i.e. the harness asked the kernel for a core with every one of those branches switched off; whether a core file survived the ten-second wait that follows cannot be told from what was uploaded, which is itself the problem. Of the 403s an earlier investigation saw, dmesg.log is explained by this defect - gdb.log is not, since no stateless path has ever written that name.
c Fix matches root cause? Yes, at the point the information is lost. The per-statement bound the failing job hit is not widened, no no-random-* tag, no suppression, nothing masked. The stack capture adds the one artifact no existing path could produce for an unresponsive server: SIGTRAP yielded zero log output and SYSTEM FLUSH LOGS returned Code: 209 SOCKET_TIMEOUT, so system.stack_trace is unreachable by construction.
d Test intent preserved / new tests added? No test weakened. No committed test, deliberately: .claude/CLAUDE.md:190 sanctions an uncommitted throwaway for CI-script changes, and ci/tests/ was deleted from master (#115650) - git tracks files not directories, so adding one there merges without conflict and resurrects a dead directory. Throwaways live in tmp/.
e Both directions demonstrated? Yes, as an A/B of two modules: tmp/v7_green.py loads the pristine branch-base copy of clickhouse_proc.py alongside the modified one, pinned to the base revision rather than to HEAD (once committed, HEAD is the modified module) and guarded by hasattr assertions that the base arm really predates the change. Setup-failure row: all=False (artifacts dropped) -> all=True (collected). The other four rows - green, stage-limited, ordinary test failure, bugfix no-repro - are identical, and "exactly one row flips" is asserted mechanically.
f Fix is general across code paths? All three prepare_logs call sites enumerated: clickbench.py:152 passes a literal all=False and fast_test.py:414 gates on attach_debug, so neither derives a predicate from a test result. The bugfix-validation re-prepare site already set test_result.status = ERROR, so it was already collecting; the capture fires there too, living inside prepare_stateful_data. The tightened predicate's other consumer, dump_system_tables, is covered in V2b. Multi-server runs loop pid_0/1/2.
g Fix generalizes across inputs? (test_result, res): all 5 reachable combinations. (rc, stderr): 7 combinations plus four real-artifact arms over both recorded reprints of the failing job's tail, in its genuine U+2018-quoted form and its ASCII-quoted LC_ALL=C form. build_type: the closed set of 8 from bugfix_build_types, all driven, plus the two private *_ubsan ASan+UBSan lanes and 2 non-sanitizer extras. The log text itself: six line separators against the pre-change slicing expression. Boundaries: pid 0, nonexistent pid, gdb absent from PATH, dmesg unavailable, dmesg.log present vs absent.
h Backward compatible? Yes. No setting, no serialization format, no SettingsChangesHistory.cpp, nothing user-visible. Green runs are byte-identical. Behaviour changes only on an already-failing job, and there the artifact set changes by design: a failing run gains a dmesg.log where the fatal-message scan is skipped, or a dmesg.at-collect.log beside it where that scan already produced and graded one.
i Invariants and contracts preserved? prepare_stateful_data still returns rc == 0 and records a byte-identical stateful_setup_error - by construction, since the tail is sliced with io.StringIO(text).readlines()[-15:], exactly readlines() on the same text, asserted against the pre-change expression over six separators. prepare_logs still returns the list it assigns to self.logs. The capture cannot raise (Shell.check returns a bool), so a broken capture never turns a setup failure into a crash - asserted with a nonexistent pid and with gdb off PATH. The tightened predicate only ever becomes stricter. dmesg is handled in two directions at once: start clears the ring buffer per server generation, so declining to capture would upload an earlier generation's buffer, while overwriting the file the OOM check already graded would leave that row and the uploaded bytes disagreeing - so a graded file is kept and the current buffer is written beside it, and both are uploaded. Where the failure returned before start ever ran (functional_tests.py:1019-1021, ahead of CH.start() at :1022) the buffer was never cleared, so that dump can carry lines from earlier on the host; nothing grades it, because the only grader is check_ch_is_oom_killed and every route to it is gated on test results (:1186 and :1339 inside if is_bugfix_validation: after tests ran, :1485 on if test_result and ...), so no false OOM in dmesg verdict is reachable. A failed dmesg unlinks the empty file the shell's redirect leaves, so an empty artifact never reads as "no OOM" when it means "no dmesg".

Capture validated on the failing job's own TSan binary (build id 66b21ff2c033...)
against a real s3_cache disk over SeaweedFS: 381 threads, 1874 DB:: frames,
1280 with at ./src/...:NNN, 13.5 s. Two consecutive attaches mid-INSERT left the
server serving (SELECT 1 OK, same pid, thread state S) and the INSERT finished
with all 8873898 rows. STACK_CAPTURE_TIMEOUT_S = 300 is ~15x the slowest of four
measurements; the in-tree equivalent in stress_tests.lib allows 1800 s.

The ASan skip is driven over every reachable build type with a negative control that
it does not swallow the timeout handling; a dead pid and an absent gdb are covered;
and the green path is an A/B against the pristine copy of the same module asserting
exactly one row of the predicate flips. What local validation cannot settle is a live
in-container attach: the image ships gdb, and the job's own docker run line
carries --cap-add=SYS_PTRACE --privileged and no --user, but that is inference
from the harness rather than an observed attach.

Session id: cron:clickhouse-review-slot-9:20260831-083300

@clickhouse-gh

clickhouse-gh Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ebed802]

Summary: ✅


AI Review

Summary

This PR fixes the functional_tests.py failure predicate so setup failures collect the same debug bundle as test failures, and it adds external gdb stack capture for timed-out stateful preparation. I would still block it as written, because the widened dmesg upload path is now reachable before CH.start() has cleared the kernel ring buffer.

Findings

❌ Blockers

  • [ci/jobs/functional_tests.py:1507; ci/jobs/scripts/clickhouse_proc.py:854-866] [dismissed by author -- https://github.com/Collect the full diagnostics when a stateless job fails during setup #117294#discussion_r3893238324] setup_failed makes prepare_logs(all=True) run on install / start_seaweedfs / start_azurite failures too, but those paths return before CH.start() executes dmesg --clear. The new dmesg capture therefore uploads the host's uncleared kernel ring buffer from unrelated jobs and host activity. The dump not being graded only avoids a false OOM in dmesg verdict; it does not remove the new cross-job disclosure surface. Gate this upload on "buffer was cleared for this run", or skip dmesg when the failure happened before start().
Final Verdict

Changes requested. The extra diagnostics are useful, but the pre-start() dmesg upload still needs to be removed or gated before this is safe to merge.

LLVM Coverage Report

⚠️ No coverage measurement for commit ebed802: incomplete coverage measurement: 16 of 21 shard profiles are missing: LLVM_COVERAGE_FILE_ft_2.profdata, LLVM_COVERAGE_FILE_ft_3.profdata, LLVM_COVERAGE_FILE_ft_old_s3_db_repl_parallel_2.profdata, LLVM_COVERAGE_FILE_ft_old_s3_db_repl_parallel_3.profdata, LLVM_COVERAGE_FILE_ft_old_s3_db_repl_sequential_1.profdata, LLVM_COVERAGE_FILE_ft_old_s3_db_repl_sequential_2.profdata, LLVM_COVERAGE_FILE_ft_s3_async_sequential.profdata, LLVM_COVERAGE_FILE_ft_s3_sequential.profdata, LLVM_COVERAGE_FILE_it_1.profdata, LLVM_COVERAGE_FILE_it_2.profdata, LLVM_COVERAGE_FILE_it_3.profdata, LLVM_COVERAGE_FILE_it_4.profdata, LLVM_COVERAGE_FILE_it_5.profdata, LLVM_COVERAGE_FILE_it_6.profdata, LLVM_COVERAGE_FILE_it_7.profdata, LLVM_COVERAGE_FILE_it_8.profdata.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @leshikus, could you review this? functional_tests.py derives its artifact-collection predicate from test_result, which a setup failure leaves None, so a job that failed before any test ran uploaded none of the cores, system-table dumps, dmesg or Keeper logs. This repairs that predicate and adds an external gdb all-thread backtrace when a stateful-prep statement hits its bound, since a wedged server cannot serve system.stack_trace.

if Path(self.DMESG_LOG).exists()
else self.DMESG_LOG
)
if not Shell.check(f"dmesg > {dmesg_target}", verbose=True):

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.

This now runs on every all=True failure, but all=True also became reachable before CH.start() runs at all (functional_tests.py:1507). On the install / start_seaweedfs / start_azurite failure paths, start() never executed the dmesg --clear at clickhouse_proc.py:349-351, so this uploads the host's uncleared kernel ring buffer from previous jobs and unrelated host activity. That is a new cross-job information disclosure surface, and it can also misattribute an older OOM to the current setup failure.

Please gate the dmesg capture on a flag that is set only after start() successfully clears the buffer, or skip uploading dmesg for failures that happen before that point.

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 reachability is right, and it is already disclosed. functional_tests.py:1019-1021 returns before CH.start() at :1022, so dmesg --clear never runs on the install, seaweedfs or azurite paths. The description lists it under what this does not fix ("a failure before start dumps an uncleared ring buffer"), and row 6 of the adjudication comment covers it together with both remedies suggested here.

I am not gating the capture. Nothing grades that dump: check_ch_is_oom_killed has a single caller, check_fatal_messages_in_logs (clickhouse_proc.py:1183), and all three of its call sites need test results (functional_tests.py:1186 and :1339 sit inside if is_bugfix_validation:, which dereferences test_result.results at :1182; :1491 sits under the if test_result and ... gate at :1485). So no OOM in dmesg verdict is reachable on the pre-start path, and the residual is a human reading an artifact the description already labels.

Skipping the upload instead would remove the artifact on the one path this change exists to serve, which is the defect being fixed. Clearing the buffer earlier destroys pre-job host history and needs privilege the sibling call takes with sudo.

Comment thread ci/jobs/scripts/clickhouse_proc.py Resolved
@alexey-milovidov alexey-milovidov self-assigned this Sep 3, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 3, 2026
Merged via the queue into ClickHouse:master with commit 69b2d1b Sep 3, 2026
513 of 514 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 3, 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 manual approve Manual approve required to run CI 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.

3 participants