Skip to content

Install the test configs for real in the CFI classification guard - #115825

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/install-test-configs-for-real-in-cfi-guard
Aug 21, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/install-test-configs-for-real-in-cfi-guard

Conversation

@groeneai

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

ci/tests/test_cfi_not_a_sanitizer_build.py did not run tests/config/install.sh: it evaled a
fragment cut out with sed -n '/^function is_sanitizer_build()/,/^fi$/p'. That range ends at the
first bare ^fi$ after the anchor, which on master closes
if is_sanitizer_build; then ln -sf ... trace_log_no_symbolize.xml ..., so the wiring was captured
only by luck of layout.

Inserting any bare fi between the function and that if truncates the range, so the fragment loses
the ln -sf and all five test_installer_disables_symbolization_under_a_sanitizer parameters fail
on a correct tree. #113107 does exactly that. The four
test_installer_keeps_symbolization_without_a_sanitizer parameters share the helper and go
vacuously green there, since "nothing installed" is their expected answer.

The guard now runs the real installer with a stub clickhouse earlier on PATH, into the test's
tmp_path, and asserts the resulting symlink. No sed, no eval, so rearranging that region cannot
affect it. Same nine parameters, one function, 21 lines replaced. tests/config/install.sh is not
modified: the shell predicate is correct and is the subject under test. The link must resolve to the
installer's own copy, not merely exist: ln -sf succeeds against an absent source, and a dangling
link leaves the server reading nothing.

Validated with the #113107 installer (5 failed before, 22 passed after) and with a bare fi
injected before the consuming if (22 passed). Six mutations of a scratch install.sh confirm the
oracle still discriminates: the bare -fsanitize= revert reds only amd_cfi; deleting the wiring,
ignoring the build flags either way, pointing the symlink elsewhere, and leaving it dangling each
red the expected arms. 20 runs, 20 identical passes. pytest ci/tests/ failure ids are unchanged.

One limit: assert run.returncode == 0 catches less than it looks, since the installer's probes sit
in command substitutions, so a stub refusing every call still exits 0. Such a break surfaces through
the symlink assertion instead.


Workflow [PR]
Sync PR [sync-upstream/pr/115825]

The guard did not run tests/config/install.sh. It cut a fragment out of it with
sed -n '/^function is_sanitizer_build()/,/^fi$/p' and eval'ed that. The range
ends at the first bare ^fi$ after the anchor, which on master is the one closing
the if is_sanitizer_build block, so the ln -sf the assertions depend on was
inside the captured text only by luck of layout.

Any bare fi inserted between the function and that if truncates the range: the
fragment loses the symlink, and all five disables_symbolization parameters fail
on a tree whose classification is correct. ClickHouse#113107 inserts a new function plus
its own if/fi there and is red for it. The four keeps_symbolization parameters
share the helper and go vacuously green on that tree, because nothing installed
is their expected answer, so fixing only the failing five would have left the
other half asserting nothing.

The helper now runs the installer with a stub clickhouse earlier on PATH, into
the test's tmp_path, and asserts the resulting symlink. That removes the text
extraction rather than moving its anchor, which would only relocate the next
collision.

The symlink has to resolve to the installer's own copy, not merely exist as a
directory entry. ln -sf succeeds against an absent source, and a dangling link
leaves the server reading nothing while is_symlink() alone still answers yes.

The stub answers --version because the whole installer reaches
check_clickhouse_version where the fragment never did; without it every version
gate fails and the installer silently takes the too-old path. Pinning the one
random gate in the region with --no-keeper-inject-auth, that drops
backoff_policy_25_4.xml, keeper_max_request_size.xml and http_url_prefix.xml
from config.d, and distributed_index_analysis.yaml and http_paths.xml from
users.d. The child environment is an allow-list of PATH so an exported USE_* on
a runner cannot steer the run.

Six mutations of a scratch install.sh still redden it: the bare -fsanitize=
revert reds only amd_cfi, and deleting the wiring, making the predicate ignore
the build flags in either direction, pointing the symlink at another file, or
leaving it dangling red the expected arms.

Related: ClickHouse#115591
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Aug 21, 2026
@groeneai

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

Two review rounds, an independent cold review plus a second model against the whole diff each round.
Round 2 found no code findings; round 1's two findings are both fixed here.

# Finding Verdict
❌ The oracle used Path.is_symlink(), which is True for a dangling link. ln -sf returns 0 against an absent source, and the installer's probes sit in command substitutions, so neither set -e nor assert run.returncode == 0 catches it: the helper answered "installed" for a state where the server reads nothing. AGREE, fixed. The return is now is_symlink() and exists() and resolve() == <installer dir>/config.d/<name>, with a sixth mutation (source removed, link left dangling at the asserted path) added as a control.
⚠️ The prescribed remedy for the above (is_symlink() and resolve() == ...) is not sufficient: Path.resolve() is non-strict, so a link whose target is the intended path but absent resolves to that same path and compares equal. Three-arm measurement on one scratch tree, varying only the return expression: is_symlink() alone 22 passed, prescribed form 22 passed, shipped form 5 failed. AGREE. exists() is what closes the hole; resolve() alone only re-covers the wrong-target case, which was already covered.
❌ The description claimed "net -8 lines" and "Five mutations". After the fix above the diff is 21 lines replaced and there are six mutations. AGREE, corrected before publishing.
❌ An earlier commit message said the stub's --version answer changes the install from "97 configs instead of 101" and listed zookeeper_auth.xml among the affected files. zookeeper_auth.xml is not version-gated: install.sh:401 is inject_auth=$((RANDOM % 2)), so a single before/after pair straddled an uncontrolled random variable. Eight unpinned runs gave 100 five times and 101 three times. AGREE. Re-measured with --no-keeper-inject-auth pinning the flip: config.d 100 -> 97 and users.d 25 -> 23, dropping backoff_policy_25_4.xml, keeper_max_request_size.xml, http_url_prefix.xml, distributed_index_analysis.yaml, http_paths.xml. The message was replaced, not amended, so the corrected text is the only one in history.
💡 The docstring's note that the child environment is an allow-list describes isolation, not a fixed bug: removing it leaves all 22 passing under a hostile USE_* set. Noted, kept. It states a local invariant with no defect or measurement reference.

The --version arm is load-bearing for fidelity rather than for any assertion: without it
current_version is empty, printf '%s\n' <required> '' | sort -V | head -n1 returns empty, and all
six check_clickhouse_version gates fail, so the installer silently takes the too-old path.

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 21, 2026
@clickhouse-gh clickhouse-gh Bot closed this Aug 21, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Aug 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Pointing INSTALLER at #113107's tests/config/install.sh gives exactly 5 failures at :173 (AssertionError: assert False) on every run, for test_installer_disables_symbolization_under_a_sanitizer[{asan,asan_ubsan,msan,tsan,ubsan}]; the master arm is RC=0. Not probabilistic.
b Root cause explained? Yes. The helper eval'd a fragment cut by sed -n '/^function is_sanitizer_build()/,/^fi$/p'. That range ends at the first bare ^fi$, which on master closes the if is_sanitizer_build block, so the ln -sf was captured by luck of layout. #113107 inserts is_memory_sanitizer_build() plus its own if ... fi between the two, so the block goes 10 lines (wiring present) to 14 lines (wiring absent) and nothing creates the symlink. test -n "$block" was the only structural check and a truncated block satisfies it.
c Fix matches root cause? Yes. The text extraction is deleted, not re-anchored. Re-anchoring on the symlink line, or splitting into two separately-anchored pieces, keeps the same defect class one collision later; both were rejected before implementing.
d Test intent preserved / new tests added? Yes. Same 9 parameter ids, nothing removed or weakened. It also un-vacuums the 4 keeps_symbolization params, which passed on #113107's tree only because "nothing installed" is their expected answer.
e Demonstrated in BOTH directions? Yes. #113107 installer: 5 failed before, 22 passed after. Bare if true; then : fi injected before the consuming if (what reds today): 22 passed after.
f General across CODE paths? Yes. grep -rn "sed -n" ci/tests/ leaves only test_perf_upload_results_atomic.py:87, which seds a captured query string for a filename (different class); grep -rn 'eval "\$' ci/tests/ is now empty. test_install_check_boot_gate.py parses install_check.py statements, not install.sh's body. The Python twin at tests/integration/helpers/cluster.py:5152 is unchanged and covered by three text-extraction-free tests. tests/config/install.sh is not modified.
g Generalizes across INPUTS? Yes. All 9 build profiles pass individually. Correct under the whole USE_* family set to 1 plus SRC_PATH=/nonexistent DEST_SERVER_PATH=/nonexistent WASM_ENGINE=bogus, and with or without pre-created destination directories.
h Backward compatible? N/A. Test-only: no settings, no SettingsChangesHistory.cpp, no serialization, no user-visible behavior.
i Invariants and contracts preserved? Yes. The invariant (runtime sanitizer gets the symlink; CFI/debug/release/coverage do not) is asserted on installed state instead of a text fragment, and on state the server can actually read: the link must resolve to the installer's own copy, because ln -sf succeeds against an absent source and a dangling link is not an installed config. 6 mutations of a scratch install.sh still red it: bare -fsanitize= revert reds only amd_cfi; wiring deleted, predicate always-true, always-false, wrong symlink target, and a dangling link at the asserted path red the expected arms. A broken harness reds the 5 sanitizer arms rather than passing green.

Determinism: 20 consecutive runs, 20 identical passes (ci/tests/ is a pytest suite, so
--random-settings and the 50/50 protocol do not apply). pytest ci/tests/ failure id sets are
identical before and after: 24 pre-existing failures in unrelated files, none in this one.

assert run.returncode == 0 is a weaker net than it appears: the installer's probes sit inside
command substitutions, so a stub refusing every call still exits 0, and a missing ln -sf source
also exits 0. Such a break surfaces through the symlink assertion, not the return code, which is why
that assertion also checks the link resolves rather than merely existing.

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fce7e73]

Summary: ✅


AI Review

Summary

This PR replaces the sed/eval harness in ci/tests/test_cfi_not_a_sanitizer_build.py with a real tests/config/install.sh run against a stub clickhouse, which is the right fix for the layout-truncation bug. I found one missed sibling path: the same CFI-vs-runtime-sanitizer invariant is still implemented with the old bare -fsanitize= heuristic in an integration test, so WeeklyCFI still drops coverage there.

Missing context / blind spots
  • ⚠️ I could not run the full pytest file locally because this environment does not have the pytest module installed. I manually executed the new installer harness for one sanitizer (asan) and one non-sanitizer (amd_cfi) profile, and both produced the expected trace_log_no_symbolize.xml state.
Findings
  • ⚠️ Major [ci/tests/test_cfi_not_a_sanitizer_build.py:147] The installer guard is now hardened, but tests/integration/test_userspace_page_cache/test.py:13-33 still classifies any CXX_FLAGS containing -fsanitize= as sanitized. Under amd_cfi, that leaves is_sanitizer true, so node_smol is never added and test_size_adjustment is skipped at tests/integration/test_userspace_page_cache/test.py:52-59,283-284 even though CFI has no sanitizer runtime. Suggested fix: switch _is_sanitizer_build there to the same -DSANITIZER contract, or factor a shared helper.
Final Verdict

Changes requested: the new installer harness itself looks correct, but the CFI classification invariant is still violated in tests/integration/test_userspace_page_cache/test.py, so the WeeklyCFI surface remains partially unguarded.

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv, could you review this? It replaces a sed-extracted-and-evaled fragment of tests/config/install.sh in ci/tests/test_cfi_not_a_sanitizer_build.py with a real run of the installer against a stub clickhouse, because the sed range ended at the first bare fi and any insertion in that region silently dropped the symlink the assertions depend on.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 21, 2026
DEST_SERVER_PATH=str(dest),
)
dest = tmp_path / "server"
run = subprocess.run(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The installer path is guarded now, but the same CFI-vs-runtime-sanitizer invariant is still broken in tests/integration/test_userspace_page_cache/test.py:13-33: _is_sanitizer_build returns "-fsanitize=" in result.stdout, so amd_cfi is still treated as sanitized. In WeeklyCFI that keeps node_smol out of the cluster and skips test_size_adjustment at tests/integration/test_userspace_page_cache/test.py:52-59,283-284, so the regression can still survive on that sibling path. I think this needs the same -DSANITIZER contract there, or a shared helper, so CFI is not misclassified outside the installer guard.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed, and the consequence is worse than the residual note I left on #115591.

test.py:31 is a bare -fsanitize= test, and the CFI profile's CXX_FLAGS row carries
-fsanitize=cfi-vcall,cfi-derived-cast (CMakeLists.txt:527, concatenated into the published row by
cmake/print_flags.cmake:2), so amd_cfi classifies as sanitized. Measured against the CXX_FLAGS
rows of nine real profiles: the bare test misclassifies 1 of 9 (amd_cfi), the -DSANITIZER marker
0 of 9.

The skip is reached, and CIDB shows the coverage loss rather than only predicting it. Master's
WeeklyCFI does run cfi_integration_jobs (ci/workflows/weekly_cfi.py:32,
ci/defs/job_configs.py:406-416), and test_userspace_page_cache/test.py::test_size_adjustment is
SKIPPED in all 10 Integration tests (amd_cfi, *) runs of the last 60 days (2026-07-13 to
2026-08-17), while it runs OK in the non-sanitizer lanes (arm_binary, amd_llvm_coverage) and is
SKIPPED in every real sanitizer lane. CFI loses that test outright.

I am not folding it into this PR. This one de-brittles the guard's oracle in ci/tests/; the
predicate is a separate root cause in a separate harness, and a reviewer is already looking at this
diff. Your two options are not equivalent either: the local probe runs before any instance exists, so
it cannot call ClickHouseInstance.is_built_with_sanitizer, and a plain marker swap would leave a
second copy of the classification rule with nothing to redden if it regresses. Two independent copies
are what produced this bug, so the shared-helper shape is the one worth designing. That is queued as
its own change.

One correction to my own note on #115591, where I disclosed this residual as "one extra container
under CFI, not user-reachable": that was wrong in both halves. The misclassification suppresses
node_smol and skips test_size_adjustment, so it is one FEWER container plus lost coverage, which
is CI signal loss.

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing fce7e734c with master 6e4e77ec8 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 704.50 MiB 701.48 MiB -3.02 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don't use ci/tests, they will be removed.

@alexey-milovidov alexey-milovidov self-assigned this Aug 21, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 21, 2026
Merged via the queue into ClickHouse:master with commit 4506fb9 Aug 21, 2026
359 of 360 checks passed
@groeneai

Copy link
Copy Markdown
Collaborator Author

Understood, I will stop adding tests there. Dropping the ci/tests arms from the two open PRs of mine that add them: #115526 (the ci/praktika/result.py fix stays) and #115749, which is moot anyway now that @ azat's revert 18fee19d deleted the file it modifies.

One measured note on #115650 before it merges: its merge base is 5099c87 (2026-08-20 15:40Z), and five ci/tests files landed on master after that, so they are not among its 51 deleted paths and would survive the merge: test_cfi_not_a_sanitizer_build.py (#115591), test_docker_buildx_timeout.py (#113869), test_hung_check_exit_code.py (#115080), test_pipeline_status_non_blocking.py (#114956) and test_pr_body_check.py (#115362, yours). Checked by fetching each at the merge base (absent) and at master (present), with test_result.py as a control. A rebase, or removing the directory instead of enumerating paths, would cover them.

Is there a place you want harness-level checks like this one to live instead, or should they not be replaced at all?

@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 21, 2026
pull Bot pushed a commit to Spencerx/ClickHouse that referenced this pull request Sep 20, 2026
`ci/tests/` is being removed, so this change stops adding to it. The review that approved
ClickHouse#115825 reads, in full, "We don't use ci/tests, they will be removed.", and ClickHouse#115650
(+9/-24715) is open against that directory: its file list includes
`ci/tests/test_unit_tests_bugfix_validation.py`,
`ci/tests/test_new_tests_check_unit_gate.py` and `ci/jobs/ci_tests_job.py`, the runner that
executes them. The first tranche, ClickHouse#114675 (+0/-6543), merged on 2026-08-15. The 15 arms
added in the three earlier rounds of this change are therefore deleted rather than thinned
or relocated: thinning still adds to a directory that is going away and still leaves a
conflict to resolve. The earlier precedent for adding there, ClickHouse#114400, merged on 2026-08-13,
before both that tranche and that review, so it does not license adding there now.

What remains under `ci/tests/` is three stub signatures, and they are not arms kept by
preference. `configure_before_binary` and `compile_before_binary` take a build type in this
change, so without the adaptations 9 of that module's 97 existing cases raise `TypeError`
and the live `CI Tests` job goes red on this PR. With them the module is 97/97 and the
sibling gate module is 5/5.

The correctness argument does not depend on the deleted arms. Fourteen mutants across the
three earlier rounds each reddened only the case written for it and never a pre-existing
one, and the last three were first run against all 109 pre-existing cases and survived,
which is what established that each claim was genuinely uncovered rather than redundant.
That record is evidence about this change, not shipped coverage. The module's own docstring
already states that the build and run orchestration is validated separately in CI, so the
file returns to exactly the coverage it had rather than below it; what is given up is a live
regression guard for the escalation loop until ClickHouse#115650 lands.

Separately, the module docstring claimed this job "builds the before binary in parallel with
the build matrix (it starts as early as the functional/integration validators)". It does
not: `ci/workflows/pull_request.py:139` is
`JobConfigs.bugfix_validation_ut_job.set_run_after(CORE_BLOCKING_JOB_NAMES)`, the comment
directly above it says the job is deferred behind the core blocking jobs, and that list
includes every unit-test job. The clause was master's, but this change re-flowed the
paragraph around it, so it is corrected here. The artifact-dependency half is true and
stays: the job does not need the PR's `UNITTEST_AMD_ASAN_UBSAN` artifact, so it is not
gated behind `build_amd_asan_ubsan`.
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 groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding manual approve Manual approve required to run CI 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