Skip to content

Don't fail CI when only the CIDB staging log cluster is unresponsive - #106176

Closed
groeneai wants to merge 20 commits into
ClickHouse:masterfrom
groeneai:fix-cidb-staging-cluster-overload-server-died
Closed

groeneai wants to merge 20 commits into
ClickHouse:masterfrom
groeneai:fix-cidb-staging-cluster-overload-server-died

Conversation

@groeneai

@groeneai groeneai commented May 31, 2026 •

Copy link
Copy Markdown
Collaborator

Per @alexey-milovidov on PR #106154 (2026-05-31T02:17:47Z):

Send another PR that will work around that by not making the CI check red if that staging cluster is not responding.

Problem

FTResultsProcessor in ci/jobs/scripts/functional_tests_results.py adds a synthetic Server died FAIL leaf whenever runner_exit_code is in ABORTED_RUN_EXIT_CODES = {2, 137, 143, -15, -9}. This covers in-band aborts (StopTesting, exit code 2) but also any out-of-band kill, including the harness wall-clock timeout.

A pathological pattern hits stateless jobs that run with the targeted/test-batch wall-clock budget (e.g. Stateless tests (arm_asan_ubsan, targeted), 50-minute cap): the ClickHouse server is healthy and every individual test passes, but the background Distributed system-log sender keeps retrying to ship rows from system.<table>_sender tables to the CIDB staging log cluster (kng4alm55c.us-east-2.aws.clickhouse-staging.com:9440). When that staging cluster is overloaded, the retries pile up, _flush_system_logs blocks, the runner runs out of wall-clock time, the harness sends SIGTERM (Python subprocess.returncode == -15), and FTResultsProcessor paints the check red with Server died.

CIDB shows this is a real chronic infra-noise pattern, not a hypothetical: 77 hits across 57 distinct PRs and 0 master in the trailing 30 days, with a single-day burst of 50 hits across 43 unrelated PRs on 2026-05-30. PR #106154 was one such victim - all 1683 tests passed, server exited normally with code 0, and clickhouse-server.err.log contained 1902 errors, every one of which was a DistributedAsyncInsertQueue / BgDistSchPool retry targeting the staging cluster (1533 TOO_MANY_PARTS + 253 SOCKET_TIMEOUT + 246 NETWORK_ERROR).

Fix

Add a conservative classifier is_ci_logs_cluster_overload that scans clickhouse-server.err.log when runner_exit_code is in ABORTED_RUN_EXIT_CODES and no individual tests failed. The classifier reports an overload iff:

  • no real-crash markers (<Fatal>, AddressSanitizer:, MemorySanitizer:, ThreadSanitizer:, UndefinedBehaviorSanitizer:, LOGICAL_ERROR) appear;
  • at least 100 <Error> lines are present (chronic-overload signature, not transient blip);
  • at least 95% of those <Error> lines name a Distributed-shipping logger (DistributedAsyncInsertQueue, DistributedAsyncInsertBatch, DistributedSink, BgDistSchPool, StorageDistributed, system.<table>_sender).

When it fires, the run gets an informational CIDB log cluster unresponsive SKIPPED leaf instead of a Server died FAIL leaf, the outer status stays OK, and the secondary clickhouse-test exited with code N FAIL guard is bypassed. Any real crash, sanitizer report, LOGICAL_ERROR, or individual test failure keeps the legacy Server died FAIL path - the heuristic only ever silences a run that would otherwise be a false positive.

Tests

New ci/tests/test_functional_tests_results.py covers:

  • the classifier directly (missing log, empty log, threshold edge, real-crash marker abstention, dominance threshold);
  • FTResultsProcessor.run end-to-end across all four aborted exit codes (-15, -9, 143, 137), with and without staging-overload signals and with and without a real crash mixed in.

15 / 15 pass locally. Existing ci/tests/test_bugfix_validation_inverter.py and ci/tests/test_cidb.py continue to pass.

References

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

...

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

…sive

When the test runner (`clickhouse-test`) is killed by the harness
wall-clock timeout (signal `SIGTERM` -> `runner_exit_code` of `-15`),
`FTResultsProcessor` currently appends a synthetic `Server died` `FAIL`
leaf regardless of why the runner timed out. On `PR` and `Stateless
tests (arm_asan_ubsan, targeted)` jobs the actual ClickHouse server was
healthy in many of these cases - the runner only ran out of wall-clock
time because its background `Distributed` system-log sender kept retrying
to ship rows to the CIDB staging cluster
(`kng4alm55c.us-east-2.aws.clickhouse-staging.com:9440`) and the cluster
was overloaded. The result was hundreds of cross-PR false-positive
"Server died" failures (77 hits / 57 distinct PRs / 0 master in the
trailing 30 days), with PR ClickHouse#106154 being one such victim.

Per @alexey-milovidov on PR ClickHouse#106154:

  > Send another PR that will work around that by not making the CI check
  > red if that staging cluster is not responding.

Add a conservative classifier `is_ci_logs_cluster_overload` that scans
`clickhouse-server.err.log` when `runner_exit_code` is in
`ABORTED_RUN_EXIT_CODES` and no individual tests failed. The classifier
reports an overload iff:

  * no real-crash markers (`<Fatal>`, `AddressSanitizer:`,
    `MemorySanitizer:`, `ThreadSanitizer:`, `UndefinedBehaviorSanitizer:`,
    `LOGICAL_ERROR`) appear in the log;
  * at least 100 `<Error>` lines are present (chronic-overload signature,
    not transient blip);
  * at least 95% of those `<Error>` lines name a `Distributed`-shipping
    logger (`DistributedAsyncInsertQueue`, `DistributedAsyncInsertBatch`,
    `DistributedSink`, `BgDistSchPool`, `StorageDistributed`,
    `system.<table>_sender`).

When the classifier fires, the run gets an informational `CIDB log
cluster unresponsive` `SKIPPED` leaf instead of a `Server died` `FAIL`
leaf, the outer status stays `OK`, and the secondary
"clickhouse-test exited with code N" `FAIL` guard is bypassed. Any real
crash, sanitizer report, `LOGICAL_ERROR`, or individual test failure
keeps the legacy `Server died` `FAIL` path - the heuristic only ever
silences a run that would otherwise be a false positive.

Unit tests in `ci/tests/test_functional_tests_results.py` cover:

  * the classifier directly (missing log, empty log, threshold edge,
    real-crash marker abstention, dominance threshold);
  * `FTResultsProcessor.run` end-to-end across the four aborted exit
    codes (-15, -9, 143, 137), with and without staging-overload signals
    and with and without a real crash mixed in.

Original sighting: ClickHouse#106154
CI report:        https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106154&sha=cb7df05db57791a4c0a6930f529efba79066e075&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29

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

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

a) Deterministic repro? Yes. The classifier reads a sample err.log and the FTResultsProcessor.run integration test feeds the four aborted exit codes directly. 15/15 unit tests pass locally. The chronic CI signal that triggered this work is reproducible via CIDB (77 hits / 57 distinct PRs / 0 master in the trailing 30 days, including the PR #106154 instance).

b) Root cause explained? The CIDB staging log cluster kng4alm55c.us-east-2.aws.clickhouse-staging.com:9440 is overloaded → system.<table>_sender Distributed retries pile up in BgDistSchPool with TOO_MANY_PARTS / SOCKET_TIMEOUT / NETWORK_ERROR → _flush_system_logs blocks → runner runs out of wall-clock time → harness sends SIGTERM → subprocess.returncode == -15 ∈ ABORTED_RUN_EXIT_CODES → FTResultsProcessor appends synthetic Server died FAIL leaf → CI red. PR #106154's CI evidence: 1683/0/62 tests passed, server exited with code 0, clickhouse-server.err.log carries 1902 Distributed-shipping errors and zero <Fatal> / sanitizer / LOGICAL_ERROR markers.

c) Fix matches root cause? The fix is the explicit @alexey-milovidov workaround — it is not a speculative defensive change. The classifier only fires when the err.log evidence matches the documented infra signature, and it never silences a real crash, sanitizer report, LOGICAL_ERROR, or individual test failure. The real-root infrastructure work (the staging cluster) is out of scope per his comment ("This might be a wrongly configured cluster or just bad infrastructure. Send another PR that will work around that...").

d) Test intent preserved? / New tests added? Preserved. The legacy Server died FAIL path is unchanged for every condition that previously emitted it (real <Fatal>, sanitizer report, LOGICAL_ERROR, any individual test failure, missing err.log, transient noise below the threshold, or err.log dominated by unrelated errors). Tests cover all these abstention paths.

e) Both directions demonstrated? Yes. test_run_classifies_staging_overload_as_skipped runs all four aborted exit codes against a pure staging-overload log and confirms the run is OK with the new SKIPPED leaf and no Server died / clickhouse-test FAIL leaves. test_run_keeps_server_died_when_real_crash_marker_present runs the same scenario with a single <Fatal> line added and confirms the run reverts to FAIL with Server died. test_run_keeps_server_died_when_tests_failed does the same for a failed individual test.

f) Fix is general? Yes. FTResultsProcessor is the shared post-processor used by every functional test job (parallel, sequential, targeted, flaky, s3, replicated, ParallelReplicas, ...), so the fix lands uniformly. The classifier matches by logger name (DistributedAsyncInsertQueue, DistributedAsyncInsertBatch, DistributedSink, BgDistSchPool, StorageDistributed, system.<table>_sender), not the staging hostname — so a future host rename does not bypass the heuristic, and an entirely different Distributed table going wrong would also be classified consistently.

session: cron:clickhouse-ci-task-worker:20260531-031500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv — could you review this? It adds a conservative FTResultsProcessor heuristic that downgrades runner_exit_code -15 / -9 / 143 / 137 from a synthetic Server died FAIL to a SKIPPED informational leaf when clickhouse-server.err.log is dominated by Distributed-shipping retries to the CIDB staging log cluster and shows no real-crash markers — per @alexey-milovidov's directive on #106154.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label May 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1d5c485]

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 31, 2026
Two blockers identified in the bot review on commit `109d3ed6`:

1. The reclassification branch in `FTResultsProcessor.run` did not check
   `success_finish`. If the harness wall-clock fired mid-suite, no test
   may have emitted `FAIL` yet and `err.log` could still be dominated by
   `Distributed`-shipping retries, so the run was marked OK with only a
   `SKIPPED` leaf even though not all selected tests ran. Require
   `s.success_finish` before reclassifying.

2. `is_ci_logs_cluster_overload` read only the first 64 MiB of
   `clickhouse-server.err.log`, but under chronic overload the file can
   grow to hundreds of MiB. A `<Fatal>` / sanitizer / `LOGICAL_ERROR`
   marker appended past 64 MiB was missed, silently suppressing real
   `Server died` failures. Stream the full file line by line.

Three regression tests added in `ci/tests/test_functional_tests_results.py`:

* `test_run_keeps_server_died_when_test_run_was_incomplete` —
  `test_result.txt` lacks `All tests have finished`, `err.log` matches
  the overload pattern, runner exit `-SIGTERM`. Result must stay FAIL
  with `Server died`.
* `test_overload_classifier_scans_full_file_for_late_fatal_marker` —
  65 MiB `err.log` of shipping noise followed by a single `<Fatal>` line
  on the last line. Classifier must return `False`.
* `test_run_keeps_server_died_when_oversized_log_has_late_logical_error` —
  same shape end-to-end through `FTResultsProcessor.run` with
  `LOGICAL_ERROR`. Result must stay FAIL with `Server died`.

All 18 tests pass locally (`pytest ci/tests/test_functional_tests_results.py`).
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label May 31, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, resolve the conflicts.

Resolves conflicts in `ci/jobs/scripts/functional_tests_results.py` between
the CIDB staging cluster overload heuristic on this branch and master's
`GLOBAL_TIME_LIMIT_EXIT_CODE` graceful-stop branch (commit `5dc349c6e9a`).

Both behaviors are preserved:

  * Aborted run by `STOP_TESTING_EXIT_CODE` / signals -> attempt the
    CIDB staging-cluster overload reclassification (gated on
    `s.success_finish` and `is_ci_logs_cluster_overload`); else emit
    `Server died`.
  * Aborted run by `GLOBAL_TIME_LIMIT_EXIT_CODE` -> emit the benign
    `Global time limit reached` informational leaf.
  * Non-zero exit code guard now excludes BOTH `GLOBAL_TIME_LIMIT_EXIT_CODE`
    (graceful) AND `ci_logs_cluster_overload` (infrastructure) so neither
    repaints the run red.

Local verification: `pytest ci/tests/test_functional_tests_results.py -v`
-> 18/18 pass.

Resolves merge conflict per `@ alexey-milovidov` directive on
ClickHouse#106176.

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

groeneai commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov rebased onto current master via merge commit and pushed (d9e9cbc569f). Conflicts in ci/jobs/scripts/functional_tests_results.py were against master's GLOBAL_TIME_LIMIT_EXIT_CODE graceful-stop branch (5dc349c6e9a). Both branches preserved:

  • STOP_TESTING_EXIT_CODE / signals -> attempt CIDB staging-cluster overload reclassification, else Server died.
  • GLOBAL_TIME_LIMIT_EXIT_CODE -> benign Global time limit reached leaf.
  • Non-zero-exit guard excludes both codes (graceful + infrastructure) so neither repaints the run red.

pytest ci/tests/test_functional_tests_results.py -v -> 18/18 pass locally.

Resolves conflicts in ci/jobs/scripts/functional_tests_results.py and the
add/add conflict in ci/tests/test_functional_tests_results.py against master's
new MAX_FAILURES_EXIT_CODE handling (the --max-failures / --max-failures-chain
"Too many test failures" leaf).

Production file: the ABORTED_RUN_EXIT_CODES branch keeps this branch's CIDB
staging-cluster overload reclassification (gated on s.success_finish and
is_ci_logs_cluster_overload), and master's new elif MAX_FAILURES_EXIT_CODE
branch is appended after it. The non-zero-exit guard already excludes both
GLOBAL_TIME_LIMIT_EXIT_CODE and ci_logs_cluster_overload.

Test file: both sides independently created ci/tests/test_functional_tests_results.py.
Unioned all 18 CIDB-overload tests with master's 2 max-failures tests; merged
the import block (FTResultsProcessor, ABORTED_RUN_EXIT_CODES, MAX_FAILURES_EXIT_CODE,
STOP_TESTING_EXIT_CODE, is_ci_logs_cluster_overload, _STAGING_OVERLOAD_MIN_ERRORS)
and the helpers (_write_err_log, _process, _named).

Local verification: 20/20 pass.

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

Copy link
Copy Markdown
Collaborator Author

@alexey-milovidov conflicts resolved. Merged master into the branch (commit 08b8859); no rebase per repo convention.

Two conflicts, both in the FT results parser:

  • ci/jobs/scripts/functional_tests_results.py: master added the --max-failures (MAX_FAILURES_EXIT_CODE) branch alongside the aborted-run path. Kept both — this branch's CIDB staging-overload reclassification in the aborted-run branch, master's new Too many test failures branch after it; the non-zero-exit guard already excludes both GLOBAL_TIME_LIMIT_EXIT_CODE and the overload case.
  • ci/tests/test_functional_tests_results.py: add/add — both sides created this file. Unioned the 18 overload tests with master's 2 max-failures tests.

Local: pytest ci/tests/test_functional_tests_results.py -> 20/20 pass. CI re-running.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 08b8859

CI fully finished on this head (Finish Workflow + Mergeable Check SUCCESS, no checks queued/in_progress). Every failure below has an owner: a fixing PR, or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
CH Inc sync private upstream sync CH Inc sync (private, not actionable by us)

No ClickHouse test FAIL/ERROR on this commit (CIDB): the 23 executed checks passed, the rest skipped. Ready for review.

Session id: cron:our-pr-ci-monitor:20260625-040000

alexey-milovidov and others added 2 commits July 3, 2026 01:03
Address the `clickhouse-gh` / AI review blocker on PR ClickHouse#106176. The CIDB
staging-cluster overload classifier counted any `<Error>` line naming a
bare `Distributed` logger/engine (`DistributedAsyncInsertQueue`,
`BgDistSchPool`, `DistributedSink`, `StorageDistributed`, ...). Those also
fire for a test-owned `Distributed` table, and `FTResultsProcessor` is
shared with `ci/jobs/fast_test.py`, which never starts log export - so a
completed run killed by the wall-clock timeout after a real non-CIDB
`Distributed` regression could be reported `OK` with only a
`CIDB log cluster unresponsive` leaf.

Key the classifier strictly on the CIDB log-export path
`system.<table>_sender` instead. `setup_log_cluster.sh` ships system logs
through `Distributed` tables named `system.<table>_sender`, and their
retries are logged under the directory-queue logger
`system.<table>_sender.DistributedInsertQueue.<disk>` (see
`DistributedAsyncInsertDirectoryQueue::getLoggerName`), which always
contains that substring. Tables cannot be created in the `system` database
by tests, so this name space is CI-owned and a run that never started log
export has no `_sender` tables - a real non-CIDB `Distributed` failure can
no longer be silenced.

Fix the sample lines in the test to the real logger-name format and add
two regressions (classifier-level and end-to-end through
`FTResultsProcessor.run`) covering a non-CIDB `Distributed` error log.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Addressed the clickhouse-gh / AI-review ❌ Block on ci/jobs/scripts/functional_tests_results.py:91 (the only unresolved thread), and merged current master.

What was too broad: the overload classifier counted any <Error> line naming a bare Distributed logger/engine (DistributedAsyncInsertQueue, BgDistSchPool, DistributedSink, StorageDistributed). Those also fire for a test-owned Distributed table, and FTResultsProcessor is shared with ci/jobs/fast_test.py, which never calls setup_logs_replication — so a completed run killed by the wall-clock timeout after a real non-CIDB Distributed regression could have been reported OK with only a CIDB log cluster unresponsive leaf.

Fix: key the classifier strictly on the CIDB log-export path system.<table>_sender. setup_log_cluster.sh ships system logs through Distributed tables named system.<table>_sender, and every shipping retry is logged under the directory-queue logger system.<table>_sender.DistributedInsertQueue.<disk> (DistributedAsyncInsertDirectoryQueue::getLoggerName), which always contains that substring. Tables cannot be created in the system database by tests, so this name space is CI-owned, and a run that never started log export has no _sender tables — a real non-CIDB Distributed failure can no longer be silenced.

Tests: corrected the sample err.log lines to the real logger-name format and added two regressions covering a non-CIDB Distributed error log — test_overload_classifier_rejects_non_cidb_distributed_errors (classifier level) and test_run_keeps_server_died_on_non_cidb_distributed_errors (end-to-end through FTResultsProcessor.run, the fast_test.py shape). pytest ci/tests/test_functional_tests_results.py → 22/22 pass; test_bugfix_validation_inverter.py + test_cidb.py → 15/15 pass.

@alexey-milovidov alexey-milovidov added can be tested Allows running workflows for external contributors and removed can be tested Allows running workflows for external contributors labels Jul 3, 2026
The `Style check` job's `ruff` step failed with `F401` on
`ci/tests/test_functional_tests_results.py:26`: `pytest` was imported but
never used (the regression tests added in the prior commit use plain
`assert` and are discovered by name, so the import is dead). Drop it.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106176&sha=ba4adc0b7e770483ec104d7933f3d83551de777a&name_0=PR&name_1=Style%20check

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov alexey-milovidov added can be tested Allows running workflows for external contributors and removed can be tested Allows running workflows for external contributors labels Jul 3, 2026
groeneai and others added 2 commits July 3, 2026 06:36
clickhouse-gh[bot] correctness follow-up on the system.<table>_sender
narrowing: keying on any system.*_sender log line is still forgeable,
because a functional test can create tables in the system database
(e.g. 02494_query_cache_system_tables.sql creates system.system), so a
test could create system.fake_sender and flood the log with matching
Distributed shipping errors. FTResultsProcessor is also shared with
fast_test.py, which never starts log export, so it can never legitimately
ship to the CIDB staging cluster.

Two independent layers now guard the reclassification:

1. Un-forgeable gate: thread log_export_started from functional_tests.py
   into FTResultsProcessor. The overload reclassification is consulted
   only when the harness actually ran start_log_exports for this run. A
   test cannot flip the harness process flag, so fast_test.py runs and
   local runs (which never start log export) can never be greened.

2. Tightened regex: system.\w+_sender -> system.\w+_log_sender. Senders
   are created only for system.%_log tables by setup_log_cluster.sh, so a
   bare system.foo_sender no longer matches.

Regression tests: a run with 500 forged system.fake_sender lines and no
log export stays Server died; the same with log export started also stays
Server died (regex layer); the classifier rejects the forged bare _sender
name. pytest ci/tests/test_functional_tests_results.py: 25/25 pass.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…uster-overload-server-died

Resolves the conflict in ci/jobs/functional_tests.py: master removed the
create_minio_log_tables() setup step, this branch had added an else-branch
after start_log_exports() that snapshots the concrete system.<table>_sender
tables. Kept master's removal and this branch's snapshot.
@groeneai

Copy link
Copy Markdown
Collaborator Author

Conflicts resolved in merge commit c2645b1 (fast-forward push, your merge commits untouched). mergeable is back to MERGEABLE.

One conflict, in ci/jobs/functional_tests.py: master removed the create_minio_log_tables() setup step, and this branch had added an else: branch right after start_log_exports() that snapshots the concrete system.<table>_sender tables. Kept master's removal, kept the snapshot. The classifier files themselves did not conflict and are byte-identical to 57ae6cf.

Local: pytest ci/tests/test_functional_tests_results.py ci/tests/test_bugfix_validation_inverter.py ci/tests/test_cidb.py -> 49/49 pass. ruff check clean on the four touched files. Diff vs master is exactly the 4 intended ci/ files, no submodule drift.

…uster-overload-server-died

Conflicts in `ci/jobs/scripts/functional_tests_results.py` and
`ci/tests/test_functional_tests_results.py`, both in the
`ABORTED_RUN_EXIT_CODES` branch that this PR restructured.

Master added the bugfix-validation carve-out to the single-culprit
demotion (keep `FAIL` instead of `ERROR` when `is_bugfix_validation`,
see ClickHouse#105789) inside the same block that this branch moved under the
`else` of the CIDB-staging-overload check. Resolution keeps both: the
overload reclassification stays the outer condition, and master's
bugfix-validation-aware demotion is used verbatim in the `else` arm.
Test-file conflicts were purely additive on both sides - kept every
test from master and from this branch.
…binaries

Address the `clickhouse-gh[bot]` review: the overload heuristic is safe
only because it is keyed off the concrete `system.<table>_sender`
`Distributed` tables captured before any test ran. The
bugfix-validation loop restarts the server for each master-HEAD build
type and `CH.start` wipes the server data directory, so after the first
swap those CI-owned tables are gone and log export is not set up again.
Carrying the pre-swap snapshot into the later runs left the classifier
keyed off names that no longer belong to CI, so a test could create
`system.query_log_sender` itself and have its shipping errors read as
log-export noise.

Reset the snapshot on the swap path. With an empty set the classifier
abstains and the run stays on the `Server died` path, which is the
fail-close behavior already covered by
`test_run_keeps_server_died_when_log_export_not_started`.

New `ci/tests/test_bugfix_validation_sender_snapshot.py` pins the reset,
its position relative to the restart and to the per-build-type
`FTResultsProcessor`, and that the only other writer of the snapshot is
the pre-suite `CH.get_log_export_senders` capture.
@alexey-milovidov alexey-milovidov added can be tested Allows running workflows for external contributors and removed can be tested Allows running workflows for external contributors labels Aug 3, 2026
Comment thread ci/jobs/scripts/clickhouse_proc.py Resolved
Address the `clickhouse-gh[bot]` blocker: keying the overload heuristic
off captured `system.<table>_sender` NAMES is still forgeable. A test can
create and drop tables in the `system` database (see
`02494_query_cache_system_tables.sql`), so it can drop a CI-created
sender, recreate its own `Distributed` table under the same captured
name, emit `system.query_log_sender.DistributedInsertQueue.*` errors and
have them read as CI log-export noise.

`system` is an `Atomic` database in the server, so a recreated table gets
a fresh `uuid`. `get_log_export_senders` now captures `{name: uuid}`
before any test runs (and skips a zero `uuid`, which carries no identity
to verify), and the new `verify_log_export_senders` re-reads
`system.tables` after the suite and keeps only the names whose `uuid` is
unchanged. Every `FTResultsProcessor` is constructed from that verified
set. It fails closed: a dropped, rebound, or unreadable sender - and a
server that really did die, so the query returns nothing - yields an
empty set, the classifier abstains, and the run keeps `Server died`.

New `ci/tests/test_log_export_sender_identity.py` covers the snapshot and
the verification, including the bot's rebind-under-the-same-name
scenario; `test_bugfix_validation_sender_snapshot.py` additionally pins
that no processor is handed the unverified snapshot.
@alexey-milovidov alexey-milovidov added can be tested Allows running workflows for external contributors and removed can be tested Allows running workflows for external contributors labels Aug 3, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Rebased onto current master (merge commit 15153dd10ac) and addressed both outstanding clickhouse-gh[bot] blockers.

Conflicts. master had landed the bugfix-validation carve-out for the single-culprit demotion (keep FAIL instead of ERROR when is_bugfix_validation, #105789) inside the same ABORTED_RUN_EXIT_CODES block this branch restructured, plus the new MAX_FAILURES_EXIT_CODE / GLOBAL_TIME_LIMIT_EXIT_CODE branches. Resolution keeps both: the CIDB-overload reclassification stays the outer condition and master's bugfix-validation-aware demotion is used verbatim in the else arm. The test-file conflict was purely additive on both sides — every test from both is kept.

Blocker 1 (stale sender snapshot across the bugfix-validation binary swap) — 911c4b9f61c. CH.start wipes the data directory, so the CI-owned system.<table>_sender tables are gone after the first swap. The snapshot is now cleared on that path, so later build types abstain (fail closed) and keep the Server died verdict.

Blocker 2 (a captured name can be rebound by a test) — 8d6eac41b65. The snapshot is now keyed by uuid, not name: captured as {name: uuid} before any test runs and re-verified against system.tables after the suite, keeping only unchanged entries. system is Atomic in the server, so a dropped-and-recreated sender gets a fresh uuid and drops out.

Locally: pytest ci/tests/test_functional_tests_results.py ci/tests/test_log_export_sender_identity.py ci/tests/test_bugfix_validation_sender_snapshot.py ci/tests/test_bugfix_validation_inverter.py ci/tests/test_cidb.py → 65/65 pass; ruff check clean over ci/. Style check, Fast test and Code Review were already green on the merge commit; CI re-triggered for the two fix commits.

Address the `clickhouse-gh[bot]` follow-up: `CREATE TABLE ... UUID
'<captured uuid>'` IS accepted in an `Atomic` database, so a test can
drop a captured `system.<table>_sender` and recreate its own
`Distributed` table under both the same name and the same `uuid`.

Widen the captured identity to `uuid`, `metadata_modification_time` and a
hash of `engine_full`. The metadata timestamp is the component no SQL can
choose: it is the mtime of the table's metadata file, so a table
recreated while the suite runs is necessarily stamped later than the
pre-suite snapshot. `setup_log_cluster.sh` creates the senders once at
setup and never alters them afterwards, so the timestamp is stable for a
genuine CI-owned sender, and `stop_logs_replication` drops them only
after the results are processed.

Entries with a zero `uuid` or an unset metadata timestamp are dropped
from the snapshot instead of being trusted, and any mismatch at
verification time removes the name, so the classifier abstains and the
run keeps `Server died`.

`ci/tests/test_log_export_sender_identity.py` gains the requested
regression - a sender recreated with the captured `uuid`, both at the
`verify_log_export_senders` level and end-to-end through
`FTResultsProcessor` with a log flooded by that rebound table - plus the
differing-engine and missing-timestamp cases.
@alexey-milovidov alexey-milovidov added can be tested Allows running workflows for external contributors and removed can be tested Allows running workflows for external contributors labels Aug 3, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Addressed the 08:32 AI Review blocker (uuid alone is forgeable) in 1734be959dd.

You are right: CREATE TABLE ... UUID '<captured uuid>' is accepted in an Atomic database (InterpreterCreateQuery only rejects an explicit UUID when the database engine is not Atomic), so reusing the captured uuid on recreate was possible.

The captured identity is now a fingerprint of uuid + metadata_modification_time + a hash of engine_full. The metadata timestamp is the component no SQL can choose — it is the mtime of the table's metadata file, so a sender recreated while the suite runs is necessarily stamped later than the pre-suite snapshot. It is stable for a genuine CI-owned sender: setup_log_cluster.sh creates the system.<table>_sender tables once during setup and never alters them afterwards, and stop_logs_replication drops them only after the results are processed (CH.stop_log_exports() runs well after the TEST stage). A zero uuid or an unset timestamp is dropped from the snapshot rather than trusted, and any mismatch at verification time removes the name, so the classifier abstains and the run keeps Server died.

Regression tests as requested, in ci/tests/test_log_export_sender_identity.py:

  • test_verify_drops_a_sender_recreated_with_the_captured_uuid — exactly your scenario, at the verify_log_export_senders level;
  • test_rebound_sender_keeps_server_died_end_to_end — the same rebind driven all the way through FTResultsProcessor with an err.log flooded by system.query_log_sender.DistributedInsertQueue.* errors and a SIGTERM runner exit, asserting the Server died FAIL survives and no CIDB log cluster unresponsive leaf appears;
  • plus the differing-engine_full and missing-timestamp cases.

69/69 local tests pass across the five related ci/tests files; ruff check clean over ci/. CI re-triggered.

Address the `clickhouse-gh[bot]` follow-up: `metadata_modification_time`
is a `DateTime`, so a test that recreates a captured
`system.<table>_sender` with the same explicit `UUID` and engine inside
the snapshot second still matched the fingerprint.

Capture the sender's `metadata_path` and `stat` it on the host, folding
the inode and the NANOSECOND mtime into the fingerprint. That is the one
component no query can choose. `metadata_path` is relative to the
server's data directory, so it is resolved against the `path` server
setting before the `stat` - otherwise every lookup would miss and the
heuristic would silently never fire. A metadata file that cannot be
stat'ed drops its sender from the snapshot, so the classifier abstains
and the run keeps `Server died`.

Verified against a running server (26.7): `DROP TABLE ... SYNC` plus
`CREATE TABLE system.query_log_sender UUID '<captured uuid>' ENGINE =
Distributed(...)` in the same second keeps `uuid`, the `engine_full`
hash, `metadata_path` and `metadata_modification_time` identical - and
the metadata file's mtime still moves (`09:16:31.351259320` ->
`09:16:31.552260858`), so `verify_log_export_senders` returns an empty
set.

`ci/tests/test_log_export_sender_identity.py` adds the same-second
rebind at both the unit and the end-to-end `FTResultsProcessor` level,
the unstat'able-metadata-file case, and a guard that the query resolves
the relative `metadata_path`.
@alexey-milovidov alexey-milovidov added can be tested Allows running workflows for external contributors and removed can be tested Allows running workflows for external contributors labels Aug 3, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Addressed the 09:07 AI Review blocker (second-resolution metadata_modification_time) in 9708226cd94.

Took the suggested route: the fingerprint now includes the sender's metadata file identity read from the host — metadata_path plus its inode and nanosecond mtime from stat --printf — which is the one component no query can choose. One implementation detail worth flagging: system.tables.metadata_path is relative to the server data directory (store/6f4/<db-uuid>/query_log_sender.sql), so it is resolved against the path server setting before the stat; without that every lookup would have missed and the heuristic would have silently never fired. A metadata file that cannot be stat'ed drops its sender from the snapshot, so the classifier abstains and the run keeps Server died.

I verified the attack and the defence against a real server (26.7.1), not just in unit tests. DROP TABLE system.query_log_sender SYNC followed by CREATE TABLE system.query_log_sender UUID '<captured uuid>' ENGINE = Distributed(...), repeated until it landed inside the snapshot second:

SAME-SECOND rebind reproduced
  uuid/engine/path identical: True True True
  DateTime identical:         True
  ns mtime differs:           True | 44355298:2026-08-03 09:16:31.351259320 +0000
                                  -> 44355298:2026-08-03 09:16:31.552260858 +0000
  verified set:               set()

So the exact scenario you described reproduces (every system.tables column matches) and verification still drops the sender. Note the inode was reused by the filesystem there — the nanosecond mtime is what carries the signal, which is why both are captured.

Regressions added in ci/tests/test_log_export_sender_identity.py: test_verify_drops_a_sender_recreated_inside_the_snapshot_second, the end-to-end test_rebound_sender_keeps_server_died_end_to_end (now the same-second variant, driven through FTResultsProcessor with a flooded err.log), test_snapshot_drops_tables_whose_metadata_file_cannot_be_stated, and test_snapshot_resolves_the_relative_metadata_path.

71/71 local tests pass across the related ci/tests files; ruff check clean over ci/. CI re-triggered.

@alexey-milovidov alexey-milovidov added can be tested Allows running workflows for external contributors and removed can be tested Allows running workflows for external contributors labels Aug 10, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status update.

The previous head was never actually tested. The run for 9708226cd94 (run 30800764637) died in Config Workflow on a GitHub infrastructure error - fatal: unable to access 'https://github.com/ClickHouse/ClickHouse/': The requested URL returned error: 503, then the job was killed at the wall clock (Run failed with exit code [-15]) and every dependent job was set to DROPPED. The Build profile diff / Finish Workflow reds are that same cascade (Finish Workflow ends in NoSuchKey because Config Workflow never uploaded the workflow result to S3). None of it is caused by this PR, and the green report still visible on the PR page belongs to the earlier commit 1734be95.

Actions in this pass:

  • Merged a week-stale master into the branch - clean, no conflicts. The only overlap in the touched files was an unrelated change to the failures_cnt < 4 -> failures_cnt < 2 threshold in ci/jobs/functional_tests.py; the sender-snapshot plumbing (CH.get_log_export_senders before the suite, CH.verify_log_export_senders at both FTResultsProcessor construction sites) survived the merge intact.
  • Re-ran the CI unit tests on the merged tree: ci/tests/test_functional_tests_results.py, ci/tests/test_log_export_sender_identity.py, ci/tests/test_bugfix_validation_sender_snapshot.py plus the siblings test_bugfix_validation_inverter.py / test_cidb.py - 72/72 passed. ruff check --output-format=concise --quiet ci/ is clean.
  • Pushed 9708226cd94..be3700e3f6d and re-triggered CI by re-applying can be tested (a push alone does not restart the hosted pipeline for a fork PR).

On the outstanding AI Review verdict: it was generated against 1734be95, i.e. before 9708226cd94 "Anchor the CIDB sender identity to the metadata file on the host", which implements exactly the suggested fix - the fingerprint now folds in the metadata file's inode and nanosecond mtime read with stat on the host, so a sender recreated inside the snapshot second with the same explicit UUID and the same engine_full no longer verifies. That is covered by regressions in ci/tests/test_log_export_sender_identity.py at both the unit and the end-to-end FTResultsProcessor level. The verdict should regenerate against the new head.

Now blocked solely on the fresh CI run plus human review and merge.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - be3700e

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (arm_release) / Hung check failed, possible deadlock found deadlock, pre-existing on master #113692 (mine, open)
Sync - CH Inc sync (private, not actionable)

This diff is confined to ci/ Python (functional_tests.py, clickhouse_proc.py,
functional_tests_results.py and their unit tests). ci/jobs/stress_job.py imports none of the
changed modules - it uses ClickHouseService, DockerImage, FuzzerLogParser - so the stress
hung check cannot be reached from this change, and the signature is the chronic trunk one.

Build (arm_release) / Post Hooks reports a failed row while that check's own conclusion is
success - bookkeeping noise, not ledgered.

Session id: cron:our-pr-ci-monitor:20260810-193000

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Closing this PR: the requested non-failing reclassification cannot be made safe while functional tests can write to the genuine CI log-export sender tables. The pushed fail-closed commit removes the unsafe implementation; the branch is source-identical to master.

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 manual approve Manual approve required to run CI pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants