Skip to content

Report the CI logs cluster's error when a Build profile diff read fails, and skip if it is unavailable - #118708

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:build-profile-diff-report-cluster-error
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:build-profile-diff-report-cluster-error

Conversation

@groeneai

@groeneai groeneai commented Sep 8, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #115706
Related: #120121

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

A failed CI logs cluster read in the Build profile diff check now reports the HTTP status and the server's error instead of being reported as a commit with no build profile data, and a read the cluster could not serve skips the comparison instead of failing the check.

Description

The reason: hand the cluster's error to the caller instead of printing it inside select(), and do not red a commit for a cluster that could not answer the read.

select returned None, so Db.query could only name the SQL it had sent. It now raises ReadFailure with the status and the cluster's error; the body check is generic, so no caller passes one in.

When every observed failure was the cluster failing to serve the read, it raises TransientReadFailure instead and the job is SKIPPED with a pinned comment saying the comparison did not run. That covers a >= 500, a timeout, and an error the server reports after already committing an ok status, which is how MEMORY_LIMIT_EXCEEDED usually arrives. A 403 or any other refusal, a probe answering something other than 1, and a comment that did not post all keep the check red. The skip is not cached, so a later run retries. The readiness probe is classified the same way; it used to print No connection to LogCluster with neither status nor body.

Replaces #120121, closed in favour of this one.


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

@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Sep 8, 2026
@groeneai

groeneai commented Sep 8, 2026

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

Pre-publication review by an independent model (engine: codex; 1 finding in the full pass,
0 in the delta recheck; bounded: 1 full pass + 1 fix round + 1 delta recheck). Four passes
in total, two of them the independent model, and one round of fixes, all of it in this branch
before it was published.

# Sev Finding Verdict Evidence / action
1 ⚠️ A body that is not a JSON object still lost the cause: the parse failure became an empty string and the raw-body branch ran only for a failing status, so an HTTP 200 carrying a plain-text error reached the second json.loads and raised a bare JSONDecodeError with neither the status nor the body, which is the defect this change exists to remove AGREE, fixed @ 833161d5 Raised independently by both passes. That shape is what a server writes when http_write_exception_in_output_format is off, the default since 25.11, and HTTPHandler.cpp says so where it falls back ("the error message will possibly be sent after some data. Also HTTP code 200 could have already been sent"). The body is now parsed once and a missing data is a failure, so the status and the capped body are reported at any status
2 ⚠️ "select is the only read transport in the repository" is false: CIDBCluster.do_select_query has the same shape AGREE, fixed @ 833161d5 Now "the CI logs cluster's only read path", in the commit message and here. The load-bearing half held up and I verified it separately: select has exactly one caller repository-wide, which is what makes the return-type change safe
3 💡 Db.query's docstring claimed the query is always in the log AGREE, fixed @ 833161d5 select prints it only when the status itself reported the failure; on the leg this change newly turns into a raise, select returns before printing and the call site comes from the traceback. Narrowed to exactly that
4 💡 select can hand back an earlier attempt's response when the last attempts raise, so the reported status may be a superseded one DISAGREE Returning None instead would discard a status and body the server really did produce, and the failed attempts already print their own tracebacks just above. Terminal
5 💡 The first version parsed the body twice DROPPED Measured at 9 ms on a 2.6 MB body against the ~47 s this job spends on one cluster round trip, so never a cost. Finding 1 removes it as a side effect, not as a performance fix

The delta recheck found nothing. One thing it looked for specifically: finding 1 adds a condition
that can reject, so the fix could have turned every pull request with no baseline row into a hard
failure. It does not, because the test is rows is None rather than truthiness, and an ordinary
empty result is still returned as []. A probe case pins that on both trees, alongside the two
that must now raise.

Not changed, deliberately: do_query and CIDBCluster.do_select_query keep their shape, and
whether an unreachable cluster should fail this job at all is left open for @ alexey-milovidov,
since it is his call and not something to decide by implementing it.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-9:20260908-035200

@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Sep 8, 2026
@clickhouse-gh clickhouse-gh Bot closed this Sep 8, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 8, 2026
@groeneai

groeneai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A real server plus a user granted SELECT(size) but not the queried columns reproduces the Code: 497 ACCESS_DENIED read failure on demand through the actual failing call site, has_pr_data -> Db.query -> LogCluster.select. 50/50 runs, exactly one distinct message.
b Root cause explained? LogCluster.select holds response.status_code and response.text, prints them, then return None. The cause is destroyed at that return, not at the raise, so its only caller Db.query could report just the SQL.
c Fix matches root cause? Yes: the discarded value is restored at the point of loss (select returns the response), and the one caller interprets it in the format it asked for. No widened bound, no suppression, nothing made green.
d Test intent preserved / new tests added? No committed test, deliberately: .claude/CLAUDE.md sanctions a throwaway for CI scripts and ci/tests/ was removed from master in #115650. The throwaway asserts 23 properties over eight response shapes and is reported here instead.
e Both directions demonstrated? Yes, on the shipped tree. Before: CI logs cluster query failed: SELECT count() AS c .... After: CI logs cluster query failed with status 403: Code: 497. DB::Exception: ... (ACCESS_DENIED). As a negative control the probe was run on the pristine tree: 15 of its 23 assertions fail there, while the two shapes that must keep working (a clean result, and an empty result set) pass on both.
f Fix is general across code paths? select is the CI logs cluster's only read path and has exactly one caller repo-wide, both changed here. Siblings enumerated: do_query returns bool and all three callers assert on it, so it has no silent-partial path; is_ready now surfaces through the "returned no response" branch; CIDBCluster.do_select_query has the same shape on a different cluster with no failure at hand, and is disclosed as out of scope.
g Fix generalizes across inputs? The input space is the response shape, and all eight probed shapes are covered: 4xx, 5xx, 2xx-with-exception, 2xx clean, 2xx whose body is not JSON at all, 2xx whose JSON object carries no data key, 2xx whose data is present but empty, and no response at all. A body that is not a JSON object carrying data is reported with its status and body at an ok status as well as at a failing one, so no shape reaches json.loads(...)["data"] unguarded. Both body formats are real: a server with the master default http_write_exception_in_output_format = false answers in plain text while the CI cluster answers in JSON, and both were observed on real servers.
h Backward compatible? Yes. CI scripts only: no setting, no SettingsChangesHistory surface, no serialized format, no user-visible behaviour beyond the text of a failure. The one contract change, select returning a response rather than a string, has a single caller updated in the same commit.
i Invariants and contracts preserved? Db.query keeps its List[dict] return and its raise-on-failure contract; select keeps None meaning "no response arrived" and keeps both prints: it prints the SQL and the raw body when the status reported the failure, and the traceback names the call site otherwise. Checked the Python-specific trap that bool(requests.Response) is response.ok and bool({}) is False: the caller tests is None explicitly on both the response and the parsed body, so no truthiness path decides control flow.

Session id: cron:clickhouse-impl-slot-7:20260908-032200

@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [81e3d56]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) FAIL
Error message in clickhouse-server.log (see upgrade_error_messages.txt) FAIL cidb

AI Review

Summary

This PR changes the Build profile diff reader to raise typed read failures, surface cluster-side errors from the main select path, and skip the comparison when every observed read failure looks transient. That closes the original "green check on a failed read" hole, but one probe-side failure path still drops the concrete server error before it reaches the job result or pinned PR comment.

Findings

⚠️ Majors

  • [ci/jobs/scripts/log_cluster.py:370-406] [dismissed by author -- https://github.com/Report the CI logs cluster's error when a Build profile diff read fails, and skip if it is unavailable #118708#discussion_r4018343561] select now preserves status/body for failures returned by the actual query, but the is_ready() gate in front of every attempt still reduces a real probe refusal to Readiness(False, transient=False). Because the probe never populates failure, a stable 403 / ACCESS_DENIED on SELECT 1 still burns the full retry loop and ends as ReadFailure("the endpoint never became ready"), so the caller at ci/jobs/build_profile_diff_job.py:1583-1597 loses the exact server error this PR is meant to report. Suggested fix: return the probe failure text (or a ReadFailure-like object) from is_ready() and have select preserve it, breaking immediately on non-transient probe failures instead of falling through to the generic message.
Final Verdict

Status: ⚠️ Request changes

Minimum required action:

  • Preserve the probe-side status/body in the raised failure so a readiness refusal reports the actual server error instead of the generic the endpoint never became ready fallback.

LLVM Coverage Report

⚠️ No coverage measurement for commit 81e3d56: incomplete coverage measurement: 16 of 21 shard profiles are missing: LLVM_COVERAGE_FILE_ft_2.profdata, LLVM_COVERAGE_FILE_ft_3.profdata, LLVM_COVERAGE_FILE_ft_s3_async_sequential.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_parallel_2.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_parallel_3.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_sequential_1.profdata, LLVM_COVERAGE_FILE_ft_s3_db_repl_sequential_2.profdata, LLVM_COVERAGE_FILE_ft_s3_sequential.profdata, LLVM_COVERAGE_FILE_it_1.profdata, LLVM_COVERAGE_FILE_it_2.profdata, LLVM_COVERAGE_FILE_it_3.profdata, LLVM_COVERAGE_FILE_it_4.profdata, LLVM_COVERAGE_FILE_it_5.profdata, LLVM_COVERAGE_FILE_it_6.profdata, LLVM_COVERAGE_FILE_it_7.profdata, LLVM_COVERAGE_FILE_it_8.profdata.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 8, 2026
@groeneai

groeneai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @maxknv @leshikus, could you review this? LogCluster.select printed the cluster's status and body and then returned None, so its one caller Db.query had only the SQL left to raise with. It now returns the response, and the raise carries the status and the server's exception field, which also stops a failure arriving with an ok status from being read as rows and reported as a green "no build profile data".

Comment thread ci/jobs/build_profile_diff_job.py Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-ci-infrastructure CI/CD pipelines (GitHub Actions, CI scripts, runners). label Sep 8, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Sep 8, 2026
A failure the server raises after it has started writing the result cannot
travel in the HTTP status, because the status is already on the wire. It
arrives inside the body instead, next to the rows produced before it, under a
200. Reporting that as a failed read is what the previous commit fixed; it also
made such a read fail on its first attempt, while LogCluster.select retried a
500 eight times with a growing backoff.

The distinction the retry policy needs is not the error code but where the
failure was detected. A query the server refuses is rejected before it writes
anything, so it comes back with an error status: locally, an unknown table
gives 404, and Code 241 raised during aggregation or in a window frame gives
500, which select already retried. What a committed 200 can still carry is a
failure that struck mid-query: a timeout mid-stream arrives with 7 rows and
Code 159 TIMEOUT_EXCEEDED in the body, and that is exactly the transient class
select's own comment is about.

So select now takes body_failed, a predicate over a response whose status looks
successful, and gives a body that reports a failure the same backoff as a 500.
Db.query passes the condition its own raise already used, so the two cannot
drift, and an ordinary empty result set stays a successful read on the first
attempt: the "no build profile data yet" answer must not cost eight reads.

An in-band failure that clears on a later attempt now returns that attempt's
rows. Before this commit it failed the job immediately; before the previous one
it returned the failed attempt's truncated rows as a complete result.

Raised by clickhouse-gh[bot] in review of this pull request:
ClickHouse#118708 (comment)

Co-Authored-By: Claude Opus 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 81e3d56d0 with master 5549a36a8 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of b3059a14f; 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

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@groeneai

groeneai commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 889a353

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Upgrade check (amd_release) / Error message in clickhouse-server.log a background mutation on part all_1_1_1_2 retries forever reading a column the table no longer has: Code: 47, Unknown expression identifier 'b', Maybe you meant: ['a'], raised from MutatePlainMergeTreeTask #115962 (mine, open), "Do not read a part column that the table no longer has"

Mergeable Check and PR are the workflow aggregators of the row above and carry no failure of their own. The signature is not reachable from this diff, which only adds CI job definitions: it is the same mutation-retry class already owned by #115962 and observed on unrelated heads.

Session id: cron:our-pr-ci-monitor:20260908-113133

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

Please remove all the water from the description, you generated a lot of text, but what we need is the clear reason of this PR instead.

The reason - we want to return the error to the caller to instead of printing it in the select() function itself, but those scripts are very hacky, and I'm not even sure that we need to bother...

And if we do, we need to rely on exceptions instead, so that the caller cannot ignore the error.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Superseded. @ alexey-milovidov has ruled to keep #121048 and close this one (#120288 (comment)): the green-on-outage outcome is the one he wants, and two rewrites of the same select should not both land. I am standing this PR down, no further pushes.

@azat, you have four review rounds in it and you closed #120121 in its favour, so I am not closing it behind your back: say the word and it is closed. Where your asks stand in #121048:

  • the cluster's error reaching the caller: covered, the exception carries code <status>: <body> and the job prints it into the result info and into the pinned comment;
  • an error reported in the body of a committed 200 (MEMORY_LIMIT_EXCEEDED) counted like a >= 500: not parsed there, but in my local probe of that path the job's own client, requests, saw status=500 for it in 6 runs of 6, so the >= 500 leg covers it with that client. Parsing the in-band marker is the one thing this PR has that CI: "Build profile diff" is green when the CI logs cluster does not answer #121048 does not; if you want it, I will take it there.

The is_ready() hard-failure classification he asked for is posted on #121048.

alexey-milovidov added a commit that referenced this pull request Sep 21, 2026
…e status

Address review: `status >= 500` is not "the cluster never answered". The
server reports several of its own verdicts on a query as a 500 - 164 for a
setting change on a readonly profile, 158 for `max_rows_to_read`, 241 for the
memory limit, 395 for a `throwIf` after the result started - so a real defect
in one of the `Build profile diff` reads would have reported the check green.

`X-ClickHouse-Exception-Code` is the exact discriminator: it is present on
every answer the server produced and absent when the answer did not come from
it, whatever the status. `LogCluster._classify` keys on it - absent means a
gateway, a proxy or a closed connection (`LogClusterUnavailable`); a code in
`TRANSIENT_EXCEPTION_CODES` (159, 202, 209, 241) is the shared cluster talking
about its own load (`LogClusterUnavailable`); anything else is its verdict on
this very query (`LogClusterQueryError`, fail closed, and the same verdict on
every retry so it is not retried). 241 in the transient set also closes azat's
ask on #118708 in its general form, by the exception code rather than by the
coincidence that the status happens to be 500.

`raise` on that verdict has to escape the loop, so `except LogClusterError:
raise` precedes the generic transport handler; without it the handler catches
the verdict and retries it eight times.

An endpoint that never became ready is now its own `LogClusterNotReady`, a
sibling of `LogClusterError` that `main` does not catch: a readiness probe
that never answers is indistinguishable from a rotated password or a deleted
SSM parameter, and completing green on that would blank the check fleet-wide
for as long as the condition lasts.

Neither change affects the outage this pull request is about: those failures
never get a response at all (`ReadTimeout`), so they end at "every POST
attempt failed with an exception".

Related: #118708
Related: #118467

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@azat

azat commented Sep 21, 2026

Copy link
Copy Markdown
Member

Superseded. @ alexey-milovidov has ruled to keep #121048 and close this one

@azat azat closed this Sep 21, 2026
clickgapai pushed a commit to clickgapai/ClickHouse that referenced this pull request Sep 21, 2026
`LogCluster._classify` treated exception codes `159` (`TIMEOUT_EXCEEDED`)
and `209` (`SOCKET_TIMEOUT`) as `LogClusterUnavailable`, so they reached
`main`'s green handler in `ci/jobs/build_profile_diff_job.py` and
reported the check `OK`.

Both are the server's verdicts on a query it accepted, not statements
about the shared cluster's load, and `_classify` is reached from `select`
only - `is_ready` posts its own constant `SELECT 1` and returns a bool
without consulting the set, and `do_query` retries on the status. So the
only path the two codes affected is the reporting `SELECT`s, and there a
query that regressed into a server-side timeout was retried eight times,
classified as an outage, and hidden behind a green check - exactly what
the contract of `report_cluster_unavailable` excludes.

They bought nothing for the outage that motivated the green path either:
that shape returns no response at all (`ReadTimeout`), which leaves
through the transport handler and is `LogClusterUnavailable` whatever the
set contains.

`TRANSIENT_EXCEPTION_CODES` is now `{202, 241}` - too many simultaneous
queries, and the server-wide memory-pressure windows - both verdicts
about the cluster's own load, and both observed rather than inferred.

Verified with a throwaway harness (not committed - we have no automated
tests for the CI scripts): `159` and `209` now classify as
`LogClusterQueryError` and raise after exactly one POST, `202` and `241`
still classify as `LogClusterUnavailable` and exhaust the eight retries,
a headerless `502`/`503` is still `LogClusterUnavailable`, a non-numeric
header value still falls closed, and `164`, `158`, `62` and `60` are
unchanged.

Follow-up to ClickHouse#121048,
addressing the review finding left unresolved there.

Related: ClickHouse#121048
Related: ClickHouse#118708

Co-Authored-By: Claude Opus 5 (1M context) <[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-request PR origin: a maintainer pinged or directed groeneai 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