Repository navigation
Do not discard finished test results when a functional-test job is killed in teardown - #113200
Conversation
…-ft-results-before-teardown
…lled in teardown `Stateless tests (amd_msan, WasmEdge, parallel, 2/2)` on PR ClickHouse#112959 reported `error` with zero test failures: all 6174 tests passed and `All tests have finished` printed at t=8893s, then the job was killed at the 9000s budget, 122s into teardown. `main` holds the complete per-test result in memory from the moment the suite finishes until `Result.complete_job` at the very end, and everything in between is teardown: `SYSTEM FLUSH LOGS`, log-export shutdown against a remote staging cluster, coverage export, log collection. The single job timeout covers setup, suite and teardown together, and praktika's watchdog SIGKILLs the process group with no knowledge of which phase is running, so a total overrun discards results that were already finished. Measured against the sibling shard that passed at the same sha: the killed shard inserted 1 CIDB row and uploaded 1 artifact, the passing one 6178 and 5. The run becomes invisible to every flaky-detection query, and an unrelated PR gets a red check with nothing to inspect. Write the collected results into the job's existing result file as soon as they exist, before any teardown, and leave the status non-terminal. `Runner._get_result_object` then patches a killed job with `add_error` + `set_status(ERROR)`, neither of which touches `result.results`, so the job still reports `ERROR` (it was killed) but carries all 6174 rows. Keeping the status non-terminal is what makes this safe by construction rather than by careful placement: a terminal status here could publish green over a fatal that teardown had not yet discovered, and would publish the bugfix-validation verdict before `invert_bugfix_validation_status` runs. Published by rename rather than `Result.dump`, which is `open(..., "w")` + `json.dump` and so truncates before serializing: a kill mid-write would leave JSON `Result.from_fs` refuses to parse, turning a lost result into a harder failure. The bugfix-validation loop gets its own call site because it replaces `test_result.results` per build type and then stops the server and re-prepares the environment, so a single post-loop call loses the rows of every build type but the last. This does not fix the overrun itself, and does not make teardown reliable: logs gathered later can still be lost. It makes the run attributable. Nothing under `ci/praktika/` is touched. All eight `common_ft_job_config` derivations and `bugfix_validation_ft_pr_jobs` run this same `main` and inherit the checkpoint.
The checkpoint writes an early, redundant copy of what `Result.complete_job` writes again at the end of `main`, so failing it costs nothing. But it was called unguarded and `main` has no enclosing try, so any exception it raised aborted the job script. Because the checkpoint is the first write after `Runner._pre_run`, that left the on-disk result as the bare RUNNING with zero children, which the runner then publishes as an empty ERROR: a run that would have completed normally would lose its results, its logs (COLLECT_LOGS runs later) and its correct status. That inverts the point of the change, trading a gain on the runs that get killed for a worse outcome on the ones that do not. Reachable raisers include `JSONDecodeError` from `Result.from_fs` on a truncated result file (not an `OSError`, hence `except Exception`), ENOSPC on the write, which is 2.4 MB for 6174 rows and 4.3 MB with 300-char info, and EACCES from the docker-as-root ownership skew the runner already repairs. Measured with ENOSPC injected on the checkpoint's write, over the real `main`: unguarded publishes RUNNING with 0 per-test rows, guarded completes with all of them. This matches how the repo already writes best-effort post-processing (`Result.complete_job`'s file sort, `ClickHouseProc.prepare_logs`). Tests: two behavioural arms (a failing write and an unparseable input must both degrade to a no-op) plus a structural arm pinning the breadth and extent of the guard, since the behavioural arms alone are satisfied by an `except OSError` that leaves the load exposed. The mutation matrix is re-run at 14 mutations, each reddening at least one test and none silenced by the new swallow. Also narrows one test docstring: it justified itself with TEMP_DIR being archived wholesale, which nothing in praktika does. The assertion is unchanged.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model, plus an independent reviewer pass over the
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260803-220300 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-42:20260803-204900 |
|
cc @maxknv, could you review this? The job script holds every per-test result in memory until |
|
Workflow [PR], commit [1080281] Summary: ✅ AI ReviewSummaryThis PR checkpoints functional-test per-test rows before teardown and makes some Findings
Final Verdict
LLVM Coverage Report |
The post-suite checkpoint runs before the bugfix-validation rows are final. Between it and teardown, main labels every row with its build type, folds in the fatal-log rows via reconcile_bugfix_crash_repro, and can append a startup_error or setup_error row and break. The break paths jump past the in-loop checkpoint, so a teardown kill published rows that named neither the build type that produced them nor the failure that ended the job. That is the same data-loss window this branch closes, on a second path. One call after the build-type loop covers it: every exit from the bugfix-validation block passes there, including both breaks. The bt_result-not-ok break needs nothing new, since it already follows the in-loop call. Measured against the real main() under a SIGKILL in stop_log_exports. With the first build type failing, so the build_types[1:] loop never runs, the published rows went from unlabelled and missing the fatal row to fully labelled with it present. With the second build type's server failing to start, the Server startup (bt_second) ERROR row now survives the kill. The status stays non-terminal in both, so the runner still decides the verdict. Three test arms added, two behavioural and one structural. The structural arm is load-bearing: hoisting the call out of the block satisfies both behavioural arms and is caught only by it. All four mutations of the new code redden at least one arm. Reported by clickhouse-gh[bot]. Co-Authored-By: Claude Fable 5 <[email protected]>
…er's `Settings.WORKFLOW_STATUS_FILE` is derived from the default `TEMP_DIR` when the dataclass is defined, so the probe's `Settings.TEMP_DIR` override did not move it. On a real runner that file exists and holds the context of the job executing the test, so `_Environment.get` took the `from_workflow_data` branch and `main` saw the PR's real `changed_files`. That sent it into the batch-skip branch, which calls `Targeting.is_functional_test_file` - a classmethod the probe's stub `Targeting` does not provide - so `main` died before reaching the teardown step the arm blocks in. The probe passed on any box without that file and failed only in CI. The early-exit branch that should have reported this instead raised `AttributeError: 'NoneType' object has no attribute 'read'`: the child's output is redirected to a log file, so `Popen.stdout` is None. Read the log instead, so a probe that cannot run says why, and apply the same tail to the timeout assertion. Two new arms: one drives the diagnostic path with a forced early exit and requires the child's own output in the message, the other pins the redirect. Both redden without the corresponding fix, as does the reported arm. Co-Authored-By: Claude Fable 5 <[email protected]>
The child runs in its own session and sleeps 600s once it has blocked, so an assertion raised while it is alive left it running past the end of the test. The new early-exit arm drives exactly that path, so the leak became reachable on every run: measured over the whole file, 4 children survived it, and the log handle was reported unclosed. Reap in a `finally` and own the handle with `with`. Co-Authored-By: Claude Fable 5 <[email protected]>
…ting them The isolation arm searched the probe template for the assignment, which passes while the isolation itself is broken: with the redirect in place but no file at the new path, `_Environment.get` falls back to `from_env` and the ambient case is never exercised. Plant a workflow-status file where the default `TEMP_DIR` points, which is the CI condition, and require the rows. Removing the redirect now reproduces the reported `AttributeError` at the same line rather than a text mismatch. The runner-patch arm re-enacted `Runner._get_result_object`'s mutators by hand, so it could not fail if praktika stopped applying them. Call the real method, which needs only `name` and `force_success` off the job, and assert the recorded `KILLED` error alongside the preserved rows. Add an arm for the child reap: it drives the timeout exit, the one place the child is guaranteed alive, and witnesses the child running before requiring it gone, so a detector that sees nothing cannot satisfy it. 7 mutations, 7 redden. Co-Authored-By: Claude Fable 5 <[email protected]>
On a runner the default workflow-status path already holds that job's context, and the arm reused it when present. Its `changed_files` are whatever the PR touched, so the branch the arm exists to reach was entered only if they were non-empty: `main` guards on that. Always write our own payload with a known test file, and restore any previous content. The arm now reddens with or without a pre-existing file. Co-Authored-By: Claude Fable 5 <[email protected]>
The redirect leads the child to the `from_env` fallback, and nothing said why that is safe. It is safe structurally: `changed_files` reaches the environment only through the workflow status file, and `from_env` builds `JOB_KV_DATA` from a fixed pair of keys, so the fallback cannot carry one. Assert that, so a change adding it to the fallback fails here instead of silently making a one-line fix incomplete. Co-Authored-By: Claude Fable 5 <[email protected]>
The post-suite checkpoint runs before the first build type is labelled and before `reconcile_bugfix_crash_repro`, and the loop's own checkpoint is only reached after the switch, whose `stop_server` can take a long time. A kill in between published the first build's rows stripped of the attribution and the fatal row that explain them. Measured before the fix: five rows, every label empty, no fatal row. The existing between-build-types arm kills at the SECOND switch, so it could not see this window. The new arm kills at the first and asserts both the labels and the fatal row; it fails when the added checkpoint is removed. No row is duplicated, since the loop replaces `test_result.results` rather than appending. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Root cause. The reported Also fixed, found while verifying. The first bugfix build type was not checkpointed after its Validation. 27 arms pass, 20 consecutive runs green, 8 mutations all redden: removing the |
…/ci-persist-ft-results-before-teardown
`main` now passes `allow_no_tests` to `FTResultsProcessor.run`. The stub stood in with the older signature, so driving `main` raised `TypeError` before it reached teardown and seven arms failed for a reason unrelated to what they measure. Co-Authored-By: Claude Opus 5 <[email protected]>
`check_fatal_messages_in_logs` scans `job.log` for a column-zero `Traceback (most recent call last):` and turns a hit into a failing `Exception in test runner` row, which bugfix validation then inverts into a reproduced bug. The checkpoint is best-effort by contract, so its own diagnostics must not be able to forge a runner failure. Not reachable from CI as generated today: all 541 `praktika run` invocations pass `--timestamp`, and `_TimestampedStream` prefixes every line of a traceback including the first. Indenting drops the dependency on that flag. Co-Authored-By: Claude Opus 5 <[email protected]>
The module's standalone runner calls each `tmp_path` arm directly, so a required `capsys` parameter made it raise `TypeError`. Redirecting both streams inside the arm keeps it callable either way, and stderr is part of the capture because an unguarded traceback would go there. Co-Authored-By: Claude Opus 5 <[email protected]>
A job that overruns its timeout is patched in `Runner._run`, which adds `TIMEOUT` and `ERROR` while the result is still incomplete; `_get_result_object` then finds it completed and skips its own `KILLED` patch. The existing arm drives only the latter, so a change to `_run` that emptied `results` while setting `ERROR` would have left every arm green. Driving `_run` needs a workflow, a patched `_Environment` and a `TeePopen` fake, so both patch blocks are read instead. Validated against three mutants: dropping the rows in either block, and removing the `is_completed` guard, each redden it. Co-Authored-By: Claude Opus 5 <[email protected]>
Listing destructive spellings cannot be complete: `set_results([])`, a slice assignment, a `del` and a `pop` all empty `results` without naming it. The blocks are now required to call only the six methods that were read and shown to leave `results` alone, and to rebind only local names, so an unrecognised call fails the arm instead of slipping past it. The docstring says what is not covered: neither block is executed, so a row dropped inside one of the allowed methods is still invisible here. Co-Authored-By: Claude Opus 5 <[email protected]>
Only `If.body` was read, so inverting the guard and hanging a clearing branch off the `else` emptied `results` while the arm stayed green. Co-Authored-By: Claude Opus 5 <[email protected]>
A build type's rows are complete when FTResultsProcessor.run returns, but check_fatal_messages_in_logs scans the whole server log before the checkpoint that persists them. The first build type already had its own save before that scan; the later ones only had the one after it, so a job killed inside the scan published the previous build type's rows and the one that had just finished was missing entirely. Measured with the probe that drives the real main() and SIGKILLs it inside the second build type's fatal scan: without this, 0 rows of the finished build type are published and the file still holds the previous one's; with it, all 9. Both the adoption of bt_result and the checkpoint itself are load-bearing - deleting either reddens the new arm and nothing else. Nothing reads test_result between run() and the assignment that followed the scan, and that assignment stays because reconcile_bugfix_crash_repro can change bt_result.status and the build-type labels are applied there.
The bugfix-validation job name carries only the architecture, so a per-test row is attributable to the master build type that produced it only through its label. Both pre-scan checkpoints published rows before that label was set: the first build type's label came after the checkpoint that precedes it, and the later build types were labelled only after the fatal scan. A job killed in either scan therefore published rows that the report cannot attribute. Move each labelling loop above the checkpoint that first publishes those rows. set_label merges by name (ci/praktika/result.py:426), so this is idempotent; the duplicate loop after the later build's fatal scan is dropped because the fatal rows extend_sub_results appends are already labelled where they are collected. The assignments after the scan stay: reconcile_bugfix_crash_repro can change bt_result.status. The new arm now asserts the label as well as the row count, over both windows: reverting either hoist leaves the rows present but unattributable, and reddens only the case for that build type.
Address review: `Result.complete_job` rewrote `result_<job>.json` in place via `dump`, so a timeout kill during the final publish truncated the file and erased the rows checkpointed by `checkpoint_collected_results`. Add `Result.dump_atomically` (write to a temp file, then `os.replace`), use it in `complete_job`, and reuse it in the checkpoint helper. Other `dump` callers and `Serializable.dump` are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
# Conflicts: # ci/praktika/result.py
`_dump_if_persisted` rewrote an existing result file with the in-place `dump`, so setters called after the functional-test checkpoint (`set_success` on coverage jobs, `set_status`/`set_info` on bugfix validation, `set_info` from `_add_job_summary_to_info`) reopened the truncation window that `dump_atomically` closes for the final publish. Use `dump_atomically` there; `Serializable.dump` and non-`Result` callers are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
| raise | ||
| if exists: | ||
| self.dump() | ||
| self.dump_atomically() |
There was a problem hiding this comment.
The invariant is still incomplete here because later runner stages keep rewriting the same persisted Result with plain dump(). The common timeout path goes through Runner._finalize_job_result() (ci/praktika/runner.py:495-536), and that function still does result.dump() after the add_error / set_status / set_info calls. I verified the current code locally by seeding a checkpointed RUNNING result and tracing that finalizer: it executes dump_atomically, dump_atomically, dump_atomically, then dump.
That means a second interruption while the runner is classifying the timed-out job can still truncate result_<job>.json and lose the checkpointed rows again. The same pattern still exists later in _post_run / _ResultS3.copy_result_to_s3, so I think the fix needs to move to Result.dump itself, or all remaining runner-side Result.dump() calls on persisted job results need to switch to the atomic path.
…container exit A root (`+root`) job container publishes its final result with `Result.complete_job` -> `dump_atomically` (tmp file + `os.replace`, since ClickHouse#113200), so the result JSON in `ci/tmp` becomes a new root-owned inode. The server log dir under `ci/tmp` is created by root as well. The runner relies on the docker-based `chown -R` fix-up to give both back to the host user. When the docker daemon goes away together with the job container (CLI exit 125, "Error waiting for container: Canceled" + "grpc: the client connection is closing", the ClickHouse#109673 signature), that fix-up fails too (`docker.sock/_ping: EOF`) and its exit code was discarded. Then: - `_finalize_job_result` rewrites the root-owned result in place -> `PermissionError`, and the job is reported `exit code [None]`; - the log upload compresses next to the source in the root-owned log dir -> `Permission denied`, server logs are not uploaded; - with those fixed, the job would still be red: the CLI's 125 overrides the job's own completed OK verdict (`exit code [125]`, also seen on SQLLogic and tsan shards) and the `provides` artifacts are not uploaded. Changes: - When the docker chown fails, fall back to `sudo -n chown -R` on the host (`Runner._run` and the sibling `Utils.fix_ownership_after_docker` used by the stress and AST fuzzer jobs). `-n` fails fast where sudo is not passwordless, so such hosts behave as before. - `Result.complete_job` stamps `ext["completed_by_job"]` in the same atomic publish as the verdict. A setter can persist OK earlier (for example `integration_test_job.py` calls `set_success()` before the coverage merge, the late OOM scan and `complete_job`), so a persisted OK alone is not a final verdict. - `Runner._run` keeps an OK result published by `complete_job` when the exit is the daemon-death 125 and the job did not time out: `complete_job` exits 0 on an OK verdict and nothing runs after it, so 0 is the exit code the container would have reported. FAIL/ERROR verdicts, timeouts, incomplete results (still labeled `infra`) and a 125 without both markers are unchanged. Failing job: https://github.com/ClickHouse/ClickHouse/actions/runs/36384768039/job/108966719660 Report: ClickHouse#113201 (comment) Validated with throwaway probes (a docker shim that runs the job body as root and loses the daemon at exit), not committed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Stateless tests (amd_msan, WasmEdge, parallel, 2/2)on #112959(report)
reported
errorwith zero test failures. All 6174 tests passed andAll tests have finishedprinted at t=8893s; the job was killed at the 9000s budget, 122s into teardown.Root cause:
mainholds the complete per-test result in memory from the moment the suitefinishes until
Result.complete_jobat the very end, and everything in between is teardown.A kill there discards finished results. The killed shard inserted 1 CIDB row and uploaded
1 artifact; its passing sibling at the same sha, 6178 and 5. The run is invisible
to flaky-detection queries and paints an empty red check on an unrelated PR.
The change writes the collected results into the job's existing result file as soon as they
exist, before any teardown, leaving the status non-terminal. praktika then patches the killed
job to
ERRORwithout touchingresult.results, so it still reportsERROR, correctly, but with all 6174rows. It publishes by rename, since
Result.dumptruncates in place. The bugfix-validationloop checkpoints per build type, before and after each fatal-log scan, because each build
replaces the previous one's rows and the scan runs between them.
The helper never raises, since
mainhas no enclosingtry; withENOSPC injected on that write the job still publishes
OKand every row.This fixes neither the overrun nor teardown reliability - logs gathered later can still be
lost. It makes the run attributable.
complete_job's final publish goes through the samerename (
Result.dump_atomically), so a kill inside it leaves the checkpointed file in placeinstead of a truncated one. The shared
Serializable.dumpand all other callers are unchanged.Validated against the real
main, SIGKILLed inside teardown as praktika's watchdog does: unpatched publishes 0 per-test rows, patched 6174.Workflow [PR]
Sync PR [sync-upstream/pr/113200]
Version info
26.10.1.531-master(included in26.10and later)