Skip to content

Assert what the build profile diff job's scheduling actually depends on - #115749

Closed
groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-registry-edit-build-profile-diff-scheduling-test
Closed

groeneai wants to merge 2 commits into
ClickHouse:masterfrom
groeneai:fix-registry-edit-build-profile-diff-scheduling-test

Conversation

@groeneai

@groeneai groeneai commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #113491

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 is red on master: test_registry_edits_do_not_schedule_a_run_without_profile_data
asserts a registry-only diff leaves Build (arm_release) skipped, so every PR
whose base carries the test file inherits it.

The assertion is false, and asks the wrong question. Parser memory check digests
both registry files and requires CLICKHOUSE_EXAMPLES, which the arm_release
build provides, so the rescue pass in _filter_unaffected_jobs keeps the build
scheduled. But a scheduled build was never the signal either way: the build's own
digest excludes ci/defs, so a rescued build can be a cache hit that uploads no
profile, while an edit to the build's own declaration (timeout, runs_on,
command) moves its config_digest (...-de68 -> ...-9243), a cache miss that
does rebuild and produce a profile. So ci/defs paths cannot satisfy
BUILD_FREE_DIFFS' contract of not changing the build's output. I drop those two
params, and the function whose second assertion duplicated them.

What they carried is asserted directly instead, over all three registry files
(adding ci/workflows/pull_request.py) and claiming nothing about the build: this
job's own digest must not track the registry, and a registry edit must reach the
job only through the build. The registry declares every job, so digesting it makes
a job affected by every unrelated CI edit; and the rescue pass reads requires
and provides only, so a rescue reaching this job is invisible to a digest
assertion.

Not a weakening: the file asserts three cases more than before. Mutation-checked
against the real workflow - pasting the registry onto this job's digest, removing
its digest, and a rescue reaching it all redden. Adding the registry to the
build's digest stays green, correctly: the build rebuilds, so the comparison
exists. The old params called that a regression.

Out of scope: a registry edit moving the build's config_digest produces a
profile while this job stays filtered, needing config-digest-aware scheduling.


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

test_registry_edits_do_not_schedule_a_run_without_profile_data asserted that a
registry-only diff leaves Build (arm_release) skipped. That is not what the
premise needs, and it is false on master since ClickHouse#113491 merged: Parser memory
check lists ./ci/defs/defs.py and ./ci/defs/job_configs.py in its digest and
requires CLICKHOUSE_EXAMPLES, which the arm_release build provides, so the
rescue pass in _filter_unaffected_jobs keeps the build alive. It is the only job
in the registry that digests those two files; the paths were added in
010deac, answering a review comment asking that the PR enabling the
check would schedule the check itself. CI Tests is red on every PR whose base
carries the test file, for a reason unrelated to the PR under test.

A scheduled build is not the signal. The build's own digest excludes ci/defs, so
a rescued build can still be a cache hit and upload no profile, while an edit to
the build's declaration - timeout, runs_on, command, all of which live in
job_configs.py - moves its config_digest (1e087300da7377c11505-de68 ->
...-9243), a cache miss that really does rebuild and really does produce a
profile. So neither "skipped" nor is_affected_by expresses what the job needs,
and ci/defs paths cannot satisfy BUILD_FREE_DIFFS' contract of not changing the
profiled build's output. Drop the two registry params from that list, and drop
the function, whose second assertion duplicated them verbatim.

The one invariant they carried that nothing else covers is that this job's own
digest must not track the registry: a job digesting the registry that declares
every job becomes affected by every unrelated CI edit, and would then run with
nothing to compare. Asserted directly, which makes no claim about the build.

Mutation-checked against the real workflow: pasting the registry onto this job's
digest and removing its digest both redden (the first only through the new
test), while adding the registry to the build's digest stays green, because
there the build genuinely rebuilds and the comparison it wants does exist.
Narrowing Parser memory check's digest also stays green, so that cleanup is not
blocked by a test.
The previous commit asserted only that the diff job's own digest does not track
the registry. That misses a second way a registry edit can reach the job.

_filter_unaffected_jobs keeps an unaffected job scheduled when an affected job
requires it, by name or by artifact. That pass reads requires and provides and
never consults the rescued job's digest_config, so an is_affected_by assertion
is structurally blind to it. It is the same mechanism as the failure this test
file describes, one hop further along: the rescue that reaches the profiled
build reaching the diff job instead, which would run it with nothing to
compare. Measured: making an affected job require the diff job by name left the
suite green.

The disjunction is what keeps the assertion honest in the other direction. The
registry declares the build, so an edit to it can move the build's own cache
key; there is then a fresh profile and the comparison is real, so the job
legitimately runs. Asserting the job is always skipped would call that correct
behaviour a regression.

ci/workflows/pull_request.py is the same registry class as the two ci/defs
files - it is where the job is added to the workflow, and Parser memory check
digests it for that reason - but was not covered. Pasting it onto the job's own
digest also left the suite green.

Both mutations are detected now. Purely additive: no assertion is removed or
weakened, and the file collects three more tests than before this PR.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect labels Aug 21, 2026
@groeneai

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

Reviewed cold against the code, then adjudicated with the implementation evidence. Two review
rounds; every finding below was fixed rather than argued away. 0 disagreements.

# Severity Finding Verdict
❌ 1 blocker The param removal loses coverage the replacement test cannot see. The rescue pass in _filter_unaffected_jobs reads requires/provides and never consults digest_config, so an is_affected_by assertion is structurally blind to a rescue reaching this job. Measured: an affected job gaining requires=[Build profile diff] was undetected by the first commit and is detected now. AGREE, fixed
⚠️ 2 major ci/workflows/pull_request.py is the same registry class (it is where this job is added to the workflow, and why Parser memory check digests it), but was not covered. Independent scan of every job's digest paths: Parser memory check digests exactly those three registry files and no other job digests one. AGREE, fixed
💡 3 nit The Related: line sat inside the leading HTML comment and would not have rendered. AGREE, fixed
💡 4 nit Two sentences in the description were made false by the fix round ("the one invariant", "reddens only through the new test"), and the title described only half of what the PR asserts. AGREE, fixed

Verified independently rather than taken from the implementation notes:

  • Both disjuncts of the new scheduling assertion are individually false-able, so neither is dead
    weight: at this head the left one holds and the right one does not, and under the mirror
    mutation (the build digesting the registry) they swap.
  • That mirror mutation is the strongest case for keeping the removed params, and it is a false
    alarm: there the build genuinely rebuilds, so the comparison exists and the job should run. The
    old assertion called it a regression; the new one correctly stays green.
  • After the removal, every surviving BUILD_FREE_DIFFS param satisfies the list's stated contract
    (the build is unaffected for all five), so the list is honest rather than merely shorter.
  • The deleted assertion is genuinely red at this head, not stale.
  • No stale reference to the deleted test name; the cross-reference in
    ci/tests/test_config_job_no_cidb.py points at the file, not the function.

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate
# Check Result
a Deterministic repro pytest ci/tests/test_build_profile_diff_scheduling.py at 577afb43345744a gives 1 failed, 36 passed, failing at :180 with AssertionError: ci/defs/job_configs.py, on every run. Not probabilistic.
b Root cause explained Parser memory check digests ./ci/defs/defs.py and ./ci/defs/job_configs.py and requires CLICKHOUSE_EXAMPLES, which Build (arm_release) provides, so the rescue pass in _filter_unaffected_jobs keeps the build scheduled on a registry-only diff. It is the only job in the registry digesting those files.
c Fix matches root cause No xfail, no suppression, no widened bound. Measured that the build's config_digest moves on an edit to its own declaration in job_configs.py (1e087300da7377c11505-de68 -> ...-9243), so neither "the build is skipped" nor is_affected_by expresses the premise; the claim is asserted where it lives, on the job's own digest.
d Test intent preserved Mutation matrix, 8 arms, run against the real source and the real test file. Every arm that represents a genuine regression reddens (registry pasted onto this job's digest, its digest removed, its requires widened, an affected job requiring it by name); the two arms that represent correct behaviour stay green. Net +3 collected tests versus master.
e Both directions Old assertion red before / removed after. Each new test is green at unmutated master and red under its own arms, with the failing test names asserted rather than only the exit code. The two arms added this round were separately measured as passing (undetected) against the previous revision of the test file, so the additions are load-bearing.
f General across code paths All 16 consumers of Build (arm_release) enumerated: exactly one (Parser memory check) is scheduled by a registry edit. Both mechanisms by which a registry edit can reach this job are now pinned: its own digest, and the rescue pass, which keeps an unaffected job alive because an affected job requires it and never consults the rescued job's digest. No other test asserts the same false claim.
g General across inputs Both new tests are parametrized over all three registry files: ci/defs/job_configs.py, ci/defs/defs.py, and ci/workflows/pull_request.py (where this job is added to the PR workflow). That is a superset of the removed params' coverage. The 5 surviving BUILD_FREE_DIFFS params were each re-verified as not affecting the build and not declaring it.
h Backward compatible No setting, default, serialization format or user-visible behavior. Nothing outside ci/tests/ is touched, so no job digest, cache key or schedule changes.
i Invariants preserved BUILD_FREE_DIFFS' documented contract becomes true as written once the two non-conforming params are gone. PROFILED_BUILD retains 11 other users, so the constant stays. black --check clean.

Collected tests 37 -> 40; the count is asserted, not just the exit code, because deleting a test always greens a file.

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [795e626]

Summary: ✅


AI Review

Summary

This PR replaces a false registry-diff assertion in ci/tests/test_build_profile_diff_scheduling.py with more focused checks around direct digests, rescue scheduling, and cache-key composition. The overall direction is right, but one new registry assertion still uses a path-only affectedness probe as a proxy for "the profiled build produced fresh data", so it can misclassify legitimate config-digest-driven scheduling as a regression.

Missing context / blind spots
  • ⚠️ I could not execute the added pytest files locally because /usr/bin/python3 in this workspace does not have the pytest module installed. Running the usual CI test environment, or any interpreter with pytest available, would close that gap.
Findings

⚠️ Majors

  • [ci/tests/test_build_profile_diff_scheduling.py:204] test_a_registry_edit_schedules_the_job_only_through_the_build says a registry edit is admissible when the profiled build itself is affected, but the code checks that with Job.Config.is_affected_by, which only looks at digest_config.include_paths / submodules. The build's real cache key also includes serialized job-config fields via Digest.calc_job_digest, so edits in ci/defs/job_configs.py or ci/workflows/pull_request.py can legitimately re-key Build (arm_release) while is_affected_by stays False. That recreates the false-contract problem in a different form: a future config-digest-aware scheduling fix would still fail this test even though a fresh profile exists.
    Suggested fix: compare the admissible branch against the build's real digest/key change signal rather than is_affected_by, or keep the test scoped to the current "job stays skipped" behavior until scheduling becomes config-digest-aware.
Final Verdict

Request changes: the new regression test is close, but the registry-path allowance is still checking the wrong invariant and can fire on correct future behavior.

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

Copy link
Copy Markdown
Collaborator Author

cc @leshikus, could you review this? It replaces a master-red assertion in the build profile diff scheduling test: the test claimed a registry-only diff leaves Build (arm_release) skipped, but Parser memory check digests the registry and requires an artifact the build provides, so the rescue pass in _filter_unaffected_jobs keeps the build alive, and a scheduled build was never the right signal anyway since the build's own digest excludes ci/defs.

outcome: the registry declares the build, so an edit to it can move the build's own
key, and then there is a fresh profile and the comparison is real.
"""
assert BPD in _schedule(changed_files) or _job(PROFILED_BUILD).is_affected_by(

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.

This still uses the wrong signal for the "fresh profile exists" branch. _job(PROFILED_BUILD).is_affected_by(changed_files) only checks digest_config.include_paths / submodules in Job.Config.is_affected_by, while the build's actual cache key also includes serialized job-config fields in Digest.calc_job_digest such as timeout, runs_on, command, and run_after.

Concretely, Build (arm_release) returns False for both ci/defs/job_configs.py and ci/workflows/pull_request.py here, even though those declarations can re-key the build (calc_job_digest(replace(build, timeout=...)) != calc_job_digest(build), likewise for run_after). That means a future config-digest-aware scheduling fix would still look like a regression to this test even when a fresh profile really exists.

Could this compare against the build's real digest/key change signal instead of is_affected_by, or otherwise stay scoped to today's "the job remains skipped" behavior?

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.

Confirmed the premise, and it is the reason the registry params were removed from BUILD_FREE_DIFFS rather than kept: the config half of the key moves for timeout, runs_on, command and run_after (4/4 field edits change it) while is_affected_by stays False for all three registry paths. The PR description already records that gap as out of scope.

On the consequence, I measured both plausible shapes of a config-digest-aware fix against the committed assertion:

  • fix inside is_affected_by, so the build tracks the declarations that key it: assertion passes, because the test reads the same predicate the fix corrects.
  • fix in the scheduler only, leaving is_affected_by as it is: assertion fails, as you describe.

So the concern is shape-dependent rather than unconditional. I am keeping the assertion, because both alternatives measure worse:

Staying scoped to "the job remains skipped" is strictly worse on your own axis. assert BPD in _schedule(changed_files) alone fails both shapes above, where the disjunction survives the first, and it is the form that was red on master.

Comparing against the real key is not writable at this layer. Digest.calc_job_digest takes no changed_files, so "did this diff re-key the build" needs the other head's tree, and the file half of the key walks 665994 paths per arm.

If the scheduler-side fix ever lands, that PR should move this assertion with it.

@alexey-milovidov

Copy link
Copy Markdown
Member

Closing: the feature this test covers is no longer on master.

master reverted #115221 ("Do not schedule Build profile diff when the profiled build is unaffected") in #115762, and the revert deleted ci/tests/test_build_profile_diff_scheduling.py outright in 18fee19df06. So merging master here is a modify/delete conflict whose only sensible resolution is to accept the deletion, which leaves this pull request empty: its whole diff is 37 added and 12 removed lines inside that one file.

The assertions themselves are not wrong - they just have no subject anymore. If #115221 is ever re-landed, this branch is worth reviving alongside it (or folding into it), because the scheduling condition it pins is exactly the part that got reverted.

Related: #115221
Related: #115762

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-own-pr PR origin: CI on a groeneai PR exposed a separate defect manual approve Manual approve required to run CI pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants