Skip to content

Fix flaky test_kafka_formats_with_broken_message integration test - #108252

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-kafka-broken-message-errors-flush-retry
Jun 27, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-kafka-broken-message-errors-flush-retry

Conversation

@groeneai

@groeneai groeneai commented Jun 23, 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

Stabilizes the flaky integration test
test_storage_kafka/test_batch_slow_0.py::test_kafka_formats_with_broken_message.

Root cause. The error row written into kafka_errors_<format>_mv can lag
behind the data rows on slow builds. The test polls for it with
query_with_retry(retry_count=30, sleep_time=1, check_callback=lambda res: len(res) > 0),
but query_with_retry returns its last result even when check_callback never
passed (if result is not None: return result). So when the error MV has not
flushed within the 30s budget, the call returns an empty string and
json.loads("") raises the opaque JSONDecodeError: Expecting value: line 1 column 1 (char 0) at line 405.

Slow-build only. Over the last 60 days, every json.loads-mode failure of
this test was on a slow build: amd_asan_ubsan (x10), amd_tsan (x1),
amd_msan (x1), amd_llvm_coverage (x1). Zero on fast/release builds. 30 days:
~15 hits across 11 distinct PRs plus 2 on master, all amd_asan_ubsan. This is
the classic "30s wait calibrated for fast builds" timing race; the same class was
fixed for sibling Kafka tests in #100286 and #105138.

Fix. Double the error-MV poll budget (30s -> 60s) to give slow builds headroom,
and assert the polled result is non-empty before json.loads so any genuine
residual failure surfaces with a clear message instead of an opaque JSON decode
error. Test-only change; the test's assertions on raw_message/error are
unchanged.

CI report (latest, PR #108182, commit 17b519a):
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108182&sha=17b519a0248e&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20old%20analyzer%2C%202%2F6%29

Version info

  • Merged into: 26.7.1.144 (included in 26.7 and later)
  • Backported to: 26.6.2.11, 26.3.33.65

…V flush)

The error row in kafka_errors_*_mv can lag behind the data rows on slow
sanitizer/coverage builds. query_with_retry returns its last result even when
the check_callback never passed, so on a too-short budget it returns an empty
string and json.loads("") raised an opaque JSONDecodeError (Expecting value:
line 1 column 1). Over 60 days every json.loads-mode failure was on a slow
build (asan_ubsan/tsan/msan/llvm_coverage), zero on fast/release builds.

Double the error-MV poll budget (30s -> 60s) for slow-build headroom and assert
the result is non-empty before json.loads so any residual failure surfaces with
a clear message instead of an opaque JSON decode error.

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

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes for the failing mechanism: query_with_retry returns its last result even when check_callback never passes, so on retry exhaustion it returns "" and json.loads("") raises exactly JSONDecodeError: Expecting value: line 1 column 1 (char 0) — reproduced deterministically and matching the CIDB test_context_raw signature. The full Dockerized slow-build flush race is inherently non-deterministic (same as the merged sibling fixes #100286 / #105138).
b Root cause explained? The kafka_errors_<format>_mv row lags behind data rows on slow builds. The poll budget (30 x 1s) is too short for slow sanitizer/coverage builds; query_with_retry then silently returns an empty result instead of raising, and json.loads("") throws the opaque JSONDecodeError at line 405.
c Fix matches root cause? Yes. Raises the poll budget 30s -> 60s (more flush headroom on slow builds) and asserts non-empty before json.loads. Not a band-aid: no assertion is weakened, no randomization disabled, no data reduced.
d Test intent preserved / new tests added? Preserved. The raw_message and error prefix assertions are unchanged; the new assert only converts the silent-empty path into a clear failure. No new test needed (this is a harness timing fix, not a product code change).
e Both directions demonstrated? Mechanism demonstrated both ways: with errors_text="", the old path raises the opaque JSONDecodeError; the new assert len(errors_text) > 0 raises a clear AssertionError naming the format/MV, and on a flushed (non-empty) result both paths json.loads identically. CI on this PR exercises the full path on slow builds.
f Fix is general, not a narrow patch? The json.loads of a _errors MV exists only at this one call site in this test (verified by grep). The sibling Kafka error-MV flush class was already fixed in #100286 (this same test) and #105138 (other Kafka tests). The second function in this file (test_kafka_formats) does not json.loads an error MV and does not appear in the failure data, so it is intentionally left unchanged.

Session id: cron:clickhouse-worker-slot-3:20260623-024200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @antaljanosbenjamin — could you review this? It stabilizes the flaky test_kafka_formats_with_broken_message on slow sanitizer/coverage builds: the kafka_errors_*_mv row can lag past the 30s poll budget, query_with_retry then returns an empty string (it returns its last result even when check_callback never passed), and json.loads("") raised an opaque JSONDecodeError. Raises the budget to 60s and asserts non-empty before json.loads. Same class as #100286/#105138.

@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Jun 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b0f0a79]

Summary: ✅


AI Review

Summary

This PR updates the Kafka integration test test_kafka_formats_with_broken_message so the error materialized view poll has more slow-build headroom and fails with an explicit assertion before json.loads when query_with_retry returns its last empty result. I did not find correctness or CI-review blockers in the current diff.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.50% 92.50% +0.00%
Branches 77.50% 77.50% +0.00%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 363 line(s), 29 function(s) across 122 file(s) · Details

Top files
  • src/Storages/StorageReplicatedMergeTree.cpp: 23 line(s)
  • src/AggregateFunctions/AggregateFunctionQuantileGK.cpp: 14 line(s)
  • src/Common/ShellCommand.cpp: 13 line(s)
  • src/Functions/FunctionsBitmap.h: 12 line(s)
  • src/Storages/MergeTree/ReplicatedMergeTreeRestartingThread.cpp: 12 line(s)

Full report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's give it a chance.

@alexey-milovidov alexey-milovidov self-assigned this Jun 27, 2026
@alexey-milovidov
alexey-milovidov merged commit a7ba3cd into ClickHouse:master Jun 27, 2026
166 of 167 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 27, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 28, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Jun 28, 2026
Cherry pick #108252 to 26.6: Fix flaky test_kafka_formats_with_broken_message integration test
robot-clickhouse added a commit that referenced this pull request Jun 28, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 28, 2026
clickhouse-gh Bot added a commit that referenced this pull request Jun 28, 2026
Backport #108252 to 26.6: Fix flaky test_kafka_formats_with_broken_message integration test
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…essage-errors-flush-retry

Fix flaky test_kafka_formats_with_broken_message integration test
@PedroTadim

Copy link
Copy Markdown
Member

Backporting further to fix CI

@PedroTadim PedroTadim removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo labels Sep 12, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 12, 2026
PedroTadim added a commit that referenced this pull request Sep 12, 2026
…_message

26.3's per-format error check predates the retry wrapper master already had
around it, so #108252's diff (retry_count 30->60, empty-result guard) doesn't
apply textually. Brought in master's retry + guard directly with #108252's fix
folded in; the resolved block is byte-identical to master's current text.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
robot-clickhouse added a commit that referenced this pull request Sep 12, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 12, 2026
alexey-milovidov added a commit that referenced this pull request Sep 12, 2026
Backport #108252 to 26.3: Fix flaky test_kafka_formats_with_broken_message integration test
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-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR v26.3-must-backport v26.6-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants