Skip to content

Fix two stateless tests a Replicated database refuses to run - #113187

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-112052-dbreplicated-stateless-carriers
Aug 5, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-112052-dbreplicated-stateless-carriers

Conversation

@groeneai

@groeneai groeneai commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #112052

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

Two of the nine failures @alexey-milovidov asked me to investigate on #112052, in the
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, WasmEdge, parallel, 1/3)
job. Both fail on every run of that flavour, and look flaky only because the diagnostics rerun drops
--replicated-database and llvm-coverage force-sets OK. Six of the nine are already fixed (#112862,
#112993); 04511 is a distributed-DDL timeout tracked elsewhere. Tests only.

1. 03990_alter_rename_column_swap_different_types, Code: 392 QUERY_IS_PROHIBITED. One assertion
issues RENAME COLUMN ..., RENAME COLUMN ..., UPDATE ... WHERE 1 as a single ALTER, which
InterpreterAlterQuery refuses on a DatabaseReplicated because it spans two command kinds. That form
is the assertion: the UPDATE forces the part rewrite exercising getColumnsForNewDataPart while the
renamed-from column holds no data, so splitting it loses the #103247 coverage. Tagged
no-replicated-database, as merged for 04278 in #112862, which costs Replicated, Cloud and
shared-catalog coverage. The file's twelve other ALTERs are single-kind and unaffected.

2. 04510_s3_explicit_url_named_secret_mask, result differs by 14 lines. Its closing oracle is a
byte-exact system.query_log transcript scoped only by current_database, and the DDL replay worker
logs each DDL a second time. Every secret is still [HIDDEN] there: masking is intact, the oracle
over-specifies. A skip tag would lose coverage of 47 tagged secrets, so I scoped the transcript with
AND query_id = initial_query_id: a replay row gets a fresh query_id but inherits the initiator's.
That path masks a rewritten AST independently instead of copying the initiator's masked text, so the
filter alone would leave a regression there undetected. So I also assert over every row, replay
included, that no tagged secret appears, guarded by count() > 0 against a vacuous pass.

Both reproduce deterministically with --replicated-database, pass after the fix, still pass without
it, and survive 50 randomized runs per flavour. The new assertion is armed both ways.

Version info

  • Merged into: 26.8.1.814 (included in 26.8 and later)

Both fail on every run of the
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, WasmEdge, parallel, 1/3)
job. They read as flaky only because the llvm-coverage diagnostics rerun drops
--replicated-database, so the failure reruns green, is labelled flaky, and is
force-set to OK in the CI database. Requested by alexey-milovidov on ClickHouse#112052.

03990_alter_rename_column_swap_different_types

One assertion issues RENAME COLUMN ..., RENAME COLUMN ..., UPDATE ... WHERE 1 as
a single ALTER. InterpreterAlterQuery groups an ALTER's commands into segments by
kind, and validateReplicatedDatabaseSegments rejects any multi-segment ALTER on a
DatabaseReplicated, so the server refuses the statement with
Code: 392 QUERY_IS_PROHIBITED before any storage code runs.

The combined form is the assertion: the non-key UPDATE is what forces the part to
be rewritten by the mutation, so getColumnsForNewDataPart processes the part while
the renamed-from column holds no data. Splitting it into two ALTERs would make the
mutation observe a different part state and stop exercising the issue ClickHouse#103247 code
path, so the honest fix is the tag. This matches the disposition already merged for
the sibling test 04278 in ClickHouse#112862. The other twelve ALTERs in the file are
single-kind and execute normally on a Replicated database, verified individually.

The tag also suppresses Cloud and shared-catalog runs, which is a real coverage
cost, accepted because the statement is unsupported there.

04510_s3_explicit_url_named_secret_mask

The closing oracle compares a byte-exact system.query_log transcript scoped only by
current_database. On a Replicated database the DDL replay worker logs each DDL a
second time, so the transcript gains 7 replayed entries and 7 rewritten CREATE
statements with a materialized UUID: 14 extra lines.

Every secret is still [HIDDEN] in those extra rows, so masking is intact and this
is not a security failure; the oracle simply over-specifies which rows exist. A
skip tag would delete real coverage of 47 tagged secrets across roughly 60
carriers, so the oracle is scoped to the initiating query instead.

DDLTaskBase::makeQueryContext calls setCurrentQueryId(""), giving the replay
context a fresh random query_id, and DDLWorker then calls
setInitialQueryId(task.entry.initial_query_id), inheriting the initiator's id. For
a directly issued query Context::setCurrentQueryId sets initial_query_id equal to
current_query_id. So query_id = initial_query_id selects exactly the statements the
test issued, on both Atomic and Replicated databases, and the reference needs no
change. Filtering on the text of the ddl_entry comment was rejected as a fragile
match on the very column under assertion; is_replicated_database_internal is
semantically exact but is not exposed in query_log.

Validation: both reproduce deterministically with --replicated-database and pass
after the fix, both still pass without it, and each survives 50 randomized runs per
flavour. The 04510 filter was checked for vacuity in both directions: injecting a
statement that logs a plaintext secret as an initiating row still makes the filtered
oracle fail, and on a non-Replicated database the added clause changes nothing.
The previous commit scoped the closing query_log transcript to query_id =
initial_query_id, so it no longer contains the rows the DDL replay worker writes
on a Replicated database. That filter is correct: the replay rows are what made
the byte-exact transcript diverge on that flavour. But it also removed the only
coverage of the replay logging path, and the replay row is not a copy of the
initiator's already-masked text.

DDLTaskBase::formatRewrittenQuery sets query_str from formatWithSecretsOneLine,
so it carries secrets in plaintext. DDLWorker::tryExecuteQuery then hands that
string to executeQuery, which masks it again, over the DDL-rewritten AST rather
than the AST the initiator masked. A regression confined to that path would leak
plaintext into query_log while every remaining assertion in the file passed.

Add one assertion over every row the test produces, replay rows included, that
no tagged secret appears. count() > 0 is in-band anti-vacuity: an "assert no
secret appears" oracle otherwise passes silently when its scoping predicate
matches nothing. Both columns are flavour-independent, so one shared reference
line serves Atomic and Replicated and the test still needs no tag.

Measured under --replicated-database: 96 rows unfiltered against 82 filtered, a
delta equal to the 14 replay rows, so the assertion does cover the path. It was
proven armed two ways: injecting a statement that logs a plaintext secret flips
its result from "1 0" to "1 1", and pointing its predicate at a non-existent
database flips it to "0 0". 50 randomized runs pass on each flavour.
@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds, 3 findings adjudicated)

Every change here was reviewed by a second model that did not write it, then adjudicated against the
recorded evidence. Round 1 found a real gap and sent the change back for a fix.

❌ Blocking, fixed before this PR was opened

04510: scoping the transcript to the initiator silently dropped the replay path's masking coverage.
Round 1 flagged that AND query_id = initial_query_id removes every DDL replay row, and I agreed after
tracing it: DDLTaskBase::formatRewrittenQuery re-serializes the AST with secrets present, and
DDLWorker::tryExecuteQuery hands that string to executeQuery, which masks it again over the
DDL-rewritten AST. The replay row is an independent masking application, not a copy of the initiator's
masked text, so a regression confined there would have leaked plaintext into query_log while every
remaining assertion in the file still passed. The filter is correct and stays; what was missing was
replacement coverage. Fixed by asserting over every row the test produces, replay rows included, that no
tagged secret appears, with count() > 0 as an in-band guard so an empty row set cannot pass vacuously.

Proven to actually cover that path rather than being assumed: under --replicated-database the
unfiltered row set is 96 against 82 filtered, a delta equal to the 14 replay rows. Proven armed two ways:
a statement logging a plaintext secret flips its result, and an unmatchable predicate flips the guard.

💡 Noted, not blocking

The all-row assertion is not usable under clickhouse-test --database=<fixed>, because its own query
text contains the marker token and a fixed database retains the previous run's rows. Not new: the
pre-existing byte-exact transcript was already scoped only by current_database over a five-minute
window with no per-run discriminator, so this file was already incompatible with a shared database
regardless of this change. In the default mode a fresh database is created per test invocation, including
each diagnostics rerun, so neither assertion can observe an earlier run. Happy to split the literal if
you would rather have it robust in that mode too.

Coverage residual: count() > 0 proves the row set is non-empty, not that replay rows are in it, so
if the replay worker ever stopped logging the assertion would silently narrow to initiator coverage. An
in-band guard is not expressible here because any replay-row count is flavour-dependent (0 on Atomic, 14
on Replicated) and both flavours share one reference file, so this was verified out of band instead.

Verified clean

The refusing clause for 03990 is validateReplicatedDatabaseSegments's segments.size() != 1,
identified by message text: the reported error lacks the (replicated and non replicated) parenthetical
the adjacent clause adds. That second clause cannot fire for this file either, since it tests only
settings- and comment-ALTERs, so the tag hides no other refusal. Of the 13 ALTERs in the file exactly one
spans two command kinds. Repo-wide only two stateless tests issue a mixed-kind single ALTER, and the other
already carries the tag. Both tests reproduce deterministically before the fix and survive 50 randomized
runs per flavour after it.

Session id: cron:clickhouse-review-slot-9:20260803-193500

@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, both. tests/clickhouse-test --replicated-database 03990_alter_rename_column_swap_different_types fails Code: 392; the same for 04510_s3_explicit_url_named_secret_mask fails result differs with 14 extra lines. Every run, not intermittent. The 03990 refusal also reproduces as a single hand-issued ALTER. CIDB agrees: 106/106 and 105/105 rows in a 12 hour window on that job flavour.
b Root cause explained? Yes. 03990: InterpreterAlterQuery groups an ALTER's commands into segments by kind and validateReplicatedDatabaseSegments rejects any multi-segment ALTER on a DatabaseReplicated; the test's RENAME, RENAME, UPDATE is 2 segments, so the server refuses it before storage code runs. 04510: the closing oracle is a byte-exact system.query_log transcript scoped only by current_database, and a Replicated database logs each DDL a second time from the replay worker, so 7 ddl_entry rows plus 7 rewritten CREATE ... UUID rows appear.
c Fix matches root cause? Yes. 03990: the refused statement IS the assertion, so the file is tagged no-replicated-database with the refusing clause named in the file. 04510: the oracle's scoping predicate was wrong, so the predicate is corrected with AND query_id = initial_query_id, and a second assertion checks the masking property over every row the test produces, replay rows included, so narrowing the transcript costs no coverage. No widened bound, no no-random-* silencer, no dataset reduction, no defensive check masking an upstream bug.
d Test intent preserved / new tests added? Strengthened. 03990 keeps every assertion and still runs everywhere except Replicated, Cloud and shared-catalog. 04510 keeps all 47 tagged secrets and roughly 60 carriers asserted on every flavour including Replicated, and additionally asserts that no secret appears in any logged row including those written by the DDL replay worker, which re-masks a rewritten AST independently of the initiator. On the Replicated flavour the file now asserts strictly more than it ever did on master.
e Both directions demonstrated? Yes. Before: 03990 no flag OK, with flag FAIL Code: 392; 04510 no flag OK, with flag FAIL. After: 03990 no flag OK, with flag SKIPPED; 04510 OK on both. The 04510 reference gains exactly one line for the new assertion, 220 to 221; 03990's reference is unchanged. The new assertion was proven armed by two mutations: injecting a statement that logs a plaintext secret flips its result from 1 0 to 1 1, and pointing its predicate at a non-existent database flips it to 0 0, so an empty row set cannot pass vacuously.
f Fix is general across code paths? Yes. 03990: all 13 ALTERs in the file were executed individually against a Replicated database; only lines 89-90 are multi-segment, and the tag covers the file. Siblings refused by the same clause are already tagged (04278 in #112862, 04296, 04541). 04510: all 6 extra-row carrier classes were checked. Replay DDL and the rewritten CREATE are dropped; the non-DDL statements (the s3() probes, EXPLAIN QUERY TREE, BACKUP, the failing CREATE DATABASEs) survive, proven by the unchanged 220 line output. SYSTEM FLUSH and harness SETs were already excluded, and the unfiltered assertion covers the dropped rows: measured 96 rows unfiltered against 82 filtered under --replicated-database, and 82 against 82 without it.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for type wrappers: no src/ change and no type handling. The settings matrix dimension is covered by 50 randomized runs per arm, and 03990 additionally asserts both the wide and the compact part layout.
h Backward compatible? Yes, trivially. Test-only change: no setting default, no serialization format, no SettingsChangesHistory.cpp obligation.
i Invariants and contracts preserved? Yes. 04510 only changes diagnostic SELECTs inside a test and cannot affect server behaviour. Its invariant, that the oracle sees exactly the statements the test issued and that no secret appears in any logged row, now holds on both flavours where it previously held on only one, and the second assertion is flavour-independent by construction (it returns two counts rather than a transcript), which is why one shared reference line serves both. On a non-Replicated database the added filter clause changes nothing. 03990 changes only a tag line.

Session id: cron:clickhouse-impl-slot-45:20260803-173400

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

cc @tuanpach, could you review this? Two stateless tests fail on every run of the DBReplicated coverage flavour: one issues a mixed-kind single ALTER that InterpreterAlterQuery refuses on a Replicated database, and the other has a byte-exact query_log oracle that the DDL replay worker's second log entry breaks, so I scoped the oracle to the initiating query and added an assertion covering the replay rows rather than skipping the test.

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

clickhouse-gh Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c85dda3]

Summary: ✅


AI Review

Summary

This PR fixes two deterministic DatabaseReplicated stateless-test failures by tagging the one mixed-kind ALTER test case that Replicated databases reject up front, and by narrowing the 04510 query_log transcript to initiator rows while adding a separate no-plaintext-secrets assertion over the logged rows. I reviewed the current diff, the changed tests in full, the relevant InterpreterAlterQuery and DDL/query-id code paths, the prior PR discussion, and the current CI state. I did not find a new actionable issue in the current version.

Final Verdict

✅ No findings.

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

groeneai commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - c85dda3

Every failure below has an owner: a fixing PR (mine 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
Build (arm_release) / Post Hooks CI harness, not a test result: build_profile_hook.py fails uploading build telemetry (LogCluster query failed with code 500 on the INSERT INTO build_time_trace). Job-level check_status = success, so the build itself is green. Breadth over 7 d: 887 rows / 301 PRs / 502 master rows a fix task is moved to pending (investigating at full effort - fixing-PR link to follow here)

No check is queued or in progress, Finish Workflow and Config Workflow are both green, and no
check-run reports a failure conclusion. The one CIDB failure row is the harness row above; this diff
is three stateless test files, so it cannot reach a build-telemetry upload.

Session id: cron:our-pr-ci-monitor:20260804-033000

@PedroTadim PedroTadim self-assigned this Aug 5, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 5, 2026
Merged via the queue into ClickHouse:master with commit e33f785 Aug 5, 2026
181 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 5, 2026
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