Repository navigation
Add a documentation search Web UI backed by system.documentation - #108345
Conversation
Add `/docs` ("ClickHouse Reference"), an embedded single-page Web UI for
instant search over `system.documentation`, rendering each entity's Markdown
(with KaTeX math, ClickHouse SQL syntax highlighting via the embedded
`Lexer.wasm`, `:::note` admonitions, heading anchors, and in-app links to
related/aliased entities). Wired up like the other built-in pages (`/play`,
`/merges`, ...) in `WebUIRequestHandler` and `HTTPHandlerFactory`.
Also fix the embedded documentation so it does not emit empty fenced code
blocks: `examplesAsString` no longer emits a `Query`/`Response` block when that
field is empty, and the `filesystem`/`format` table-function examples no longer
double-wrap their already-fenced queries. Covered by a new stateless test.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [4ad7e742] Summary: ✅
AI ReviewSummaryThis PR adds the built-in Final Verdict
|
|
I'm already in shock at how good it looks and feels. A draft - because not every visual detail is polished. |
The built-in `/docs` documentation search page loaded the `marked` (Markdown) and `katex` (TeX math) renderers from `cdn.jsdelivr.net`. That executes third-party network code inside the ClickHouse HTTP origin, which also handles the `user`/`password` credentials entered on the page, so a CDN or package compromise could read those credentials or issue and exfiltrate queries as the user. It also broke the page's self-contained/offline contract. Vendor `marked.min.js`, `katex.min.js`, and `katex.min.css` under `programs/server/js/` and serve them from the binary via the existing `JavaScriptWebUIRequestHandler` `/js/` route. The KaTeX fonts are inlined into the stylesheet as `data:` URIs, so the page pulls no external font files either. `DocsWebUIRequestHandler` rewrites the CDN links to the same-origin `/js/` paths when serving the page, mirroring how `DashboardWebUIRequestHandler` handles `uplot.js`/`lz-string.js`; the CDN URLs are kept in the source so the page still works when opened as a local file against a remote server. Add a stateless test `04409_docs_web_ui_local_assets` that checks the served page references the local `/js/` assets, loads no `cdn.jsdelivr.net` code, and that the assets are served from the binary with the fonts inlined. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`loadAllNames` on the `/docs` page caches the entity-name map even when the request to `system.documentation` failed or returned a non-OK response. On a server that requires credentials, the background call during initial page load runs before the user enters them, stores an empty map, and then `rewriteLinks` and `linkifyReferences` keep using that stale empty cache even after later searches succeed with the new credentials, until the page is reloaded. Publish `all_names` only after a successful response (a failed or errored request returns an empty map for that call but leaves the cache unset so a later call retries), and invalidate the cache when the connection URL, user, or password changes so it is rebuilt against the new connection. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Document the new built-in `/docs` HTTP page (the documentation search Web UI backed by `system.documentation`): what it does, how it connects, that all renderer assets are served from the binary rather than a CDN, and the security considerations. Mirrors the structure of the `web-terminal.md` page. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
In the dark theme of the `/docs` documentation search page, links used a blue (`#4AA8FF`) that does not fit the dark palette. Use the ClickHouse yellow (`#FF0`) — the same accent the page header already uses — instead. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `/docs` page issued its queries without an `Authorization` header, so the browser could attach stored HTTP Basic credentials and the page would authenticate as a cached `default` login instead of the empty credentials in the form. Send `Authorization: never` on the fetches, exactly as `play.html` does, so that empty `user`/`password` fields connect as the default user with an empty password rather than as a cached `default` login. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…cpp`
`WebUIRequestHandler.cpp` embeds its web UI resources with `#embed`, but the
`OBJECT_DEPENDS` list was missing several of them — `viz-standalone.js`,
`processors_profile.html`, and `docs.html` — as well as the newly added
`marked.min.js` and `katex.min.{js,css}`. Without those entries, editing one of
the missing files did not trigger a recompile, so an incremental build kept
embedding (and serving) a stale page. List every embedded resource so each one is
tracked as a dependency.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…rged 04409 test Merging master brought in 04409_system_documentation_source_and_entities, which collides with this PR's 04409_docs_web_ui_local_assets. Renumber the latter to 04410. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…` page The merged \`system.documentation\` work added more kinds of documented entities (compression codecs, profile events, current and asynchronous metrics, and the system tables themselves) and a \`source\` column with the repository-relative path of the file each entity's documentation comes from. Color-code the new entity kinds in the result list, and select \`source\` in the search query so it is available for rendering. Next to the title of the open entity, show a pencil link to its source file on GitHub (the \`master\` branch); it is omitted when the source location is unknown (e.g. an alias of an undocumented function). Test 04411 checks that the served page selects \`source\`, points the pencil link at GitHub, and color-codes the new entity kinds. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
When the page is opened as a local file (`file://`) and pointed at a remote ClickHouse server, the queries are cross-origin (the browser sends `Origin: null`), and ClickHouse only adds `Access-Control-Allow-Origin` when `add_http_cors_header=1` is set. The previous condition suppressed the header in exactly the `file://` case that needs it, so searches and `loadAllNames` were blocked by CORS. Request the header unconditionally, like `/play` and `/schema`. Addresses review feedback. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…that produced it The cross-link name cache (`all_names`) was published unconditionally at the end of `loadAllNames`. If the user changed the connection (server URL, user, or password) while the request was in flight, the `change` handler cleared `all_names`, but the older in-flight request then resolved and re-populated the cache with names fetched from the previous server or user. Subsequent searches ran against the new connection while `rewriteLinks`/`linkifyReferences` used the stale names, so in-app documentation links could point to entities that do not exist or mean something different on the active server. Snapshot a connection generation counter (`connection_seq`, bumped on every connection change, mirroring the existing `request_seq` pattern used to discard superseded keystrokes) before issuing the request, and publish into `all_names` only when the snapshot still matches. The immediate caller still receives the fetched map, but a stale in-flight response is no longer cached. Addresses the AI review finding on `programs/server/docs.html`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ry and connection `runSearch` checked `request_seq` only after `fetch` returned, but then awaited `response.text()` a second time without re-checking. A newer keystroke (bumping `request_seq`) or a connection change (bumping `connection_seq` and clearing `all_names`) during that second await let the stale body still replace `current` and render against the now-current `URL`/credentials, mixing results from the previous connection into the rebuilt cross-link cache. Snapshot `connection_seq` at the start of `runSearch` (mirroring `loadAllNames`) and re-check both `request_seq` and that snapshot after each `await`, so a superseded response is dropped instead of rendered. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `/docs` documentation search page rendered the Markdown stored in `system.documentation` by feeding the output of `marked.parse` straight into `innerHTML`. `marked` is not a sanitizer: it passes raw HTML through verbatim and keeps any URL scheme in links and images. Because this page intentionally queries the server `URL` the user enters and renders the response in the same HTTP origin that holds the connection credentials, an untrusted or compromised `system.documentation` could inject `<img src=x onerror=...>` or `[x](javascript:...)` that runs in this origin, reads the `user`/`password` fields, and issues same-origin queries. Sanitize every rendered document against an allowlist before it reaches the DOM: elements not on the list are dropped with their subtree, attributes not on the list (including all `on*` event handlers) are removed, and `href`/`src` are kept only for safe URL schemes (`http`, `https`, `mailto`, relative, and `#` fragments) — `javascript:`, `data:`, `vbscript:`, and the like are rejected, with ASCII whitespace and control characters stripped first so tricks like `java\tscript:` are still caught. The allowlist covers what Markdown, the admonition and math extensions, and KaTeX (its HTML and the parallel MathML) legitimately produce, so syntax highlighting, math, admonitions, and cross-links are unaffected. Add `04412_docs_web_ui_markdown_sanitized` to guard that the served page routes rendered Markdown through the sanitizer, keeps the element/attribute allowlist and the URL-scheme policy, and no longer contains the direct-`innerHTML` sink. Addresses the review at #108345 (review) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Related downstream PR here when this merges ClickHouse/clickhouse-docs#6453 |
`preprocessMarkdown` strips MDX status badges so that an unstripped self-closing custom tag such as `<ScalePlanFeatureBadge .../>` does not get parsed by the HTML parser as an unclosed non-void element that swallows the rest of the document into its subtree (which the sanitizer then drops, rendering the entry empty or truncated). It stripped the known names in `MDX_COMPONENTS` plus any component brought in by a local `import`. That leaves a `*Badge` the documentation toolchain adds later and that an entry uses without a local import unhandled. Strip any `*Badge` component by name regardless of import, removing the dependency on the local `import` being present, the same way the terminal Markdown renderer (`TerminalMarkdownRenderer`) already does. A `*Badge` is a PascalCase component name that does not occur in documentation prose, so this does not over-strip. New test `04493_docs_web_ui_badge_strip`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed Relative-link routing (
|
|
@alexey-milovidov Attribution: STID Evidence:
So this is the same transient-exception-hits-fail-fast-terminate bug as #106736 (its example was CI reports:
|
|
The two CI reds on the current head (
Neither can be caused by a documentation-UI / doc-string change; a rerun should clear both once the in-progress run completes.
|
|
Both CI reds on the current head (
@groeneai, for attribution: the |
|
CI triage for head The single red on this head is a flaky, unrelated test:
I could not re-run the single failed job yet (the @groeneai, this test ( |
|
1. A fix is already in progress: #108854 (yours, opened 2026-06-29, currently MERGEABLE), which targets exactly this signature ( CIDB (since 2026-06-01) backs the "widespread pre-existing flake" read: 45 failures across 33 distinct PRs and 4 So no separate PR from me is needed. There is no dedicated open tracking issue (only the closed #93018, which #108854 already references), so I have not opened a redundant one; happy to if you want a canonical open tracker until #108854 lands. 2. Confirmed: it belongs to #104857 (crash site 3. functions stress test Superseded. On the current head |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 3801/3816 (99.61%) · Uncovered code |
|
CI triage for head The sole red on this head is a new, unrelated flake that surfaced (job completed
I re-ran the failed job (workflow @groeneai, for attribution: please confirm the |
|
@groeneai, fix the "Not ready set" problem. |
|
@alexey-milovidov confirmed: STID
Not a blocker for this PR. |
|
@alexey-milovidov On it. Root cause (independent read, matches your #107924 diagnosis): during primary-key / skip-index analysis, Scope: chronic and master-wide, not PR-specific. Family STID #107924 addresses exactly this by making the speculative build non-destructive. The open point is the clone-vs-flag design question in the review. My plan: deterministically reproduce it (via your |
Adds the `interfaces/documentation-search` page (the /docs search Web UI) to the "Native clients & interfaces" sidebar group so it is not a floating page once it syncs from the ClickHouse repo. Depends on ClickHouse/ClickHouse#108345, which adds the page source. Must not be merged until that PR is in ClickHouse master, otherwise the docs build fails on a sidebar entry pointing at a non-existent doc. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Step 1 of adding the /docs Web UI page (ClickHouse/ClickHouse#108345): excepts the new interfaces/documentation-search page from the floating-pages check so the docs check on #108345 passes. Once #108345 merges, a follow-up PR removes this entry and adds the page to sidebars.js. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The `/docs` documentation search page rendered the Markdown stored in `system.documentation` by feeding the output of `marked.parse` straight into `innerHTML`. `marked` is not a sanitizer: it passes raw HTML through verbatim and keeps any URL scheme in links and images. Because this page intentionally queries the server `URL` the user enters and renders the response in the same HTTP origin that holds the connection credentials, an untrusted or compromised `system.documentation` could inject `<img src=x onerror=...>` or `[x](javascript:...)` that runs in this origin, reads the `user`/`password` fields, and issues same-origin queries. Sanitize every rendered document against an allowlist before it reaches the DOM: elements not on the list are dropped with their subtree, attributes not on the list (including all `on*` event handlers) are removed, and `href`/`src` are kept only for safe URL schemes (`http`, `https`, `mailto`, relative, and `#` fragments) — `javascript:`, `data:`, `vbscript:`, and the like are rejected, with ASCII whitespace and control characters stripped first so tricks like `java\tscript:` are still caught. The allowlist covers what Markdown, the admonition and math extensions, and KaTeX (its HTML and the parallel MathML) legitimately produce, so syntax highlighting, math, admonitions, and cross-links are unaffected. Add `04412_docs_web_ui_markdown_sanitized` to guard that the served page routes rendered Markdown through the sanitizer, keeps the element/attribute allowlist and the URL-scheme policy, and no longer contains the direct-`innerHTML` sink. Addresses the review at ClickHouse#108345 (review) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Some embedded documentation entries open with an MDX status badge that the text does not `import` locally: `transactionID`, `transactionLatestSnapshot`, and `transactionOldestSnapshot` start with a bare `<ExperimentalBadge/>` / `<CloudNotSupportedBadge/>`. `preprocessMarkdown` only stripped the components that were actually imported, so these survived. The HTML parser then treats the self-closing custom tag as an unclosed non-void element that swallows the rest of the document, and the sanitizer drops that whole subtree, so the entry renders as an empty page. Seed the strip set with a curated allowlist of known MDX components (`MDX_COMPONENTS`) so they are removed whether or not they were imported, while still preserving literal `<...>` placeholders in prose (e.g. a `<SearchPhrase>` in an XML example). Adds `04418_docs_web_ui_importless_mdx_badge` and updates `04415_docs_web_ui_mdx_components_stripped` for the changed initialization. Addresses review on ClickHouse#108345 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…down sanitizer The `/docs` page renders Markdown from `system.documentation` through an allowlist sanitizer that drops elements not on the list together with their whole subtree. Some embedded docs wrap a note in an ordinary `<details><summary>...</summary>...</details>` disclosure block, for example the "Implementation details" sections of the `uniq` and `uniqCombined` aggregate functions. Because `details` and `summary` were not on the allowlist, those sections were removed from the rendered page entirely. Add `details` and `summary` to the tag allowlist and `open` to the attribute allowlist; these are safe, standard HTML5 disclosure elements. Adds `04417_docs_web_ui_disclosure_details`. Addresses review on ClickHouse#108345 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…d relative cross-section paths Two gaps in the `/docs` renderer's link handling, both losing or misrouting real existing documentation: - `rewriteLinks` collapsed every entity type to one lower-cased `name`, but names are not unique across types in `system.documentation` (for example `JSON` is both a data type and a format). A link such as `[JSON](/interfaces/formats/JSON)` was rewritten to the `JSON` data type instead of the `JSON` format. Keep all same-named entities (`all_names` now maps a name to the list that share it) and disambiguate by the link's target route (`typeFromDocsHref` / `resolveDocEntity`); when the route gives no hint, leave the link as an external docs link rather than guessing. `linkifyCode` (for `Related:`/`Alias of` references, which carry no route) linkifies only an unambiguous single match. - `toDocsURL` resolved every relative fallback as if it were rooted at `/docs` by stripping the leading `../`, so a source-relative cross-section link such as `mortonEncode`'s `../data-types/int-uint.md` became the broken `/docs/data-types/int-uint` instead of `/docs/sql-reference/data-types/int-uint`. Resolve the first segment of a relative path to its canonical section route (`DOCS_SECTION_ROUTE` / `DOCS_ROUTE_ROOTS`). Adds `04419_docs_web_ui_link_disambiguation` and `04420_docs_web_ui_relative_link_route`. Addresses review on ClickHouse#108345 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…d of a fabricated path Addresses the review on PR ClickHouse#108345: `toDocsURL` resolved the leading segment of an unmappable relative link from the docs root, so a bare same-directory link such as `textindexes.md` became `https://clickhouse.com/docs/textindexes`, which 404s (the real route is `/engines/table-engines/mergetree-family/textindexes`). Such a link carries no section information, and an entity's embedded `source` is a code path, not a docs path, so its docs route cannot be determined. `toDocsURL` now falls back to the docs root for any relative link whose route it cannot map, matching the function's own stated intent ("fall back to the docs root") and the fail-close principle of not emitting a fabricated path. The few embedded documentation entries that used bare same-directory links now spell them as absolute docs routes that resolve correctly in both the `/docs` page and the website: `textindexes`/`annindexes` in the `MergeTree` table-engine docs and `memory-overcommit` in the memory-limit settings. New test `04489_docs_web_ui_same_directory_link` covers the same-directory case.
…rch-demo Add a documentation search Web UI backed by system.documentation
Adds
/docs— "ClickHouse Reference", a small, self-contained Web UI for instant search over the newsystem.documentationtable.Type in the search box and it queries
system.documentationover HTTP (parameterized, debounced), shows the matches in a type-color-coded list, and renders the selected entity's Markdown. Rendering includes:Lexer.wasm(the same lexerplay.htmluses);corrpage);:::note/:::tip/... admonitions, heading anchors with shareable links, and a hover "Copy" button on code blocks;https://clickhouse.com/docs; "Related" and "Alias of" references become in-app links.State (search term, open entity, section) is mirrored into the URL fragment via the History API; there is a light/dark theme switcher with autodetection and memoization, matching
play.html(logo, typefaces, theme-aware scrollbars).The page is wired up like the other built-in UIs (
/play,/merges,/schema, ...) inWebUIRequestHandlerandHTTPHandlerFactory.The renderer assets (
marked,katex, and the KaTeX fonts, which are inlined into the stylesheet) are embedded in the binary and served from/js/, not from a CDN.DocsWebUIRequestHandlerrewrites the CDN links in the source to the same-origin/js/paths when serving the page, mirroringdashboard.html, so no third-party network code runs in the ClickHouse HTTP origin that handles the user's credentials, and the page stays self-contained. The/docscross-link name cache is no longer populated from a failed or unauthenticated request, and it is invalidated when the connection (URL/user/password) changes.While building this, I also fixed the embedded documentation so it does not produce empty code boxes:
FunctionDocumentation::examplesAsString/Documentation::examplesAsStringno longer emit aQuery/Responsefenced block when that field is empty (e.g. some internal functions);filesystemandformattable-function examples no longer double-wrap their already-fenced queries.Stateless tests guard against regressions:
04408_system_documentation_no_empty_code_blockschecks for emptyQuery/Responsefences, and04409_docs_web_ui_local_assetschecks that the served/docspage references the local/js/assets and loads no CDN code.Related: #89377
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added a built-in documentation search page, available at the
/docspath of the HTTP interface, that provides instant search over thesystem.documentationtable and renders the reference documentation (with syntax highlighting, math, and cross-links).Documentation entry for user-facing changes
Documented at
docs/en/interfaces/documentation-search.md(slug/interfaces/documentation-search).