Skip to content

Add a notebook mode to the Web UI - #115378

Merged
alexey-milovidov merged 35 commits into
masterfrom
web-ui-notebook-mode
Oct 2, 2026
Merged

alexey-milovidov merged 35 commits into
masterfrom
web-ui-notebook-mode

Conversation

@alexey-milovidov

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

Copy link
Copy Markdown
Member

Adds a notebook mode to the Web SQL UI (/play): a tab can become an ordered sequence of cells, each either a query with its own result or a block of Markdown text — the shape of document Jupyter, Observable, Hex and Deepnote use, and for the same purpose: keeping a chain of queries, and the reasoning between them, on one page.

How it works

A tab starts as a single query cell and looks exactly as it always has — no headers, no cell chrome, no notebook. Once a query has produced a result, a large muted [+] appears under it and expands into the two kinds of cell that can be added, query or text. Adding the second cell is what turns notebook mode on, and it is per tab: one tab can be a notebook while another stays a plain single-query editor, and each tab remembers its own notebook across reloads.

From two cells on, each cell gets a header with its position and kind (1. Query, 2. Text) and the editing actions: run, edit, insert a cell before, move up/down, delete.

There is still exactly one query editor on the page — the full one, with its highlighting backdrop, autocompletion and query-parameter inputs. In notebook mode it is docked into whichever query cell is active, and shown only while it has the focus; as soon as focus leaves, that cell collapses to its query on a single line, syntax highlighted, whitespace runs reduced to one space, fading out on the right. The Run / progress / copy / download row docks under the query being edited, between it and its result, and appears and disappears with the editor.

Results are more compact: a smaller font with the cell padding scaled to match, and a table of at most a quarter of the viewport that is its own scroll container on both axes, so its (thin) scrollbars sit at its own edges and a long or wide result neither pushes the notebook down the page nor widens it. Results and Markdown editors can be resized by dragging their bottom edge, as the query editor already could.

A text cell shows its Markdown source with the markers highlighted while it is being edited, and the rendered result once editing finishes. Raw HTML is escaped and link targets are restricted to http, https, mailto and relative URLs.

Implementation

The query text, parameters and result snapshot moved from the tab to a cell. tab.query / tab.result / tab.resultEl and the rest are now accessors onto the cell the editor is docked in, so the editor, history, URL and persistence code is unchanged and always means "the cell in front of the user". A run captures its own cell, so moving on to another cell mid-run does not redirect the response. The Logs/Metrics view and the resource meters follow the cell whose result they describe. The whole notebook is persisted in IndexedDB alongside the rest of the workspace, and history entries record the cell they belong to so Back/Forward cannot push one cell's query into another.

A tab holding a single cell renders exactly as before — verified by screenshot diff against master: 51 pixels differ, all on one row, all by 1 in a single channel.

Testing

Driven in headless Chrome against a local server: cell creation and deletion, moving and inserting cells, collapsing and expanding, per-tab independence, tab duplicate/close with a docked editor, query parameters inside a cell, per-cell errors, reload restore from IndexedDB, "Run all" inside a cell, the Logs and Metrics views per cell, column and result resizing, the theme switch and download menu inside the docked Run row, Markdown rendering and backdrop alignment, and light and dark themes.

Two pre-existing issues were fixed along the way: the download drop-down positioned itself without accounting for #main's scroll offset, and the #run submit button needed form="controls" once it could be moved out of the form's subtree.

Changelog category (leave one):

  • New Feature

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

Added a notebook mode to the Web UI (/play). After a query is run, a [+] button under the result adds further cells, each either a query with its own result or a block of Markdown text, turning the tab into a notebook in the style of Jupyter or Observable. Cells can be run, reordered, inserted and deleted individually; the query editor collapses to a single line when it is not focused, results are bounded and scroll inside themselves, and the whole notebook is restored on reload. Notebook mode is per tab, so a tab that has only one cell looks and behaves exactly as before.


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

Version info

  • Merged into: 26.10.1.1348-master (included in 26.10 and later)

A tab in the Web UI can now be turned into a notebook — an ordered
sequence of cells, each either a query with its own result or a block of
Markdown text — in the spirit of Jupyter, Observable, Hex and Deepnote.

Once a query has produced a result, a large, deliberately muted `[+]`
appears under it and expands into the two kinds of cell that can be
added: query or text. Adding the second cell activates notebook mode for
that tab; notebook mode is per tab, so one tab can be a notebook while
another stays a plain single-query editor.

From two cells on, every cell gets a header with its position, its kind,
a run-status dot, and the editing actions: run, edit, insert a cell
before, move up/down, delete.

There is still exactly one query editor on the page — the full one with
its highlighting backdrop, autocompletion and query-parameter inputs. In
notebook mode it is docked into whichever query cell is active; every
other query cell shows its query collapsed to a single syntax-highlighted
line, with runs of whitespace reduced to one space, no background of its
own, and the tail faded out on the right. Results are shown more
compactly: a smaller font and a pane of at most a quarter of the viewport
that scrolls internally instead of pushing the notebook down the page.

A text cell shows its Markdown source with the markers highlighted while
it is being edited, and the rendered Markdown once editing finishes;
clicking the rendered text switches back to the source. Raw HTML is
escaped and link targets are restricted to `http`, `https`, `mailto` and
relative URLs.

Internally, the query text, parameters and result snapshot moved from the
tab to the cell. `tab.query` / `tab.result` / `tab.resultEl` are now
accessors onto the cell the editor is docked in, so the editor, history,
URL and persistence code is unchanged; a run captures its own cell, so
moving on to another cell mid-run does not redirect the response. The
whole notebook is persisted in IndexedDB alongside the rest of the
workspace, and history entries record the cell they describe.

A tab holding a single cell renders exactly as before: no cell chrome,
the editor in its usual place, the result at full height.
A text cell now uses the same monospace family as a query, both while its
Markdown source is being edited and once it is rendered, so the notebook
reads as one document and the font does not jump when a cell switches
between the two states. A code span is set apart by its tint alone, since
the surrounding text is already monospace.

Two alignment fixes fall out of this, both affecting the transparent text
area laid over its highlight backdrop:

- Add `.md-backdrop` to the coarse-pointer rule that raises every layer
  mirroring a text area's metrics to 16px. The `textarea` selector there
  already covered the text area itself, so on a touch device the two
  layers were set at different sizes.
- Build the backdrop by joining the highlighted lines rather than
  appending a newline to each. The old form emitted one line more than
  the source, leaving the backdrop a line taller than the text area it
  sizes itself against.
In notebook mode the docked editor is now shown only while it has the
focus. Losing focus collapses that cell to its one-line preview, so a
notebook you are reading shows no open text areas at all; clicking a
collapsed query gives the editor back. Focus moving WITHIN the editor —
to a query-parameter input or a completion candidate — does not count as
leaving, so the decision is deferred past `blur` (which fires before
focus lands anywhere). A click on Run is exempt too: the launched run
focuses the editor straight back to select the statement it executes, and
collapsing in between would flash the preview for one frame. Because a
hidden text area cannot take focus, the paths that mean "let the user
type" go through `focusEditor`, which reveals it first.

Layout, alongside it:

- Cells lose their left border and indent. They are separated by
  whitespace alone, so the notebook reads as one flowing document and a
  result lines up with the query above it. Which cell holds the editor is
  already evident — it is the one that is not collapsed.

- A result's table is now the scroll container itself, on both axes
  (`--result-max-height` / `--result-max-width` / `--result-overflow`),
  instead of a wrapper around it: the scrollbars sit at the table's own
  edges, the column headers pin to the top of the table, and a wide
  result no longer widens the whole page. The scrollbars are thin, as the
  database panel and the expanded-cell view already are.

- The header reserves just enough room above the column name for the
  column's type, which is drawn there rather than above the header, where
  a bounded table would clip it away. The space belongs to the opaque,
  sticky header, so no row shows through it at any scroll position — the
  header is pulled up by 1px because `border-collapse` leaves a stuck
  cell without its own top border, through which the row underneath would
  otherwise show. The gap above the table is a margin, outside the scroll
  container, so it shows the page through it and does not scroll away.

- The last column's resize grip no longer overhangs the table's right
  edge in a bounded table, where those few pixels became a horizontal
  scroll range on a table that otherwise fits exactly.

Single-cell mode renders exactly as before: every knob above is a custom
property that defaults to the previous value.
The resize grip is a plain div inside `#query_div`, so pressing it moved
the focus to `<body>`. In notebook mode that reads as leaving the editor,
which collapsed the cell the instant the drag began, taking the grip with
it.

The grip's `pointerdown` now prevents the default action, so the focus
stays in the text area; `pointermove`/`pointerup` are unaffected, so the
drag itself works as before. The deferred blur check also treats a pointer
held down anywhere on the editor's own surface as "not left" and takes the
focus back, so any other non-focusable chrome added there later cannot
reintroduce this.
In notebook mode the Run / Run all / progress / copy / download row now
docks under the active cell's query, between it and its result, instead of
staying in the page header. That is where the run it describes belongs, it
makes it obvious how to run a given cell, and it supplies the separation
between a query and its table by itself. The row stays in place when the
cell collapses, so a running cell keeps showing its progress and a
collapsed cell can still be re-run.

The column type hint goes back to hanging BELOW the header rather than
inside it, so the header keeps its ordinary height. The reserved strip
added for it in the previous commit is gone; a bounded table's header sits
at the very top of its own scroll container, so the hint has to hang the
other way regardless, and doing it that way costs no header height.

Two things this move exposed, fixed here:

- `#run` gets `form="controls"`, so the implicit submission that runs a
  query still works once the button is outside the form's subtree. (The
  connection inputs already carry the attribute for the same reason.)
- The download drop-down positioned itself from client rects without
  adding `#main`'s scroll offsets, so it landed at the wrong place on a
  scrolled page. Harmless while the button lived in the sticky header;
  now that it rides with the active cell, it is normally well down a
  scrolled page.
…lish

The header's top border no longer disappears when the table is scrolled.
It used to be hidden deliberately: with `border-collapse` the table paints
the cell borders and a stuck header does not carry them along, so the row
scrolling underneath showed through that one-pixel line, and the header was
pulled up by 1px to cover it. Instead the top border is now drawn on the
header cells themselves, so it travels with them and covers the line — the
same reason `td.pinned-column` draws its side edges with a shadow. The
header sticks flush with the table's top edge again. The strip deliberately
does not overhang the last column: that pixel lands outside the table, and
a bounded table counts it as scrollable overflow, which showed up as a
one-pixel horizontal scroll on a table that fits exactly.

Alongside it:

- The cell header reads `1. Query` rather than `1 · QUERY`: no caps, no
  middle dot. The status dot marks only a run in flight or a failure; a
  finished cell is not marked, its result being right below it.

- The Run row is part of the editor and now appears and disappears with
  it, rather than staying behind when the cell collapses.

- Table cell padding is in `em`, so it scales with the font: a result
  shown at 85% in a notebook cell tightens instead of keeping the padding
  of a full-size table. Identical to the previous `rem` values at the
  default size.

- A result can be resized by dragging its bottom edge, exactly as the
  query editor is, and so can a text cell's Markdown editor: the query
  editor's drag handle is now a shared helper. A result's height is
  remembered for the cell and re-applied to the elements a later run or
  restore builds. Raw (non-table) output is bounded by the same variables
  as a table, so the height applies whatever the format is.

- The big [+] is square rather than a wide bar.
A previous commit added a `th:last-child .resizer` rule for the last
column's grip and, in doing so, split the `.resizer` rule it was inserted
after: `cursor: col-resize`, `user-select: none` and `height: 100%` ended
up inside the new `th:last-child` block. Every other column's grip was
therefore zero pixels tall, with no hit area and no resize cursor, so only
the last column could be resized. This affected both notebook mode and the
ordinary single-query view.

The three declarations go back where they belong; the last-column rule
keeps only the `right` offset it was added for.
… scrollbar

Pressing anything in the docked Run row blurred the editor, and the
deferred collapse then hid the row before the `click` arrived — so the
theme switch did nothing in notebook mode, and the copy, download and
Logs/Metrics controls would have behaved the same way. Only Run and Run
all worked, because they are buttons that take the focus, and were
special-cased.

That special case is replaced by an explicit notion of the editor's
surface: the editor, its parameter inputs, the Run row docked with it, and
the download menu that row opens (which lives elsewhere in the DOM so it
can be positioned freely). Focus landing anywhere in it, or a pointer held
down on any non-focusable part of it, is not the user moving on, so the
cell stays expanded and the control keeps the pointer.

Also: while the active tab is a notebook, the page keeps its vertical
scrollbar (`overflow-y: scroll` on `#main`). A notebook's height changes
constantly — cells expand and collapse as they take the editor, results
are resized, cells are added and removed — and letting the scrollbar come
and go with it shifted the whole layout sideways each time.
@robot-clickhouse
robot-clickhouse requested a review from a team August 19, 2026 00:42
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4ec7c56]

Summary: ✅


AI Review

Summary

This PR adds notebook mode to /play, with per-cell query and Markdown cells, per-cell result state, persistence, and Markdown save/load. Most of the earlier history and persistence issues are fixed, but there is still one important popstate regression: an older history entry restores a full notebook only after the tab has been closed and recreated, not when the tab is still open. That breaks the promised Back/Forward time travel for notebook structure and can also leave the visible result DOM on the newer state.

Findings
  • ⚠️ Majors
    • [programs/server/play.html:17132] window.onpopstate restores only cellId for an already-open tab; it never reapplies event.state.cells, so Back/Forward to an older entry of the same open notebook cannot resurrect deleted or moved sibling cells. The later tab.materialized = false does not fix the result side either, because materialized is cell-owned now. Suggested fix: on the open-tab path, rebuild or patch tab.cells from event.state.cells before activateTab, and clear each query cell's materialized flag so the entry snapshots are re-rendered too.
Tests
  • ⚠️ Add a focused harness scenario that keeps the tab open, creates an older entry with a two-cell notebook, deletes or reorders a cell, then calls window.onpopstate back to that older entry and asserts both notebook structure and the restored cell result DOM come from state.cells.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: restore event.state.cells for already-open tabs during popstate, and add a harness case that covers same-tab Back/Forward after notebook structure changes.

LLVM Coverage Report

Measured on commit 4ec7c56.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage).

Newly covered: +154 lines in 43 files (-137 lines lost coverage) · Details

Full report

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Aug 19, 2026
Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4ec7c56da with master d046101ce (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

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

3 object files changed (+99.65 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Server/WebUIRequestHandler.cpp.o 12.17 MiB 12.27 MiB +99.65 KiB (+0.80%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
…e running cell

Two run-lifecycle defects found by the review of the notebook mode.

The cell header's `▶` called `postAll` directly, bypassing the `activeInFlight` /
`cancel` gate the Run button goes through. A second request was therefore started
while the first was still streaming, and `tab.controller` was overwritten with the
new one, leaving the earlier query running with no `Stop` handle. `cancel` is split
into `cancelTabRun`, which takes the tab, and `runCell` now ends the tab's current
run through it before launching, so a tab still has exactly one query in flight.

The shared run row (`Run`/`Stop`, the progress bar and its resource meters, the
Logs/Metrics toggles and the download/copy buttons) followed `activeCell`, while the
response of a run keeps streaming into the cell captured at `beginFlight`. Moving
the editor to another cell mid-run therefore took the `Stop` row away from the
running query, and `syncActiveTabChrome` repainted the bar and the meters from the
idle cell, erasing the live progress of a query that was still going. The chrome now
follows `chromeCell` — the running cell while the tab is in flight, the active cell
otherwise — and `endFlight` repaints it once the run is over.

`test_play_image_preview` is updated for the renamed `clearPanel` (now `clearCell`,
taking a cell) and for `postMulti` taking the cell it renders into.
`clearPanel` gained the Download/Copy withdrawal on `master` while it became the
per-cell `clearCell` here; the new clearing is carried over onto the cell, and its
shared repaint runs through `paintDownloadCopy` for the cell that owns the chrome.
`test_play_image_preview` gets the same treatment for the scenario `master` added.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The stress-test red (Logical error: Not-ready Set is passed as the second argument for function 'A (STID: 0250-4e52)) is the known open #107619 (the matching issue #115010 was closed as its duplicate), unrelated to this Web UI change.

The test_play_image_preview failures were real and are fixed: the harness drove clearPanel(getActiveTab()) and postMulti(tab, ...), which this PR turned into the per-cell clearCell(cell) / postMulti(cell, ...).

Comment thread programs/server/play.html Resolved
Comment thread programs/server/play.html Resolved
@mintlify

mintlify Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

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

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 2, 2026, 12:46 PM

…URLs to the cell

Three fixes for the notebook mode, from the AI review of `68427b1025a1`:

- The shared run row is docked under `chromeCell(tab)`, but its `Logs` / `Metrics`
  handler still wrote through `activeCell(tab)` and the logo was still repainted from
  `tab.logoVisible` (an accessor onto the active cell). Moving the editor off a still
  running cell therefore retargeted those toggles at the newly active cell's result and
  could regrow the idle logo over a running `Run all` row. Both now read `chromeCell`,
  like the rest of that row.

- `colorModes` / `pinnedColumns` are per cell, but the toggle repainted every
  `query-result` of the whole tab and `persistColorModes` / `persistPinnedColumns`
  wrote through the ACTIVE cell, so a toggle made in another cell of the notebook never
  reached its own result snapshot and was lost on reload. The repaint is now scoped to
  the owning cell (`_sharedColorScope`, which still covers all the tables of that cell's
  `Run all`), and both persist functions take the owning cell: they record onto its
  snapshot always, and re-stamp the URL and the history entry only when it is the active
  cell, which is what those describe. The now unused `activeColorModes` /
  `activePinnedColumns` helpers are dropped.

- `safeMarkdownUrl` whitelisted only `#`, `/`, `./` and `../`, rejecting ordinary
  relative targets like `[guide](guide.md)`, `![pic](images/pic.png)` or `[q](?q=1)`,
  which contradicts the documented text-cell contract. It now allows any scheme-less,
  authority-less URL and rejects a named scheme other than `http` / `https` / `mailto`
  as well as a protocol-relative `//host` (the scheme is decided on a copy with ASCII
  whitespace and control characters stripped, so `java<tab>script:` cannot slip past).

Tested by a new `test_play_notebook` harness, which runs the real page script in a
stubbed browser environment and drives the notebook: a mid-run cell switch followed by a
`Logs` toggle, a color/pin toggle in a non-active cell with the persistence round-trip,
and the Markdown URL policy. All three scenarios fail against the previous page.
`04548_play_ui_framing_fallbacks` pins the new source lines.
…and stop clearing the shared row after a repaint

Two findings of the AI review on `programs/server/play.html`.

1. `serializeCellsForHistory` counted only the result snapshots against
   `HISTORY_NOTEBOOK_BUDGET`, so a text-heavy notebook could exceed the
   browser's per-entry history-state limit through its Markdown alone and
   `writeHistoryEntry` fell through to the `cells: []` fallback, after which
   `Back` could recover only the active query cell of a closed tab. The
   budget now covers the whole serialized cell (query, parameters, text,
   result): result snapshots are stripped first, largest first, then
   Markdown text is trimmed by no more than the remaining excess. Queries
   are never cut, because a truncated statement can be a different, still
   valid statement. `writeHistoryEntry` gained a rung between "results
   stripped" and "no notebook copy" that drops the Markdown text but keeps
   the structure and every query.

2. `deleteCell` stopped a run in the deleted cell with an unconditional
   `progressEl.clear()` after `endFlight` had already repainted the shared
   row from the surviving active cell, wiping that cell's stats. The delete
   path now goes through `cancelTabRun`, whose own trailing clear is made
   conditional on `cellOwnsChrome(cell)`: the widget is cleared only while
   it still describes the stopped cell.

Tests: `notebook_harness.js` gains `delete-running-cell-keeps-active-chrome`
and `history-budget-covers-text`, and `stop-after-editor-moved-repaints-chrome`
now records the calls made on the shared widget. All three fail against
the previous page. `04548_play_ui_framing_fallbacks` expects five
`cancelTabRun(tab);` call sites.

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

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failures on 69aa6edad1a8 and provide a fix in a separate PR. If the fix is already in progress, link it here.

  1. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115378&sha=69aa6edad1a81101f70ca1bd2f3d85205b7320f7&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20parallel%29 — 03207_json_read_subcolumns_2_wide_merge_tree failed with Code: 117. DB::Exception: Unexpected format of compact discriminators granule: 224: (while reading column json.b.b._1) from SerializationVariant::readDiscriminatorsGranuleStart while reading the merged wide part all_1_8_1. CIDB has this signature once in the last 30 days outside PR Add a type-aware Bloom filter index for JSON #113022 (where it recurs 17 times on a JSON Bloom filter change), and this is that one occurrence. This PR touches only programs/server/play.html, its docs and the /play harnesses, so the server-side read is unrelated; I found no open issue for it. Fix out-of-bounds read on truncated compact Variant discriminators #120252 (merged 2026-09-17) fixes a truncated Native stream read of compact discriminators and is already in this branch, but the path here is a MergeTree part, so it is likely a different defect.
  2. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115378&sha=69aa6edad1a81101f70ca1bd2f3d85205b7320f7&name_0=PR&name_1=Stateless%20tests%20%28amd_llvm_coverage%2C%20AsyncInsert%2C%20s3%20storage%2C%20parallel%29 — the job ran into its 9000 s timeout at test 13571 of 13818 with every listed test OK (labels under-utilized RAM, io-bound); no test failed.

Comment thread programs/server/play.html Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

Both failures already have an open fix of mine, so I am linking them rather than opening new PRs.

  1. 03207_json_read_subcolumns_2_wide_merge_tree / Unexpected format of compact discriminators granule: 224: Fix wrong results and CANNOT_READ_ALL_DATA when reading parts in packed storage #116920. That report URL is the sighting I root-caused on 2026-09-09, so the write-up with the instrumented trace is already on the PR: Fix wrong results and CANNOT_READ_ALL_DATA when reading parts in packed storage #116920 (comment). It is a different defect from Fix out-of-bounds read on truncated compact Variant discriminators #120252, and the Variant serialization is only the caller. ReadBufferFromFileView::prefetch() republishes the impl's untruncated buffer while file_offset_of_buffer_end still names the truncated end, so getPosition() under-reports by exactly the truncation amount, CompressedReadBufferFromFile::seek matches that false position and takes the "already at the required position" early return, and the next read pulls a block header out of the middle of the previous block's payload. Reaching it needs packed part storage (min_bytes_for_full_part_storage above the part size) plus local_filesystem_read_prefetch = 1, both randomized by clickhouse-test, which is why the signature is this rare. 5/5 fail on master, 0/5 with the change.

  2. Stateless tests (amd_llvm_coverage, AsyncInsert, s3 storage, parallel) at the 9000 s cap with no failing test: Split the two un-batched amd_llvm_coverage s3 parallel stateless jobs into 2 batches #116209, which splits that job and its ParallelReplicas twin into 1/2 + 2/2. Those two are the only coverage stateless parallel jobs still running the whole suite un-batched, which is why they are the two that saturate the budget; 43 runs reached the cap in 90 days, 12 of them on AsyncInsert. The runtime drift and the N=2 sizing are in that PR description.

alexey-milovidov and others added 3 commits September 23, 2026 22:30
Conflicts in `programs/server/play.html`, all resolved in favour of master's
single layout while keeping the notebook structure:
- markup: the connection `#inputs` now live in the drop-down (master); the
  editor keeps its `#editor-home` wrapper and gains master's `Format` button;
- `renderTabBar`: `syncConnectionUI` is gone (master), `focusEditor` kept;
- `saveHistory`: `cell.result` kept with master's comment;
- startup blank-tab pruning comment merged.

Reconciled with master's new code:
- master dropped the `controls_elem` declaration that the notebook run row
  still needs; re-declared as `controls_form_elem` (so `05234`, which pins that
  the connection inputs never move, keeps its meaning);
- Save / Load of tabs as Markdown now covers every cell of a notebook: each
  query cell as before (query, parameters, result tables), each Markdown cell
  as a `markdown` code block; Load turns every block under a tab heading into
  a cell. A single-query tab saves exactly as before. `05233` updated;
- the `Format` button also drops its result when the editor moved to another
  cell while the request was in flight.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…once

Adding, editing or deleting a Markdown cell, moving a cell, or deleting an
inactive query cell only armed the 400 ms `scheduleSave` debounce. No cell
activation or run follows such a change, so nothing else recorded it: a reload
inside that window found the pre-change notebook both in `IndexedDB` and in
the current history entry (whose `cells` recreate the tab on Back/Forward).

- `commitNotebookChange(tab)` refreshes the active tab's history entry in place
  and saves at once (`saveNow`, which takes over a pending debounce); used by
  `addCell` (Markdown cell), `moveCell`, `deleteCell` and the Markdown editor's
  `blur`. Keystrokes stay debounced, like the query editor's.
- `addCell` for a query cell saves once the activation has loaded the new cell.
- A save still pending when the page goes away is started on `pagehide`.

New `notebook_harness.js` scenarios: `notebook-change-survives-immediate-reload`
(each change snapshotted 30 ms after it and rebooted; all 8 checks fail on the
previous `play.html`), and `save-load-round-trips-notebook` for the notebook-aware
Save / Load from the master merge. `waitForNextPersist` now waits until no save
is pending, since a notebook change no longer leaves a debounced one behind.

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

Copy link
Copy Markdown
Member Author

🕵 @groeneai, thanks. Both reds on 357db4fca770 are unrelated to this PR (it changes only play.html, its docs and the /play harnesses), and both are still open on your side: #116920 for the Unexpected format of compact discriminators granule read, and #116209 for the coverage job timeout. The branch now has master merged in (240e654e2cea, including master's Save / Load of tabs, which is now notebook-aware) plus the fix for the open AI-review Major (9e6ce70e1574); the new head is fccc0c58eeae.

Comment thread programs/server/play.html Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

Both attributions are right. Where the two stand, measured now:

@alexey-milovidov
alexey-milovidov marked this pull request as ready for review September 24, 2026 01:32
alexey-milovidov and others added 2 commits October 2, 2026 12:11
Conflict in the `Format` button handler of `programs/server/play.html`: master added the
`connectionGeneration` check; the branch checks that the editor is still docked in the same
notebook cell. Both checks are kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`buildTabsMarkdown` wrote `cell.params` verbatim, while `loadTabsFromMarkdown` stamps the
loaded pair as coherent (`paramsSyncedQuery = query`). A cell whose bindings were committed
for an older text therefore had them saved, and made durable on Load, under the new text.
Prune them against the text with `pruneParamsToText` unless `paramsSyncedQuery` matches,
as `writeHistoryEntry` does, and cover it with the `save-drops-stale-parameters` scenario.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Merged master (2c882a661bc, the branch was 5924 commits behind). The one conflict was in the Format button handler: master added the connectionGeneration check, and the branch checks that the editor is still docked in the same notebook cell. Both checks are kept. Also addressed the open AI-review thread on stale parameters in Save (4ec7c56da97).

All five /play harnesses (test_play_notebook, test_play_reconcile_startup, test_play_image_preview, test_play_result_shaping, test_play_chart_helpers) pass against the merged page, and so do the page-grep stateless tests, including master's new 05230_play_ui_digit_group_separators.

The Upgrade check (amd_release) red on fccc0c58eea is unrelated to this Web UI change. Tables that the previous release's own tests leave behind (countResample(10, 5, 1) states, and quantile('0.5') from 05079) no longer attach after #119728. The fix is #121590 on the 26.9 branch (merged 2026-09-22), so it should clear once the upgrade check runs against a 26.9 release that includes it.

Comment thread programs/server/play.html
/// Restore which notebook cell this entry belongs to before anything is written through the
/// tab's cell accessors. A cell deleted since the entry was written simply keeps the tab's
/// current cell.
if (event.state.cellId && tab.cells.some(c => c.id === event.state.cellId && c.type === 'query')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This only restores cellId for an already-open notebook tab; the full notebook snapshot in event.state.cells is still only applied inside resolveTabForState when the tab had been closed and recreated. That leaves same-tab Back/Forward broken for notebook structure.

Concrete trace:

  1. Start with two query cells and visit both so an older entry carries state.cells for the two-cell notebook.
  2. Delete one cell, which rewrites only the current entry in place.
  3. Hit Back to the older entry without closing the tab.

Expected: the older entry rehydrates the two-cell notebook.
Actual: tab.cells stays in its newer one-cell shape, because this branch only flips activeCellId. The later tab.materialized = false does not rescue the result path either — materialized is per-cell now — so activateTab also keeps the newer live DOM instead of re-rendering the entry snapshot.

Can we reapply deserializeCells(event.state) (or otherwise patch tab.cells) on the already-open-tab path before activateTab, and clear each query cell's materialized flag so the entry's snapshots are rematerialized too?

@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.

Surprised to see an ad-hoc Markdown renderer, we likely already have a library that we use in /docs. But everything else is ok.

Approved.

@alexey-milovidov alexey-milovidov self-assigned this Oct 2, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 2, 2026
Merged via the queue into master with commit 88dbf4b Oct 2, 2026
295 of 296 checks passed
@alexey-milovidov
alexey-milovidov deleted the web-ui-notebook-mode branch October 2, 2026 23:02
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 2026
valerypetrov added a commit to valerypetrov/ClickHouse that referenced this pull request Oct 3, 2026
…ress

Master's client progress rework (ClickHouse#118536, ClickHouse#123549) moved the CPU, memory
and temp-disk reads of `writeProgress` into one `getProfileSnapshot()` call
under `profile_events_mutex` and added a "waited" meter. The IO rate now
comes from the same snapshot (`ProfileSnapshot::io_rate`), so it is read
together with the other values, and the IO counters are summed next to the
other `INCREMENT` rows in `ClientBase::onProfileEvents`.

The Web UI notebook mode (ClickHouse#115378) moved the resource-meter state from the
tab to the cell, so both `payloadMeter` callbacks now add to
`cell.resources`. Left as merged, the live one would read `tab.resources`,
which no longer exists, and throw on the first result packet. 04548 greps
the new spelling and keeps master's new checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-web-ui Web UI embedded in the server: Play, the dashboards, the merges and processors visualisers, the w... and removed comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... labels Nov 22, 2026

This branch was successfully deployed

1 active deployment
staging - docs — 4ec7c56d Deployed Oct 2, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-web-ui Web UI embedded in the server: Play, the dashboards, the merges and processors visualisers, the w... pr-feature Pull request with new product feature 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.

3 participants