Skip to content

Fix clickhouse-local printing TSV instead of PrettyCompact in interactive mode - #115360

Merged
alexey-milovidov merged 8 commits into
masterfrom
fix-local-interactive-default-format
Aug 22, 2026
Merged

alexey-milovidov merged 8 commits into
masterfrom
fix-local-interactive-default-format

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

Related: #105249

Interactive clickhouse-local on master renders query results as TSV instead of the terminal default PrettyCompact.

applyCmdOptions seeds the default_format setting on global_context as the fallback format of the sessions of the embedded protocol listeners (SYSTEM START LISTEN), where it must match a real clickhouse-server (TabSeparated). client_context is copied from global_context and inherits the seed, and the per-query output-format resolution introduced in #105249 treats a non-empty default_format setting as the fallback format, so the seed overrode the interactive display default. (#105249 guarded --vertical against exactly this failure mode, but the plain interactive default slipped through: it is the one case where is_default_format stays true.)

The fix clears the seeded value on client_context, in makeFormatOptionsPrivateToTheClient, which already handles the mirror image of this problem for the format / input_format / output_format settings. This client renders results from its own ClientBase::default_output_format, so the seed is not needed there. Explicit choices keep working: an explicit --default_format on the command line is left in place (guarded by cmd_settings->isChanged), and a later SET default_format = ... or an in-query SETTINGS clause lands on client_context after the clearing. The served sessions still get the fallback through global_context.

Verified against the master CI binary (26.8.1.1658, where the regression reproduces): emulating the fix by forcing an empty default_format on the client restores PrettyCompact, while SET default_format = 'JSONEachRow' and SETTINGS default_format = 'CSV' continue to be honored. The added 04927_local_interactive_default_format.expect test fails on current master and passes with the fix emulated; the listener-side default is already covered by 04501_local_http_default_format.expect.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed a regression on master (not present in any release): interactive clickhouse-local rendered query results as TSV instead of PrettyCompact.


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

…teractive mode

`applyCmdOptions` seeds the `default_format` setting on the global context as
the fallback format of the sessions of the embedded protocol listeners
(`SYSTEM START LISTEN`), where it must match a real `clickhouse-server`
(`TabSeparated`). The client context is copied from the global context and
inherited the seed, and the per-query output-format resolution introduced in
#105249 treats a non-empty `default_format` setting as the fallback format, so
the seed overrode the interactive display default (`PrettyCompact`) with `TSV`.

Clear the seeded value on the client context: this client renders results from
its own `ClientBase::default_output_format`. An explicit `--default_format` on
the command line stays honored, as do `SET default_format = ...` and an
in-query `SETTINGS` clause; the sessions of the embedded listeners still get
the seed through the global context.

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

clickhouse-gh Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [065c3ea]

Summary: ✅


AI Review

Summary

The PR fixes the clickhouse-local regression where the synthetic listener default_format leaked into the local client session and forced interactive output to TSV. On the current head, the listener fallback is seeded only when no real default_format was provided by the command line or the default profile, and the local client clears only that synthetic seed while preserving explicit or profile-provided defaults, including the equal-value TSV case covered by the new regression test. I did not find remaining correctness or coverage issues in the touched surface.

Final Verdict

✅ Approved.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.00% 87.10% +0.10%
Functions 91.90% 91.90% +0.00%
Branches 79.30% 79.40% +0.10%

Changed lines: Changed C/C++ lines covered: 11/11 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Aug 18, 2026
alexey-milovidov and others added 4 commits August 19, 2026 06:25
…ty value

Assigning `String{}` marked the setting as changed on the client session, so
`system.settings WHERE changed` listed `default_format` with an empty value
and `02800_clickhouse_local_default_settings` failed. `resetSettingsToDefaultValue`
copies the pristine default field, clearing the `changed` flag along with the
value, so the session looks exactly like one where nothing was seeded.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The Fast test failure (02800_clickhouse_local_default_settings) was caused by the fix itself: assigning String{} marks default_format as changed on the client session, so it shows up in system.settings WHERE changed with an empty value. Fixed in 3578a91 by resetting the setting to its default instead (resetSettingsToDefaultValue copies the pristine default field, clearing the changed flag along with the value).

Validated locally against a fresh build: 02800_clickhouse_local_default_settings matches the updated reference (no default_format row at all), 04927_local_interactive_default_format.expect passes, and 04489_local_http_listener_default_format_override / 04903_local_http_listener_format_option_not_leaked still pass.

Note: this regression is what makes the two interactive client tests of #114043 (04909_client_hints_history_navigation, 04911_client_ai_mode_history_recall) fail — they assert the PrettyCompact rendering of a query result in interactive clickhouse-local.

alexey-milovidov pushed a commit that referenced this pull request Aug 20, 2026
The interactive tests of this PR (04909, 04911) assert the PrettyCompact
rendering of query results in interactive `clickhouse-local`, which is broken
on master (#115360): the `default_format` seed for the embedded protocol
listeners overrides the terminal display default. This merge will fall out of
the diff once #115360 lands in master.
Comment thread programs/local/LocalServer.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 065c3ead4 with master 06af43bc2 (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
Binary Master PR Δ
programs/clickhouse-stripped 705.38 MiB 702.36 MiB -3.02 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

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

Job report

…nly the synthetic listener seed

`makeFormatOptionsPrivateToTheClient` reset `default_format` on `client_context` whenever
the command line did not set it, which also erased a `default_format` legitimately configured
in the default profile (`setDefaultProfiles` applies it after `applyCmdOptions` seeds the
listener fallback). Remember the exact seeded value in `listener_default_format_seed` and
reset only when the inherited value still equals that seed, so a profile override keeps its
role in the per-query format resolution.

Adds the test `05023_local_profile_default_format` covering a profile-provided
`default_format` in batch output, `system.settings` visibility, the command-line override,
and the reset of the untouched seed.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115360&sha=3578a91592e58c6999d621d597e0187a8ced9812&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. 04891_distributed_plan_limit_early_stop fails on arm_binary across unrelated PRs (#115632, #111427, #115314, #110968 within the last three days), so it is a fleet-wide flake unrelated to this PR; #114806 ("Stop exchange sinks when the consumer needs no more data", merged 2026-08-17) did not clear it, and I found no open tracking issue.

@groeneai

Copy link
Copy Markdown
Collaborator

No fix PR exists (searched open PRs for the test name: only this PR and #110997, both carriers). Root cause below, and I will open a separate PR.

This is a test defect, not an engine bug. All six failures on unrelated PRs are TIMEOUT_EXCEEDED at 25030 to 25646 ms against the test's own max_execution_time = 25, so each crosses the cap by under 2.6 percent, and each passed on rerun with identical randomized settings (5/5 to 9/9). No failure has ever been a result diff, so the early stop itself works.

The oracle is a wall clock by construction: sleepEachRow(0.001) over 300k rows at max_block_size = 1000 makes "the LIMIT stopped the upstream scan" observable only as "finished inside 25s", so any host stall becomes a red. Stalls of that size are common on parallel checks and are not specific to this test: on Stateless tests (arm_binary, parallel), 1177 of 10955 tests whose own median is under 2s have a maximum over 12s. Both arms are affected, so it is not the streaming sink specifically: five carriers failed query 6 (distributed_plan_execute_locally = 0) and #110997 failed query 5, the local in-memory arm.

Planned fix: assert the early stop directly instead of timing it, with a PAUSEABLE_ONCE failpoint at each of the two input.close() sites (StreamingExchangeSink.cpp:156, and SinkFromInMemoryExchange in DistributedPlanExecutor.cpp:410), following 04512_distributed_limit_no_more_packets_race.sh. That removes the clock and covers both arms.

Two costs worth flagging first: it adds failpoints to the exchange sinks @ davenger shipped in #114806 six days ago, and a test that waits on global failpoints has to be no-parallel. I will proceed this way unless you prefer otherwise.

Ruled out already: raising the cap (the assertion rests on the ~7s correct versus 50s+ incorrect separation), max_rows_to_read (a range-analysis estimate checked before execution, so it rejects correct runs), and a row-count sentinel (producers legitimately run ahead behind 16 MiB of sink buffering, and query_log never snapshots the local arm's counters).

…nance, not by value

`makeFormatOptionsPrivateToTheClient` compared the inherited value with the
seeded one, so a `default_format` provided by the default profile that happened
to be the same format as the seed was reset as if it were synthetic.

Seed the listener fallback in a separate `seedListenerDefaultFormat`, called
after `setDefaultProfiles`, and only when neither the command line nor the
default profile has set `default_format`. The provenance of the value is then
known outright: only a seed the program itself introduced is taken back out of
`client_context`, whatever its value.

Extended `05023_local_profile_default_format` with a profile whose
`default_format` equals the seed (`TSV`).
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master and addressed the AI Review "Changes requested" verdict.

  • seedListenerDefaultFormat (new) applies the listener fallback default_format after setDefaultProfiles and only when neither the command line nor the default profile set the setting, so the synthetic seed is identified by provenance rather than by value equality; makeFormatOptionsPrivateToTheClient resets only that seed on client_context. Details in Fix clickhouse-local printing TSV instead of PrettyCompact in interactive mode #115360 (comment).
  • 05023_local_profile_default_format now also covers a profile whose default_format equals the seed (TSV).

The only red on the previous head was Docker server image, an infrastructure failure: the job spent 5 hours in apt-get update against the in-region Ubuntu mirror, which is exactly what #115726 ("Rebuild against Canonical when the in-region apt mirror is broken") fixes. Unrelated to this change.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@alexey-milovidov alexey-milovidov self-assigned this Aug 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 22, 2026
Merged via the queue into master with commit c1f6931 Aug 22, 2026
178 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-local-interactive-default-format branch August 22, 2026 23:39
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 23, 2026
@groeneai

groeneai commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Fix: #117764.

The design changed from what I described above. Instead of PAUSEABLE_ONCE failpoints at the two
sink-side input.close() sites, both tests now assert the propagation out of system.text_log: for
every exchange stream between the LIMIT and the sleeping scan, the sink closing its input and the
source sending NoMoreDataNeeded must both appear. A name-keyed one-shot failpoint cannot tell the
several streams of one query apart, so the hop next to the LIMIT consumes it and the assertion goes
vacuous; per-stream identity is what catches a single stuck bucket, which is the case 05024 exists
for. It also drops both costs I flagged: no failpoints in the exchange sinks @ davenger shipped, and
neither test needs no-parallel.

The primary control is 649a4ebd10fc577^, where the instrumentation applies cleanly: 05024 fails
there with 18 of its 21 streams never stopped, while 04891 still passes.

One correction to my message above: local distributed-plan tasks do write QueryFinish rows, 15 of
them, under the initiator's query_id. What they do not do is roll their counters up to the
initiating query, which is the part that actually rules out a row-count sentinel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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