Skip to content

Make integration flaky check finish within its time budget (best effort) - #107453

Merged
alexey-milovidov merged 4 commits into
masterfrom
integration-flaky-check-time-budget
Jun 17, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
integration-flaky-check-time-budget

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 14, 2026 •

Copy link
Copy Markdown
Member

The Integration tests (amd_asan_ubsan, flaky) job can time out and report a red failure with 0 results when a PR touches many integration test modules. It runs every changed module under -n 3 --dist=each (e.g. 544 test items × 3 workers on #105171), and the soft FLAKY_CHECK_TIME_LIMIT (90 min, measured from main) sat above the external ~80-90 min ceiling at which a lone integration job is cancelled. So the graceful xdist --session-timeout and the subprocess hard-kill backstop (which still collects partial results) never fired — the whole process was killed first, leaving an empty result that surfaced as a failure instead of a best-effort partial report.

Changes to ci/jobs/integration_test_job.py:

  • Lower FLAKY_CHECK_TIME_LIMIT from 90 to 45 min (matching the functional flaky check in ci/jobs/functional_tests.py) so the internal timeout/backstop fires and a report is produced well before the external cancellation. Worst-case wall-clock is now ~66 min.
  • Add MAX_FLAKY_CHECK_MODULES (10): run a deterministic sorted subset when a PR changes more modules than fit the budget, and report the rest as SKIPPED so the reduced coverage is explicit, not silent.
  • Report SKIPPED instead of ERROR when no results are collected within the budget, so a fully time-limited run does not block the PR.

Surfaced by the flaky check on #105171: https://github.com/ClickHouse/ClickHouse/actions/runs/27483289227/job/81298702498

Related: #105171

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

...

Version info

  • Merged into: 26.6.1.944

The `Integration tests (amd_asan_ubsan, flaky)` job timed out and reported a
red failure with 0 results on PR #105171, which mechanically touches ~24
integration test modules. The flaky check runs every changed module under
`-n 3 --dist=each` (544 test items x 3 workers) and was killed before it could
produce a report.

Root cause: the soft `FLAKY_CHECK_TIME_LIMIT` was 90 min, measured from `main`
(~91.5 min from the job clock). A lone integration job is cancelled by an
external ceiling at ~80-90 min from job start, so the graceful xdist
`--session-timeout` and the subprocess hard-kill backstop (which still collects
partial results) never fired - the whole process was killed first, leaving an
empty result that surfaced as a failure rather than a best-effort partial report.
A ~19 min hang on `test_storage_delta` made it worse.

Changes to `ci/jobs/integration_test_job.py`:

- Lower `FLAKY_CHECK_TIME_LIMIT` from 90 to 45 min, matching the functional flaky
  check, so the internal timeout/backstop fires and a report is produced well
  before the external cancellation. Worst-case wall-clock is now ~66 min.
- Add `MAX_FLAKY_CHECK_MODULES` (10): when a PR changes more modules than fit the
  budget, run a deterministic sorted subset and skip the rest on a best-effort
  basis. The skipped modules are reported as `SKIPPED` entries so the reduced
  coverage is explicit, not silent.
- When no results are collected within the budget, report `SKIPPED` instead of
  letting an empty result default to `ERROR` and block the PR.

CI report: https://github.com/ClickHouse/ClickHouse/actions/runs/27483289227/job/81298702498
PR: #105171

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

clickhouse-gh Bot commented Jun 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3748267]

Summary: ✅


AI Review

Summary

This PR makes the integration flaky check best-effort within a bounded time budget: it caps the number of changed integration modules run in one flaky job, lowers the flaky time budget, reports capped modules as SKIPPED, and preserves ERROR for empty pytest output unless a timeout was actually observed. The two prior AI findings are addressed in the current code, and I found no new blocking issues in the changed logic.

Missing context / blind spots
  • ⚠️ I could not verify the Praktika CI report with .claude/tools/fetch_ci_report.js because GitHub returned a token/enterprise 403; gh pr checks showed the PR-level CI still pending for commit 3748267caa0d737563faf09bd0b4f152facf915f.
  • ⚠️ I could not run python3 -m pytest ci/tests/test_integration_flaky_empty_result.py locally because this checkout does not have the pytest Python module installed.
Final Verdict

Status: ✅ Approve

No code changes are required from this review. The remaining validation is CI completion / an environment with pytest installed.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 16, 2026
Comment thread ci/jobs/integration_test_job.py Resolved
… on timeout

The integration flaky/targeted check reports an empty pytest run as a
best-effort `SKIPPED` so a fully time-limited run does not block the PR. As
written, `empty_best_effort` treated *every* empty result as expected budget
exhaustion. But `Result.from_pytest_run` also returns an `ERROR` with an empty
`results` list when pytest fails to produce output for an unrelated reason (it
crashes before writing `pytest_parallel.jsonl`, or exits with a plugin/internal
error and no test rows). Because flaky and targeted checks deliberately do not
set `has_error`, such a real harness failure was being forced to `SKIPPED` and
the job reported green.

Carry an explicit `timed_out` signal out of `run_pytest_and_collect_results`,
set when the graceful xdist `--session-timeout` marker is found or when the hard
subprocess backstop (`Shell.run` `timeout`) kills pytest, and only downgrade an
empty flaky/targeted result to `SKIPPED` when a timeout was actually observed.
Empty results without a timeout fall through to `create_from`'s default `ERROR`.

Add `ci/tests/test_integration_flaky_empty_result.py` covering the decision
truth table and the end-to-end status (timeout-empty -> SKIPPED,
non-timeout-empty -> ERROR).

Addresses the AI review on #107453

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

Copy link
Copy Markdown
Member Author

Addressed the AI review (empty_best_effort conflating expected timeout exhaustion with real harness failures) in 91c609fbf12.

run_pytest_and_collect_results now returns an explicit timed_out flag, set when either the graceful xdist --session-timeout marker is present or the hard subprocess backstop (Shell.run timeout) killed pytest before it could finish (a completed run always returns under timeout). The empty-result downgrade is gated on that signal:

  • flaky/targeted + empty + timeout observed → SKIPPED (best effort, as before);
  • flaky/targeted + empty + no timeout → falls through to create_from’s default ERROR, so a pytest crash/plugin/internal error that writes no pytest_parallel.jsonl stays red instead of reporting green.

Added ci/tests/test_integration_flaky_empty_result.py covering the decision truth table and the end-to-end status (timeout-empty → SKIPPED, non-timeout-empty → ERROR).

Comment thread ci/jobs/integration_test_job.py Resolved
alexey-milovidov added a commit that referenced this pull request Jun 16, 2026
#107453 ("Make integration flaky check finish within its time budget")
carries the canonical version of this logic and was refined in review to
distinguish an expected timeout from a real harness failure. Bring that
version into this PR so the two do not diverge.

Replace the previous `empty_best_effort = is_flaky_check and not test_results`
heuristic with the timeout-gated approach from #107453:

- `run_pytest_and_collect_results` now returns an explicit `timed_out` flag,
  set when the graceful xdist `--session-timeout` marker is found or when the
  hard subprocess backstop (`Shell.run` `timeout`) kills pytest before it
  finishes (a completed run always returns under `timeout`).
- A flaky/targeted check that produced no results is downgraded to `SKIPPED`
  (via the new `is_empty_best_effort_skip` helper) *only* when a timeout was
  actually observed. An empty result without a timeout - pytest crashed before
  writing `pytest_parallel.jsonl`, or exited with a plugin/internal error and no
  test rows - falls through to `create_from`'s default `ERROR` and stays red.

Add `ci/tests/test_integration_flaky_empty_result.py` (from #107453) covering
the decision truth table and the end-to-end status (timeout-empty -> `SKIPPED`,
non-timeout-empty -> `ERROR`).

The dead `from more_itertools import tail` import that #107453 still has is
intentionally not brought over: the local `tail` shadows it and `ruff` `F811`
(enabled by this PR) flags it - it was removed here in 408f1c3.

Related: #107453

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…d entries

The empty-result status decision in `ci/jobs/integration_test_job.py` used
`bool(test_results)` *after* the best-effort scope cap (`MAX_FLAKY_CHECK_MODULES`)
had already appended synthetic `SKIPPED` entries for the dropped modules. In a
scope-capped flaky run where the selected modules produced no pytest rows,
`test_results` was therefore non-empty even though pytest produced nothing, so:

- a timeout-empty run collapsed to a green top-level status instead of the
  intended best-effort `SKIPPED`, and
- a non-timeout empty run (a real harness failure) reported green instead of
  `ERROR`, masking the failure.

Capture `pytest_has_results` before appending the synthetic skipped-module
entries and use it for both `is_empty_best_effort_skip` and
`empty_harness_failure`. Because the synthetic `SKIPPED` rows make `test_results`
non-empty, `create_from` no longer defaults the empty set to `ERROR`, so the
harness-failure status is now forced explicitly.

Add `test_capped_empty_timeout_run_reports_skipped` and
`test_capped_empty_non_timeout_run_reports_error` covering the capped path:
selected pytest results empty plus a synthetic skipped module, for both
`timed_out=True` (top-level `SKIPPED`) and `timed_out=False` (top-level `ERROR`).

Addresses the AI review on #107453

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

Copy link
Copy Markdown
Member Author

Addressed the follow-up AI review (capped-path empty-result status) in 3748267caa0.

The empty-result decision previously used bool(test_results) after the best-effort scope cap had already appended the synthetic skipped_flaky_modules SKIPPED rows, so a scope-capped flaky run whose selected modules produced nothing was no longer "empty":

  • timeout-empty + cap → collapsed to a green top-level status instead of best-effort SKIPPED;
  • non-timeout empty + cap (a real harness failure) → reported green instead of ERROR.

Now pytest_has_results = bool(test_results) is captured before the synthetic skipped-module entries are appended, and both is_empty_best_effort_skip and empty_harness_failure use it. Since the synthetic SKIPPED rows make test_results non-empty, create_from no longer defaults the empty set to ERROR, so the harness-failure status is forced explicitly.

Added focused coverage for the capped path in ci/tests/test_integration_flaky_empty_result.py: selected results empty plus a synthetic skipped module, for both timed_out=True (top-level SKIPPED) and timed_out=False (top-level ERROR).

@alexey-milovidov
alexey-milovidov merged commit 817f14b into master Jun 17, 2026
164 of 165 checks passed
@alexey-milovidov
alexey-milovidov deleted the integration-flaky-check-time-budget branch June 17, 2026 22:16
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants