Skip to content

CLI client: some XML defaults - #110607

Merged
alexey-milovidov merged 30 commits into
ClickHouse:masterfrom
larry-cdn77:cli-some-xml-defaults
Jul 26, 2026
Merged

alexey-milovidov merged 30 commits into
ClickHouse:masterfrom
larry-cdn77:cli-some-xml-defaults

Conversation

@larry-cdn77

@larry-cdn77 larry-cdn77 commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category

  • Improvement

Changelog entry

Make some commonly-used clickhouse-client arguments XML configurable for convenience (<hints/> <highlight/> <echo/> <echo_query_id/> <echo_formatted/> <print-profile-events/>), and preserve values from the client config file when the corresponding defaulted CLI flags are omitted for settings such as history_max_entries, suggestion_limit, progress, progress-table, enable_progress_table_toggle, print-memory-to-stderr, chime-threshold-seconds, and profile-events-delay-ms.

Version info

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

@alexey-milovidov alexey-milovidov self-assigned this Jul 15, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0ac0575]

Summary: ✅


AI Review

Summary

The PR extends clickhouse-client and clickhouse-local config handling so XML-backed defaults are no longer overwritten by defaulted CLI values, adds shared underscore-alias remapping and fail-fast validation for the new config-backed keys, and covers the changed behavior with focused regressions. I re-checked the current head against the full prior discussion and did not find a remaining correctness, compatibility, or safety issue in the live diff.

Missing context / blind spots
  • ⚠️ At review time, Style check and Fast test were green, but the wider build/sanitizer matrix was still queued. Final merge confidence still depends on those jobs staying green.
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jul 15, 2026
@larry-cdn77

larry-cdn77 commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor Author

I used &#45;&#45;foo-bar say --foo-bar in XML comments but noticed elsewhere - -foo-bar (double dash broken by space) used; misleading but not so ugly so maybe I should use that

Comment thread programs/client/Client.cpp Resolved
Comment thread src/Client/ClientBase.cpp Resolved
larry-cdn77 and others added 4 commits July 17, 2026 14:11
…ght 0

CLICKHOUSE_CLIENT_EXPECT_OPT always contains `--highlight 0`, which broke
all four cases of the test:
- cases 1/2 failed outright with "Bad arguments: option '--highlight'
  cannot be specified more than once" when adding `--highlight=1`;
- case 1 would otherwise disable highlighting via the explicit CLI flag
  instead of the `<highlight>false</highlight>` config under test;
- cases 3/4 never showed inline hints regardless of `<hints>`, because
  `ReplxxLineReader` gates the hint callback on the highlighter, which
  `--highlight 0` removes.

Strip `--highlight 0` from the spawned client options in all four cases,
the same way case 3 already stripped `--disable_suggestion`. Verified
locally: the test passes with the `!defaulted()` fix in
`ClientBase::addOptionsToTheClientConfiguration` and fails when that fix
is reverted, so it now really guards the regression.

CI failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110607&sha=f5647cab6dac12d0a4ed2e018601ca4413f7b6ca&name_0=PR&name_1=Fast%20test
PR: ClickHouse#110607

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread src/Client/ClientBase.cpp Resolved
@larry-cdn77

larry-cdn77 commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you for a quick reaction

I've added tests and the PR now looks kind of ready to me

As per the latest bot suggestion, I'm not convinced this PR is the right place to change and test any other options that lack 'defaulted' – it sounds like something for another PR

alexey-milovidov and others added 5 commits July 19, 2026 23:18
The test used a fixed `--query-id test-query-123`, but the flaky check runs
the same test concurrently, so parallel runs collided with
`QUERY_WITH_SAME_ID_IS_ALREADY_RUNNING` (surfacing as unexpected stderr and a
FAIL). Derive the query id from `$CLICKHOUSE_DATABASE` so it is unique per run,
and normalise it back to a stable value in the output for the reference.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110607&sha=23b40e8ebceb0f0879923db7c2f0fbf52267cef4&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Address the AI review on PR ClickHouse#110607: the `!defaulted()` guard was applied only
to `--highlight` / `--hints`, but the same precedence bug affected other
default-valued client options in `ClientBase::addOptionsToTheClientConfiguration`.
Because a `default_value(...)` option always satisfies `options.contains(...)`,
the CLI default was unconditionally materialised into the configuration layer
and silently overrode any value coming from the client XML config (or, for
`history_max_entries`, from `<connections_credentials>`).

Guard `history_max_entries`, `suggestion_limit`, `progress` and
`progress-table` with `!defaulted()` too, so an XML-configured value is no
longer clobbered by the CLI default. The read sites of `progress` /
`progress-table` (`config().getString(..., "default")`) and
`history_max_entries` (`getUInt(..., 1000000)`) already supply the default, so
skipping the write is safe. The `suggestion_limit` read sites did not, so add
the documented default `10000` as a fallback at every read
(`Client::connect` and `ClientBase::runInteractive`); otherwise the client
threw `Not found: suggestion_limit` once the default was no longer written.

Add `04614_client_history_max_entries_config` as the focused config-file
regression test the review asked for: with `<history_max_entries>1</...>` in
the config only the most recent query is kept in the history file, which fails
if the CLI default (1000000) still won.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The CLI default `true` of `--enable-progress-table-toggle` was written
into the configuration unconditionally, clobbering a value from the
client XML before `initTTYBuffer` reads it. Add the same `!defaulted()`
guard as for the sibling options, supply the default at the read site,
and accept `<enable_progress_table_toggle>` as the underscore-style tag,
consistently with the `echo_*` options.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread src/Client/ClientBase.cpp Resolved
alexey-milovidov and others added 2 commits July 20, 2026 08:00
With the toggle disabled from the XML config (both the dashed key and the
underscore-style alias), the client must print the final progress table
after each interactive query; with an explicit
`--enable-progress-table-toggle=1` on the CLI the flag must win over the
config and no final progress table may appear.

Co-Authored-By: Claude Fable 5 <[email protected]>
@larry-cdn77

Copy link
Copy Markdown
Contributor Author

You are right that a dashed tag name would be unidiomatic in the client XML — so, in the same commit, I also made <enable_progress_table_toggle> work as the underscore-style tag, following exactly the echo_* → echo-* remap pattern this PR introduced in Client::initialize. This way the precedence bug is fixed for the (dashed) key the code actually reads, and users get the idiomatic underscore spelling.

Great, thank you, that makes sense!

By the way echo_formatted/echo_query_id is not a precedent, there is also server_client_version_message with its --no-server-client-version-message counterpart (#87784) or ssh_key_file/ssh_key_passphrase (#87786, pending)

alexey-milovidov and others added 2 commits July 20, 2026 13:39
…chime`

Both options are declared with `default_value(...)`, so `options.contains(...)`
was always true and the CLI defaults unconditionally overwrote
`print-memory-to-stderr` and `chime-threshold-seconds` values loaded from the
client config file. The `chime` default of 5 seconds moves to the read site
(`getUInt64("chime-threshold-seconds", 5)`) so that omitting the flag keeps
the current default without clobbering the config.

Addresses the AI review on ClickHouse#110607

Co-Authored-By: Claude Fable 5 <[email protected]>
…w keys

`04622_client_memory_usage_config` checks that `<print-memory-to-stderr>` from
the client config file takes effect and that an explicit `--memory-usage` on
the command line overrides it. Also mention `print-memory-to-stderr` and
`chime-threshold-seconds` in the sample clickhouse-client.xml.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread src/Client/ClientBase.cpp Resolved
`--profile-events-delay-ms` is declared with `default_value(...)`, so
`options.contains(...)` stayed true even when the flag was omitted and the CLI
default (0) was materialized into the configuration layer, silently overriding
an XML `<profile-events-delay-ms>` value. On top of that,
`ClientApplicationBase::processOptions` initialized `profile_events.delay_ms`
from `options[...]`, so the config layer was never consulted at runtime.

Guard the write with `!options[...].defaulted()` and read the value from the
client configuration at the use site in `ClientBase::onProfileEvents` (the
client config file is loaded after the command line options are processed, so
an early read would miss it), with the previous default 0 as the fallback.
Add `04623_client_profile_events_delay_config` covering both directions of the
precedence and mention the key in the sample clickhouse-client.xml.

Addresses the AI review finding in
ClickHouse#110607
@larry-cdn77

Copy link
Copy Markdown
Contributor Author

👍

In the flaky check, one run out of 50 timed out: the live progress table
rendering stalled on a loaded machine and the prompt did not return within
the 60-second expect timeout, although the "Event name" header under test
had already appeared.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110607&sha=83b8c6fbd04a97097226f30ed5eebf75a18523ef&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29
Related: ClickHouse#110607

Reduce the exposure: a 120-column terminal drops the wide documentation
column from every redrawn frame, `numbers(100000)` shortens the query, and
the expect timeout is doubled to 120 seconds.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread src/Client/ClientBase.cpp Resolved
… their read sites

`validateClientConfiguration` checked all four numeric keys with `getUInt64`, but
`history_max_entries` is consumed via `getUInt` and `suggestion_limit` via `getInt`,
so an out-of-range value such as `5000000000` passed the validator and still threw
later from the narrower read. Validate each key with the same parser as its consumer
and add boundary regression cases to `04629_client_config_numeric_validation`.

Also de-flake the empty `<print-profile-events/>` case of that test: under load the
server can deliver profile events in several packets, splitting the `SelectedRows`
increment across multiple lines, so check that the counter is printed at all instead
of expecting a single exact aggregated line.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110607&sha=8533d1bba003f8bf2a7a207ed25d04b4d02bce48&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29
@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110607&sha=8533d1bba003f8bf2a7a207ed25d04b4d02bce48&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

Specifically the Error message in clickhouse-server.log row: void DB::AsyncLoader::worker(Pool &): Code: 27. DB::Exception: Cannot parse input: expected '\n' before: 'version: 1 storing_version: 0 creation_tid: ...' — an old-vs-new VersionInfo (version.txt) format parsing error during part loading after the upgrade. It is unrelated to this PR (which only touches client-side option handling), and I found no open issue tracking it. The other two rows in that report (join_runtime_filter_min_probe_rows settings-history) are cleared by merging current master, and the system.metric_log rotation error is addressed by #111703.

Comment thread src/Client/ClientBase.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov Investigated. This is the 04241_part_loading_tree_rollback_contains fabricated-part corruption class (issue #111053), not an old-vs-new format-compat parse of a genuine part.

The Code: 27 expected '\n' before: 'version: 1\nstoring_version: 0\ncreation_tid: (2, 33, ...)' fires on the part the test fabricates by printf-ing a txn_version.txt with exactly that creation_tid: (2, 33, 00000000-...). The on-disk file has a doubled version: 1version: 1\n... prefix: the parser consumes one version: 1, then assertChar('\n') fails on the second v. So the fabricated file was rewritten/raced, not a legitimate older-format record.

#111055 (merged 2026-07-23 17:29 UTC) fixed the stress-restart variant by detaching the table permanently. It does NOT eliminate the Upgrade check variant: at least 3 runs whose branch already contains #111055 still fail with the identical error, e.g. PR 96130 @ 0aa6569, 2026-07-24 10:37 UTC: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96130&sha=0aa6569f3e6563c982227857effd5d2d19c97527&name_0=PR&name_1=Upgrade%20check%20%28amd_release%29 . 0 occurrences on master in the last 10 days.

Both failures you cited predate #111055, but since #111055 does not cover the Upgrade path, merging master will not reliably clear it. This variant is untracked, as you suspected. I am preparing a fix in a separate PR and will link it here.

@groeneai

Copy link
Copy Markdown
Collaborator

Fix PR: #111772

Root cause is not this PR (confirmed): the Upgrade check configures the server object-storage-default (configure --s3-storage) and randomly enables encrypted storage, but ran clickhouse-test without --s3-storage and never forwarded --encrypted-storage. So clickhouse-test had args.s3_storage/args.encrypted_storage = False and ignored the no-object-storage / no-encrypted-storage skip tags. The four 04*_part_loading_tree_rollback_* tests (all no-object-storage) then ran on object storage, where their raw plaintext txn_version.txt is unreadable, so PartLoadingTree::add (from #100992) reports CORRUPTED_DATA / Code: 27 at the test's own ATTACH; --upgrade-check implies --fake-drop, so the corrupt part survives into the new server. #111055 / #111661 hardened these tests on master, but the Upgrade check runs the frozen previous-release suite, so those changes cannot reach it.

#111772 forwards --s3-storage and --encrypted-storage in upgrade_runner.sh so clickhouse-test matches the server and skips incompatible tests.

…tBool

The changelog advertises self-closing forms such as <hints/>, <highlight/>,
<echo/>, <echo_query_id/> and <echo_formatted/>, but raw Poco boolean parsing
throws `Syntax error: Cannot convert to boolean` on an empty value, so only
<print-profile-events/> (explicitly normalized) actually worked. Route the
underscore remaps in `Client::initialize` and the effective boolean reads
(`ClientBase::setupEchoAndHighlightSettings`, the `highlight`/`hints` reads in
`ClientBase::runInteractive`, and `enable_highlight` in `Client` and
`ClientEmbedded`) through `ConfigHelper::getBool`, which treats the empty tag
as `true`. Add `04642_client_empty_boolean_config_tags` covering every
advertised empty-tag boolean (the old binary fails all of its cases).
Comment thread programs/local/LocalServer.cpp Resolved
…ocal

The remap of the underscore XML spellings (`<echo_query_id/>`, `<echo_formatted/>`,
`<enable_progress_table_toggle/>`) to the dashed keys the read sites use lived only in
`Client::initialize`, so `clickhouse-local --config-file` silently ignored them even
though the equivalent CLI flags worked. Move the remap into
`ClientBase::remapClientConfigurationAliases` and call it from both entry points, with a
focused `clickhouse-local` regression test.
@clickhouse-gh

clickhouse-gh Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.30% +0.10%
Functions 92.00% 92.00% +0.00%
Branches 78.40% 78.50% +0.10%

Changed lines: Changed C/C++ lines covered: 142/150 (94.67%) · Uncovered code

Full report · Diff report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 26, 2026
Merged via the queue into ClickHouse:master with commit d5d8d6b Jul 26, 2026
179 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 26, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ght 0

CLICKHOUSE_CLIENT_EXPECT_OPT always contains `--highlight 0`, which broke
all four cases of the test:
- cases 1/2 failed outright with "Bad arguments: option '--highlight'
  cannot be specified more than once" when adding `--highlight=1`;
- case 1 would otherwise disable highlighting via the explicit CLI flag
  instead of the `<highlight>false</highlight>` config under test;
- cases 3/4 never showed inline hints regardless of `<hints>`, because
  `ReplxxLineReader` gates the hint callback on the highlighter, which
  `--highlight 0` removes.

Strip `--highlight 0` from the spawned client options in all four cases,
the same way case 3 already stripped `--disable_suggestion`. Verified
locally: the test passes with the `!defaulted()` fix in
`ClientBase::addOptionsToTheClientConfiguration` and fails when that fix
is reverted, so it now really guards the regression.

CI failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110607&sha=f5647cab6dac12d0a4ed2e018601ca4413f7b6ca&name_0=PR&name_1=Fast%20test
PR: ClickHouse#110607

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Address the AI review on PR ClickHouse#110607: the `!defaulted()` guard was applied only
to `--highlight` / `--hints`, but the same precedence bug affected other
default-valued client options in `ClientBase::addOptionsToTheClientConfiguration`.
Because a `default_value(...)` option always satisfies `options.contains(...)`,
the CLI default was unconditionally materialised into the configuration layer
and silently overrode any value coming from the client XML config (or, for
`history_max_entries`, from `<connections_credentials>`).

Guard `history_max_entries`, `suggestion_limit`, `progress` and
`progress-table` with `!defaulted()` too, so an XML-configured value is no
longer clobbered by the CLI default. The read sites of `progress` /
`progress-table` (`config().getString(..., "default")`) and
`history_max_entries` (`getUInt(..., 1000000)`) already supply the default, so
skipping the write is safe. The `suggestion_limit` read sites did not, so add
the documented default `10000` as a fallback at every read
(`Client::connect` and `ClientBase::runInteractive`); otherwise the client
threw `Not found: suggestion_limit` once the default was no longer written.

Add `04614_client_history_max_entries_config` as the focused config-file
regression test the review asked for: with `<history_max_entries>1</...>` in
the config only the most recent query is kept in the history file, which fails
if the CLI default (1000000) still won.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…chime`

Both options are declared with `default_value(...)`, so `options.contains(...)`
was always true and the CLI defaults unconditionally overwrote
`print-memory-to-stderr` and `chime-threshold-seconds` values loaded from the
client config file. The `chime` default of 5 seconds moves to the read site
(`getUInt64("chime-threshold-seconds", 5)`) so that omitting the flag keeps
the current default without clobbering the config.

Addresses the AI review on ClickHouse#110607

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`--profile-events-delay-ms` is declared with `default_value(...)`, so
`options.contains(...)` stayed true even when the flag was omitted and the CLI
default (0) was materialized into the configuration layer, silently overriding
an XML `<profile-events-delay-ms>` value. On top of that,
`ClientApplicationBase::processOptions` initialized `profile_events.delay_ms`
from `options[...]`, so the config layer was never consulted at runtime.

Guard the write with `!options[...].defaulted()` and read the value from the
client configuration at the use site in `ClientBase::onProfileEvents` (the
client config file is loaded after the command line options are processed, so
an early read would miss it), with the previous default 0 as the fallback.
Add `04623_client_profile_events_delay_config` covering both directions of the
precedence and mention the key in the sample clickhouse-client.xml.

Addresses the AI review finding in
ClickHouse#110607
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
In the flaky check, one run out of 50 timed out: the live progress table
rendering stalled on a loaded machine and the prompt did not return within
the 60-second expect timeout, although the "Event name" header under test
had already appeared.
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110607&sha=83b8c6fbd04a97097226f30ed5eebf75a18523ef&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29
Related: ClickHouse#110607

Reduce the exposure: a 120-column terminal drops the wide documentation
column from every redrawn frame, `numbers(100000)` shortens the query, and
the expect timeout is doubled to 120 seconds.

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The AI review asked for a focused `--config` + pty case guarding the
`!defaulted()` fix for `--chime` in
`ClientBase::addOptionsToTheClientConfiguration`: without it, the CLI
default of 5 seconds silently overwrites `<chime-threshold-seconds>` loaded
from the client config file. `04625_client_chime_config` checks that a
1-second threshold from the config makes a 1.5-second query chime when no
`--chime` flag is given, and that an explicit `--chime 0` still wins over
the config.
Related: ClickHouse#110607

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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 pr-improvement Pull request with some product improvements 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