Skip to content

Build profile diff: report why a gh api call failed - #115201

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-build-profile-diff-gh-api-error-reporting
Sep 20, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-build-profile-diff-gh-api-error-reporting

Conversation

@groeneai

@groeneai groeneai commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #115061

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 failed on #115061 with a message naming only the gh argv
(report,
job log):

CalledProcessError: Command '['gh', 'api', 'repos/ClickHouse/ClickHouse/commits?sha=a3f55f04…

Two things discarded the reason. _list_commits_page used check=True, and
CalledProcessError.__str__ renders only argv, so the captured stderr/stdout carrying the HTTP
status were never read. The message then went through md_code, a table-cell name formatter
(MAX_NAME_LEN = 100), cutting the tail. So 404, 403 and 5xx produced the same 102-character
string, and the walk makes up to 60 calls without naming which failed.

Report it instead: exit code and endpoint first, then stderr and stdout each capped at 300
characters with an elision marker, in the field order GH.get_output_with_retries uses.
TimeoutExpired is caught in the same place. timeout=120 is kept deliberately - gh bounds
connect and TLS handshake but not a stalled response body (measured 240 s unbounded), so the shared
praktika helper, which passes no timeout, would unbound a bounded call site.

md_message is added beside md_code for the comment path, bounded head+tail so the end of a
message survives. Its fence is also longer than any backtick run in the text: this file's
own `master_track_commits_sha` fail-close message otherwise closes the span early and leaks
into prose, as it already does under md_code. md_code and MAX_NAME_LEN are untouched: its 17
name callers are byte-identical. The bound matters beyond gh: a cluster query failure reaches the
same handler carrying its whole inlined SQL, 54952 characters against GitHub's 65536 limit.

The gh api failure itself is environmental and out of scope: the same call succeeds 25/25 by
hand.

Validated with throwaway harnesses plus mutation arms reverting each hunk; every rendering verdict
comes from GitHub's own /markdown endpoint. ci/tests/: 711
passed, its 2 failures pre-existing on master. No committed test, per .claude/CLAUDE.md:
ci/tests/test_build_profile_diff_job.py was removed in #114675.


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

The job's only record of a failed commits-walk fetch was the gh argv:

  CalledProcessError: Command '['gh', 'api', 'repos/ClickHouse/ClickHouse/
  commits?sha=a3f55f0418cdd06...

Two places discarded the reason. _list_commits_page ran subprocess.run with
check=True, and CalledProcessError.__str__ renders only argv, so the captured
stderr and stdout - the fields carrying the HTTP status - were never read
(measured against a real 404: e.stderr held 'gh: Not Found (HTTP 404)' and
e.stdout the full JSON body). The resulting message then passed through
md_code, a table-cell name formatter whose MAX_NAME_LEN is 100, which
head-truncates and so dropped the tail as well. A 404, a 403 rate limit and a
5xx therefore rendered the same 102-character string in the public pull
request comment, and since the walk performs up to EXTEND_MAX_PAGES fetches
the message did not say which anchor or page had failed.

Report the failure instead: exit code and endpoint first, then stderr and
stdout each capped at 300 characters with an explicit elision marker,
mirroring the field order and cap that GH.get_output_with_retries already
uses. Catch TimeoutExpired in the same place so a stalled request says it
timed out. The timeout is kept: gh self-bounds connect (30 s) and TLS
handshake (10 s) but not a stalled response body, measured at 240 s
unbounded, so routing this through the shared praktika helper - which passes
no timeout - would have regressed a bounded call site to an unbounded one.

Add md_message beside md_code for the comment path, bounded head+tail so the
end of a message survives. md_code and MAX_NAME_LEN are untouched, so the
name callers keep their behaviour. The bound matters beyond gh: a cluster
query failure reaches the same handler carrying its whole inlined SQL, which
for the extended master chain measures 54952 characters against GitHub's
65536-character comment body limit.

The underlying gh api failure is not addressed here. It is environmental and
unreproducible outside CI - the byte-identical call succeeds 25 of 25 by
hand, failures interleave with successes through the day, and carriers are
both fork and non-fork pull requests. The point of this change is that the
next occurrence records its own HTTP status.

No committed test: ci/tests/test_build_profile_diff_job.py was removed in
PR ClickHouse#114675 and .claude/CLAUDE.md asks for a throwaway test for CI scripts.
Verified with a 30-assertion throwaway harness plus three mutation arms, each
reverting one hunk and reddening named assertions.
@groeneai

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

Two independent passes over this diff: a cold read of the resulting code, then a second-model
review of the full change scope. Both found no blocking issue. Three nits, all disposed below.

# Finding Verdict
💡 1 The validation-gate table claimed backtick and pipe handling was "at parity with md_code". Measured false: md_code escapes |, md_message does not. ❌ Fixed in the text. The behaviour is right and unchanged - all 17 md_code calls feed table cells, where an unescaped pipe splits a column, while md_message has one caller, in prose. The wording overstated it; corrected rather than the code.
💡 2 Raising the comment bound from 100 to 1000 characters lets more of the fixed No \master_track_commits_sha` metadata` message through, and its two unescaped backticks break an inline code span. ⚠️ Pre-existing, not introduced. Under the old 100-character cap the cut falls at index 99 while the backticks sit at 17 and 42, so both already survive and the span is already broken today. An AST scan of every non-docstring literal confirms no generated SQL carries a backtick, so the cluster-query path is clean. Escaping it would change a message unrelated to this root cause.
💡 3 _elide_stream duplicates ci/praktika/gh.py:_elide byte for byte, cap included. ⚠️ Deliberate. _elide is a module-private name in another package; the only precedent for importing one is praktika._environment._Environment. Importing the enclosing GH.get_output_with_retries instead was measured and rejected: it passes no timeout, and a stalled response body ran 240 s unbounded, so it would have made this bounded call site unbounded. Five duplicated lines beat that coupling.

Also verified independently rather than taken from the change: CalledProcessError.__str__
renders argv only, with both captured streams dropped; md_code on the real 268-character message
yields a 102-character render that stops mid-sha; the real 404 message measures 289 characters and
the worst case with both streams at the cap measures 793, so the reason genuinely survives to the
comment rather than being re-truncated. md_code and MAX_NAME_LEN are byte-identical, the
extend_master_shas fail-close is unchanged, exactly one attempt is still made, and gh does not
echo its token on a 401.

Session id: cron:clickhouse-review-slot-10:20260817-192500

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, no network and no build. A fake gh on PATH selects the HTTP status, and _list_commits_page then reproduces the live comment byte for byte: `CalledProcessError: Command '['gh', 'api', 'repos/ClickHouse/ClickHouse/commits?sha=a3f55f0418cdd06…` (268 chars truncated to 102), with e.stderr == 'gh: Not Found (HTTP 404)' and the JSON body unread in e.stdout.
b Root cause explained? Yes. check=True raises CalledProcessError, whose __str__ renders only argv, so the captured streams naming the HTTP status are dropped. The message then passes through md_code, a table-cell name formatter (MAX_NAME_LEN = 100) that head-truncates and loses the tail. The walk makes up to EXTEND_MAX_PAGES = 60 calls, so the old message did not identify which anchor or page failed.
c Fix matches root cause? Yes. It reports the streams that were already captured, at the site owning the call. No retry, no widened bound, no suppression, no defensive guard. The documented fail-close in extend_master_shas is unchanged; only what it reports changed.
d Test intent preserved / new tests added? No test weakened: md_code and MAX_NAME_LEN are untouched and a control assertion pins their behaviour. No committed test by design - ci/tests/test_build_profile_diff_job.py was removed in #114675 and .claude/CLAUDE.md asks for a throwaway for CI scripts. A 30-assertion throwaway harness plus three mutation arms was used instead.
e Both directions demonstrated? Yes. Before: 404, 403 and 5xx render 1 distinct message of 3, cause unrecoverable. After: 3 of 3, each naming its status. Reverting each hunk reddens named assertions (arm A 20/30, arm B 16/30, arm T 20/30); the fix arm is 30/30.
f Fix is general across code paths? Yes. The file's only gh call site is fixed; the one remaining check=True is a [tool, "--version"] presence probe with no remote body and is deliberately left. Both _walk_first_parent callers propagate the new RuntimeError as they did CalledProcessError, and the --local path (seed_master_shas) gains the message too. The comment bound covers every exception reaching that handler, not only the gh one, which is why a cluster query failure (54952 chars) is now bounded rather than cut to 102.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes, boundary matrix run for both bounds. md_message: 0/1/2/999/1000 pass through unchanged, 1001/1002/65536/200000 elide with a marked char count. _elide_stream: 0/1/299/300 pass through, 301/100000 elide, whitespace-only becomes empty. Stream sources covered: stderr only, stdout only (the measured real 404 put JSON only there), and both empty (500). md_message deliberately does not escape `
h Backward compatible? (maintainer-approved exception only) N/A, nothing engaged. No setting, no SettingsChangesHistory.cpp, no serialization format, no user-visible behaviour. The job still fails, still red, still fail-closes, still posts a comment. Category CI Fix or Improvement.
i Invariants and contracts preserved? Yes. Same argv, same timeout value, same parsed list on success (verified including row keys), raises on failure. Exactly one attempt is asserted by counting invocations, pinning that no retry was added. TimeoutExpired is re-raised with from e, preserving the cause chain; json.JSONDecodeError on a malformed success body still propagates. Only stderr, stdout and our own argv are interpolated, never an env value: a ghp_-shaped GH_TOKEN is asserted never to appear.

Session id: cron:clickhouse-impl-slot-7:20260817-183500

@clickhouse-gh

clickhouse-gh Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [869bfdd]

Summary: ✅


AI Review

Summary

This PR changes Build profile diff so a failing gh api call reports the exit code, endpoint, and capped stderr/stdout, and it switches the public failure comment from md_code to a backtick-safe md_message. After reviewing the current diff, the live code, and the existing discussion, I did not find a new correctness, safety, or reliability issue.

Final Verdict

✅ No findings.

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

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov @leshikus, could you review this? _list_commits_page ran gh api with check=True, and CalledProcessError.__str__ renders only argv, so the captured stderr and stdout naming the HTTP status were dropped; the message then went through md_code, a table-cell name formatter capped at 100 chars, which cut the tail, so 404, 403 and 5xx all rendered the same string in the PR comment.

@groeneai groeneai added the groeneai-origin-ci-own-pr PR origin: CI on a groeneai PR exposed a separate defect label Aug 19, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Sep 4, 2026
@groeneai groeneai added the can be tested Allows running workflows for external contributors label Sep 5, 2026
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 5, 2026
Comment thread ci/jobs/build_profile_diff_job.py Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 869bfddd7 with master 4b3f269d1 (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

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

14 translation units recompiled, 9 s compile time in total, 12 of them have a recent master baseline.

Job report

groeneai and others added 2 commits September 5, 2026 21:21
The build-profile-diff comment renders a failing exception inline in a code
span. A CommonMark span closes at the first backtick run whose length equals
the opener, and a backslash is not an escape inside a span, so a message
carrying backticks of its own escaped the span and the remainder of the
diagnostic rendered as prose.

This file raises exactly such a message: "No `master_track_commits_sha`
metadata - cannot anchor the baseline on the PR's master parent". Measured
through GitHub's /markdown endpoint in gfm mode, the whole message now lands
in a single <code> element; before, it split into three spans with the
setting name leaking out as prose. The defect predates this change (the same
message under md_code's 100-char cap keeps both backticks and breaks
identically), but md_message is the helper that promises to carry free-form
text, so that is where it belongs.

The fence is the shortest backtick run absent from the text. A message whose
first or last character is a backtick additionally gets a space, which the
renderer strips back off: without it the run merges with the fence into a
longer run and the span never opens at all.

Reported by clickhouse-gh[bot] on the pull request.
@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 19, 2026
Merged via the queue into ClickHouse:master with commit ff454dd Sep 20, 2026
175 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 20, 2026
alexey-milovidov pushed a commit to tripleaceme/ClickHouse that referenced this pull request Oct 19, 2026
…ter walk

`_list_commits_page` ran one `gh api repos/ClickHouse/ClickHouse/commits`
call and raised on the first non-zero exit or timeout, and the per-TU
master first-parent walk makes ~20 such calls per job. GitHub fails single
requests (HTTP 503 and 504, a body cut short so `--jq` reports `unexpected
end of JSON input`, a stalled body) while the requests around them succeed,
so one blip errored the whole check: 9 jobs on 9 PRs between 2026-10-03 and
2026-10-14, the failing anchors 11-15 days deep in walks whose earlier
fetches had just succeeded, and the same commits passing on other runs.

Retry the listing up to 3 times (after 5 s, then 10 s), keeping the 120 s
per-call timeout. A timeout, an HTTP 5xx or 429, or a failure whose stderr
names no HTTP status is retried; any other 4xx (unknown sha, permissions)
fails at once, since `gh` reports an HTTP error as `gh: <message> (HTTP
<status>)`. After the last attempt the error propagates as before, so the
walk stays fail-close as the `extend_master_shas` docstring requires. The
praktika `GH` helpers retry but pass no subprocess timeout, which ClickHouse#115201
kept on this call site on purpose.

CI reports:
- https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=124959&sha=1d61eebf3fe5ed809d4811ea947169074a3e1712&name_0=PR&name_1=Build%20profile%20diff
  (ClickHouse#124959)
- https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125328&sha=ab772cc3b97c2e6777f2ef60723bcbeb5a5f29e3&name_0=PR&name_1=Build%20profile%20diff
  (ClickHouse#125328)
- https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122585&sha=bf8b2d2470663e1b5703c2014b7887fe2d5dd239&name_0=PR&name_1=Build%20profile%20diff
  (ClickHouse#122585)
- https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119371&sha=88edddd16dcd4250ac56e1642f964a03763097f4&name_0=PR&name_1=Build%20profile%20diff
  (ClickHouse#119371)

Co-Authored-By: Claude Opus 5.5 <[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 comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). 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 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