Skip to content

Web UI prototype for framing formats - #110210

Merged
alexey-milovidov merged 148 commits into
masterfrom
framing-web-ui
Aug 17, 2026
Merged

alexey-milovidov merged 148 commits into
masterfrom
framing-web-ui

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jul 13, 2026 •

Copy link
Copy Markdown
Member

Prototype changes to the Web UI (programs/server/play.html) to test and showcase the framing formats feature. This is a draft for experimentation and review of the client-side experience, not intended to merge as-is.

It builds on the framing-formats server work in #110127 (this branch is based on that PR, so the diff includes those commits until it merges into master).

What the prototype does:

  • Streams every query with the EventStream framing format over HTTP (framing_output_format=EventStream, send_logs_level=trace), decoding data / progress / log / profile_events / exception packets as they arrive - so progress and logs work regardless of the output format (including FORMAT Pretty, binary formats via base64, and images).
  • Shows realtime CPU, memory, and disk usage like clickhouse-client, aggregated per host (total and max/host), switching to peak RAM when the query finishes. The meter state is owned by each tab: the CPU counters in profile_events packets are per-packet increments, so a query running in a background tab keeps accumulating them, and reopening the tab continues the meter from its live values (rather than restarting near zero).
  • Merges elapsed time, realtime metrics, and rows/bytes read stats into a single progress area with the progress-bar gradient rendered behind all of them; the text is tinted by a mask clipped from the same gradient so it stays readable over the fill.
  • Displays server logs in real time, colored like the client, with a Logs button available even on exception; the log view stays fast for 100k+ lines while keeping native browser search, bounding retention to the most recent 100k lines (older lines are dropped and counted in a marker line). The full response text kept for the tab/history snapshot is also capped as it is collected (at ~100 KB, the size above which the snapshot is dropped), so a single large framed data/log burst is not retained in full only to be discarded later. A failed run whose reply outgrew that cap is persisted as a compact snapshot that keeps the exception carrier in the form its framing kind replays (the terminal event: exception block, the {"packet":"exception",...} line, or the plain {"exception":...} line, captured at stream-read time since the capped text stops growing before the terminal exception arrives), so reopening or reloading a failed tab still shows the error reason.
  • Base64-decodes every data/totals/extremes payload (the EventStream wire encodes each block as a single base64 data: field and the Content-Type carries payload=base64), deciding the rendering by the output format: the default format is reassembled into the table, an image format (or bytes carrying an image signature) is rendered as an inline image once the stream completes, and any other format is decoded and shown incrementally as raw text.
  • Uses a framing-compatible default format for queries without an explicit FORMAT clause: the framed request asks for JSONCompactStringsEachRowWithNamesAndTypes (the framing rejects the in-band-progress JSONStringsEachRowWithProgress) and the client reassembles the compact rows into the table renderer's shapes; on the server side (Framing formats: multiplex data, totals, extremes, progress, logs, and profile events in the HTTP response stream #110127) the compact family emits totals and extremes under framing, so WITH TOTALS and extremes-based column coloring keep working on the default path. When such a format is shown as raw text instead (an explicit FORMAT JSONCompactEachRow), only the data packets are concatenated, so the rendered text is exactly the plain output of that format rather than one carrying the totals and extremes rows the format itself drops.
  • Propagates a framed exception packet as a query failure even when the HTTP status was already 200 (so Run all stops at the failed statement) - and, when a query chooses its own JSONEachPacket* framing that fails before the 200 OK header (coming back as a non-200 application/x-ndjson packet stream ending with a {"packet":"exception",...} line), shows those packets verbatim and records framing_kind = 'ndjson_packets' for replay rather than rendering the whole stream as one opaque error string; retries framing-incompatible explicit formats (e.g. FORMAT JSONEachRowWithProgress, FORMAT Template) once without framing for read-only queries (read-only-ness is resolved with a CTE-aware lexer walk - WITH y AS (SELECT 1) INSERT INTO t SELECT * FROM y is a write - shared with Run all's grouping, so such a statement is also a barrier there and never runs in parallel with the reads that follow it; the port with regression coverage lives in src/Parsers/tests/gtest_play_query_is_read_only.cpp); a retried JSON*EachRowWithProgress format that itself reports a failure in-band - a trailing {"exception":...} object while the HTTP status stays 200 (http_write_exception_in_output_format) - is detected as a failure too, keyed off the output format rather than only a user-chosen JSONEachPacket* framing, so Run all stops after such a retried query fails; and does not add its own framing to a query that sets its own framing_output_format to a real framing choice (the response is then dispatched by content type, so the requested packets are shown verbatim); a query that sets framing_output_format = 'None' is refused client-side instead, since this page's rendering depends on framing (values the page cannot know upfront - = DEFAULT, a reset to the session/server default, and query-parameter placeholders like = {fmt:String} - are classified conservatively the same way and refused, rather than sent with a request shape the response might not match); likewise a standalone SET framing_output_format = ... is refused, because it would change the setting for the whole session (with a session_id) while the page keeps adding its own framing per request - a query-level SETTINGS framing_output_format = ... clause is the supported way to choose framing for one query. A query that carries its own framing_output_format is also refused for download (the setting would override the download's chosen default_format, so the file would be the framing packet stream), and if such a query fails, its history snapshot - the raw JSONEachPacket* packet stream - is replayed as raw text on tab-switch/reload rather than as one opaque error string.
  • Pins framing_output_format=None on every request that expects an unframed response (the plain/chart request, the compatibility retry, the download, and the panel/server-status/completion queries), rather than only omitting the setting - otherwise a framing carried by the connection URL or by the HTTP session behind it would frame those responses too. A query-level SETTINGS framing_output_format = ... clause is applied after the URL parameters, so a query that intentionally chooses a framing still overrides the pin.
  • Records the framing kind (event_stream / ndjson_packets / none) with each result snapshot and keys the history/tab replay off it, instead of guessing from the payload's first bytes - so a raw result whose text happens to start with event: (e.g. SELECT 'event: data' FORMAT RawBLOB) or {"packet": is not reparsed as a framing stream after a tab switch or reload. A snapshot recorded as ndjson_packets is replayed as raw text regardless of whether the run succeeded and of its underlying output format, matching the live path - so a successful user-framed JSONEachPacket* result whose format has its own restore path (a table or a JSONCompactColumns chart) is not reparsed as that format's JSON. The snapshot also records whether the framed stream was truncated, so replay keeps the live fail-closed behavior for images: a cut-off framed FORMAT PNG response that showed only its error live reopens from history / Back / Forward as that error too, never as a partially decoded picture (a failed but complete stream - a terminal exception packet after the payload - still renders its collected image, as live).
  • Detects both the query's FORMAT clause and its framing_output_format setting with the WASM lexer rather than a raw text match, so a mention inside a string literal or a comment - e.g. SELECT 'FORMAT JSONCompactColumns' - does not make the page silently opt out of its own framing. The detection is positional, not keyword-adjacent: a settings context is recognized by its name = value list grammar (a column merely named settings does not open one), and a FORMAT clause candidate must follow a token that ends an expression (so in WITH 1 AS format SELECT format JSONCompactColumns SETTINGS max_threads = 1 both format words are identifiers, not a clause). The download reuses the same FORMAT-clause detection (now returning the clause span) to strip only a real trailing FORMAT clause from the download query, leaving text or ordinary SQL like SELECT 'FORMAT TSV' AS s untouched. Both detectors also accept a quoted spelling of the name - the server parses setting names and FORMAT names with identifier parsers, so a backquoted framing_output_format or format name is real - comparing by the unquoted name. Regression coverage for both lives in src/Parsers/tests/gtest_play_detect_explicit_format.cpp and gtest_play_detect_framing_setting.cpp (ports of the token walking onto the real DB::Lexer).
  • Dispatches on the response output format case-insensitively. Format names are case-insensitive in ClickHouse (FormatFactory looks them up by their lowercased name), while X-ClickHouse-Format echoes the identifier exactly as the FORMAT clause spelled it, so FORMAT jsoncompactcolumns used to lose the chart renderer, a lowercased default format lost the table renderer, and the late in-band exception probes did not recognize FORMAT xml / FORMAT json / FORMAT jsoneachrowwithprogress - a query failing after its 200 OK header was then reported as a success and Run all continued past it. Every dispatch now compares a lowercased copy of the format name.
  • On the server side (Framing formats: multiplex data, totals, extremes, progress, logs, and profile events in the HTTP response stream #110127), framed pulling SELECT queries now also end with the documented final progress packet carrying result_rows / result_bytes / memory_usage, matching the native protocol and the no-result path.

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

Prototype Web UI changes to test framing formats (draft).

Related: #110127

Version info

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

alexey-milovidov and others added 2 commits July 13, 2026 05:17
Rework the query progress display in the Web UI to consume the
`EventStream` framing format over HTTP, so it works regardless of the
output format (including `FORMAT Pretty`, binary formats via base64, and
images).

- Stream every query with `framing_output_format=EventStream` and
  `send_logs_level=trace`, decoding data/progress/log/profile_events/
  exception packets as they arrive.
- Show realtime CPU, memory, and disk usage like `clickhouse-client`,
  aggregated per host (total and max/host), switching to peak RAM when
  the query finishes.
- Merge elapsed time and realtime metrics into a single element rendered
  on top of the progress bar; keep the text readable with a
  background-clip gradient that darkens the glyphs only over the colored
  fill (per-theme peak color and fraction).
- Display server logs in real time, colored like the client, with a
  Logs button available even on exception; keep the view fast for 100k+
  lines via batched appends and content-visibility while preserving
  native browser search.
- Render inline images for image output formats, and base64-decode
  binary payloads signalled by the `payload=base64` content type.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Iterate on the query progress display:

- Merge the elapsed time, realtime resource metrics, and rows/bytes read
  stats into a single progress area so the progress-bar gradient renders
  behind all of them; the read stats stay right-aligned and wrap when
  long, the elapsed/metrics text keeps its natural width.
- Draw the colored bar only one text line tall, so when the read stats
  wrap and grow the area the fill stays a single-line strip.
- Tint every glyph (left metrics and right stats alike) with a text mask
  clipped from the same full-width `--progress` gradient as the bar, so
  the two correspond exactly and the text stays readable over the fill.
  Light theme uses a plain gray to black; dark theme uses a steep
  gray to white (first quarter) then a jump to black.
- Use a 10pt font for the progress area.

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

mintlify Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Jul 13, 2026, 11:14 AM

@clickhouse-gh

clickhouse-gh Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c0da97c]

Summary: ✅


AI Review

Summary

This PR turns the Web UI prototype into a framing-aware client with substantial new request-shaping, replay, and tab-state logic in play.html, plus parser-style regression ports and shell/integration coverage. The current head is much closer than earlier revisions, but I still found three user-visible correctness gaps: wrapped inline INSERT queries can still be misparsed as if their payload were SQL, restore of failed plain JSONEachRow / NDJSON responses can diverge from what the live run showed, and auxiliary-connection failures can leave stale Download/Copy actions wired to an older result.

Findings

⚠️ Majors

  • [programs/server/play.html:13623] tokensBeforeInlineInsertPayload only recognizes inline-payload boundaries when the first top-level keyword is literally INSERT. ParserInsertQuery also accepts a leading WITH, and ParserExplainQuery can wrap an INSERT while keeping the inner input-FORMAT semantics. As a result, WITH ... INSERT ... FORMAT <input> / EXPLAIN INSERT ... FORMAT <input> can leak payload bytes into detectFramingSetting and detectExplicitFormatClause, so the page can reject or reshape valid queries based on payload text.
    Suggested fix: detect wrapped INSERT forms before deciding whether to stop at the input FORMAT boundary, and add the same cases to the mirrored parser-port tests.

  • [programs/server/play.html:10217] renderFailedSnapshot no longer reproduces the live rendering for failed plain JSONEachRow / NDJSON responses. The live non-200 path parses the first {"exception":...} line and shows only the error, but restore falls through the “partial output + display_error” branch because parseInbandException deliberately does not recognize those ambiguous each-row formats. A restored failure can therefore replay the raw exception line as output and then render the error again, which is not what the original run showed.
    Suggested fix: treat the saved plain-JSON error body the same way the live !response.ok path does instead of replaying it as raw output when display_error came from that branch.

  • [programs/server/play.html:11231] clearPanel resets the visible pane and progress chrome but does not clear tab.downloadVisible / tab.copyVisible or repaint the shared download/copy targets. The connection-check error path still calls clear() before rendering its error, so a tab that previously had a successful result can keep exposing Download/Copy actions that still point at the old last_*_for_download state while the pane now shows only a network/auth failure.
    Suggested fix: clear the tab’s download/copy visibility and stale download targets in clearPanel (or repaint them explicitly in the auxiliary-error path).

Tests
  • ⚠️ Add focused detectFramingSetting / detectExplicitFormatClause coverage for wrapped inline inserts such as WITH ... INSERT ... FORMAT ... and EXPLAIN INSERT ... FORMAT ...; the current gtest ports only cover bare INSERT forms and copy the same assumption as production.
  • ⚠️ Add restore-path coverage for failed plain JSONEachRow / NDJSON snapshots and for connection-check failures after a successful downloadable result; the current shell/harness tests pin wire contracts and some browser flows, but not these replay/chrome-state cases.
Final Verdict

⚠️ Request changes. The framing/runtime work is substantial and many earlier gaps are fixed, but the current head still has three correctness issues in request shaping and state restoration that can produce the wrong query behavior or the wrong UI state.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.80% 86.80% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.10% 79.10% +0.00%

Changed lines: Changed C/C++ lines covered: 681/730 (93.29%) · 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 Jul 13, 2026
- Replace the Result/Logs button pair with a single "Logs" toggle at the
  front of the progress line (just before the elapsed/metrics text). It
  switches the result element(s) between the query result and the
  streamed server logs, shows a dotted underline, uses the monospace
  font, and gets a yellow background while the logs view is active.
- Show the toggle only when the query produced at least one log line, so
  it stays hidden when a query has not started or produced no logs.
- Drop the now-meaningless leading `NN.N%, ` from the read stats once the
  query finishes (the percentage only matters while progressing to 100%).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Interpreters/executeQuery.cpp Resolved
Comment thread src/Interpreters/executeQuery.cpp Resolved
Comment thread programs/server/play.html Resolved
alexey-milovidov and others added 3 commits July 13, 2026 08:35
…m snapshot

Address review (#110210): the
history/tab replay path only distinguished the default (table) output from
`rawText`; it never recorded whether the saved `EventStream` response used
`payload=base64` (a binary or raw output format such as `Native` or `RawBLOB`).
A restored snapshot of such a result was therefore replayed as literal base64
text, whereas the live `readEventStream` path decodes the payload to bytes and
renders it as an image or raw text.

Persist an `is_base64` bit with the result snapshot (single-query, multi-query,
and the `saveHistory` / flat-entry serialization) and have `renderEventStreamText`
decode the base64 `data`/`totals`/`extremes` payloads and hand them to
`renderBinaryPayload`, exactly like the live path. A base64 snapshot is rendered
as an image or raw text and is never finished as a table.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Keep the Web UI prototype current with master and clear the reported conflict
with the base branch. The only conflict was a single hunk in
`programs/server/play.html`, in the non-OK response branch of `postImpl`:
master added query-error highlighting (`highlightQueryError`, guarded by
`editorInteractionGen === runEditorInteraction`) while this branch added the
`is_base64` field to the returned result and reworked the image `else if`
condition to exclude framed (`text/event-stream`) responses. Resolved by
keeping both: master's error-highlighting block, followed by this branch's
`is_base64` return and framing-aware image branch. The `queryStart` argument
that master threads into `postImpl` is already present (auto-merged), so the
highlight call is in scope.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread programs/server/play.html Resolved
Comment thread src/Interpreters/executeQuery.cpp Resolved
Comment thread src/Interpreters/executeQuery.cpp Resolved
Comment thread src/Interpreters/executeQuery.cpp Resolved
Comment thread programs/server/play.html Resolved
alexey-milovidov and others added 3 commits July 13, 2026 12:28
…o read-only queries

Two fixes to the framing `EventStream` consumer in `play.html`, addressing the
AI review of the PR:

- `profile_events`: `EventStream` serializes each `profile_events` packet as a
  single JSON array of event objects in one `data:` field, but the client pushed
  every parsed line as one element, producing `[[...]]`. `feedProfileEvents` then
  saw the whole batch as a single element with no `thread_id` / `name`, so the
  realtime CPU / RAM / disk meters stopped updating for framed queries. Flatten
  the parsed batch into individual events (a bare object is tolerated too, for
  older one-per-line servers).

- No-framing retry: the Web UI enables framing for every query, and a non-pulling
  pipeline (`INSERT`, DDL) never creates a framing stream, so such a statement can
  return a plain-HTTP error after it has already run. The previous code retried
  the whole request on any non-event-stream error, which could duplicate the
  side effect. Gate the retry to read-only queries (`queryIsReadOnly`, the same
  read-only kinds treated as parallelizable), so a side-effecting statement is
  never blindly resubmitted.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Comment thread src/Interpreters/executeQuery.cpp Resolved
Comment thread programs/server/play.html Resolved
alexey-milovidov added a commit that referenced this pull request Jul 13, 2026
…ed but rejected

When a query requested framing and the output format was rejected by
`IOutputFormat::setFraming` on the data path (a format that defers totals
and extremes to finalization, such as `Template`, or writes progress
in-band, such as `JSONEachRowWithProgress`), the rejection was thrown
after `output_format` had already been assigned. The exception-recovery
path in `executeQuery` only recreated the format when `output_format` was
null, so it treated the leftover format as usable - but it is not framed,
and it writes to the payload buffer of a framing format that was already
destroyed during stack unwinding. The error therefore fell back to a
plain HTTP error body instead of a framed `exception` packet.

Recovery now also recreates the format when framing is requested by the
effective settings but the existing format is not framed. In addition,
the framed exception path uses a `Null` carrier format instead of the
query's own format: with a framing format the exception packet is
written by the framing itself and the output format writes nothing in
exception-only mode (`framing_exception_only`), while the real format
may not even be constructible on the exception path - for example
`Template` referencing header columns when the header is empty. This
also frames exceptions raised before the output format existed for such
formats.

Extends `04512_framing_formats` with regressions for all three cases:
the deferred-totals rejection and the in-band-progress rejection are
delivered as framed exception packets, and a pre-format exception with
`Template` is framed too.

Addresses an AI review finding on #110210 (which carries this PR's
commits): #110210 (comment)
The "Run all" snapshot mapper stored `data: null` for every statement
with `is_image`, on the assumption that images stream as a blob and
cannot be re-rendered from text. That is only true for non-framed image
responses; a framed image (`FORMAT PNG` over the `EventStream` framing)
has a replayable `reply` - the full event stream whose base64 payload
`renderEventStreamText` decodes back into the picture on restore. Such
statements were lost on tab switch / reload in multi-query mode, while
the single-query history path kept them.

Persist the `reply` for framed (`is_base64`) images and store `data:
null` only for non-framed blob images, whose `reply` is empty anyway.

Addresses an AI review finding:
#110210 (comment)
Comment thread programs/server/play.html Resolved
alexey-milovidov and others added 2 commits July 14, 2026 04:15
Add a "Metrics" toggle next to "Logs" in the progress line that shows an
extended profile-event metrics table, mirroring the clickhouse-client
progress table shown on Space:

- Live table of profile events (thread_id 0, aggregated per host), with
  Event name, Value, per-second rate, and a realtime sparkline; rows
  reorder by freshness then magnitude while the query runs, and switch to
  totals / query-average rates when it finishes.
- Value type inferred from the metric name (`*Bytes`/`*Chars` and the
  memory trackers are sizes, `*Microseconds`/`*Milliseconds`/
  `*Nanoseconds` are durations); the rate is tinted by magnitude with the
  client's escalating palette (per-theme variables).
- Sparklines: one sample per pixel, grow left-to-right, scroll (latest
  window) on overflow, and compress to the cell on finish; zero samples
  are skipped; each fragment is colored by its own sample's tier;
  unbounded, lock-step history so all sparklines stay time-aligned.
- Each CamelCase word of the metric name is hash-colored; hovering a word
  highlights every row sharing it; hovering or clicking a row highlights
  it, and a clicked (or hovered) row is pinned in place while the others
  reorder; metric-name text stays selectable.
- Header removed; horizontal row lines only; K/M/G/T suffixes for counts.

Also:
- Fix the result table collapsing to zero-width columns when returning
  from the logs/metrics view: defer the fixed-layout measurement while
  the table is hidden and run it when the result view is shown again.
- Reset the progress-line metric-width debouncing for every new query.
- Harden formatReadable against unit overflow (no more "undefined/s").

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Added the remaining executable Run all failure-barrier coverage in 587b148. The VM harness executes production postMulti with a decoded in-band failure result, verifies the first failed statement leaves the tab in error, and proves a following INSERT is never dispatched. The full harness passes locally (56 assertions).

Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
Do not treat  immediately after  as a query-level  clause. This avoids incorrectly disabling the Web UI framing path for a select-list column named .

Add fallback-tokenizer coverage for the real production path.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110210&sha=2da21a1f9edfcde825b7e651313d6548766543d8&name_0=PR

PR: #110210
Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
@alexey-milovidov alexey-milovidov self-assigned this Aug 17, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 17, 2026
Merged via the queue into master with commit 3773be5 Aug 17, 2026
181 checks passed
@alexey-milovidov
alexey-milovidov deleted the framing-web-ui branch August 17, 2026 01:42
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 17, 2026
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Aug 21, 2026
…w-feedback

Fix remaining Web UI review feedback from ClickHouse#110210
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