Repository navigation
Run the 03008_deduplication debug-on-fail diagnostics only on failure - #112913
Conversation
The six 03008_deduplication_* drivers pass --debug-on-fail True, and the shared
generator builds its diagnostic probes into the same multi-statement script as the
assertions. Every probe is guarded with
WITH (SELECT count() FROM t) AS c ... WHERE c != <expected>
so it prints nothing when a case passes, but the guard suppresses output, not
execution: each probe is still parsed, analyzed, planned and round-tripped on the
success path. That is 32 extra statements per case and 2048 per 64-case run, on six
long tests that consequently run much closer to the 600s per-test budget and
occasionally time out at exactly 600s.
Make the diagnostics run only once a case has actually failed:
* each throwIf carries a phase-identifying message
(DEDUP_ASSERT_FAILED phase=<first|second> table=<t>), which costs nothing when
the assertion does not fire and is what lets a driver tell the two phases apart
(48 of the 192 case shapes have identical expected counts in both phases, so
surviving state alone cannot identify the phase);
* a new generator flag --emit-debug-only {first,second} prints only that phase's
diagnostic block, preceded by the same session SET block, with no DROP, CREATE,
INSERT or assertion;
* the drivers extract phase= from the captured stderr and re-run just the
diagnostics against the surviving tables.
The client stops at the first error (src/Client/ClientBase.cpp:3497, and the drivers
do not pass --ignore-error), so the failing state is still on disk and the
diagnostics report the execution that actually failed rather than a fresh run of it.
Re-running the whole case with --debug-on-fail True would instead start with
DROP TABLE IF EXISTS and destroy that state. The probe statements and their guards
are unchanged, and stderr is still forwarded to the harness on both paths.
Measured: statements reaching the server on insert_several_blocks_nonreplicated drop
from 3905 to 2113; across four drivers, three reps, alternating arms, 446.1s to
336.7s (1.32x). Failure output is byte-identical to the previous behaviour for both
phases, and the settings probe still reports the failing run's values rather than
fresh-session defaults. All seven reference files are unchanged.
03008_deduplication_random_settings.sh gains the long tag. Editing the shared
.python file maps to all seven 03008_* tests, because .python is not in
_TEST_FILE_EXTENSIONS so find_tests.py falls back to the data-file owners, and unlike
the six drivers this test carries no no-flaky-check tag while running close to the
180s flaky-check limit. long exempts that limit and reduces 50 iterations to 5;
no-flaky-check would have skipped the test and deleted coverage.
… mechanism Replace the long tag on 03008_deduplication_random_settings.sh with no-flaky-check. long is consumed by two independent mechanisms and the previous commit accounted for only one. tests/clickhouse-test:3364-3369 exempts a test from the 180s TOO_LONG failure inside a flaky check, which was the intent. But tests/clickhouse-test:2821-2825 also maps long to FailureReason.NO_LONG, skipping the test entirely whenever --no-long is passed, and --no-long is passed by ci/jobs/fast_test.py:378 and ci/jobs/functional_tests.py:532. So long would have removed this test from Fast test on both arches and from the LLVM-coverage stateless jobs, roughly 21960 and 33906 runs per 30 days, in order to protect about 53 flaky-check runs. no-flaky-check is read at exactly one skip site, tests/clickhouse-test:2925, and by no --no-long path, so it covers precisely the flaky check that editing the shared .python file pulls this test into. --flaky-check is passed by both the flaky check and targeted flavours, so both are covered. The six sibling drivers already carry the same tag. The TOO_LONG exemption is given up deliberately: it is unreachable once the test is skipped there. Add tests/queries/0_stateless/03008_deduplication_diagnostics_opt_in.sh and its reference so CI observes the mechanism. All eleven pre-existing 03008 references contain no DEBUG line and no assertion marker, because they encode only the success path, so nothing committed would have caught a future edit that put the probes back into the main script or broke the phase extraction. The new test asserts generator-level properties only, with no server and no ClickHouse binary, so it runs in about a second and cannot be flaky: the main script emits no diagnostics, every assertion names its phase, and the diagnostics-only script for each phase carries that phase's diagnostics and the session settings they report on while containing nothing that could mutate the state it inspects. It reuses the existing 03008 prefix, so it introduces no new test number. Each assertion family was mutation-tested separately, one mutation at a time with the generator restored and checksummed after each. Restoring the unconditional debug block reddens the success-path rows alone; dropping the phase-naming message reddens the marker rows alone; removing the settings block from the diagnostics-only script reddens the settings rows alone; making the phase argument ignored reddens the second-phase rows alone.
… tag Executes fixplan-r2 (3 majors + 2 nits). Both weak assertions were defects in the round-1 prescription rather than in its execution: the test asserted counts of loose substrings, and each count survived a real regression. Round 1 counted a bare DEDUP_ASSERT_FAILED token, but the mechanism depends on the phase=<word> shape every driver parses with sed, so renaming phase= to stage=, or labelling every assertion first, kept the count at 4 while the extraction silently yielded the empty string. The two phases are now counted separately, with the trailing space, in the exact spelling the drivers parse. Round 1 counted the 5 DEBUG tokens from one probe helper, but a complete diagnostics block carries 10 or 11, so making the other two helpers return nothing left the test green. A total is now asserted alongside the narrower per-phase count, which keeps a mutation attributable to one row. Round 1 counted SET lines, which is blind to the value, so a wrong max_insert_threads constant kept it at 7 or 9 while the diagnostics would report a value the failing run never used. Distinct name=value pairs actually present are now asserted. The consumer half was unobserved: eight files couple on the marker and the test referenced no driver, so re-adding --debug-on-fail True, corrupting the extraction token, or deleting the diagnostics re-run were all invisible. The test now reads each of the six drivers and reuses that driver's own sed program, taken from its source, so a change on either side of the coupling reddens by construction. The no-fasttest tag is removed. It made tests/clickhouse-test skip the test in both Fast test jobs, and nothing justified it: the file starts no server, needs no ClickHouse binary and runs nine generator invocations in about a second. The file now carries no tags, which also makes it eligible for the flaky check as intended. Validation: 51 rows, RC=0 with 0 bytes of stderr, and byte-identical output with CLICKHOUSE_BINARY pointed at a nonexistent path. 11 mutations, 11 reddening exactly their predicted rows, one at a time with the generator and driver md5 asserted restored after each; the round-1 mutations still redden, and the one covering the settings property still reddens a settings row alone. 50 randomized runs all pass. Both arms of all 03008_deduplication tests ran the same set with 0 new regressions and an identical failure-reason multiset.
The test observed the six drivers as text: it extracted each driver's sed program and grepped for the flags, but never ran the failure branch. Measured on a sandbox copy, it stayed byte-identically green when the `[ -n "$FAILED_PHASE" ]` guard was inverted, when the whole diagnostics re-run block was deleted, when either stderr forward was replaced by `true`, and when the stderr redirect was dropped. The inverted guard is exactly the regression this pull request exists to prevent: diagnostics would never run on a real failure and nothing in the repository would notice. Each driver's failure-handling block is now extracted verbatim from that driver's source and run against a stub client that fails the first invocation the way the server does, recording the SQL of the re-run. Extracting rather than reimplementing is what makes either side of the coupling break the test by construction, the same principle the existing sed-program extraction uses. The assertions were also token counts rather than payload, on a shape where every boolean is True so both phases have identical expected counts and the `max_insert_threads` branch of the settings report is never reached. The test stayed green with a phase's expected count corrupted, with a probe pointed at a table that does not exist, and with invalid SQL in a probe. That last one matters most: on master the probes ran on the success path, so a syntax error there broke every case immediately, and this pull request silently drops that coverage. A second argument shape with differing per-phase counts now pins the guard constants, the tables the probes read, the carried-over `max_insert_threads` value, and that each emitted script parses. The tag comment on 03008_deduplication_random_settings.sh said the data-file owner fallback maps to seven tests. Driving the real Targeting._tests_owning_data_file returns eight, because this test shares the generator too, so the wording no longer names a number. Twenty-one mutations, one at a time with every file's md5 asserted restored and a clean re-run verified after each: the eleven from earlier rounds still redden, two of them now strictly wider, and the ten new ones each redden exactly their predicted rows. 50 randomized runs pass. A both-arms sweep over all twelve 03008_deduplication tests shows no new regressions with an identical error-code multiset in both arms; the one apparent improvement was re-tested on the baseline arm and is sandbox-flaky either way.
… test Two gaps in 03008_deduplication_diagnostics_opt_in.sh, both measured to leave the whole reference byte-identical before this change. The oracle asserted DEBUG token counts, guard constants, FROM targets, settings and mutation-freedom, and clickhouse format only parses the AST, so nothing observed which columns each probe selects. Thinning `SELECT table, name, rows, bytes_on_disk` to `SELECT table, name`, or replacing a column with an unresolvable identifier, both passed. The second is the worse half: because the probes no longer run on the success path, an unresolvable probe would throw only at the moment a real failure needs the diagnostics, whereas on master invalid probe SQL broke every case immediately. Assert the sorted set of projection lists per subcommand and phase instead, which also pins each guard subquery's source table. SETTINGS_RE listed bare `name=1` alternatives with no terminator, so grep -oE matched a prefix: `SET max_insert_threads=10;` matched the `max_insert_threads=1` branch. Making the single-thread branch emit 10 therefore left every row unchanged, because the mixed shape legitimately expects 10. Match complete, semicolon-terminated assignments, with one pattern per argument shape so each shape carries its own expected values. The mixed shape's pattern is used as well, which additionally catches a shared setting mutated on only the many-threads branch and keeps shellcheck at zero hits. Test-only. The generator, the six drivers and random_settings.sh are untouched.
The opt-in diagnostics test observed only half the driver dispatch surface and pinned the probe payload through a hand-written list of observables. Both gaps were measured, not assumed: narrowing one driver's phase parser to a single phase left all 123 reference rows byte-identical while making that driver skip the diagnostics re-run entirely for the other phase's failures, and corrupting a probe's ORDER BY, redirecting its system.parts IN list, or replacing the probe guard with 1 = 1 so the probes fire unconditionally were each invisible too. The last of those is a direct regression of the contract this change exists to establish. Both driver-coupling blocks are now parameterized over first and second, with the marker built from output the generator really emits for that phase, so a one-phase parser and a one-phase dispatch each redden. The five aggregate payload rows are replaced by a normalized dump of every statement the emit script produces, which is closed by construction under the class of clauses that nobody thought to enumerate; it literally contains the guard constants, read tables, projections, carried-over SET values, filters and orderings the deleted rows checked. The parse check stays because it fails with a clearer signal than a multi-line diff. Reference 123 to 273 rows, runtime 2.07s to 3.5s, still starts no server. Each of the five newly closed gaps reddens, and all sixteen mutations from the earlier rounds still redden, so nothing was traded away.
…play
The replay drove each driver's failure-handling block and then asserted only
properties of the resulting rerun: that it contains DEBUG statements, that it
names the failed phase, that it mutates nothing. Every diagnostics-only script
satisfies those, so two real defects in a driver passed unnoticed: dropping
"${CASE_ARGS[@]}" from the rerun, which makes the diagnostics report the wrong
expected counts and the wrong max_insert_threads for 63 of the 64 cases, and
replaying a different subcommand, which reports on tables the failed case never
touched.
Compare the rerun's whole payload against what the generator produces for this
driver's own subcommand and this replay's own arguments instead. That is closed
under the whole class rather than adding one more property to enumerate. The
subcommand is derived from the driver's main invocation, not from its rerun line,
so the comparison cannot become tautological under the subcommand swap it exists
to catch, and it is emitted in a row of its own so a driver edit that breaks the
derivation fails loudly.
The replay's arguments previously coincided with the generator's argparse
defaults, which made the argument-dropping defect produce a byte-identical
payload. They now differ from the defaults in the flags that move the payload,
which pins both the reported settings and the expected counts.
Co-Authored-By: Claude Fable 5 <[email protected]>
A failing case's stderr is captured into a private temp file so the driver can name the phase that failed. It was forwarded to the real stderr only at the end of the failure branch, after the diagnostics rerun had returned. That loses the error when the per-test deadline expires while the rerun is in flight: the harness signals the process group, the EXIT trap removes the temp file, and the forwarding cat is never reached. The reader then gets a timeout naming neither the failing case nor the phase, which is less than the pre-change behaviour gave, where the client wrote to the real stderr directly. Forwarding before the rerun keeps exactly one copy on stderr and makes the outcome independent of when the deadline lands. The uninterrupted failure path is unaffected: same verdict, same forwarded bytes, same rerun payload. The opt-in test drives each driver's failure block under a deterministic interrupt, so the regression is observable rather than merely reasoned about. The stub announces that the rerun has started and waits, so the signal always lands inside the rerun; it reads 0 forwarded markers on the previous shape and 1 on this one. Co-Authored-By: Claude Fable 5 <[email protected]>
Internal second-model reviewEight rounds of an internal review pipeline. Each round is an independent cold code review of Most of the substantive findings were defects in an earlier round's own prescribed test The last four rounds, in order:
Earlier rounds fixed a tag that would have removed 33 distinct mutations were used across the eight rounds; each reddens exactly its predicted |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-review-slot-50:20260801-140200 |
|
cc @yariks5s, could you review this? It keeps the |
|
Workflow [PR], commit [960fae3] Summary: ✅ AI ReviewSummaryThis PR moves the Final Verdict✅ No blocking issues found. |
CI finish ledger - 960fae3Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260803-180000 |
…agnostics_opt_in and skip only that half on Darwin The AI review pointed out that skipping the whole test dropped the only Darwin fast-test coverage of the diagnostics-only rerun path from #112913. Split the expensive part - the stub-client driver failure-handling replay and the interrupted-rerun harness - into a new test 03008_deduplication_diagnostics_replay.sh, which is the half that carries most of the runtime (~80% measured locally) and where the macOS timeout was landing. Only that test goes into ci/defs/darwin.skip; the cheap marker/payload/phase-parsing assertions keep running in the macOS fast test. Reference files are split at the same boundary; both halves pass locally with empty diffs. Co-Authored-By: Claude Fable 5 <[email protected]>
The test (added in ClickHouse#112913) averages ~47s on the macOS CI runner with a 60s per-test limit (vs ~27s on the Linux fast test), so a few percent of runs cross the limit and fail with a timeout. 7 failures across unrelated PRs since 2026-08-08. The test keeps full coverage on Linux. https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110321&sha=bab60560471334d48a72389dd778555360dc85fe&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29 Co-Authored-By: Claude Fable 5 <[email protected]>
Related: #111965
Related: #90094
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
The six
03008_deduplication_*drivers pass--debug-on-fail True, and the generator buildsits diagnostic probes into the same script as the assertions. Each probe is guarded
(
WHERE c_dst != <expected>), but the guard suppresses output, not execution: the probes arestill parsed, analyzed and executed on the success path.
That is 28 to 32 extra statements per case, 1792 to 2048 per 64-case run, on six
longteststhat occasionally hit the 600s per-test timeout.
This makes the diagnostics run only when a case has actually failed. Each
throwIfnow carries aphase-identifying message, a new generator flag
--emit-debug-only {first,second}prints justthat phase's diagnostic block, and the drivers re-run it on the failure path. Because the client
stops at the first error, the failing tables are still there, so the diagnostics report the state
that actually failed. The probes and their guards are unchanged, and
--debug-on-failis kept,defaulting off, as a manual entry point.
Measured on
insert_several_blocks_nonreplicated: statements reaching the server drop from 3905to 2113. Across four drivers: 446.1s to 336.8s, a 1.32x speedup. No existing
.referencefile changes.
A new test,
03008_deduplication_diagnostics_opt_in.sh, pins these properties on both sidesof the coupling: the generator's success path, diagnostic payload, settings and phase
markers, and each driver's own marker-parsing program. A future edit that puts the probes
back on the success path, thins the diagnostics or breaks the phase dispatch fails CI.
It starts no server.
03008_deduplication_random_settings.shgainsno-flaky-check, matching its six siblings:editing the shared
.pythonfile pulls all 803008_*tests that read it into the flakycheck, and this one runs close to the 180s limit there.
longwould be the wrong tag: italso means
--no-longand would drop the test from Fast test and LLVM coverage.I am not proposing to raise the timeout.
Validation detail
Success path, generator level: 384 shapes (3 subcommands x InsertSelect/InsertValues x
MergeTree/ReplicatedMergeTree x 5 booleans). Statement counts match
master --debug-on-fail Falseexactly (32/40/31 per subcommand), and each script is statement-equivalent to master after
whitespace normalization and modulo the added
throwIfmessage, with exactly 4 markers perscript.
End-to-end,
system.query_logQueryStartrows for a real driver run:Runtime A/B, arms alternated, set-equality asserted per rep:
Failure path: over all 384 shapes,
emit(first) + emit(second)reproduces every statement--debug-on-fail Trueadds over the default, with nothing missing; the only additions are theshared
SETlines the diagnostics themselves report on. No DROP/CREATE/INSERT and no assertionappears in the emitted script. On a real failure the diagnostics are byte-identical to master,
including a case shape whose two phases have identical expected counts, and the settings probe
reports the failing run's values rather than fresh-session defaults.
50 randomized runs each:
several_mv_into_one_table_replicated,insert_several_blocks_replicatedand
diagnostics_opt_in, 50/50 OK. Both arms were swept over every03008_deduplication*test atthe commit that last touched the generator and the six drivers, and over the two opt-in test files
for each later commit: same ran-set, no new failures either time.