Repository navigation
Conversation
The Style check / settings_changes_history validator needs the diff of
src/Core/SettingsChangesHistory.cpp, which the store_data.py workflow hook
fetches from the GitHub API. When that fetch failed, the report never said why.
The fetch used Shell.get_output, which defaults to strict=False and makes a
single attempt: on a non-zero exit it prints stderr as a warning and returns
stdout anyway, i.e. an empty string. The following
`if patch.strip() in ("", "null")` then relabelled that empty string as
GitHub's large-diff case, so an expired token and a transient 502 both raised
"GitHub omits the patch for very large diffs". The except clause only printed,
and none of the hook's store_kv_data calls wrote the
settings_history_fetch_error key that check_style.py reads, so the report fell
back to "no data recorded by the store_data.py workflow hook". A single
transient 5xx was therefore fatal on a merge-blocking check instead of retried.
GH.get_output_with_retries already owns the retry policy and still holds the
exit code and stderr where it gives up, so it gains an opt-in strict parameter
that raises that diagnostic, now including the exit code, instead of returning
an empty string. This is the same shape as GH.get_changed_files(strict=False)
in the same file, which the hook calls one line above. store_data.py calls it
with strict=True, keeps the existing message for a genuine null patch, adds a
distinct message for rc=0 with no output, and stores the bounded reason under
settings_history_fetch_error. The hook still does not raise, so the
changed_files storage other merge-queue jobs depend on is unaffected. The fetch
moved to a module-level function because the block was __main__-guarded and so
unreachable from a test.
Worst-case retry cost is 4+8+16 = 28 s, paid only when the fetch is already
failing; the non-retryable classes still fail after one attempt.
The new parameter defaults to the previous behaviour: none of the existing call
sites passes a second positional argument, both existing test stubs accept
arbitrary keywords, and one of the new tests pins that default.
Two related problems are deliberately left for separate changes:
Shell.get_output ignores retries when strict=True, and the master_commits fetch
in this same hook is also un-retried.
Co-Authored-By: Claude Fable 5 <[email protected]>
The previous commit bounds the stored `settings_history_fetch_error` at 500 chars because it lands on a public report page, but `GH.get_output_with_retries` built its give-up diagnostic with the unbounded `out` field before `err`, and the prefix is already 190 chars before `out:[` opens. `gh api --paginate` streams each page as it arrives, so a 502 on the second page exits non-zero with the first page's patch already on stdout. The 500-char window then filled with the command and the patch text, and the stored message named neither the 502, the exit code, nor the attempt count. That is worse than the behaviour this branch replaced, where a definite but wrong reason at least appeared. `GH.get_output_with_retries` now puts the fields that identify the failure - command, exit code, attempt count - before the API-controlled output, and caps `out` and `err` individually with an explicit elision marker. All 18 call sites print this diagnostic and only one of them bounds it, so front-loading the cause helps every caller and keeps one large response from burying the rest in a log. `settings_history_fetch_error_message` keeps its own bound as a second line of defence, and now elides the middle rather than the tail so a cause that happens to sit last still survives. Three test gaps that let this through are closed. The only test of the bound asserted `len == 500` on a message whose informative text was at the front, which head-, tail- and middle-truncation satisfy alike, and no cell drove the fetch with a `gh` that both wrote large output and failed. The fake `gh` also ignored its arguments, so the issued command was unconstrained: pointing the fetch at another pull request left every test green. And nothing pinned the call from `__main__`, so deleting it left every test green too. The fixture now records its argv, the success paths assert the command targets the right pull request and selects the right file, and the entrypoint wiring is asserted by parsing the module rather than importing it, which would run the whole hook. Co-Authored-By: Claude Fable 5 <[email protected]>
`GH.get_output_with_retries` reported `retry_count` in its give-up diagnostic, but that counter is only incremented on the retryable path, after the three non-retryable classes have already broken out of the loop. A `Bad credentials`, `Validation Failed` or `Resource not accessible` failure therefore reported `after [0] attempts` next to `exit_code:[1]` and the stderr that prove the command ran once, so the two halves of the same sentence contradicted each other. That field only reached a CI log before this branch. It now reaches a public report page through `settings_history_fetch_error`, and the preceding commit deliberately made it survive the message bound, so a field that is wrong is worse than one that gets cut: on an expired token, the likeliest real cause, it points a maintainer at the workflow wiring instead of the credentials. Count attempts where the subprocess is invoked and report that counter. `retry_count` still drives the loop condition and the backoff delay, so the retry policy is unchanged and exhaustion still reports `MAX_RETRIES_GH`. The existing non-retryable test asserted how many times `gh` ran but never the count the message reports, which is why the two could disagree unnoticed. Both are now asserted, for all three non-retryable classes.
Two of the new tests could pass on code that had lost the property they exist to protect. `test_hook_stores_the_cause_so_the_style_check_reports_it` asserted against `_style_check_report`, a local copy of `check_style.py`'s reporting branch, so a change that stopped `check_settings_changes_history` surfacing the stored cause would have left the whole file green while the report went back to the generic `no data recorded` fallback. That end-to-end path is the point of the change, so a cell now drives the real function: a failing fake `gh`, then `store_settings_history_changes` to obtain the stored value, then the production consumer. The copy is kept as a cheap local oracle, with its docstring corrected to say so. `test_get_output_with_retries_default_returns_empty_string` asserted only that a non-strict failure returns `""`, which a mutant short-circuiting on `not strict` also produces, having run nothing. The invocation count is now asserted alongside the return value, so the retrying half of the contract the other 14 callers depend on is actually pinned. Two comments corrected. The `_FETCH_ERROR_MESSAGE_TAIL` note claimed the tail window hedges against a cause that sits last; since `GH.get_output_with_retries` orders `err` before `out`, that window belongs to `out` whenever stdout is non-empty, so it is a hedge for arbitrary exception texts rather than a guarantee for `err`. The note above the hook's call said only setting names are stored, never the raw diff, which is now true of the success key alone: the error key stores a separately bounded diagnostic that can include a capped slice of `gh` output. Comments and tests only. `store_data.py`'s syntax tree is unchanged, and `check_style.py` and `ci/praktika/utils.py` are untouched.
Internal second-model review (click to expand)Four review rounds, each an independent cold read of the resulting code followed by a
Round 4 found no blocker and no major. Independently re-derived rather than accepted on |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260802-003900 |
|
cc @maxknv @leshikus, could you review this? The settings-history diff fetch used |
|
Workflow [PR], commit [eacc707] Summary: ✅ AI ReviewSummaryThis PR makes the Final VerdictStatus: ✅ Approve |
CI finish ledger - 3174a5dCI is fully finished on this head and there are no failures to own.
Session id: cron:our-pr-ci-monitor:20260802-020000 |
`store_data.py` conflicted with the merged ClickHouse#112782, which extended `parse_settings_history_changes` to also report value-edits, removals, moves between `addSettingsChanges` blocks and block-header edits. Union resolution, verified by AST rather than by reading: the two sides add disjoint top-level symbols at the same anchor (`fetch_settings_history_patch`, `settings_history_fetch_error_message`, `store_settings_history_changes`, `SETTINGS_HISTORY_FILE` here; `_settings_history_block_at`, `_settings_history_block_entries`, `_settings_history_block_header_index`, `_SETTINGS_HISTORY_BLOCK_END_RE` there), zero name collisions, and `parse_settings_history_changes` keeps master's signature and body byte-identical, so the parser rewrite is taken whole and the fetch/diagnostic machinery is preserved whole. The second hunk is this branch's extraction of the inline fetch into `store_settings_history_changes` against master's comment update in `__main__`. Kept the extracted form and adopted master's semantic wording; master's `settings_history_file` local and its `Best-effort` tail are dead under the fail-close design this branch introduces, so they are dropped rather than merged. Verified against the merged tree: this branch's 24 tests pass unchanged, as do all 49 tests across the three settings-history modules, including master's own `test_settings_history_source_gate.py` cells for removals, moves and header edits. Full `ci/tests` run shows no new failure - the 7 remaining are a subset of the 20 a pristine `origin/master` `ci/` tree produces on this host, and none of the 3 failing modules reaches a changed file through its transitive import closure. No `contrib` gitlink drift.
Master rewrote the settings-history fetch this branch had extracted into `fetch_settings_history_patch`, so the resolution is not a union: taking either side whole would drop real behaviour. Master's two changes are semantic and are preserved. `a7c28646f014464` reads `src/Core/SettingsChangesHistory.cpp` at the PR head instead of the CI checkout, because the patch's new-file line numbers refer to the head file and the checkout is the PR merged with its base, so a base branch that grew an earlier `addSettingsChanges` block shifts every line below it and the parser attributes added entries to the wrong block, even the wrong namespace. `aa4d71aa820b971` takes `.patch` and `.contents_url` from the same `pulls/N/files` entry so both halves come from one pinned revision even if the PR is updated in between. This branch's changes are preserved too. The extracted helper is renamed `fetch_settings_history_patch_and_file` and now returns the pair, both reads go through `GH.get_output_with_retries(strict=True)` so a transient 5xx is retried and a command failure raises naming the real cause, and `store_settings_history_changes` writes that cause to `settings_history_fetch_error`, the key `check_style.py` reads and which still has no writer on master. Master's own mislabelling moved rather than disappeared: with the second read added and no `strict`, a 5xx on the contents read returned an empty string that the emptiness check reported as "no content returned". Both reads are strict, so each failure mode keeps its own message. Every `ast.dump` of the five symbols master and this branch share is identical, so master's parser is taken whole and no master symbol is dropped. Verified: the two master fixes reproduced through the production entrypoint with a negative control that shows a checkout-resolving hook reports the wrong namespace; the pinned `contents_url` is the one read; 28 cells in this PR's suite and 53 across all three settings-history modules pass; seven mutants, one per preserved behaviour, each redden; full `ci/tests` shows no failure absent from a pristine `origin/master` control; `ruff check ci/` clean; no submodule pin drift.
The entrypoint oracle collected the guard's condition text and asserted substrings, so it accepted a guard that can never run: appending `and False` to the condition, or nesting the call under `if False:`, keeps both expected substrings while the hook stores neither the changed settings nor the fetch error in CI. Both mutants were measured green. The guarding statements are now extracted and EXECUTED against a fake `Info` and an injected call recorder, parametrized over four cases so the guard has to be load-bearing in both directions: a PR touching the file and a merge-queue run reach the hook, while a PR touching another file and a non-PR non-queue run do not. A hook that always ran fails the latter two rather than passing for the wrong reason. The walk starts at the `__main__` block's body rather than the block itself, because the `__name__ == '__main__'` test is a guard too and executing it would be false under pytest and never reach the guard under scrutiny. Measured: five mutants now redden, including the two the previous oracle let through and one dropping `is_merge_queue_event`; the three preserved-behaviour mutants from the merge still redden; 31 cells here and 56 across all three settings-history modules pass; full `ci/tests` shows no failure absent from a pristine `origin/master` control.
|
While resolving this PR against master I also measured a residual in the settings-history diff
It is not a fix I think is worth making, for three measured reasons:
The comment at |
|
@groeneai fix conflicts |
Master's `b5a7e34ccf42820` (recognize a renamed settings-history record) added `_settings_history_entry_without_name` at the same anchor where this branch extracts the fetch helpers out of the `__main__` block, so both sides add new top-level definitions in one place. Resolved as a UNION: the two sides are disjoint. Master rewrote `parse_settings_history_changes` and this branch never touched it; this branch rewrote the `__main__` block and master never touched it. Proven by AST rather than by reading - a per-symbol `ast.dump` index of the three merge stages and of the resolution gives 17 symbols, exactly the union of the 16 on this branch and the 11 on master, with 0 missing, 0 extra and every symbol byte-identical to one side or to both. `parse_settings_history_changes` is `ast.dump`-identical to master's; the `__main__` block is `ast.dump`-identical to this branch's. Master's rename recognition was re-probed through the merged parser, with a discriminating negative control: a pure rename inside one block reports the new name only, while the same pair whose reason text differs still reports both, so the probe can tell the two apart rather than passing vacuously. This branch's own behaviour was re-probed the same way: a 502 on the fetch is recorded under `settings_history_fetch_error` with the real cause, and the success path still records `settings_history_changed_settings` and no error key.
The comment above the hook claimed only the setting names are stored, never the raw diff. That is true of the success path, but the failure path stores the exception from `GH.get_output_with_retries`, whose message ends in an `out:[...]` field capped at 300 characters, and for a failed `--paginate` read of the file list that output is patch text. Measured through the production helper with a 16 kB synthetic patch as the API output: the stored value is 500 characters and about 200 of them are that patch text, so the old wording was wrong about what can appear there. Comment only - the bound itself is unchanged and deliberately not widened. What the comment protects still holds: `runner.py:718` base64-encodes the whole `JOB_KV_DATA` bucket before it becomes a pipeline output, so nothing here can match a secret pattern in the clear, and the key stays bounded.
|
@maxknv done, the PR is One conflicted file, Your rename recognition re-probed through the merged parser, with a control that discriminates: a The three settings-history suites are 62/62, including your One extra commit beyond the merge. The comment above the hook said only the setting names are |
CI finish ledger - eacc707Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
All 176 check-runs completed with 0 queued or in_progress (7 success, 169 skipped, 0 failing Fix presence was established per build. This supersedes the earlier ledger on Session id: cron:our-pr-ci-monitor:20260807-130000 |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
The
Style check / settings_changes_historyvalidator needs the diff ofsrc/Core/SettingsChangesHistory.cpp, whichstore_data.pyfetches from the GitHub API. Thatfetch had no retries and never reported why it failed.
Root cause.
Shell.get_outputdefaults tostrict=False: one attempt, and on a non-zero exitit warns and returns stdout anyway, i.e. an empty string.
if patch.strip() in ("", "null")thenrelabelled that as GitHub's large-diff case, so an expired token and a 502 both raised "GitHub
omits the patch for very large diffs". Nothing wrote the
settings_history_fetch_errorkeycheck_style.pyreads, so the report said "no data recorded" instead.Change.
GH.get_output_with_retriesalready owns the retry policy and still holds the exitcode and stderr where it gives up, so it gains an opt-in
strictparameter that raises thatdiagnostic instead of returning
"". That diagnostic also put the unboundedoutbeforeerr,losing the cause once a caller bounds the message, so command, exit code and attempt count come
first now and
out/errare capped individually.store_data.pycalls it withstrict=True,keeps the large-diff message for a genuine
nullpatch, adds a distinct one for rc=0-with-no-output, and stores the bounded reason. It still does not raise, so the
changed_filesstorageother jobs depend on is unaffected.
Validation. 22 new tests drive the real helper against a fake
ghonPATH, countinginvocations to tell a retry from a give-up, recording its argv to pin the issued command, and
calling the real
check_settings_changes_historyso the report is pinned against its ownproducer. Every failure mode is compared against the pre-fix code, and 28 mutations confirm each
test is load-bearing.
Discharges item (3) of
#110395 (comment). Left for separate
PRs:
Shell.get_outputignoringretriesunderstrict=True, and the un-retriedmaster_commitsfetch.