Skip to content

Anchor the Build profile diff master baseline windows on the run's own event - #115007

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-build-profile-diff-anchored-baseline-window
Aug 17, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-build-profile-diff-anchored-baseline-window

Conversation

@groeneai

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

Build profile diff fails closed with No master baseline with build profile data found - cannot compare when CI is re-run days after it was triggered, even
though the baseline rows are present. Failing run:
PR #113672 @ 494760825.

find_baseline intersects two sets measured from different origins: the
candidates are the frozen first-parent chain of the head's master parent
(master_track_commits_sha, chain relative), while the row filter was
date >= today() - BASE_DAYS (wall-clock relative). A re-run replays the frozen
event payload, so the chain stays anchored on the old merge base while today()
moves on, and once the gap exceeds BASE_DAYS the intersection is empty by
construction. On the run above, created_at is 2026-08-06T13:03:49Z against a
run_started_at of 2026-08-16T01:28:41Z: ten days, seven-day window. Eight
more sites share the mismatch, so fixing only find_baseline relocates the
error.

Every master-side window now derives from info.event_time, frozen with the
event, as a closed interval [anchor - N, min(anchor + 4 days, today)]. The
first-parent walk takes the same anchor and stops a whole upload day further
back, so the chain it returns is a superset of what those windows can match.
Closed rather than half-open because date leads the primary key of the profile
tables: the width is then fixed however old the event is, so the window slides
rather than grows. The upper bound allows for profiles uploaded after their
commit, measured at 4 hours p99 and 85 hours max over 673 master arm_release
builds.

Pull request side windows keep today() - PR_DAYS: those rows are uploaded by
the run itself. An anchor at today emits the same windows as before, a local run
keeps the wall-clock ones, and both fail-closes stand.

Driving the job with that run's real values reproduces the error on the current
module and resolves the baseline here.

Version info

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

…n event

`Build profile diff` failed closed with "No master baseline with build profile
data found - cannot compare" whenever CI was re-run some days after it was first
triggered, even though the baseline rows were present.

`find_baseline` intersected two sets measured from different origins. The
candidate set is the PR's anchored master chain, frozen at the head's `HEAD^1`
(`master_track_commits_sha`), so it is chain relative. The row filter was
`date >= today() - BASE_DAYS`, where `date` is the upload date, so it was
wall-clock relative. A GitHub Actions re-run replays the frozen event payload:
the chain stays anchored on the old merge base while `today()` moves on, and
once the gap exceeds BASE_DAYS the intersection is empty by construction rather
than for lack of data. On the run that prompted this the workflow's created_at
was 2026-08-06T13:03:49Z while run_started_at was 2026-08-16T01:28:41Z, a
ten-day gap against a seven-day window. `extend_master_shas` carried a second
instance of the same mismatch: it walks from a chain commit but stopped on a
wall-clock date.

Every master-side window is now derived from `info.event_time`, which is stamped
with the event and therefore frozen across a re-run, as a closed interval
[anchor - N, min(anchor + UPLOAD_DELAY_DAYS, today)], and the first-parent walk
takes the same anchor so it yields exactly the commits those windows accept.

The interval is closed rather than half-open because `date` leads the primary
key of all three profile tables: a bounded range prunes on it, and the width
stays fixed at N + UPLOAD_DELAY_DAYS however old the event is, so it slides
instead of growing. A half-open form would make the oldest pull requests issue
the heaviest queries against a cluster that already has a recorded per-user
memory ceiling. UPLOAD_DELAY_DAYS covers the gap between a master commit and
the last upload of its profile, measured over 673 master arm_release commits at
4 hours p99 and 85 hours maximum.

PR-side windows keep `today() - PR_DAYS`: those rows are uploaded by this run,
so they are always fresh, and widening them would only admit an older attempt of
the same commit. An anchor at today reproduces the previous behaviour exactly,
and an absent event_time (only LocalInfo, where --base-sha is mandatory and
short-circuits the baseline lookup) keeps the wall-clock windows. Both
fail-closes are unchanged: an empty result after anchoring is still a genuine
absence of data.
The first-parent walk and the per-TU SQL window share an anchor, but the window
admits rows the walk could not supply. The window's lower bound is a calendar
day, so it accepts uploads from that day's midnight, while the walk stopped at
the anchor's time of day: commits earlier on the boundary day were absent. The
window also deliberately admits a profile uploaded up to UPLOAD_DELAY_DAYS after
its commit, and those commits are older than the bound, so the walk never
reached them either. The tail the upper bound exists to admit was therefore the
tail whose shas were missing.

A missing sha is not a silent narrowing. The per-TU query intersects on
`commit_sha IN (...)`, so a translation unit whose only baseline lives on an
absent commit loses its rows and falls into the new-TU branch, which is
significant and reports "N new translation units without a master baseline"
against the pull request. Under-reaching the walk turns a delayed upload on
master into a finding about somebody's change.

The walk now stops at midnight UTC of the window's lower bound minus
UPLOAD_DELAY_DAYS, so the chain it returns is a superset of the commits the
window can return a row for. The horizon widens from TU_BASE_DAYS to
TU_BASE_DAYS + UPLOAD_DELAY_DAYS; measured against master, that costs 21 listing
fetches for 1247 first-parent commits, well inside EXTEND_MAX_PAGES.
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review

An independent model reviewed this change cold against the repository's review
skill over two rounds, and I adjudicated every finding against the code.

# Finding Verdict
❌ 1 walk_cutoff did not produce the superset its own docstring claimed: the per-TU SQL window accepts uploads from the start day (date BETWEEN '2026-07-23' AND ... for the failing run) while the walk stopped at the exact event time on that day (2026-07-23T13:03:45Z), so commits earlier that day, and commits whose upload lagged into the window, were absent from the SHA set the query intersects with. A translation unit whose baseline SHA is missing is not silently skipped: it is reported as a new TU without a baseline and marks the section significant. AGREED, fixed
❌ 2 The oracle that missed 1 pinned equality of the walk cutoff and the window start. AGREED, replaced
⚠️ 3 The description asserted the walk yields exactly the commits the windows accept. AGREED, corrected
⚠️ 4 The widened walk could push the commit_sha IN (...) list past the server's query-size limit. DISAGREED, with measurement
⚠️ 5 The four-day upper bound is measured on Build (arm_release) but also caps Build (arm_release_pr_cache_warmup) lookups, whose scheduling differs. DISAGREED, with measurement
💡 6 Comment style in the new helpers; black reports the file as unformatted. Not changed

On 1. The walk now stops at midnight of window start - 4 days. Verified as
a relation rather than a constant: over six event shapes and both window widths
the cutoff is at or before window start - 4 days and is always day-aligned.
The failing run's event now walks to 2026-07-19T00:00:00Z against a window
starting 2026-07-23.

On 2. Replaced by the invariant as a relation over event ages of 0, 1, 10 and
40 days, plus a day-alignment assertion. Two of the twelve mutation arms isolate
the day alignment and the upload-lag back-off separately, so neither correction
is decoration. The walk's page budget was then measured rather than assumed: the
19-day horizon needs 21 of the 60 available fetches (1247 first-parent commits
against a live master head), so the fetch cap is unchanged.

On 3. It yields a superset, not an equality. Corrected before publishing,
together with a second sentence claiming a fresh anchor reproduces current
behaviour "exactly": the windows are identical, but the walk deliberately reaches
further back on every run.

On 4. Refuted twice over. The query travels in the POST body rather than the
URI, so the URI limit does not apply, and the fetch cap bounds the chain at about
3.5k SHAs (153 KiB) against a 256 KiB default. The current horizon measures 1247
commits, 54 KiB.

On 5. The premise is right in kind and wrong in direction: the warmup build
is faster and tighter than the job the constant was measured on, so one cap
covers both with a wide margin. Over 30 days of master runs, commit entry to
last upload: arm_release_pr_cache_warmup 693 commits, p99 2.35 h, max
2.72 h
; arm_release 1417 commits, p99 3.71 h, max 85.1 h. Per-commit
first-to-last run spread: warmup p99 0.37 h / max 0.62 h against arm_release
p99 1.85 h / max 85.02 h. The 85-hour tail that sized the constant is an
arm_release re-run phenomenon with no warmup counterpart. The cap is 96 hours;
the warmup maximum is under 3.

On 6. The new helpers follow this file's established convention for stating
why a bound is shaped the way it is, so I left them rather than introducing a
second style into the same module. black reports this file as unformatted, but
so does master under the same invocation and there is no black gate in
check_style.py; reformatting would be unrelated churn.

One residual, disclosed and not chased: the closed upper bound can miss a master
profile uploaded more than four days after its commit, for example a manual
re-run of master's own build weeks later. That is the same fail-close direction
as today and strictly narrower than the current behaviour, which fails on every
re-run of an aged event.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Driving run_comparison with the failing run's real values (chain anchored 2026-08-06, job replayed 2026-08-16) raises No master baseline with build profile data found on the current module 100% of the time. Not probabilistic: the intersection is empty by construction once the event is older than BASE_DAYS.
b Root cause explained? Yes. find_baseline intersects a chain-relative candidate set (master_track_commits_sha, frozen HEAD^1) with a wall-clock-relative row filter (date >= today() - BASE_DAYS, on the upload date). A re-run replays the frozen event payload, so the chain stays on the old merge base while today() advances. Re-verified against the API: created_at 2026-08-06T13:03:49Z vs run_started_at 2026-08-16T01:28:41Z.
c Fix matches root cause? Yes. It makes the two sides commensurable at the origin by anchoring both on info.event_time, rather than widening a constant. Raising BASE_DAYS was rejected: it still breaks for any re-run older than the constant and scans more data on every pull request.
d Test intent preserved / new tests added? Yes. Both fail-closes are untouched, so a genuine absence of data still raises; no threshold widened, no assertion weakened. A throwaway test (28 assertions, 12 mutation arms) covers the change, per .claude/CLAUDE.md's stated convention for CI scripts. The walk-cutoff assertions pin the superset property as a relation over several event ages, not as a constant, so they survive a change to either window width.
e Both directions demonstrated? Yes. Pristine HEAD and the patched tree driven with an identical fake Db and identical inputs: BASE OUTCOME=ERROR (the reported message verbatim), FIX OUTCOME=SUCCESS.
f Fix is general across code paths? Yes. All nine carriers move together: find_baseline, find_warmup_baseline, both master-side resolve_run calls, both compare_compile_times windows, the Side drill-down, side_conditions by inheritance, and the extend_master_shas walk cutoff. Fixing only find_baseline relocates the error to the run-resolution raise; a mutation arm pins that. The three unchanged pull-request-side sites are justified and pinned by their own arm.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes, over the axis that exists here (anchor age): a future anchor clamps to today; an anchor at today emits the same windows as before; a ten-day-stale anchor widens correctly; an absent anchor falls back; the upper bound admits +4 days and excludes +5. The walk reaches a whole upload day past every window's lower bound, so its chain is a superset at every anchor age, verified over six event shapes and both widths. No type wrappers or settings matrix apply (Python CI tooling, no engine surface).
h Backward compatible? (maintainer-approved exception only) Yes. No setting default changes, so SettingsChangesHistory.cpp is not involved; no serialization or format change; no new metadata and no cross-job plumbing. The --local contract is preserved and smoke-tested. Every changed function has no callers outside this file, so the signature changes are internal.
i Invariants and contracts preserved? Yes. The baseline is still required to be an ancestor of the pull request's merge base: the candidate set is unchanged and only the date filter moved. The one-run-per-side pinning in Side still holds (the field swap is type-only), and the binary_sizes completion-marker ordering is untouched.

Session id: cron:clickhouse-review-slot-10:20260816-131400

@clickhouse-gh

clickhouse-gh Bot commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e16427c]

Summary: ✅


AI Review

Summary

This PR fixes Build profile diff reruns by anchoring the master-side date windows and the extended first-parent walk to the workflow event instead of the current wall clock. I did not find any new correctness or safety issues in the current diff; the change is threaded consistently through baseline selection, run resolution, and the per-TU compile-time path, and the follow-up walk_cutoff adjustment closes the remaining gap between the TU window and the SHA set it queries.

Final Verdict

✅ No new review findings.

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

Copy link
Copy Markdown
Collaborator Author

cc @maxknv, could you review this? Build profile diff looks for the baseline's profile rows in a wall-clock window while its candidate commits come from the frozen event payload, so any re-run more than BASE_DAYS after its trigger intersects the two to nothing and fails closed; every master-side window and the first-parent walk now anchor on info.event_time instead.

@yariks5s yariks5s added the can be tested Allows running workflows for external contributors label Aug 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - e16427c

CI is fully finished on this head and there are no failures to own: 177 leaves, 6 OK and 171 SKIPPED, 0 dropped, praktika top-level OK. Config Workflow, Style check, Code Review, CI Tests (0/655 failures) and Finish Workflow all concluded success; Mergeable Check, PR and CH Inc sync are success. CIDB reports 0 FAIL/ERROR per-test rows for this commit on the labelled run.

Check / test Reason Owner / fixing PR
(none) no failing check on this head (none required)

The high skip count is expected for a ci/-only diff and is not missing coverage: every skip carries an explicit reason (82 Not affected by the changed files and not required, 25 no build-affecting changes; coverage would be identical to master, 23 + 17 only CI scripts changed; running ... batch 1 only, 6 not labeled with 'pr-performance', 5 not a bug-fix PR, 5 no tests to run, 4 reused from cache, and 4 more), with zero DROPPED jobs. The CI Tests suite that actually exercises this change ran in full and is green.

Note the two earlier runs at this same head (13:52Z, 15:51Z) were voided by the can be tested label gate; the 21:19Z run is the first with real coverage and is the one this ledger covers.

Session id: cron:our-pr-ci-monitor:20260816-220000

@alexey-milovidov alexey-milovidov self-assigned this Aug 17, 2026

@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.

Looks okay.

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 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