Skip to content

Do not discard finished test results when a functional-test job is killed in teardown - #113200

Merged
alexey-milovidov merged 23 commits into
ClickHouse:masterfrom
groeneai:groeneai/ci-persist-ft-results-before-teardown
Sep 23, 2026
Merged

alexey-milovidov merged 23 commits into
ClickHouse:masterfrom
groeneai:groeneai/ci-persist-ft-results-before-teardown

Conversation

@groeneai

@groeneai groeneai commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

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

...

Description

Stateless tests (amd_msan, WasmEdge, parallel, 2/2) on #112959
(report)
reported error with zero test failures. All 6174 tests passed and All tests have finished printed at t=8893s; the job was killed at the 9000s budget, 122s into teardown.

Root cause: 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.
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 ERROR without touching result.results, so it still reports ERROR, correctly, but with all 6174
rows. It publishes by rename, since Result.dump truncates in place. The bugfix-validation
loop 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 main has no enclosing try; with
ENOSPC injected on that write the job still publishes OK and 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 same
rename (Result.dump_atomically), so a kill inside it leaves the checkpointed file in place
instead of a truncated one. The shared Serializable.dump and 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

  • Merged into: 26.10.1.531-master (included in 26.10 and later)

…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.
@groeneai

groeneai commented Aug 3, 2026

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

Pre-publication review by an independent model, plus an independent reviewer pass over the
resulting code. Engine: codex, 2 rounds (full pass + delta re-review of the fix round), 0
findings in both, diffstat verified against an independent measurement of the same ranges so
neither round ran against a wrong base. The reviewer pass raised the two below and drove one
fix round.

# Sev Finding Verdict Evidence / action
1 ⚠️ checkpoint_collected_results was called unguarded from both sites and main has no enclosing try, so any raise in it published the bare RUNNING with 0 children, which the runner turns into an empty ERROR on a run that would have completed (ci/jobs/functional_tests.py:1033, :1212; ci/praktika/runner.py:572-576) AGREE, fixed @ 16e930d Reproduced by injecting OSError(28) on the temp write against the real main: unguarded left ('RUNNING', 0), guarded completes ('OK', 50), with the injection counter asserted non-zero in both arms. The body is now wrapped in except Exception with the Result.from_fs load inside it, since JSONDecodeError is a ValueError and an except OSError would not have covered it. Verified by AST at the final commit: every call other than the handler's own two is inside the guarded block, and the handler is only print + traceback.print_exc, so it cannot itself raise. Four new mutations (no try; except OSError only; try after the load; re-raise from the handler) each redden a test, and the pre-existing wrong-path mutation still reddens the same five, so swallowing silenced no existing coverage
2 💡 A test docstring justified itself with "TEMP_DIR is archived and uploaded wholesale", which I could not substantiate AGREE, fixed @ 16e930d Nothing in ci/praktika/ archives or globs TEMP_DIR: the only glob.glob over it iterates explicitly declared Artifact.path values, and no functional-test job declares one under ci/tmp. Rationale narrowed to what the test checks; the assertion is unchanged

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-8:20260803-220300

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, 100%. main() is driven with the suite stubbed to produce 6174 complete per-test rows, one teardown step blocks, and the process group is SIGKILLed the way praktika's watchdog does. Result.from_fs(job_name) afterwards: 0 per-test rows unpatched, 6174 patched. Pinned as ci/tests/test_functional_tests_results_checkpoint.py::test_a_job_killed_in_teardown_still_publishes_every_test_row.
b Root cause explained? The per-test result is complete in memory at functional_tests.py:1015 and the first and only disk write is complete_job -> dump() at the end. Everything between is teardown (SYSTEM FLUSH LOGS, log-export shutdown against a remote staging cluster, coverage export, COLLECT_LOGS). The single timeout covers setup + suite + teardown, and the watchdog SIGKILLs the process group with no knowledge of which phase is running, so an overrun discards work already finished. Measured against the sibling shard that passed at the same sha: 1 CIDB row and 1 artifact vs 6178 and 5.
c Fix matches root cause? Yes. The defect is that finished results are only on disk at the very end; the fix writes them as soon as they exist, before any teardown. It does not touch the budget (rejected: measured teardown reaches 3022s, so a bigger budget only relocates the cliff) and does not special-case any log line.
d New tests added? Yes, 20 tests in ci/tests/test_functional_tests_results_checkpoint.py. Two drive the real main() under a real SIGKILL; two drive a real process death mid-write for the atomicity claim; two drive the helper against a failing write and against an unparseable input file; the rest pin placement, the non-terminal status, ext preservation, the local-run guard, the breadth and extent of the exception guard, the runner's kill-path contract and the CIDB row shape. 14 mutations were run and each reddens at least one test: remove the calls; wrong path; plain Result.dump; terminal status; create_from; drop the children; drop the per-build-type call; invert the guard; flatten the children; temp name == published name; remove the try/except; catch only OSError; start the try after the load; re-raise from the handler.
e Both directions demonstrated? Yes, on the merged base. Loss repro: unpatched ('RUNNING', 0), patched ('RUNNING', 6174). Best-effort guard: with ENOSPC injected on the checkpoint's write, the unguarded helper aborts main() so it publishes the bare RUNNING with 0 per-test rows, while the guarded one completes normally with all 50 (the injection is asserted to have fired in both arms, so neither can pass for the wrong reason). Atomicity: the same interruption against a plain open(...,"w") + json.dump leaves JSON Result.from_fs cannot parse (the negative control, which fails if the interruption misses the write window), while the checkpoint leaves a parseable file. Happy path: the final complete_job output is byte-identical to unpatched (21658 bytes both arms, timings frozen).
f Fix is general across code paths? Yes. All eight common_ft_job_config derivations run this same main() and inherit the checkpoint (flaky PR/MQ, targeted PR, functional tests, coverage, azure, llvm coverage, excluded-from-llvm), as does bugfix_validation_ft_pr_jobs. The bugfix-validation loop needed its own call site because it REPLACES test_result.results per build type and then stops the server: a single post-loop call loses the completed build's rows. Verified with three build types killed entering the third: the second build's 22 rows survive, and removing the in-loop call reduces that to 0.
g Fix generalizes across inputs? Yes, matrix run: empty list, a single empty Tests row, an extra sibling before Tests (the targeted check), unicode plus a 300-char test name, a 40000-char info, None timings, 3-level nesting, no Tests child at all, and 6174 rows. All persist, all keep the non-terminal status and ext, none leaves a temporary file.
h Backward compatible? N/A. No setting, no serialization format, no user-visible behavior. The result JSON keeps the shape main() already writes, so every existing reader (report page, CIDB insert, Runner._get_result_object) is unchanged. Nothing under ci/praktika/ is touched.
i Invariants and contracts preserved? The invariant added is "per-test results that exist in memory are on disk before any teardown step runs". Preserved: the checkpoint assigns no status, so every later status decision (fatal-log rows, the bugfix-validation inversion, force_ok_exit, set_success) still runs and the final dump wins; Runner._get_result_object patches an incomplete result via add_error/set_status, neither of which clears results, so a killed job reports ERROR with its rows intact; the existing Result object is updated so the runner's run_url survives; the write is published by os.replace within one directory, so no reader ever sees a partial file. The checkpoint is also strictly best-effort: it never raises, because the final complete_job writes the same results anyway, so it must not be able to cost a completing run its results, its logs or its status. Not claimed: the overrun itself, and logs collected later can still be lost.

Session id: cron:clickhouse-impl-slot-42:20260803-204900

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

cc @maxknv, could you review this? The job script holds every per-test result in memory until complete_job, so a watchdog kill during teardown discards results that were already finished; this writes them into the job's existing result file first and leaves the status non-terminal, so Runner._get_result_object still decides the status but keeps the children.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1080281]

Summary: ✅


AI Review

Summary

This PR checkpoints functional-test per-test rows before teardown and makes some Result rewrites publish by rename instead of truncating in place. That closes the original loss window inside functional_tests.py, but the persisted-result invariant is still incomplete: the runner later rewrites the same result_<job>.json with plain dump(), so a second interruption can still erase the checkpointed rows.

Findings

⚠️ Majors

  • ci/praktika/result.py:244 The atomic rewrite is only applied to setter-driven rewrites and complete_job, but the timeout path that consumes this checkpoint still ends with a plain Result.dump() in Runner._finalize_job_result (ci/praktika/runner.py:495-536). I verified the current code by seeding a checkpointed RUNNING result and tracing that path locally: it executes dump_atomically, dump_atomically, dump_atomically, then dump. If the runner is interrupted while reclassifying the timed-out job, result_<job>.json truncates again and the checkpointed test rows are lost. The same pattern still exists later in _post_run / _ResultS3.copy_result_to_s3, so this likely needs to move to Result.dump itself, or every remaining runner-side Result.dump() on persisted job results needs to switch to the atomic path.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: remove the remaining plain Result.dump() rewrites on the persisted job-result path, or make Result.dump itself publish atomically so timeout finalization and report upload cannot reopen the truncation window.

LLVM Coverage Report

⚠️ No coverage measurement for commit 1080281: 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_s3_async_sequential.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_parallel_2.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_parallel_3.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_sequential_1.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_sequential_2.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.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 4, 2026
Comment thread ci/jobs/functional_tests.py Resolved
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]>
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 4, 2026
groeneai and others added 6 commits August 4, 2026 10:40
…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]>
@groeneai

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI Tests failed on 16e930d1 in the new
test_a_job_killed_in_teardown_still_publishes_every_test_row, and only in CI. Fixed in
c8c37fbe7a2ddbe.

Root cause. Settings.WORKFLOW_STATUS_FILE is built from the default TEMP_DIR when the
dataclass is defined, so the probe's Settings.TEMP_DIR override did not move it. On a 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 this PR's real changed_files. That enters the
batch-skip branch, which calls Targeting.is_functional_test_file, absent from the probe's stub
Targeting, so main died before reaching the teardown step the arm blocks in. No such file
exists outside CI, which is why it passed everywhere else.

The reported AttributeError: 'NoneType' object has no attribute 'read' was only the messenger:
the branch meant to report the early exit read proc.stdout, which is None because the child's
output is redirected to a log file. It now reads the log, so a probe that cannot run says why.

Also fixed, found while verifying. The first bugfix build type was not checkpointed after its
labels and reconcile_bugfix_crash_repro rows were final, and the loop's checkpoint is only
reached after the switch, whose stop_server can be slow. A kill in between published five rows
with empty labels and no fatal row. One checkpoint_collected_results after the reconciliation
closes it; no row is duplicated, since the loop replaces test_result.results. The existing arm
kills at the second switch, so it could not see this window.

Validation. 27 arms pass, 20 consecutive runs green, 8 mutations all redden: removing the
redirect reproduces the CI AttributeError at the same line, removing the new checkpoint reddens
the new arm. The isolation arm is behavioural rather than a text search, so it is deterministic
with or without an ambient file. The runner-patch arm now calls the real
Runner._get_result_object instead of re-enacting its mutators.

groeneai and others added 6 commits August 27, 2026 23:38
`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]>
Comment thread ci/jobs/functional_tests.py Resolved
Comment thread ci/jobs/functional_tests.py Resolved
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.
@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Sep 4, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 23, 2026
alexey-milovidov and others added 2 commits September 23, 2026 06:16
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]>
@clickhouse-gh
clickhouse-gh Bot requested review from leshikus and maxknv September 23, 2026 06:20
Comment thread ci/praktika/result.py Resolved
Comment thread ci/jobs/functional_tests.py Resolved
`_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]>
Comment thread ci/praktika/result.py
raise
if exists:
self.dump()
self.dump_atomically()

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.

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.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 23, 2026
Merged via the queue into ClickHouse:master with commit 3062148 Sep 23, 2026
176 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 23, 2026
alexey-milovidov pushed a commit to UnamedRus/ClickHouse that referenced this pull request Nov 9, 2026
…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]>
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 comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect 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.

4 participants