Skip to content

Run the 03008_deduplication debug-on-fail diagnostics only on failure - #112913

Merged
PedroTadim merged 8 commits into
ClickHouse:masterfrom
groeneai:fix-03008-dedup-debug-on-fail-opt-in
Aug 7, 2026
Merged

PedroTadim merged 8 commits into
ClickHouse:masterfrom
groeneai:fix-03008-dedup-debug-on-fail-opt-in

Conversation

@groeneai

@groeneai groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Related: #111965
Related: #90094

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

The six 03008_deduplication_* drivers pass --debug-on-fail True, and the generator builds
its 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 are
still 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 long tests
that occasionally hit the 600s per-test timeout.

This makes the diagnostics run only when a case has actually failed. Each throwIf now carries a
phase-identifying message, a new generator flag --emit-debug-only {first,second} prints just
that 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-fail is kept,
defaulting off, as a manual entry point.

Measured on insert_several_blocks_nonreplicated: statements reaching the server drop from 3905
to 2113. Across four drivers: 446.1s to 336.8s, a 1.32x speedup. No existing .reference
file changes.

A new test, 03008_deduplication_diagnostics_opt_in.sh, pins these properties on both sides
of 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.sh gains no-flaky-check, matching its six siblings:
editing the shared .python file pulls all 8 03008_* tests that read it into the flaky
check, and this one runs close to the 180s limit there. long would be the wrong tag: it
also means --no-long and 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 False
exactly (32/40/31 per subcommand), and each script is statement-equivalent to master after
whitespace normalization and modulo the added throwIf message, with exactly 4 markers per
script.

End-to-end, system.query_log QueryStart rows for a real driver run:

arm queries wall
master 3905 26.30s
this PR 2113 16.78s

Runtime A/B, arms alternated, set-equality asserted per rep:

test master (s) this PR (s) ratio
insert_several_blocks_nonreplicated 25.9/25.8/25.3 17.0/17.0/16.5 1.53
insert_several_blocks_replicated 46.1/45.1/46.6 39.5/38.6/39.8 1.17
several_mv_into_one_table_nonreplicated 27.1/27.3/27.1 17.5/16.8/17.3 1.58
several_mv_into_one_table_replicated 51.2/49.5/49.1 39.6/35.8/41.4 1.28

Failure path: over all 384 shapes, emit(first) + emit(second) reproduces every statement
--debug-on-fail True adds over the default, with nothing missing; the only additions are the
shared SET lines the diagnostics themselves report on. No DROP/CREATE/INSERT and no assertion
appears 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_replicated
and diagnostics_opt_in, 50/50 OK. Both arms were swept over every 03008_deduplication* test at
the 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.

groeneai and others added 8 commits July 31, 2026 19:07
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]>
@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

Eight rounds of an internal review pipeline. Each round is an independent cold code review of
the resulting tree plus a second-model review of the diff, adjudicated against the recorded
measurements. Counts below are derived from the per-round ledgers, not summarized by hand:
17 second-model findings + 21 own-review findings, 32 adjudicated: 22 accepted and fixed, 5
declined with evidence, 5 dropped.
Round 8 is the first clean round: the second-model review
returned zero findings and my own cold review found no defect.

Most of the substantive findings were defects in an earlier round's own prescribed test
assertions
rather than in the shipped behaviour change. The mechanism is worth stating because
it is the failure mode this test family invites: the diagnostics now run only on failure, so a
regression test that merely inspects the generator's text, or counts tokens on a shape whose two
phases share expected counts, stays green while the mechanism it claims to protect is broken.
Every finding was reproduced by mutation before being accepted, and every remedy was prototyped
and mutation-tested before being prescribed.

The last four rounds, in order:

finding verdict
❌ The regression test asserted properties every diagnostics-only script shares (non-empty DEBUG, no mutations, the right phase). Dropping the case arguments from a driver's re-run, or replaying a different subcommand, preserved all of them, so a driver could report diagnostics for the wrong shape unnoticed. Fixed: the replay now compares the re-run's whole normalized payload against the generator's output for the subcommand derived from the driver's own main invocation, with a replay argument shape deliberately chosen to differ from the generator's defaults so a dropped argument list cannot produce an identical payload.
❌ The captured assertion error was forwarded only after the diagnostics re-run. If the per-test deadline expired during that re-run, the harness kills the process group, the driver's EXIT trap deletes the capture file, and the reader got a timeout naming neither the failing case nor the phase. Measured: 0/10 interrupted runs forwarded the error. Fixed: the forwarding moved to immediately after the phase is parsed, before the re-run. 10/10 interrupted runs now forward it. Covered by one new deterministic row per driver and phase, driven by a stub that signals when the re-run has started so the signal always lands inside it.
⚠️ Only the second phase was exercised in the driver-dispatch rows, so narrowing a driver's parser to accept one phase left the other phase's failures shipping with no diagnostics at all. Fixed: both phases are driven for all six drivers.
💡 The .reference dump contains em-dashes. Declined: they are a verbatim dump of a pre-existing generator comment that this PR does not touch. Normalizing them would mean editing an untouched line and desynchronizing the dump from the generator it pins.
💡 --debug-on-fail is now unused by any driver. Declined: it is retained deliberately, defaulting off, as the manual entry point for reproducing a failure by hand. Stated in the description.

Earlier rounds fixed a tag that would have removed 03008_deduplication_random_settings.sh
from Fast test and LLVM coverage entirely, corrected the phase-token spelling the drivers
actually parse, replaced a 5-of-10-probe count with the whole payload, pinned the guard
constants, the tables read and the exact setting values, added clickhouse format validation of
the emitted SQL (coverage that master got for free by running the probes on the success path),
removed an unjustified no-fasttest tag, and restated a byte-equality claim as statement
equivalence.

33 distinct mutations were used across the eight rounds; each reddens exactly its predicted
rows, with the generator and drivers checksum-verified as restored after every one, and all
earlier mutations were re-run in the final round.

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the cost this PR removes, which is what it targets: the success path executes 28 to 32 guarded probes per case, depending on the subcommand. Measured directly on insert_several_blocks_nonreplicated by counting system.query_log QueryStart rows for a real driver run: 3905 statements on master vs 2113 with this PR (delta 1792 = 28 probes x 64 cases). The 600s timeout itself needs roughly a 1.5x host slowdown (p99 403.3s) and is deliberately not chased; the statement-count and runtime oracles are the honest measurement.
b Root cause explained? The guards are WITH (SELECT count() FROM t) AS c ... WHERE c != <expected>, so they suppress output, not execution. The generator builds them into the same multi-statement script as the assertions, so every probe is parsed, analyzed, planned and round-tripped even when the case passes: +28 statements per case for insert_several_blocks_into_table and +32 for the other two subcommands, so +1792 to +2048 per 64-case run, on six long tests.
c Fix matches root cause? Yes. The probes and their guards are byte-identical; only when they are sent changes. No timeout raised, no assertion widened, no dataset reduced, no tag used to hide slowness.
d Test intent preserved / new tests added? Preserved. Every throwIf predicate is unchanged: over 384 generated shapes each script is statement-equivalent to master after whitespace normalization and modulo the added message, with exactly 4 markers per script (2 tables x 2 phases), so no assertion was missed. All 11 pre-existing 03008_deduplication*.reference files are unchanged. One new test is added, 03008_deduplication_diagnostics_opt_in.sh, so that CI observes the mechanism rather than only this PR's own session artifacts. It pins, in the exact spelling the drivers parse, that the success path emits no diagnostics at all; that every assertion names its phase, counted per phase so an always-first generator fails; that the diagnostics-only script carries the whole diagnostics block, applies the failing run's settings as distinct name and value pairs, and contains nothing that could mutate the state it inspects; and that every driver can parse the marker the generator emits, takes its main invocation without diagnostics, and re-runs them for the failed phase. It also pins the diagnostic payload completely rather than a chosen list of observables: on a second argument shape whose two phases have different expected counts, it dumps every statement of the emitted script, normalized, one row per statement, so the guard constants, the read tables, the projection lists, the carried-over SET values, the WHERE filters, the IN lists and the ORDER BY clauses are all pinned literally and a regression names the exact statements that moved. That dump is closed by construction under the "which clause did nobody think to enumerate" class that an observable-by-observable oracle is not. It additionally checks that each emitted script is parseable SQL with clickhouse format (coverage master had incidentally because the probes used to run on the success path), which fails with a clearer signal than a multi-line diff. Finally, it drives each of the six drivers' own failure-handling block, extracted verbatim from the driver source, against a stub client that fails the first invocation the way the server does, for both phases so a driver that dispatched only one of them would be caught, making the guard, the diagnostics re-run and the stderr forwarding executed rather than merely present. That replay compares the re-run's whole payload against what the generator produces for that driver's own subcommand and the replay's own arguments, rather than asserting properties of it: properties like "it contains DEBUG", "it names this phase" or "it mutates nothing" hold for every diagnostics-only script, so dropping the case arguments from a driver's re-run, or replaying a different subcommand, left every such row byte-identical while being a real defect. The subcommand is derived from the driver's main invocation, not from its re-run 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 broke the derivation fails loudly instead of silently comparing against an empty subcommand. The replay's argument shape deliberately differs from the generator's argparse defaults, because with the defaults a re-run that dropped the case arguments produced a byte-identical payload; the shape it uses instead moves SET max_insert_threads from 1 to 10 and every destination guard constant. It starts no server; over 50 randomized runs its per-run time is a median of 5.7s (max 6.2s), against the 180s per-run limit the flaky check enforces.
e Both directions demonstrated? Yes. Forward: 3905 -> 2113 statements, 446.1s -> 336.7s across 4 drivers x 3 reps with arms alternated (1.32x). Backward: 4 mutations, each reddening its predicted oracle - revert the driver (statement count returns to 3905, delta 0), revert the generator (diagnostics unreachable), drop the emit-only SET block (settings probe reports defaults; reddens that oracle alone), hard-code the phase to first (only the phase-2 half of the diagnostics oracle fails). The new test was mutation-tested the same way, one mutation at a time with the generator's and the drivers' md5 asserted restored after each and a clean re-run verified after every restore: 32 mutations, 32 for 32 reddening exactly their predicted rows. Putting the debug block back into the main script reddens only the success-path rows; dropping the phase-naming message, renaming phase= to stage=, or labelling every assertion first reddens the per-phase marker rows and every driver's parse row; making both probe helpers return nothing drops the total diagnostics count from 10 or 11 to 6 while the narrower per-phase count stays at 5, which is what proves the total is the load-bearing assertion; a wrong max_insert_threads constant, or removing the settings block from the diagnostics-only script, reddens the settings rows alone; and on the driver side, re-adding --debug-on-fail True, corrupting one driver's extraction token, or deleting its diagnostics re-run each reddens that driver's rows. Ten further mutations cover the payload and the failure branch: corrupting one phase's expected count, pointing a probe at a table that does not exist, dropping the max_insert_threads line, pointing the settings probe at a missing system table, and breaking a probe's SQL each redden their own rows, and all five were measured to be invisible to the earlier form of the test; inverting the [ -n "$FAILED_PHASE" ] guard, deleting the re-run block, corrupting the extraction token in all six drivers, replacing the failure-path stderr forward with true, and adding a DROP to the diagnostics template likewise each redden their own rows, where the earlier form stayed byte-identically green for all five. A further pair covers the diagnostic payload and the exact setting value: thinning a probe's projection list, or replacing one of its columns with an unresolvable identifier, each redden the payload rows, and making either argument shape report a max_insert_threads value the failing run never used reddens that shape's rows - all three were measured to be invisible to the earlier form, because token counts and clickhouse format see neither which columns a probe selects nor a value that merely starts with the expected digits. The final round closes the last two gaps and each half was proven to be a real gap first: narrowing one driver's phase parser to a single phase was invisible to the earlier form (all 123 rows byte-identical) although it made that driver skip the diagnostics re-run entirely for the other phase's failures, and it now reddens 5 rows, with the mirror-image narrowing reddening the mirror 5; corrupting a probe's ORDER BY, redirecting its system.parts IN list to a non-existent table, and - worst - replacing the probe guard with 1 = 1 so the probes fire unconditionally, re-creating the very success-path cost this PR removes, were each invisible too, and each now reddens 6, 6 and 16 statement rows respectively. A final group closes the last gap in the driver replay, and each half was again proven to be a real gap first: deleting "${CASE_ARGS[@]}" from a driver's diagnostics re-run, and swapping that re-run's subcommand, were both invisible to the earlier form (all six rows per driver and phase byte-identical) although each makes the diagnostics report on the wrong shape or the wrong tables, and each now reads 0 for both phases; hard-coding the re-run's phase reads 0 for the second phase alone; and breaking the subcommand derivation empties its own row rather than silently passing. One last axis is the failure signal path rather than the rerun's content: the captured assertion error was forwarded only after the diagnostics rerun returned, so an interrupt inside that window (the per-test deadline expiring) let the driver's EXIT trap delete the temp file before the forward, losing the line that names the failing case and phase - strictly less than the pre-PR behaviour, where the client wrote to the real stderr directly. Forwarding it before the rerun fixes that, and the new row drives each driver's failure block under a deterministic interrupt (the stub announces the rerun has started and waits, so the signal always lands inside it): it reads 0 forwarded markers on the previous shape and 1 on this one, measured 10/10 on both arms. The uninterrupted path is byte-identical between the two shapes - same FAIL, same 83 stderr bytes, exactly one marker copy, same 2 invocations, same rerun payload md5 c0fe468d4a68. All 32 mutations from the earlier rounds were re-run against the final form and every one still reddens, so nothing was traded away - 33 distinct mutations over the PR.
f Fix is general across code paths? Yes. All three subcommands and both phases carry the change, and all six flag-carrying drivers are changed together (git grep -ln "debug-on-fail" returns exactly that set on master and 0 hits here). Driver uniformity was asserted mechanically rather than by eye: each of the six has stderr forwarded on both branches, one mktemp, one trap, one redirect, one emit call, and zero remaining --debug-on-fail. The new test exercises all three subcommands across both phases on two argument shapes (189 generator rows) and all six drivers on both phases (84 further rows), reusing each driver's own extraction program and its own failure-handling block taken from that driver's source, so a regression on either side of the generator and driver coupling, and on either phase of the dispatch, reddens it by construction.
g Fix generalizes across inputs? Yes. 384 shapes = 3 subcommands x {InsertSelect, InsertValues} x {MergeTree, ReplicatedMergeTree} x 5 booleans, replicated and non-replicated alike, including the mv_list branch that exists only for the several-mv shapes. Over all 384, emit(first) + emit(second) reproduces exactly the multiset of statements --debug-on-fail True adds over the default, and no emitted script contains DROP/CREATE/INSERT/SYSTEM or an assertion. The new test additionally pins the four probed settings as complete, semicolon-terminated assignments per argument shape, so neither dropping the settings block nor changing a value to one the failing run never used can pass unnoticed - including a value that shares a prefix with the expected one, and including a setting mutated on only one of the two shapes. It also dumps every statement of the emitted script for that shape, so the projection lists, filters and orderings - the parts of the payload that neither a token count nor a parse check can see - are pinned literally rather than through a list of chosen observables.
h Backward compatible? Yes; tests only, no settings, no SettingsChangesHistory.cpp, no serialization, no src/ change. --debug-on-fail is kept with its existing default (False), so any out-of-tree caller keeps working; --emit-debug-only is purely additive.
i Invariants and contracts preserved? Yes, on all paths. Success path: stderr is still forwarded to real stderr, so the harness's having stderror rule sees exactly what it saw before; the temp file is always removed via trap ... EXIT. Failure path with no marker (for example Code: 60) runs no diagnostics, still forwards stderr verbatim and still echoes FAIL (verified). The diagnostics-only re-run relies on the client stopping at the first error (src/Client/ClientBase.cpp:3497; the drivers do not pass --ignore-error), verified end-to-end: after an induced failure the tables still exist and the re-run prints the expected block for the phase that failed, including on a case shape whose two phases have identical expected counts. Leaked tables are safe because every generated script begins with DROP TABLE IF EXISTS for all of its tables.

Session id: cron:clickhouse-review-slot-50:20260801-140200

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @yariks5s, could you review this? It keeps the --debug-on-fail diagnostics you added in #90094 but stops executing them on the success path: their WHERE c_dst != <expected> guards suppress output, not execution, so the probes were costing 28 to 32 statements per case, and they are now replayed only for the phase that actually failed.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [960fae3]

Summary: ✅


AI Review

Summary

This PR moves the 03008_deduplication diagnostics off the success path and replays them only after a failing case, while adding an opt-in regression test around the generator/driver coupling. I did not find a correctness, coverage, or rollout issue worth blocking on: the new failure-path rerun is wired consistently across all six drivers, the changelog metadata matches a CI Fix or Improvement, Praktika is all-green, and a local exhaustive check over all 384 argument shapes confirmed that --emit-debug-only reproduces exactly the diagnostics statements previously injected by --debug-on-fail.

Final Verdict

✅ No blocking issues found.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 1, 2026
@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 960fae3

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
(none) 174 check-runs, 0 failures nothing to own

Config Workflow and Finish Workflow both completed successfully; no check queued or in progress.

Session id: cron:our-pr-ci-monitor:20260803-180000

@PedroTadim PedroTadim self-assigned this Aug 7, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 7, 2026
Merged via the queue into ClickHouse:master with commit a5cbd58 Aug 7, 2026
179 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 7, 2026
alexey-milovidov added a commit that referenced this pull request Aug 9, 2026
…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]>
pull Bot pushed a commit to AnotherGenZ/ClickHouse that referenced this pull request Aug 9, 2026
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]>
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-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