Skip to content

Fix praktika is_merge_queue_event comparing the event type against GitHub's event name - #112227

Merged
nihalzp merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-praktika-merge-queue-event-type
Jul 28, 2026
Merged

nihalzp merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-praktika-merge-queue-event-type

Conversation

@groeneai

@groeneai groeneai commented Jul 28, 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

Info.is_merge_queue_event compared _Environment.EVENT_TYPE against "merge_group", but
EVENT_TYPE only ever holds a Workflow.Event value, and Workflow.Event.MERGE_QUEUE is
"merge_queue". merge_group is GitHub's event name; merge_queue is praktika's enum value.
So the predicate was never true in a real merge-queue run, and every consumer silently took the
pull-request branch. Fixed by comparing against the enum constant, so the two cannot drift again.

How it surfaced: Style check / settings_changes_history fails deterministically in the merge
queue for any PR that touches src/Core/SettingsChangesHistory.cpp, with

src/Core/SettingsChangesHistory.cpp changed but its diff could not be fetched to validate the settings history (the check must not be skipped when the file changed). Error: no data recorded by the store_data.py workflow hook.

Report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=gh-readonly-queue/master/pr-110395-4a44dcefc451d3da3f7a9e7c8a38f74180b34ebc&sha=999b2e18000966dd17c2060fb5c0e83f955bfb11&name_0=MergeQueueCI&name_1=Style%20check

store_data.py's __main__ computes strict=bool(info.pr_number) or info.is_merge_queue_event,
which is False in the queue (pr_number is 0 there), and gates the settings-history block on
(info.pr_number or info.is_merge_queue_event) and settings_history_file in changed_files, also
False, so settings_history_changed_settings is never stored. check_style.py's
check_settings_changes_history then sees the file in changed_files with no recorded data and
fail-closes. The check is behaving correctly; the hook silently skipped half its work. The failing
job's own environment dump confirms EVENT_TYPE='merge_queue', PR_NUMBER=0,
LINKED_PR_NUMBER=110395, and that the stored kv keys are exactly
['changed_files', 'build_digest', 'master_commits'].

CIDB, test_name = 'settings_changes_history', last 10 days as of 2026-07-28 06:37 UTC:

scope FAIL OK
merge queue (head_ref LIKE 'gh-readonly-queue/%') 5 (all with the message above) 40
PR workflow 26 (all genuine settings-history violations) 337

The 5 merge-queue failures are exactly the merge-queue entries that touched the file (2 PRs), i.e.
100% on qualifying entries. The 40 passing merge-queue rows span 36 distinct PRs and none of those
36 touches the file, so every one of them took the path not in changed_files early return: the
validator has never actually validated anything in a merge queue. The PR workflow is unaffected.

Consumers that were on the wrong branch and now work:

  • GH.get_changed_files is called with strict=True, i.e. fail-closed changed-file detection.
  • The settings-history block runs, resolving the diff through linked_pr_number.
  • GH.get_changed_files itself queries pulls/<linked>/files --paginate instead of the
    300-entry-capped commits/<sha> API, regaining the fail-closed guarantee its own comment exists
    for. For the Parallelize the final merge of single-level aggregation hash tables #110395 queue entry both endpoints return the same 17 files, so nothing changes on a
    small PR while the cap disappears on a large one.
  • functional_tests.py merge-queue flaky rerun_count 50 -> 20.
  • functional_tests.py FLAKY_CHECK_TIME_LIMIT 45 min -> 20 min.

The sibling predicates is_push_event and is_dispatch_event compare literals that happen to
equal their enum values ("push", "dispatch"), so they were never broken; converting them to the
enum form is behaviour-neutral hygiene and is out of scope here. The new test pins those two
equalities, so a later rename of Workflow.Event fails a test instead of silently repeating this
bug. _environment.py's elif "merge_group" in github_event: is correct as written - that one
legitimately reads the GitHub payload before storing the enum value - and is unchanged.

Behaviour changes worth calling out:

  1. The settings-history validator starts running in the merge queue for the first time. Expect
    newly-enforced reds on queued PRs that add or change a setting without an entry under the
    current version block. That is the intended behaviour of the check.
  2. GH.get_changed_files's fail-closed raise becomes reachable inside a pre-hook. If a
    merge-queue head ref ever yields no linked PR number, store_data.py now raises where it
    previously fell through; native_jobs.py wraps each pre-hook in a Pre Hooks result whose
    non-OK status gates the rest of the config job, so that surfaces as a loud failure rather than a
    hang or a silent skip. In practice it should not fire: all 6510 distinct merge-queue head refs
    in the last 180 days match the canonical gh-readonly-queue/<base>/pr-<N>-<sha> shape and none
    is unparseable.
  3. The tighter merge-queue flaky-check budget starts applying, as intended by the design that
    introduced it.

Test: ci/tests/test_info_event_type.py drives a real GitHub merge_group payload through
_Environment.from_env() into the real Info property and asserts the full event matrix
(merge_group -> True; pull_request, push, schedule, dispatch -> False), plus that the
queue head ref yields linked_pr_number == 110395. It deliberately does not mock the predicate:
the existing merge-queue tests in ci/tests/test_gh.py build a SimpleNamespace with
is_merge_queue_event=True, which is why they could not catch this. Reverting the one-line change
makes the new test fail on exactly that assertion.

Separately, check_style.py reads a settings_history_fetch_error key that nothing ever writes, so
a genuine diff-fetch failure reports the generic "no data recorded" text instead of its real cause.
That is a distinct root cause (the fetch goes through Shell.get_output, which returns stdout even
on a nonzero exit, so simply storing the exception would record a mislabelled reason) and is being
fixed separately rather than folded in here.

Version info

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

…'s event name

_Environment.EVENT_TYPE only ever holds a Workflow.Event value, and
Workflow.Event.MERGE_QUEUE is "merge_queue". "merge_group" is GitHub's event
NAME, which _environment.py correctly keys on when reading the webhook payload
before storing the enum value. Info.is_merge_queue_event compared EVENT_TYPE
against that event name, so it was never true in a real merge-queue run and
every consumer silently took the pull-request branch.

The visible symptom was a deterministic Style check / settings_changes_history
red in the merge queue for PRs touching src/Core/SettingsChangesHistory.cpp:
store_data.py computes strict=bool(info.pr_number) or info.is_merge_queue_event
(False in the queue, where pr_number is 0) and gates its settings-history block
on the same predicate, so settings_history_changed_settings was never stored and
check_style.py fail-closed with "no data recorded by the store_data.py workflow
hook". The check was correct; the hook skipped half its work. All 5 merge-queue
failures in the last 10 days are exactly the merge-queue entries that touched
that file, while all 39 passing merge-queue runs took the "path not in
changed_files" early return, so the validator had never validated anything
there.

Compare against the enum constant rather than swapping in the "merge_queue"
literal, so the value and GitHub's event name cannot drift apart again. Five
consumers besides the settings-history gate start working: get_changed_files
regains its fail-closed path instead of the 300-entry-capped commits API, and
the merge-queue flaky check picks up its intended 20 reruns / 20 minute budget
instead of the 50 / 45 minute PR values. The sibling is_push_event and
is_dispatch_event predicates compare literals that equal their enum values, so
they were never broken and are left alone.

The new test drives a real merge_group payload through _Environment.from_env()
into the real Info property, asserting the whole event matrix and the linked PR
number parsed from the queue head ref. It deliberately does not mock the
predicate: the merge-queue tests in ci/tests/test_gh.py build a SimpleNamespace
with is_merge_queue_event=True, which is why they could not catch this.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@groeneai

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

Two independent review passes over this diff before it was opened: a cold read by a reviewer that
had not seen the implementation notes, then an independent model gate. Verdicts below; nothing was
overridden silently.

Result: 0 blockers, 0 majors. 3 nits, all in this PR's description, all fixed before opening.
The independent gate returned no findings, having read both changed files in full plus every
EVENT_TYPE producer, the sibling predicates, the workflow mappings and the existing tests, and
having confirmed that reverting the predicate makes the new test fail.

# Finding Verdict
💡 The breadth table quoted 39 passing merge-queue rows; re-derived at review time it is 40 (36 distinct PRs). AGREE - refreshed and stamped with the measurement time. I also checked all 36 of those PRs' file lists to confirm none touches SettingsChangesHistory.cpp, which turns "took the early return" into a verified claim rather than an inference.
💡 The fail-close message was quoted but the CI report was not linked. AGREE - canonical report URL added.
💡 The same gate was cited as both store_data.py:97-99 and :98, and check_style.py:596-616 was approximate. AGREE - line numbers replaced with function names, since ci/ line numbers rot quickly.

Checks the cold pass ran independently rather than taking on trust:

  • The fix's premise is exhaustive, not merely usual. Comparing against the enum is only correct
    if EVENT_TYPE never holds anything else. All 7 writers enumerated: _environment.py (6 sites,
    all Workflow.Event.*) and runner.py (workflow.event, and every ci/workflows/*.py passes a
    Workflow.Event.* constant). No exceptions.
  • Carrier sweep re-derived from scratch, then compared against the implementation plan: it
    matched with no divergence. EVENT_TYPE == has exactly three production sites; the two siblings
    compare literals that equal their enum values, and _environment.py's "merge_group" in github_event legitimately reads the webhook payload.
  • Import-cycle safety re-proven with an independent AST walk, which also covers the
    infrastructure/ subpackage: the transitive top-level relative-import closure of workflow.py is
    16 modules and contains neither info nor _environment.
  • Test liveness traced rather than assumed. Only _Environment.get is monkeypatched; the
    property and the EVENT_TYPE it reads are production code, and the false direction is asserted
    for all four other events, so a predicate returning True unconditionally would also fail.
  • Every disclosed behaviour change verified. In particular the newly reachable fail-closed
    raise is not expected to fire: all 6510 distinct merge-queue head refs in 180 days match the
    canonical shape and none is unparseable; and 0 of 2699 refs name more than one PR, so the
    "one queue entry, one PR" premise the two call sites rely on holds empirically.
  • The two currently blocked PRs will not be spuriously reddened by the newly activated
    validator: Parallelize the final merge of single-level aggregation hash tables #110395's own entry is under the 26.8 block, and the file has a single
    addSettingsChanges map transition, so the namespace attribution the hook and the check share
    cannot mis-attribute.

Session id: cron:clickhouse-review-slot-49:20260728-054501

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Driving #110395's real merge_group payload through _Environment.from_env() prints EVENT_TYPE='merge_queue' and EVENT_TYPE == "merge_group" -> False on every run. A pure string comparison, so no timing or randomization is involved; CIDB shows 5/5 merge-queue entries that touched SettingsChangesHistory.cpp failed, 3 of them the same PR on 3 consecutive attempts.
b Root cause explained? Yes. EVENT_TYPE only ever holds a Workflow.Event value and Workflow.Event.MERGE_QUEUE == "merge_queue", while "merge_group" is GitHub's event name. The predicate is therefore never true in the queue, so store_data.py:83 computes strict=False and :97-99 skips the settings-history block, and check_style.py:596-616 fail-closes with "no data recorded by the store_data.py workflow hook".
c Fix matches root cause? Yes. The comparison is corrected at the single point where EVENT_TYPE is interpreted, against the enum constant so the value and GitHub's event name cannot drift again. No bound widened, no check disabled, no symptom guarded.
d Test intent preserved / new tests added? Yes. No existing test was weakened or removed. New ci/tests/test_info_event_type.py drives the real payload -> environment -> property chain; its docstring records why the merge-queue tests in test_gh.py structurally cannot catch this (they build a SimpleNamespace with is_merge_queue_event=True, mocking the predicate itself).
e Both directions demonstrated? Yes. With the fix: 5 passed. With info.py reverted to the "merge_group" literal: test_is_merge_queue_event_true_in_merge_queue fails on assert info.is_merge_queue_event. Restored: 5 passed.
f Fix is general across code paths? Yes. A repo-wide grep for the same drift class in ci/ finds no other offender; all 7 EVENT_TYPE writers already store enum values. The two sibling predicates compare literals that equal their enum values (verified and now asserted). _environment.py:152's "merge_group" in github_event is correct - it reads the GitHub payload - and is untouched. All 6 downstream consumers are fixed by the one change rather than patched individually.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. The full event matrix is asserted: merge_group -> True, and pull_request / push / schedule / dispatch -> False, each with its EVENT_TYPE pinned; the queue head ref is also asserted to yield linked_pr_number == 110395, so the usable merge-queue identity is pinned and not just the boolean. Type wrappers and numeric boundaries do not apply (one string field in CI tooling).
h Backward compatible? (maintainer-approved exception only) Yes. No setting, no serialization format, no C++, no YAML change (regenerating .github/workflows produces an empty diff). The behaviour change is intentional and described in the PR body: the settings-history validator starts running in the merge queue, gh.py regains its fail-closed path, and the merge-queue flaky budget tightens as its design intended.
i Invariants and contracts preserved? Yes. Invariant: a merge-queue run is identified by comparing EVENT_TYPE against praktika's own Workflow.Event enum, never against GitHub's event name. The property keeps its bool contract for all five events. The new top-level import cannot create a cycle - the transitive top-level relative-import closure of workflow.py is {Artifact, Job, docker, secret, utils} and contains neither info nor _environment - and info.py's deliberately deferred _environment import is left alone. gh.py's newly reachable fail-closed raise lands in a pre-hook, which native_jobs.py:643/657 turns into a failed Pre Hooks result rather than a hang or a silent skip.

Session id: cron:clickhouse-impl-slot-5:20260728-051600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv — could you review this? Info.is_merge_queue_event compared EVENT_TYPE against GitHub's event name merge_group while praktika only ever stores its own enum value merge_queue, so the predicate was never true in the merge queue and store_data.py silently skipped the settings-history half of its work, which is what fail-closes the settings_changes_history sub-check you added in #111605.

@nihalzp nihalzp added the can be tested Allows running workflows for external contributors label Jul 28, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9ef8826]

Summary: ✅


AI Review

Summary

This PR fixes Info.is_merge_queue_event to compare EVENT_TYPE against Workflow.Event.MERGE_QUEUE instead of GitHub's merge_group event name, and adds focused tests that drive real webhook payloads through _Environment.from_env() into Info. I did not find a surviving correctness, coverage, or metadata issue in the current head; the changed invariant matches every current EVENT_TYPE writer and the PR CI is green.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 28, 2026
@nihalzp nihalzp self-assigned this Jul 28, 2026
@nihalzp
nihalzp added this pull request to the merge queue Jul 28, 2026
Merged via the queue into ClickHouse:master with commit 5f1fed5 Jul 28, 2026
178 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 28, 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