Skip to content

Pin five stateless tests a Replicated database cannot enforce - #112993

Merged
PedroTadim merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-replicated-db-result-differs-coverage
Aug 2, 2026
Merged

PedroTadim merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-replicated-db-result-differs-coverage

Conversation

@groeneai

@groeneai groeneai commented Aug 2, 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

Five stateless tests diverge on the DBReplicated coverage flavours, then get force-set to OK by
the llvm-coverage whitewash, so they catch nothing. Over 21 days the divergence (result differs,
or having stderror for 04318) hits 100% of the four access tests' runs and 96.4% of 02440's
(6449 of 6687); 26686 rows carry the whitewash (Failed 0 out of 3 reruns).

Two causes, verified locally:

  • Four access tests (04318_remote_storage_engine_access,
    04401_remote_storage_engine_restore_access, 04401_url_engine_s3_dispatch,
    04489_remote_storage_engine_restore_tf_access) assert deny paths implemented inside
    storage construction (StorageDistributed.cpp, StorageURL.cpp). On a Replicated database
    tryEnqueueReplicatedDDL enqueues the statement and a userless worker runs it, so
    full_access no-ops those checks and the deny path silently allows: open issue Flaky test 04541_create_as_select_table_scoped_insert_grant: denied CREATE TABLE ... AS SELECT intermittently succeeds without ACCESS_DENIED (DatabaseReplicated) #111561.
  • 02440_mutations_finalization pauses merge selection with the process-local
    SYSTEM ENABLE FAILPOINT, but the test cluster gives this shard a second replica of the same
    table, whose unpaused merge-selecting task assigns the mutation that must stay pending.
    A harness assumption, not a defect.

Each pin gets a no-replicated-database tag and a comment naming its mechanism; the access pins
also name #111561, so git grep 111561 tests/ finds every pin when it resolves. No assertion is
weakened or deleted.

04401_url_engine_s3_dispatch is pinned per subcase, not per file: only its two CREATE-time
engine-grant denials are invalidated, so a file-level tag would also have dropped five live
assertions, including the only stateless coverage of S3 source-grant dispatch. Those two subcases
move to 04401_url_engine_s3_dispatch_engine_grant, which carries the pin; the rest of the file
now runs in every flavour.

The tag reaches three configurations (replicated-database, cloud, shared-catalog), all subject to
the same gap. Over 50 randomized runs: 250/250 green on the default flavour, 250/250 skipped on
the affected one.

I am not fixing the engine here: #111561 is parked on an owner-level decision, with a write-up and
three options there. Same instrument as merged #112862.

Per-test validation (before / after, both directions)

Reproduced with tests/clickhouse-test --replicated-database --no-stateful <test> on a 3-host,
2-shard cluster matching tests/config/config.d/database_replicated.xml.

test with --replicated-database, before after default flavour, after
04318_remote_storage_engine_access FAIL, TABLE_ALREADY_EXISTS on the 3rd create (first two not rejected) SKIP OK
04401_remote_storage_engine_restore_access FAIL, deny count 1 -> 0 and table-absent 0 -> 1 SKIP OK
04401_url_engine_s3_dispatch FAIL, s3-engine-denied / azure-engine-denied -> NOT DENIED, s3-source-required still passed OK (engine subcases moved out) OK
04401_url_engine_s3_dispatch_engine_grant (new) FAIL, same two lines, pin removed SKIP OK
04489_remote_storage_engine_restore_tf_access FAIL, same inversion as 04401 SKIP OK
02440_mutations_finalization FAIL, ['all_0_0_0'] 0 -> [] 1 (pause had no effect) SKIP OK

Mechanism corroborated in the server log: the RESTORE arrives as user: user_04401_..., but the
CREATE TABLE ... ENGINE = Remote(...) it produces runs as
(from 0.0.0.0:0, user: , ...) /* ddl_entry=query-0000000007 */ and succeeds, where the test
requires it to be rejected.

04541_create_as_select_table_scoped_insert_grant and
04418_create_table_as_select_subquery_access are left failing on purpose, as the live evidence
for #111561, and are not touched here.

Why 04401_url_engine_s3_dispatch splits: its url('s3://...') source-grant check is a plain
SELECT analyzed on the initiator, which has a user, and its engine-name, reload-safety and
TRUNCATE-rejection checks never touch access control, so only the two CREATE-time engine denials
are invalidated. The http allow case moves with them because it stops a denial from passing
merely because the user holds no engine grant at all.

Version info

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

These five tests fail deterministically (Failed 3 of 3 reruns) on the
DBReplicated flavours and are then force-set to OK by the llvm-coverage
whitewash, so today they assert a deny path that silently allows and catch
nothing at all on those configurations.

Two distinct causes.

Four access tests (04318_remote_storage_engine_access,
04401_remote_storage_engine_restore_access, 04401_url_engine_s3_dispatch,
04489_remote_storage_engine_restore_tf_access) assert checks implemented
inside storage construction (StorageDistributed.cpp, StorageURL.cpp). On a
Replicated database InterpreterCreateQuery returns tryEnqueueReplicatedDDL,
which performs no checkAccess, and the entry is executed by a worker whose
context has no user: DDLTask::makeQueryContext only calls setUser when
distributed_ddl_use_initial_user_and_roles is enabled and initiator_user is
set, and only the ON CLUSTER path populates initiator_user. Context::getAccess
then computes full_access = !user_id, so those in-storage checks short-circuit
to allow. Observed in the server log: the RESTORE arrives as the restricted
user, but the CREATE TABLE ... ENGINE = Remote(...) it produces executes as
(from 0.0.0.0:0, user: , initial_query_id: ...) and succeeds where the test
requires rejection. The signature that this is one cause and not three: in
04401_url_engine_s3_dispatch the table-function source check still passes,
because a table function is analyzed on the initiator, while both engine
checks flip to NOT DENIED. This is open issue ClickHouse#111561, so each of these four
comments names it and git grep 111561 tests/ finds every pin when it is
resolved.

02440_mutations_finalization pauses the merge-selecting task with a failpoint,
but SYSTEM ENABLE FAILPOINT is a process-local call and the helper macro
appends auto_{shard}, so the table is created once per shard and the untouched
shard's scheduler finishes the mutation the test expects to stay pending. That
is a harness assumption rather than a defect, so its comment cites no issue.

No assertion is weakened, inverted or removed and no reference file changes.
The tag reaches three configurations (replicated-database, cloud,
shared-catalog), all of which are replicated or shared-catalog database
environments subject to the same gap. Coverage is retained everywhere else:
250/250 green over 50 randomized runs on the default flavour, 250/250 skipped
on the affected one.

The engine fix is deliberately not attempted here. ClickHouse#111561 is parked on an
owner-level decision, since the authorization channel is either one host
(rights-dependent results then diverge per replica), or all hosts (which is
distributed_ddl_use_initial_user_and_roles, off by default), or refusing to
execute. A write-up with three options is already posted there.
04541_create_as_select_table_scoped_insert_grant and
04418_create_table_as_select_subquery_access are left failing on purpose as
that issue's live evidence and are untouched. Same instrument as ClickHouse#112862.
The `no-replicated-database` comment added for
`02440_mutations_finalization` in the previous commit named the wrong host.
It attributed the mutation to a scheduler on the cluster's other shard.
That host is the one that provably cannot affect this test, and the host that
can was left unnamed. The tag, the assertions and every reference file are
unchanged; this corrects prose only.

The real mechanism. `DatabaseReplicated` appends `auto_{shard}` to the
ZooKeeper path and `auto_{replica}` to the replica name, and the functional
test cluster in `tests/config/config.d/database_replicated.xml` has a doubled
first shard: three hosts on ports 9000, 19000 and 29000, where
`ci/jobs/scripts/clickhouse_proc.py` gives 19000 `--macros.replica r2` and
29000 `--macros.shard s2`, so the hosts are `s1/r1`, `s1/r2` and `s2/r1`.
The first two therefore land on one path, `.../mut/auto_s1`, under replica
names `1auto_r1` and `1auto_r2`: one table with two replicas, not two tables.

`ReplicatedMergeTree` is multi-leader, so the second replica is a leader too
and its `mergeSelectingTask` runs unpaused, because `SYSTEM ENABLE FAILPOINT`
is a direct process-local call in `InterpreterSystemQuery` with no
`ON CLUSTER` fan-out, and the client sends every query to one endpoint. That
task assigns the mutation on the initiator's own table, and the initiator's
own queue executor, which no failpoint touches, applies it. Both failpoint
sites sit inside `mergeSelectingTask`, not in queue execution.

The other shard cannot be the cause because the assertion cannot see it:
`StorageSystemMutations::fillData` iterates the local catalog only, so a
mutation on `.../mut/auto_s2` never appears in the `system.mutations` rows
this test selects, and `SELECT * FROM mut` likewise reads the local table.
The first commit's message, and the PR description drafted with it, said these
five tests fail deterministically on the DBReplicated flavours and cited a
reproducibility-check line reading three failures of three reruns, written in a
form the harness does not use. That citation was inherited from earlier triage
notes and never re-measured. It is wrong three ways, and no tracked file
changes here: the tags,
the assertions, every reference file and the mechanism prose corrected in the
previous commit all stay exactly as they are. This commit exists to put the
correction in the history that carries the false claim, since
`.claude/CLAUDE.md` forbids amending or rebasing a branch.

What was wrong. First, the harness never emits that string:
`tests/clickhouse-test` formats `Failed {fail_count} out of {max_reruns}
reruns.`, so someone grepping CI for the quoted text finds nothing, and the
consumer regex on the same file spells `out of` too. Second, the string covers
four carriers, never `02440_mutations_finalization`, whose 6446 rerun-carrying
rows all read `Failed 0 out of 3 reruns` and whose only honest failure in 21
days is one sequential run on an unrelated pull request. Third, for the four
access tests it appears exactly once each, all four on one commit: the run on
ClickHouse#112247 that forwards the job's flags to the diagnostics rerun. Every other row
reads `Failed 0 out of 3 reruns`, which is the whitewash this branch is about.
So the sentence read as a broad standing CI signal when the evidence is one
flags-forwarded run.

What is true instead, measured over the same 21 days on the DBReplicated
checks. The divergence is present in 100% of executed runs of the four access
tests, 4513, 4513, 6772 and 4513 rows, and in 96.4% of `02440`'s, 6447 of 6685.
On the flags-forwarding run the four access tests do report `Failed 3 out of 3
reruns`. Those numbers are stronger than the retracted claim, which is why this
is a citation fix and not a change of substance.
The previous commit retracted one false CI citation and installed a replacement
that overstates in a new way. The description drafted with it said the run
forwarding the job's flags to the diagnostics rerun is the only one that escapes
the coverage whitewash, and that every other row reports zero failures of three
reruns. Both halves are false. No tracked file changes here: this commit points
at the same tree as the previous one. The tags, the assertions, every reference
file and the two mechanism explanations all stay exactly as they are. It exists
to put the correction in the history that carries the overstatement, since
`.claude/CLAUDE.md` forbids amending or rebasing a branch.

What was wrong. Measured over the same 21 days on the DBReplicated checks,
filtering the five carriers on a failing status, there are 19 honest failure
rows across 7 commits and 5 pull requests: 108443, 109239, 109920, 112052 and
112247. The flags-forwarding run accounts for 4 of those rows and 1 of the 7
commits, so it is not the only escape. And the two-way split does not hold
either: only those 4 rows carry a reproducibility-check block at all, so the
remaining 15 report neither three-of-three nor zero-of-three, and the "every
other row" clause has no room for the majority of the escapes.

What is true instead, from one query so every figure is mutually consistent. The
whitewash is dominant but not total: 26686 rows report zero failures of three
reruns, while 19 surface honestly. The divergence, reported as a result
difference or, for `04318_remote_storage_engine_access`, as output on standard
error, covers 100% of executed runs of the four access tests, 4518, 4518, 6772
and 4518 rows, and 96.4% of `02440_mutations_finalization`'s, 6449 of 6687. The
honest failures are the same divergence rather than unrelated breakage:
`04318`'s carry `Code: 57` on `t_remote`, the third-create signature the local
reproduction produced, the other access tests differ from their reference, and
`02440`'s single row shows the predicted pending-mutation difference. The
attribution of the three-of-three reruns line to the flags-forwarding run is
retained, because that string does appear once per access test and only on that
commit. What is retracted is the claim of exclusivity.
@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 4 rounds; 1 finding raised,
plus 3 findings raised by my own cold review of the resulting code).

# Sev Finding Verdict Evidence / action
1 ⚠️ 02440's stated mechanism named the wrong host: the comment, body and commit message said the untouched shard finishes the mutation AGREE, fixed @ 0f5d660 The test cluster doubles the FIRST shard (ports 9000 + 19000 vs 29000), and DatabaseReplicated.cpp:1280 puts auto_{shard} on the ZooKeeper path but auto_{replica} on the replica name, so those two hosts are replicas of ONE table. mergeSelectingTask gates only on is_leader and RMT is multi-leader, so the second replica assigns the mutation. The other shard is invisible to the assertion: StorageSystemMutations::fillData reads the local catalog only. Reworded to name the second replica
2 ⚠️ The opening sentence cited Failed 3 of 3 reruns as a standing signal for all five tests AGREE, fixed @ d7ca540 Wrong on three axes, measured in CIDB: the harness emits Failed {n} out of {m} reruns (tests/clickhouse-test:2372), so the quoted form is not producible; 02440 never carries it; and the four access tests carry it once each, all on one flags-forwarded run. Replaced with measured divergence rates
3 ⚠️ The replacement citation then said only the flags-forwarding run escapes the whitewash, and that other rows read Failed 0 out of 3 reruns AGREE, fixed @ c4ae0c7 19 honest failures over 7 commits and 5 pull requests escape, not one; and 15 of those rows carry no rerun block at all, so the stated dichotomy has no room for most escapes. Rewritten to claim only that the flags-forwarding run adds the rerun line. Per-carrier reasons confirm the escapes share the local repro's signatures
4 ⚠️ Asked for before and after runtime evidence for all five tests in the affected mode and the default flavour DISAGREE The evidence predates the finding and lives outside the diff, so the reviewing model could not see it: 5 of 5 failing on the unmodified tests under --replicated-database, the same 5 passing without the flag, 5 of 5 skipped after the change, 5 of 5 still passing on the default flavour, and 250/250 plus 250/250 over 50 randomized runs. The cloud and shared-catalog arms are declined on measurement: those flavours have run these tests 0 times in 21 days, and both extra sites are plain control-flow returns in the harness

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

The final review pass found 0 findings, as did the final independent gate. Every figure in the
description was re-measured against the CI database immediately before publication.

Session id: cron:clickhouse-review-slot-49:20260802-110400

@groeneai

groeneai commented Aug 2, 2026 •

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. tests/clickhouse-test --replicated-database --no-stateful <test> against a 3-host / 2-shard cluster matching tests/config/config.d/database_replicated.xml: all 5 tests fail on every run locally, and 250/250 over 50 randomized runs. In CI over 21 days the divergence (result differs, or having stderror for 04318) is present in 100% of executed runs for the four access tests (4518, 4518, 6772, 4518 rows) and 96.4% for 02440 (6449 of 6687). The whitewash is the dominant outcome (26686 rows read Failed 0 out of 3 reruns), but it is not total: 19 rows across 7 commits and 5 pull requests (108443, 109239, 109920, 112052, 112247) surface as honest FAIL, and those carry the same signatures the local repro produced (Code: 57 TABLE_ALREADY_EXISTS for 04318, result differs for the rest). The run that forwards the job's flags to the diagnostics rerun (#112247 @ 682ae7a) is the only one that additionally reports Failed 3 out of 3 reruns; the other 15 honest failures carry no rerun block at all. Not a low-rate observation.
b Root cause explained? Yes, two distinct causes. (1) Four access tests: InterpreterCreateQuery returns tryEnqueueReplicatedDDL, which does no checkAccess; the entry is then executed by a worker whose context has no user (DDLTask::makeQueryContext only calls setUser when distributed_ddl_use_initial_user_and_roles is on and initiator_user is set, which only the ON CLUSTER path populates), so full_access = !user_id and the checks living inside storage construction (StorageDistributed.cpp, StorageURL.cpp) short-circuit to allow. Confirmed in the server log: the RESTORE arrives as user: user_04401_... but the CREATE TABLE ... ENGINE = Remote(...) it produces runs as (from 0.0.0.0:0, user: , initial_query_id: ...) /* ddl_entry=query-0000000007 */ and succeeds where the test requires rejection. (2) 02440: SYSTEM ENABLE FAILPOINT is process-local, while the test cluster gives this shard a second replica of the same table (auto_{shard} goes on the ZK path and auto_{replica} on the replica name, and the cluster's first shard is doubled), whose merge-selecting task is never paused and assigns the mutation.
c Fix matches root cause? Yes for what is in scope. The engine defect is issue #111561, deliberately not patched here (it is parked on an owner-level decision, with a write-up and three options already posted there). What this PR fixes is the test-side consequence: on three configurations these five tests assert a deny path that silently allows and are then whitewashed to OK, so they currently catch nothing. A config-scoped, issue-linked, temporary pin is the honest instrument, and it is the same one merged in #112862. It is explicitly not a no-random-* blanket: the divergence comes from the job's --replicated-database config flag, not from any randomized setting, so a no-random-* tag would not change the outcome while destroying genuine randomized coverage.
d Test intent preserved / new tests added? Preserved. No assertion is weakened, inverted, relaxed or deleted; every assertion still runs unmodified on every configuration that can enforce it (250/250 green on the default flavour). 04401_url_engine_s3_dispatch is pinned per subcase rather than per file: only its two CREATE-time engine-grant denials are invalidated by #111561, so those two (plus the http allow case that stops a denial from passing vacuously) moved into the new 04401_url_engine_s3_dispatch_engine_grant, which carries the pin, and their expected output moved with them. The remaining five assertions in the original file, including the only stateless coverage of url('s3://...') S3 source-grant dispatch, now run in every flavour instead of being skipped. I did not invert the references to encode the buggy output, which would bake the escalation into the expected result. No new test: this is a test-only pin, not a source fix.
e Both directions demonstrated? Yes, on the same binary and tree. With --replicated-database: 5/5 FAIL before; after, 4/5 SKIPPED (reason replicated-database) plus 04401_url_engine_s3_dispatch now passing because its two invalidated subcases moved to the pinned 04401_url_engine_s3_dispatch_engine_grant, which is SKIPPED there. Without the flag: OK before and after, for all six files. Removing the new file's pin makes it FAIL again under --replicated-database on exactly s3-engine-denied and azure-engine-denied, so the pin is load bearing rather than decorative. The second row is the check that the pin is precise rather than a global skip.
f Fix is general across code paths? Yes. The carrier population was closed by a reason-agnostic sweep (filtering on result differs alone hides members reported as having stderror, which is how 04318 was originally missed): 10 candidates resolved to 5 in scope, 2 deliberately reserved as the live evidence for #111561 (04541_, 04418_, verified untouched by this diff), and 4 belonging to other classes with existing owners. All three in-storage check sites are covered by one of the tagged tests. RemoteSecure shares the StorageDistributed registration but has no separate test to tag.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A in the type-wrapper sense: a test tag has no Nullable / LowCardinality / Const / Array / Map dimension. The relevant dimension is the configuration matrix, and it is enumerated exhaustively: no-replicated-database is honoured at three sites in tests/clickhouse-test (cloud, unconditional; replicated-database; shared-catalog). All three are replicated / shared-catalog database environments subject to the same gap, so one tag is correct for all three, and every comment says "replicated / shared-catalog database" rather than understating the reach. The cloud and shared-catalog arms were not run locally (they need infrastructure I do not have); their behaviour is established by reading the harness, where the tag's effect is a pure control-flow skip with no server interaction.
h Backward compatible? (maintainer-approved exception only) N/A, nothing to break. No settings, no SettingsChangesHistory.cpp implication, no serialization or protocol change, no user-visible behaviour, no production code path. Zero files under src/.
i Invariants and contracts preserved? Yes. No source invariant is touched. The harness contract is respected: the tag list stays a comma-separated list on the second line and parses correctly (verified programmatically for every changed test), bash -n is clean on all of them, and shellcheck finding counts are identical to origin/master for every file (one pre-existing each, none introduced).

Session id: cron:clickhouse-impl-slot-42:20260802-040400

@groeneai

groeneai commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator Author

cc @PedroTadim, could you review this? It is the same instrument you merged in #112862, applied to the harder class: five tests whose statements succeed on a Replicated database but produce different output, four because replicated DDL is replayed with no user so the in-storage access checks no-op (open issue #111561), and one because its process-local failpoint cannot pause the second replica of the same table.

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Aug 2, 2026
@PedroTadim PedroTadim self-assigned this Aug 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d4ab16c]

Summary: ✅


AI Review

Summary

This PR adds no-replicated-database pins to four Remote/URL access tests and one failpoint-based mutation test, and narrows the earlier 04401_url_engine_s3_dispatch skip by moving only the CREATE-time engine-grant subcases into a separate pinned test. I read the current diff and file contents, reconciled them against the prior discussion, and checked the latest Praktika report; the earlier over-broad skip concern is fixed, and I did not find any remaining correctness or coverage regressions in the current tree.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 2, 2026
@PedroTadim
PedroTadim enabled auto-merge August 2, 2026 12:23
The file-level no-replicated-database pin was broader than the regression it
works around. Issue ClickHouse#111561 invalidates only the two CREATE-time engine-grant
denials: those checks live inside storage construction, which a replicated DDL
runs with no user, so full_access makes them no-ops. The remaining assertions in
the file are unaffected. The url('s3://...') source-grant check is a plain
SELECT analysed on the initiator, which has a user, and the engine-name,
reload-safety and TRUNCATE-rejection checks do not depend on access control at
all. Pinning the whole file therefore dropped five live assertions, including
the only stateless coverage of S3 source-grant dispatch, from the replicated,
shared-catalog and cloud flavours.

Move the two invalidated subcases into
04401_url_engine_s3_dispatch_engine_grant, which carries the pin and the issue
link, and leave the rest of the file unpinned so it runs everywhere. The http
allow case moves with them: it is the companion that keeps a denial from
passing merely because the user holds no engine grant at all.

Measured on a private 3-host, 2-shard replicated-database harness. Before, the
whole file failed under --replicated-database with exactly the two engine lines
reading NOT DENIED while s3-source-required still passed. After, the trimmed
file passes under --replicated-database and the new file is skipped there;
both pass in the default flavour. Removing the new file's pin makes it fail
again with the same two lines, so the pin is load bearing rather than
decorative.
auto-merge was automatically disabled August 2, 2026 13:30

Head branch was pushed to by a user without write access

@PedroTadim
PedroTadim enabled auto-merge August 2, 2026 13:39
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 2, 2026
Merged via the queue into ClickHouse:master with commit c34d6c8 Aug 2, 2026
179 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 2, 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.

3 participants