Repository navigation
Client: keep pasted multi-line query under a single prompt - #104299
Conversation
When a multi-line query was pasted into clickhouse-client in a terminal that did not deliver bracketed-paste escape sequences (older terminals, some SSH/tmux setups, certain IDE consoles), every embedded newline was treated as a regular Enter event. The Enter handler called COMMIT_LINE, so the partial query was returned to the outer continuation loop and each subsequent line was rendered under the ":-]" continuation prompt. The paste therefore appeared scattered across several prompts, history was littered with line fragments, and arrow-key navigation across it was lost. Fold those embedded newlines into the same replxx edit buffer when more bytes are still queued in the TTY (i.e. the paste is in progress), regardless of whether `--multiline` is set. With replxx in raw mode all paste bytes are buffered by the kernel TTY at once, so the pending-byte check via a non-blocking select reliably distinguishes paste-in-progress from a deliberate Enter press. With bracketed paste enabled this code path is not invoked at all (replxx absorbs embedded newlines internally), so existing behavior is preserved. The continuation prompt is still used in the genuinely interactive cases - backslash extender and explicit `--multiline` mode without queued data - and those are covered by the existing tests.
|
Workflow [PR], commit [008e9fc] Summary: ✅
AI ReviewSummaryThis PR keeps non-bracketed pasted multi-line input in a single Findings
Final VerdictStatus: Minimum required action: fix the |
|
Tested manually. Old: New: |
The 04209_client_paste_without_bracketed_paste expect script asserted that no ":-]" prompt appears between pasted lines, but in CI replxx drains the kernel TTY byte-by-byte fast enough that hasInputData() returns false during commit_action, so the test caught a case where the underlying patch is a no-op rather than a regression. The fix itself remains best-effort - it helps in environments where pasted bytes stay queued in the TTY between reads, and falls back to the original ":-]" continuation prompt elsewhere. Without a reliable signal we cannot turn this into a deterministic test, so remove it. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=0841f806b9f75808e51b4b0b89fee605fe70420e
Not possible. |
The previous implementation used `select(1, ...)` which only checks file descriptor 0, so the paste-detection heuristic worked only when `in_fd` happened to be `STDIN_FILENO`. Switch to `poll` on the actual `in_fd` so the check works for any descriptor (e.g. SSH or other transports). Per #104299 (comment)
|
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=4c8770c47ae00af15728dff17dddd34f921076bd&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The AST fuzzer failure |
|
@alexey-milovidov fix is in PR #104769. Per your directive, the AST fuzzer failure on this PR ( |
|
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=af067fba3bc6ebb1b269dff7f023bb2697aa1f94&name_0=PR&name_1=Unit%20tests%20%28tsan%2C%20function_prop_fuzzer%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The failing test |
|
@alexey-milovidov fix posted at #104804. The |
|
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=5ef2c1bf4ff0d886602fff8f2ab8f6bdd384abc6&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The |
|
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=5ef2c1bf4ff0d886602fff8f2ab8f6bdd384abc6&name_0=PR&name_1=Stress%20test%20%28arm_tsan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. The |
|
@alexey-milovidov confirmed — this is the chronic Active fix in flight: #104919 by @azat — "Fix No new fix PR from our side; monitoring #104919. |
The prior commit deleted/modified workflow files in this branch as a workaround for GitHub's workflow-scope check. Restoring them to match `master` so the PR diff no longer contains unrelated changes.
# Conflicts: # src/Client/LineReader.cpp
|
@groeneai, check what is with |
|
@alexey-milovidov, fixed on master by your own commit CIDB: 0 master failures in the 32 hours since This PR's CI hit was on commit Closing my in-flight #105687 as superseded. Session: cron:clickhouse-ci-task-worker:20260526-024500 |
|
Merged The two failures on the previous CI run are unrelated to the client paste changes:
A fresh CI run on the merge commit should clear both. |
|
📊 Cloud Performance Report ✅ AI verdict: This PR changes only the interactive command-line input reader (terminal paste handling); it does not touch any server-side query execution path. The ClickBench Q28 -6.26% "improvement" therefore cannot be caused by this change and is reclassified as inconclusive run-to-run variance. The tpch_adapted_1_official Q4 result stays inconclusive as well, with noisy underlying measurements. No real performance impact is attributable to this PR. clickbenchFlagged queries (1 of 43)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_officialFlagged queries (1 of 22)
q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 5/5 (100.00%) | Lost baseline coverage: none · Uncovered code |
…hlight 0 Follow-up to ClickHouse#104299. The paste-folding behavior added there was gated on the `highlighter` callback being present, so with `clickhouse-client --highlight 0` the `highlighter` is empty, the condition short-circuited, and every embedded newline of a non-bracketed paste still took `COMMIT_LINE` and fell back to the `:-]` continuation loop. That made the single-prompt promise from the changelog hold only in the default highlighted mode, even though `--highlight` is a display option. The `NEW_LINE` action in `replxx` only inserts a newline into the edit buffer (`insert_character('\n')`) and does not use the lexer, so the paste case does not actually need the highlighter. Decouple it: the `hasInputData()` paste path now folds embedded newlines regardless of the highlighter, while the explicit `--multiline` continuation keeps requiring the highlighter, preserving the previous behavior. Related: ClickHouse#104299 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When a multi-line query is pasted into
clickhouse-clientin a terminal that does not deliver bracketed-paste escape sequences (older terminals, some SSH/tmux setups, certain IDE consoles), every embedded newline arrives as a regular Enter event. The previous behavior committed each partial line and switched to the:-]continuation prompt for the next, so the paste was scattered across several prompts, history was littered with line fragments, and arrow-key navigation across the statement was lost.This change folds those embedded newlines into the same
replxxedit buffer when more bytes are still queued in the TTY (i.e. the paste is in progress), regardless of whether--multilineis set. Withreplxxin raw mode all paste bytes from a typical paste are buffered by the kernel TTY at once, so a non-blockingpollfor pending input is a best-effort signal that distinguishes paste-in-progress from a deliberate Enter press. With bracketed paste enabled this code path is not invoked at all (replxxabsorbs embedded newlines internally), so the existing behavior is preserved.The continuation prompt is intentionally still used in the genuinely interactive cases — backslash extender (
SELECT ...\<Enter>) and explicit--multilinemode without queued data — and those are covered by01293_client_interactive_vertical_multiline.expect.A deterministic regression test is not feasible: without bracketed paste, the distinction between "paste in progress" and "user pressed Enter quickly" is fundamentally timing-based, and any pty-driven test depends on TTY scheduling that varies across CI runners.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
In
clickhouse-client, when the terminal does not support bracketed paste, embedded newlines from a pasted multi-line query are now folded into the same edit buffer instead of switching to the continuation prompt for every line. The pasted query stays under a single prompt and the arrow keys navigate across its lines. This is a best-effort improvement that relies on the typical TTY-buffered paste behavior.Documentation entry for user-facing changes
Note
Medium Risk
Touches interactive line-commit behavior and low-level TTY readiness checks (
poll), which can subtly affect when queries are committed across terminals and platforms.Overview
Keeps pasted multi-line queries under a single prompt/edit buffer in
clickhouse-clientwhen bracketed paste is unavailable by treating embedded newlines asNEW_LINEwhile more input is queued.Replaces the input-readiness probe in
LineReader::hasInputData()fromselect()to a non-blockingpoll()check, and useshasInputData()inReplxxLineReader’s Enter/commit handler to decide between inserting a newline vs committing the line.Reviewed by Cursor Bugbot for commit 42a73ab. Bugbot is set up for automated code reviews on this repo. Configure here.
Version info
26.6.1.469