Skip to content

CI: do not fail Build Post Hooks when build profile artifacts are absent - #107117

Merged
maxknv merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-build-profile-hook-missing-artifacts
Jun 18, 2026
Merged

maxknv merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-build-profile-hook-missing-artifacts

Conversation

@groeneai

@groeneai groeneai commented Jun 11, 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

The build_profile_hook post-hook runs on every master Build job and uploads three artifacts that utils/prepare-time-trace/prepare-time-trace.sh produces: the time-trace profile, binary_sizes.txt, and binary_symbols.txt.

prepare-time-trace.sh does not emit every artifact for every build:

The hook opened all three files unconditionally, so on LTO release builds and cross-arch builds the missing file raised FileNotFoundError, which the broad except turned into sys.exit(1), failing the Post Hooks check. This has failed on master across all such Build variants for months (top variants arm_release and amd_release are LTO builds).

The fix uploads whatever prepare-time-trace.sh actually produced and skips artifacts that are absent or empty, instead of failing the whole post-hook. Added ci/tests regression coverage for the LTO, cross-arch, and native-build cases.

Reproduced on master HEAD (Build (arm_release)): https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=fc73f46fae655b1fb5e5dc447c121c844a8a6295&name_0=MasterCI&name_1=Build%20(arm_release)

ERROR: Failed to upload build profile data:
  ...
  File "ci/jobs/scripts/log_cluster.py", line 135, in insert_binary_symbol_data
    with open(file, "rb") as data_fd:
FileNotFoundError: [Errno 2] No such file or directory: 'ci/tmp/profiles_source/binary_symbols.txt'

Version info

  • Merged into: 26.6.1.973

The build_profile_hook post-hook runs on every master Build job and uploads
three artifacts produced by utils/prepare-time-trace/prepare-time-trace.sh:
the time-trace profile, binary_sizes.txt, and binary_symbols.txt.

prepare-time-trace.sh does not emit every artifact for every build.
binary_symbols.txt is produced only for non-LTO builds (the script guards nm
with 'if ! grep -q -- -flto', since nm does not work with LTO), and cross-arch
or non-Linux builds produce no readable objects at all (issue ClickHouse#84159). The hook
opened all three unconditionally, so on LTO release builds and cross-arch builds
the missing file raised FileNotFoundError, which the broad except turned into
sys.exit(1), failing the 'Post Hooks' check on master across all such build
variants for months (top variants arm_release and amd_release are LTO builds).

Upload whatever prepare-time-trace.sh actually produced and skip artifacts that
are absent or empty, instead of failing the whole post-hook. Add ci/tests
regression coverage for the LTO, cross-arch, and native-build cases.

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

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. The live failure on master HEAD (Build (arm_release)) is FileNotFoundError: ...binary_symbols.txt at log_cluster.py:135. Locally reproduced deterministically by running the artifact-upload loop against a profiles_source dir that mimics an LTO build (profile + binary_sizes.txt present, binary_symbols.txt absent): old code exits 1 every time, new code exits 0 every time.
b Root cause explained? build_profile_hook.py runs only on master (Info().pr_number == 0) on every Build variant and uploads three artifacts. prepare-time-trace.sh produces binary_symbols.txt only for non-LTO builds (if ! grep -q -- '-flto'; "nm does not work with LTO"); release builds use ThinLTO so the file is never created (cross-arch/non-Linux builds produce nothing at all, issue #84159). The hook opened all three files unconditionally, so the missing file raised FileNotFoundError, the broad except did sys.exit(1), and the Post Hooks check failed. This matches the master-only, all-variants, 0-PR chronic signature exactly (top variants arm_release/amd_release are LTO).
c Fix matches root cause? Yes. The fix skips uploading any artifact that prepare-time-trace.sh legitimately did not produce (missing or empty file) and uploads the rest, instead of aborting the whole post-hook. It does not widen any assertion or silence anything beyond the genuinely-absent artifacts.
d Test intent preserved / new tests added? New tests added: ci/tests/test_build_profile_hook.py covers the LTO case (symbols absent, profile+sizes still uploaded), the cross-arch case (nothing produced, no failure), and the native build (all three uploaded). Profile and binary-size telemetry still upload on every build that produces them, so the hook's purpose is preserved.
e Both directions demonstrated? Yes. Against the original unconditional-open logic, the LTO and cross-arch regression tests FAIL with FileNotFoundError; against the fixed logic all tests PASS. (pytest is unavailable in the local sandbox, so the directions were validated via a standalone runner that mimics pytest's tmp_path; the tests use only the stdlib + pytest's tmp_path fixture, which CI's ci_tests_job.py runs under real pytest.)
f Fix is general, not a narrow patch? Yes. The guard is applied uniformly to all three artifact inserts via a shared helper, so the same defect cannot recur for profile.json or binary_sizes.txt. The fix is at the correct layer: the missing file is not an upstream bug to trace (prepare-time-trace.sh intentionally skips symbol extraction for LTO builds), it is expected build-flavor-dependent output, so the hook must tolerate it rather than the producer being "fixed".

Session id: cron:clickhouse-worker-slot-21:20260611-001400

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv — could you review this? The build profile post-hook (build_profile_hook.py) opens all three prepare-time-trace.sh artifacts unconditionally, but binary_symbols.txt is only produced for non-LTO builds and cross-arch builds produce nothing, so on LTO release / cross-arch master builds the missing file raises FileNotFoundError and fails the Post Hooks check (this is the chronic master Build Post Hooks failure, and issue #84159). The fix uploads whatever was produced and skips absent artifacts.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7040fed]

Summary: ❌

job_name test_name status info comment
BuzzHouse (amd_tsan) FAIL
Logical error: Mutation of Memory table produced incomplete output: A (STID: 2380-3043) FAIL cidb, issue ISSUE CREATED

AI Review

Summary

This PR makes build_profile_hook.py tolerate build variants where prepare-time-trace.sh legitimately produces no profile artifact data, while still uploading non-empty artifacts through the existing LogClusterBuildProfileQueries paths. The current producer-side xargs -r change fixes the previous bot finding: empty object input now leaves binary_sizes.txt empty instead of writing the malformed 0 row, and non-empty artifacts still propagate upload/parse failures. I found no unresolved review findings.

Tests
  • ⚠️ Local python3 -m pytest ci/tests/test_build_profile_hook.py could not run because this checkout environment has no pytest module. The PR CI report fetched with .claude/tools/fetch_ci_report.js reports no failed checks, and a direct prepare-time-trace.sh run against an empty build directory produced 0-byte binary_sizes.txt and binary_symbols.txt artifacts, supporting the empty-input fix.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 11, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI summary for HEAD 95fab8cf5e25 — the single red is a non-PR-caused chronic trunk finding:

  • AST fuzzer (arm_asan_ubsan) — Logical error: Column identifier A is already registered (STID 4697-4326). Chronic analyzer trunk bug: 112 unrelated PRs / 10 master hits in 30d, tracked under the dedicated P0 task. Unrelated to this CI-only change (Build Post Hooks artifact-absence guard).
  • Fast test, Style check, Build, and all other jobs pass or skip.

CH Inc sync red is the internal CH mirror sync, expected on fork PRs.

@maxknv

maxknv commented Jun 11, 2026

Copy link
Copy Markdown
Member

@groenai, can you make the hook no-op for builds that do not produce profile data and do the profile data upload for others? If any error on the way, it should explicitly fail.

@maxknv
maxknv self-requested a review June 11, 2026 08:37
@maxknv maxknv self-assigned this Jun 11, 2026
Address review on ClickHouse#107117.

prepare-time-trace.sh collects binary sizes with `find ... | xargs wc -c`.
On a build with no readable objects (cross-arch / non-Linux) GNU xargs runs
`wc -c` once with no arguments and writes a bare `0` row into
binary_sizes.txt. That row does not match the binary_sizes FORMAT Regexp, so
insert_build_size_data still failed and the post-hook exited 1 - the exact
case this PR set out to fix. The earlier "skip absent or empty artifact"
guard did not help because the file was non-empty.

Fix at the producer: use `xargs -r` on the size and symbol collection so an
empty input set leaves the artifact empty instead of emitting a junk row.
With that, an empty artifact reliably means "no such profile data for this
build", and the hook can: no-op for builds that produce no data, upload for
builds that do, and fail loudly on any genuine processing or upload error
(it never swallows one).

Regression tests now run the real producer against an empty build dir and
assert binary_sizes.txt is empty, model the present-but-empty producer output
for the cross-arch case instead of an absent file, and cover that an upload
error propagates.

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

Copy link
Copy Markdown
Collaborator Author

@maxknv pushed 7040fed, implementing exactly the model you asked for, and fixing the bot's 0\n point at the producer.

Root of the remaining failure (bot was right): the previous guard skipped absent/empty artifacts, but prepare-time-trace.sh collects sizes with find ... | xargs wc -c. On a build with no readable objects, GNU xargs runs wc -c once with no args and writes a bare 0 into binary_sizes.txt. That row is non-empty (so it passed the guard) and does not match the binary_sizes FORMAT Regexp, so insert_build_size_data still failed and the hook exited 1 - the cross-arch case this PR claims to fix.

Fix is at the producer (the bot's preferred option): xargs -r on both the size and symbol collection, so an empty input set leaves the artifact empty instead of emitting a junk row. I did not add row-skipping in the hook on purpose - that would silently swallow genuinely malformed data, which contradicts your "if any error on the way, it should explicitly fail".

With the producer fixed, an empty artifact reliably means "no such profile data for this build", so the hook now:

  • no-ops for builds that produce no data (empty artifacts are skipped),
  • uploads for builds that do,
  • fails loudly (sys.exit(1)) on any genuine error - producer crash (Shell.check(strict=True) raises) or rejected upload (assert do_query(...)).

Tests (ci/tests/test_build_profile_hook.py): added a test that runs the real producer on an empty build dir and asserts binary_sizes.txt is empty (fails on the old xargs without -r, passes now); the cross-arch test now feeds the real present-but-empty producer output instead of an absent file; and a new test asserts an upload error propagates rather than being swallowed. All 8 pass.

Verified both directions: old producer writes 0\n (2 bytes) -> new producer test fails; new producer writes empty -> passes.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. Running prepare-time-trace.sh <empty-build-dir> <out> (the no-readable-objects / cross-arch case) deterministically wrote binary_sizes.txt containing 0\n (2 bytes) on the pre-fix xargs wc -c. That 0 row is uploaded by the hook and fails _build_size_query's FORMAT Regexp (^\s*(\d+) (.+)$ needs a filename), so insert_build_size_data asserts and the post-hook exits 1.
b Root cause explained? The hook's "skip absent/empty artifact" guard was insufficient because the producer never left the artifact empty: with no matching files, GNU xargs runs wc -c once with no args -> writes 0\n -> non-empty -> passes the guard -> uploaded -> regexp parse fails -> exit 1. So the cross-arch case the PR set out to fix still failed.
c Fix matches root cause? Yes. Fix at the producer: xargs -r on both the size and symbol collection, so empty input emits no row and leaves the artifact genuinely empty. Did NOT add row-skipping in the hook on purpose - that would silently swallow truly-malformed data, contradicting the "explicitly fail on any error" requirement. With the producer fixed, empty == no-data, so the hook no-ops for no-data builds, uploads for builds with data, and fails loudly on any genuine producer/upload error.
d Test intent preserved / new tests added? Yes. Added test_producer_no_objects_leaves_binary_sizes_empty (runs the real producer on an empty build dir, asserts empty output - models the real producer per the bot's request); changed the cross-arch test to feed present-but-empty files (real producer output) instead of an absent file; added test_upload_error_propagates proving genuine errors are not swallowed. Existing LTO / native / _has_data tests retained.
e Both directions demonstrated? Yes. Pre-fix producer (xargs without -r) -> binary_sizes.txt = 0\n (2 bytes) -> new producer test FAILS. Post-fix producer (xargs -r) -> empty file -> test PASSES. Full suite: 8 passed, 0 failed.
f Fix is general, not a narrow patch? Yes. Applied xargs -r to both empty-input pipelines in the producer (size collection and symbol collection), not just the one the report named. The hook handles all three artifacts uniformly via _upload_profile_artifacts, so LTO (missing symbols), cross-arch (no objects), and native (all present) are all covered by the same logic.

Session id: cron:clickhouse-worker-slot-8:20260611-091900

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Jun 11, 2026
@maxknv
maxknv enabled auto-merge June 11, 2026 10:21
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finished on 7040fed. The only failed check is BuzzHouse (amd_tsan), and it is a known chronic trunk flake, not caused by this PR:

  • BuzzHouse (amd_tsan): Logical error "Mutation of `Memory` table produced incomplete output" (STID 2380-3043). 142 hits across 119 PRs and 15 master runs in the last 30 days; the fix is tracked separately in PR Fix Memory table abort on ALTER commands with no per-row data effect (STID 2380-3043) #106621. This PR only changes ci/jobs/scripts/job_hooks/build_profile_hook.py, utils/prepare-time-trace/prepare-time-trace.sh and ci/tests, none of which are on the Memory-engine mutation path.
  • CH Inc sync / Mergeable Check: aggregators reflecting the BuzzHouse red, not independent failures.

The other 3 BuzzHouse builds and all Stateless/Integration/Stress jobs passed on this commit. A BuzzHouse re-run clears Mergeable Check.

Session: cron:our-pr-ci-monitor:20260618-050000

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finished on 7040fed5a28b. The only red is BuzzHouse (amd_tsan):

All other checks pass. No PR-caused failures.

@maxknv
maxknv added this pull request to the merge queue Jun 18, 2026
Merged via the queue into ClickHouse:master with commit addb0fa Jun 18, 2026
164 of 166 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 18, 2026
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Jun 27, 2026
The build_profile_hook post-hook runs on every master Build variant and
uploads compile-time-trace telemetry to a shared remote analytics DB. The
~25 variants of a master push finish and upload at once, so the per-user
INSERTs routinely cross the DB's memory limit and one is killed with
Code: 241 MEMORY_LIMIT_EXCEEDED (during ParallelParsingBlockInputFormat).
insert_* turns that rejection into an AssertionError, which the hook treated
as fatal (sys.exit 1), so a successful build was reported as a failed
"Post Hooks" check.

This telemetry is observability-only and has no bearing on the produced
binaries, so a rejected upload must not fail the build. Catch upload errors
per artifact in _upload_profile_artifacts, log them, and continue. Genuine
build/producer errors still fail loudly: they surface earlier, in
prepare-time-trace.sh under strict Shell.check and in local file assembly,
outside the upload loop.

PR ClickHouse#107117 guarded the missing/empty-artifact case (ClickHouse#84159) but left the
remote-rejection case fatal; this addresses that remaining mechanism, which
is the dominant cause of the chronic master Build Post Hooks failures across
all variants (~600/day, build-content-independent).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The build_profile_hook post-hook runs on every master Build variant and
uploads compile-time-trace telemetry to a shared remote analytics DB. The
~25 variants of a master push finish and upload at once, so the per-user
INSERTs routinely cross the DB's memory limit and one is killed with
Code: 241 MEMORY_LIMIT_EXCEEDED (during ParallelParsingBlockInputFormat).
insert_* turns that rejection into an AssertionError, which the hook treated
as fatal (sys.exit 1), so a successful build was reported as a failed
"Post Hooks" check.

This telemetry is observability-only and has no bearing on the produced
binaries, so a rejected upload must not fail the build. Catch upload errors
per artifact in _upload_profile_artifacts, log them, and continue. Genuine
build/producer errors still fail loudly: they surface earlier, in
prepare-time-trace.sh under strict Shell.check and in local file assembly,
outside the upload loop.

PR ClickHouse#107117 guarded the missing/empty-artifact case (ClickHouse#84159) but left the
remote-rejection case fatal; this addresses that remaining mechanism, which
is the dominant cause of the chronic master Build Post Hooks failures across
all variants (~600/day, build-content-independent).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
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 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.

4 participants