Skip to content

Treat SIGTERM/SIGKILL kill codes as aborted run in functional-test parser - #105643

Merged
leshikus merged 2 commits into
ClickHouse:masterfrom
leshikus:ci/abort-exit-codes
May 29, 2026
Merged

leshikus merged 2 commits into
ClickHouse:masterfrom
leshikus:ci/abort-exit-codes

Conversation

@leshikus

@leshikus leshikus commented May 22, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Follow-up to PR #105298 (commit fc45ec9) which introduced
STOP_TESTING_EXIT_CODE = 2 as the stable signal from clickhouse-test
to the job-side parser for "the run was aborted mid-flight (server died,
hung-check tripped, etc.)". The parser uses that signal to attach a
synthetic Server died leaf and demote ambiguous per-test failures to
UNKNOWN.

The contract holds when clickhouse-test reaches sys.exit(STOP_TESTING_EXIT_CODE)
through the except StopTesting handler. It does not hold in the
parent-side hung-check path, which is the most common abort scenario:
when the parent terminates a worker via p.terminate(), the worker's
signal_handler raises Terminated (subclass of KeyboardInterrupt),
run_tests_array's except KeyboardInterrupt calls stop_tests,
which killpgs the entire process group - hitting the parent before it
can exit through StopTesting. The parent's own signal_handler then
raises Terminated and __main__ exits 128 + SIGTERM = 143.

Concrete failure mode

On PR #105041, bugfix validation report:
master hung running the PR's new tests, clickhouse-test was killed
with exit code 143, no per-test result lines reached test_result.txt,
the parser fell through to not s.success_finish (state = ERROR,
results = []), and the bugfix-validation inverter then overwrote that
honest ERROR with set_failed().set_info("Failed to reproduce the bug") -
exactly the opposite of what actually happened (the server died on
master, so the bug was reproduced, just more catastrophically than
the test expected).

Change

Replace the singleton runner_exit_code == STOP_TESTING_EXIT_CODE check
with a frozenset that also matches 128 + SIGTERM (143) and
128 + SIGKILL (137). All three carry the same semantics: the run was
aborted mid-flight, partial per-test results are incomplete, the
Server died leaf is appropriate.

Exit code 1 is deliberately not in the set. It is set by end-of-run
post-checks (final hung-check, runner_process_killed,
total_tests_run == 0) that run after every test has finished -
per-test results are authoritative in that case and must not be demoted.
The existing tail handler at the bottom of FTResultsProcessor.run
already handles exit 1 by appending a generic clickhouse-test exited with code N leaf without touching per-test results.

What this does not fix

This commit does not fix the underlying worker -> parent SIGTERM
feedback loop in tests/clickhouse-test. That root-cause fix (mask
SIGTERM on the parent during the worker-cleanup block, or stop
Terminated from triggering stop_tests in workers) is left for a
separate change. Adding the kill codes here is defence-in-depth that
makes the parser robust to the loop without depending on whether it
ever gets fixed - and also covers external kills (job-level timeout,
runner shutdown) which would otherwise fall through to the same
incorrect ERROR path.

A second bug surfaced by the same CI report - the bugfix-validation
inverter overwriting status=ERROR with set_failed("Failed to reproduce the bug") when test_result.results is empty - is also a
separate change.

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)

Version info

  • Merged into: 26.6.1.242

…rser

Follow-up to PR ClickHouse#105298 (commit fc45ec9) which introduced
`STOP_TESTING_EXIT_CODE = 2` as the stable signal from `clickhouse-test`
to the job-side parser for "the run was aborted mid-flight (server died,
hung-check tripped, etc.)". The parser uses that signal to attach a
synthetic `Server died` leaf and demote ambiguous per-test failures to
`UNKNOWN`.

The contract holds when `clickhouse-test` reaches `sys.exit(STOP_TESTING_EXIT_CODE)`
through the `except StopTesting` handler. It does *not* hold in the
parent-side hung-check path, which is the most common abort scenario:
when the parent terminates a worker via `p.terminate()`, the worker's
`signal_handler` raises `Terminated` (subclass of `KeyboardInterrupt`),
`run_tests_array`'s `except KeyboardInterrupt` calls `stop_tests()`,
which `killpg`s the entire process group - hitting the parent before it
can exit through `StopTesting`. The parent's own `signal_handler` then
raises `Terminated` and `__main__` exits `128 + SIGTERM = 143`.

Concrete failure mode on PR ClickHouse#105041
(https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105041&sha=68cd608314c8187b7813ab0317a528ec6aff3409&name_0=PR&name_1=Bugfix%20validation%20%28functional%20tests%29):
master hung running the PR's new tests, `clickhouse-test` was killed with
exit code 143, no per-test result lines reached `test_result.txt`, the
parser fell through to `not s.success_finish` (state = `ERROR`,
`results = []`), and the bugfix-validation inverter then overwrote that
honest ERROR with `set_failed().set_info("Failed to reproduce the bug")` -
exactly the opposite of what happened.

Replace the singleton `runner_exit_code == STOP_TESTING_EXIT_CODE` check
with a `frozenset` that also matches `128 + SIGTERM` (143) and
`128 + SIGKILL` (137). All three carry the same semantics: the run was
aborted mid-flight, partial per-test results are incomplete, the
`Server died` leaf is appropriate.

Exit code 1 is deliberately *not* in the set. It is set by end-of-run
post-checks (final hung-check, `runner_process_killed`,
`total_tests_run == 0`) that run after every test has finished -
per-test results are authoritative in that case and must not be demoted.
The existing tail handler at the bottom of `FTResultsProcessor.run` already
handles exit 1 by appending a generic `clickhouse-test exited with code N`
leaf without touching per-test results.

This commit does not fix the underlying `worker -> parent` SIGTERM
feedback loop in `tests/clickhouse-test`. That root-cause fix (mask
SIGTERM on the parent during the worker-cleanup block, or stop
`Terminated` from triggering `stop_tests` in workers) is left for a
separate change. Adding the kill codes here is defence-in-depth that
makes the parser robust to the loop without depending on whether it
ever gets fixed - and also covers external kills (job-level timeout,
runner shutdown) which would otherwise fall through to the same
incorrect ERROR path.

A second bug surfaced by the same CI report - the bugfix-validation
inverter overwriting `status=ERROR` with `set_failed("Failed to reproduce
the bug")` when `test_result.results` is empty - is a separate change.

### Changelog category (leave one):
- CI Fix or Improvement (changelog entry is not required)

### Changelog entry (a [user-readable short description](https://github.com/ClickHouse/ClickHouse/blob/master/docs/changelog_entry_guidelines.md) of the changes that goes into CHANGELOG.md):
...

### Documentation entry for user-facing changes

- [ ] Documentation is written (mandatory for new features)
@clickhouse-gh

clickhouse-gh Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [07778ae]

Summary: ✅


AI Review

Summary

This PR hardens functional-test result classification by treating SIGTERM/SIGKILL exits (both 128 + N and -N) as aborted runs, aligning parser behavior with how clickhouse-test can terminate in practice. I did not find remaining correctness, safety, or contract violations in the current diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label May 22, 2026
@leshikus
leshikus requested a review from maxknv May 22, 2026 15:35
@leshikus
leshikus marked this pull request as ready for review May 22, 2026 15:35
@novikd novikd self-assigned this May 22, 2026
`Shell.run` wraps the command in `bash -c` and tracks the wrapper via
`subprocess.Popen`. When `Shell._check_timeout` calls
`os.killpg(proc.pid, SIGTERM/SIGKILL)`, the wrapper bash can itself die
from the signal — in which case Python's `Popen.returncode` is the
negative form `-N`, not bash's `128 + N`. The realistic main case is
SIGKILL escalation after the 100s grace period (also reachable via the
kernel OOM killer or the GitHub Actions runner force-kill on
job-level timeout). Without the negative variants the kill path falls
through to `not s.success_finish` (ERROR) instead of the aborted-run
path, defeating the point of the previous commit.

Add `-SIGTERM` (-15) and `-SIGKILL` (-9) to `ABORTED_RUN_EXIT_CODES`.
niyue pushed a commit to niyue/ClickHouse that referenced this pull request May 27, 2026
…e#105789)

The bugfix-validation inverter in `ci/jobs/functional_tests.py` flipped
per-test `FAIL`/`OK` so that a regression test for a bug, which is
expected to `FAIL` on master HEAD, is reported as "bug reproduced". When
the run itself ended in `Result.Status.ERROR` (server crashed and the
runner could not finish, runner Python exception, job-level timeout,
infrastructure outage), `test_result.results` was empty or partial; the
inverter loop ran zero times, `has_failure` stayed `False`, and the
`else` branch unconditionally called `set_failed().set_info("Failed to
reproduce the bug")`. The honest `ERROR` was silently overwritten with a
misleading "the regression test does not catch the bug" `FAIL`.

Extract the inverter to a standalone module-level helper
`invert_bugfix_validation_status` and short-circuit when
`test_result.status == Result.Status.ERROR`: preserve the original
`ERROR` and its `info` instead of overwriting them. Leaves still get the
`XFAIL` label so the `json.html` view renders them consistently.

The complementary `Server died` synthesis (for `runner_exit_code in
{STOP_TESTING_EXIT_CODE, 137, 143}`) lives in PR ClickHouse#105643 by @leshikus.
With that PR, signal-killed runs surface a `FAIL` leaf that the inverter
correctly maps to "bug reproduced". This change covers all other paths
that leave `test_result.status == ERROR` (Python exceptions, non-SIGTERM
job timeouts, infra outages) so they no longer report a spurious
"Failed to reproduce the bug".

Tests: `ci/tests/test_bugfix_validation_inverter.py` covers the four
intended paths (single FAIL, single OK, mixed, synthetic Server died
leaf), the two ERROR-preservation paths (empty results, partial OK
results), the XFAIL labelling invariant, and the empty-OK fallback.
Reproduced the original buggy behaviour against an inlined copy of the
pre-fix code path to confirm both directions.
@novikd

novikd commented May 28, 2026

Copy link
Copy Markdown
Member

It would be nice if this PR were finished, since the bugfix validation check doesn't work on master right now.

@leshikus leshikus added the can be tested Allows running workflows for external contributors label May 28, 2026
@leshikus

leshikus commented May 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

@novikd the pr still lacks an approval - I cannot commit it; can I do anything to get an approval from you?

@leshikus

leshikus commented May 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

@maxknv we discussed the patch with Dima and agreed that it would be good if you could also take a look at it;
could you please?

@leshikus
leshikus added this pull request to the merge queue May 29, 2026
Merged via the queue into ClickHouse:master with commit db6d7a5 May 29, 2026
488 of 490 checks passed
@leshikus
leshikus deleted the ci/abort-exit-codes branch May 29, 2026 18:17
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 29, 2026
@leshikus

leshikus commented Jun 1, 2026 •

Copy link
Copy Markdown
Collaborator Author

@Algunenano yes, we need to distinguish "Server died" and "clickhouse-test error"; I will prepare a patch

@Algunenano

Copy link
Copy Markdown
Member

Please have a look #106228. Feel free to disregard it or adopt it or accept it

alexey-milovidov added a commit to groeneai/ClickHouse that referenced this pull request Jun 1, 2026
Master's `invert_bugfix_validation_status` (picked up by the master-merge)
gates only on top-level `Result.Status.ERROR`. The sequential 'server
died' path in `functional_tests_results.py` marks the culprit test
`ERROR` and appends a 'Server died' `FAIL` leaf, leaving the top-level
status `FAIL` — so the top-level-only gate would flip that `FAIL` to
`OK` + `set_success` and count a false validation.

Extend the gate to `test_result.is_error() or any(r.is_error() ...)`,
mirroring the `had_infra_or_error` guard in `integration_test_job.py`.
A synthetic 'Server died' `FAIL` leaf with no `ERROR` sub-result (a
crash-bug regression test whose bug IS the crash, per ClickHouse#105643) has no
`ERROR` sub-result and is still correctly counted as reproduced.

This restores the five-scenario correctness verified in the reverted
`ef0816c88eb` while keeping the inversion in the shared function rather
than an inline duplicate. Adds a regression test for the coexisting
ERROR+FAIL case.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Master's `invert_bugfix_validation_status` (picked up by the master-merge)
gates only on top-level `Result.Status.ERROR`. The sequential 'server
died' path in `functional_tests_results.py` marks the culprit test
`ERROR` and appends a 'Server died' `FAIL` leaf, leaving the top-level
status `FAIL` — so the top-level-only gate would flip that `FAIL` to
`OK` + `set_success` and count a false validation.

Extend the gate to `test_result.is_error() or any(r.is_error() ...)`,
mirroring the `had_infra_or_error` guard in `integration_test_job.py`.
A synthetic 'Server died' `FAIL` leaf with no `ERROR` sub-result (a
crash-bug regression test whose bug IS the crash, per ClickHouse#105643) has no
`ERROR` sub-result and is still correctly counted as reproduced.

This restores the five-scenario correctness verified in the reverted
`ef0816c88eb` while keeping the inversion in the shared function rather
than an inline duplicate. Adds a regression test for the coexisting
ERROR+FAIL case.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors 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.

5 participants