Repository navigation
Web UI: restore expanded databases when reopening the database panel - #108964
Conversation
In the Web UI (play.html), closing the database panel removed all database elements, so reopening it rebuilt the list with every database collapsed. Remember which databases were expanded and re-expand the ones that still exist when the panel is reopened. Fix a race condition when several databases are expanded in parallel (e.g. during restore): loadTables used a single global staleness token, so all but the last concurrent load were cancelled. The token is now scoped per container via a WeakMap, and restoring the expanded state no longer moves the current-database highlight. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [f689697] Summary: ✅
AI ReviewSummaryThis PR makes the Web UI remember expanded databases across closing and reopening the database panel, and it adds the right staleness guards for overlapping table loads, connection changes, and background restores. Most of the earlier race conditions now look covered, but one state transition is still wrong: once a previously remembered database starts failing to restore, the current Findings
Tests
Final VerdictRequest changes. |
…n token Addresses the AI review on the PR: the new per-container `loadTables` staleness token (a `WeakMap` keyed by the database container) only guards each container's own table list, but the `.current` highlight is a singleton. If the user opens database `a` and then `b` before `a`'s `loadTables` query returns, `b` could finish first and become current, then the slower `a` load would finish later, pass its own container's token check, and move `.current` back to `a` - leaving the UI highlighting response order rather than the user's last selection. Before the per-container change the single global token would have cancelled `a`'s stale load, so this is a regression introduced by it. The highlight now uses a separate `current_selection_num` token, captured synchronously before awaiting so the latest click wins regardless of which query returns first. Restoring the expanded state still passes `set_current = false` and never touches the highlight. Also guard against a missing `.current` element instead of dereferencing `null`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Pushed Fix: The per-container CI: The 2 red Stress (
The change is |
|
Merged current Motivation: The auto-merge was conflict-free and the combined code is coherent:
The PR's net contribution vs |
pamarcos
left a comment
There was a problem hiding this comment.
Nice UX improvement. I've tested it and it works fine.
…ed-databases Resolve the `programs/server/play.html` conflict with the database refresh button feature that landed on master (#108958). Both features independently reworked the database-list loop body and the 6th parameter of `loadTables`: this PR added `openDatabase(set_current)` plus the `opened_databases` restore set and a per-container `WeakMap` staleness token with a `set_current`/`current_selection_num` highlight guard, while master added `refreshTables`, the per-row `row_load_generation` counter and the `is_current` predicate for the refresh button. The merge keeps both: `refreshTables` now takes `set_current` (defaulting to true, preserving master's refresh behaviour) and threads it into `loadTables`; `openDatabase` wraps `refreshTables` to mark the row opened, remember it in `opened_databases` and attach the refresh button; restore calls `openDatabase(false)` so it never moves the current-database highlight. `loadTables` keeps the per-container token, the `is_current` predicate guard and the latest-selection highlight guard together.
|
Merged Both features are kept:
Net change versus master is exactly the restore feature layered on top of the refresh button; nothing from #108958 is lost. |
Address review (#108964, commit 44b7e36): the `opened_databases` set that remembers which databases the user expanded was page-global, so it survived changes to `url` / `user` / `password`. Reopening the panel on a different server or as a different user would then auto-expand same-named databases and issue unintended `system.tables` queries there. `system.tables` (like `system.completions`) is connection-scoped, so clear `opened_databases` from the same input handlers that already invalidate the cached completions on a connection change. Renamed the handler `resetCompletions` -> `resetConnectionScopedState` to reflect that it now resets both pieces of connection-scoped state. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108964&sha=44b7e368c817e3a3873ae053193d99f8e6d6ddda&name_0=PR Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed the AI review's
|
…ight loads The previous fix cleared `opened_databases` in `resetConnectionScopedState` when the connection settings change, but a database load started before that change could still complete afterwards and unconditionally re-add its database to the set in `openDatabase`. Reopening the panel on the new connection would then auto-expand a same-named database and fire an extra `system.tables` query there. Generalize the existing completions connection-generation counter (renamed `completionsLoadGeneration` -> `connectionGeneration`, since it already tracks exactly the connection-change event) and capture it in `openDatabase` before the load, so a stale completion no longer re-populates `opened_databases` after the connection has changed. Only the connection-scoped set is guarded; the row's own DOM state still reflects the load it actually performed. Addresses the AI review's Request-changes finding.
|
Addressed the AI review's follow-up The earlier fix cleared
|
Address the AI review's follow-up `Request changes` finding on the connection-scoped state introduced in the previous commits. `resetConnectionScopedState` bumps `connectionGeneration` (invalidating completions and the remembered expanded-database set) when the `url` / `user` / `password` fields change, and `loadCompletions` / `openDatabase` already honor that generation. `loadDatabases` did not: it only checked `load_databases_request_num`, which is bumped only when the panel is (re)opened, not when the connection settings change. So if the user starts opening the database panel on server A and edits the connection fields to server B before `system.databases` returns, the stale A response still filled `#databases` and `toggleDatabases` opened the panel. Every row handler created there closes over the connection `loadDatabases` was called with, so subsequent expand/refresh actions kept querying the old server until the panel was closed and reopened. Capture `connectionGeneration` at the start of `loadDatabases` and drop the response if it changed while the query was in flight, mirroring the guard in `loadCompletions`.
|
Addressed the AI review's follow-up The previous commits made
|
|
Merged |
Addresses the AI review's follow-up `Request changes` finding (programs/server/play.html:5367). `resetConnectionScopedState` already bumped `connectionGeneration`, cleared the cached completions, and cleared the remembered `opened_databases` set on a connection edit, but a database panel that was *already fully open* was left untouched. Its rows and refresh buttons are closures created by the earlier `loadDatabases(server_address, user, password)` call, so after editing `url`/`user`/`password` to a different server, clicking a still-visible row (or its refresh button) kept querying the previous server. None of the existing `connectionGeneration` guards covered this: they discard in-flight responses, but the query parameters are baked into each row's closure at `loadDatabases` time, so a fresh click still targets the old connection. The panel-close logic is factored out of `toggleDatabases` into `closeDatabases`, and `resetConnectionScopedState` now closes the panel when it is open. The panel is rebuilt against the new connection on the next open, and detaching the rows also drops any in-flight `loadTables` load through its `isConnected` check. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed the AI review's follow-up Editing
This completes the connection-scoped invalidation started by the earlier commits (completions, |
Address the AI review's `Request changes` finding (programs/server/play.html:3310-3313). The restore feature records an expanded database in `opened_databases` only in the success callback of `openDatabase`, after its `system.tables` load finishes. If the user clicks a collapsed database and then closes the whole panel before the query returns, `closeDatabases` detaches the row, `loadTables` bails out through its `isConnected` check, so the success callback never runs and the just-performed open is never remembered. Reopening the panel then comes back fully collapsed, contradicting the advertised behavior. Record the open synchronously at the start of `openDatabase` instead, so the user's intent survives a panel close (or any other reason the in-flight load drops). The entry is still removed only on an explicit collapse or a connection change: `resetConnectionScopedState` both clears `opened_databases` and closes the panel, so a stale load can no longer resurrect an entry after a connection edit. This makes the previous `connectionGeneration` guard around the add redundant, so it is removed. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed the AI review's latest Bug: the restore feature recorded an expanded database in Fix: record the open synchronously at the start of
|
The restore feature records an expanded database in `opened_databases` synchronously at the start of `openDatabase`, so that closing the panel while the `system.tables` load is still in flight does not forget the user's just-performed open. However, if the load instead *fails* while the row is still on screen (for example `system.tables` throws an exception or the request errors out), the row never actually expands (`database.dataset['opened']` stays unset), yet the database name is left in the restore set. Reopening the panel then auto-retries that database and replays the same error, even though the user never had a successfully expanded row. `openDatabase` now reconciles the restore set with the row's actual state once the load settles, but only while the row is still attached: a failed open is rolled back, while a genuine success (re-)adds it. A panel close detaches the row (`isConnected === false`) and is skipped, so a just-performed open still survives for restore. This keeps the restore set in sync with the visible panel. `node --check` on the extracted inline script passes. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed the AI review's Bug: the previous commit recorded an expanded database in Fix: The symmetric add-on-success also covers the double-click case (a superseded sibling load of the same row rolling the entry back just before the winning load completes). |
The previous commit reconciled `opened_databases` with the row's actual state once the load settled, dropping any database whose open did not expand the row. But that also dropped a database that had been remembered from an earlier successful open: on panel reopen the restore fires `openDatabase(false)`, and if its `system.tables` request fails once (network blip or transient server exception) the row never expands, so the reconciliation deleted the entry and the next reopen showed the database collapsed even though the user never collapsed it. That breaks the feature's contract that restored databases survive. Capture whether the database was already remembered before this open began and only roll back a brand-new open on failure; a restore (or a re-open) of an already-remembered database is kept, so a transient restore failure no longer forgets a previously expanded database. A still-failing manual open of a not-yet-remembered database is still rolled back to avoid auto-retrying it on every panel reopen, and a panel close during the load still leaves a just-performed open in the set. `node --check` on the extracted inline script passes.
|
Addressed the AI review's Bug: the previous commit reconciled Fix:
|
…sult pane Restoring the previously expanded databases on panel reopen fires background `system.tables` requests via `openDatabase(false)`, but those still went through `auxiliaryQuery`, which unconditionally calls `clear()`, `resultEl.renderError`, `resultEl.clearError()` and toggles `logoEl`. So merely reopening the panel could overwrite the main result pane: a transient restore failure wiped the current query result and replaced it with the auxiliary `system.tables` error, and a successful restore cleared an error left on screen by the user's own query. Add a `quiet` mode to `auxiliaryQuery` that suppresses those global result/error side effects, and use it for restore loads (`loadTables` with `set_current = false`). Explicit panel actions (a manual open or refresh) keep reporting their errors in the result pane as before. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ed-databases # Conflicts: # programs/server/play.html
|
continue-pr: pushed the `quiet`-mode fix (`8e0d7435a15`, includes a clean master re-merge that resolved a fresh conflict with the new `/docs` icon block) for the AI review's Request-changes finding at `play.html:3358`. Unlike the prior findings on this PR (all in the This is a genuine PR-introduced regression, so it was worth fixing, but the PR is already human-approved (@pamarcos) and has now iterated through 8 automated-review rounds. The panel-lifecycle logic is heavily guarded at this point — worth considering a merge rather than continuing the review loop, unless a future finding is a clear new correctness bug. |
… generation The per-connection staleness guard (`connectionGeneration`) only reached `loadDatabases` and `loadTables` after their `await auxiliaryQuery` returned, but `auxiliaryQuery` itself runs `clear` / `renderError` / `clearError` (and toggles the logo) on a non-quiet request before the caller can drop a stale result. So a `system.databases` load, or an explicit `system.tables` load started against one server, could - after the user edits `url` / `user` / `password` to a different server - complete and overwrite the user's current result pane (or clear a current error) with a response from the previous connection. `auxiliaryQuery` now takes the connection `generation` captured by the caller before the request started and skips its result-pane side effects once that generation no longer matches the active `connectionGeneration`. `loadDatabases` passes the generation it already captured; `loadTables` now captures it before awaiting. Restore (quiet) loads are unaffected because they already suppress these side effects, and the common path (no connection change) is unchanged because the generation still matches. Addresses the AI review's `Request changes` finding at `programs/server/play.html:3207-3224`. `node --check` on the extracted inline script passes. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
continue-pr: pushed Gap: the connection-generation guard ( Fix: CI: the only red on the previous commit was Fresh CI is running on |
| /// just-performed open in the set so it is still restored on reopen. | ||
| if (database.isConnected) { | ||
| if (database.dataset['opened']) opened_databases.add(elem.database); | ||
| else if (!was_remembered) opened_databases.delete(elem.database); |
There was a problem hiding this comment.
The was_remembered exemption fixes transient restore failures, but it also makes a previously remembered database impossible to forget once its system.tables load starts failing persistently.
Concrete trace:
- Expand
db, so it is stored inopened_databases. - Close the panel.
- Make
loadTables(db)fail on every reopen (for example a remote-database exception or a privilege change that still leavesdbvisible insystem.databases). - Reopen the panel: the restore keeps
dbremembered becausewas_remembered == true, but the row never reachesdataset['opened'], so the collapse path at3411-3413is unavailable. - Click the still-collapsed row manually: this branch runs again with
was_remembered == true, so another failure still does not clear the set.
At that point every future reopen silently reissues the same failing system.tables query and there is no panel action that clears the remembered state. Can we preserve the entry only for background restore (set_current = false), but drop it on a failed explicit click, or otherwise add an explicit way to forget a row that never actually re-opened?
There was a problem hiding this comment.
Accurate trace — but I'm going to leave this as-is deliberately, because the fix trades one edge case for another and the residual harm here is minimal.
The two directions are in tension, and the current was_remembered rule is the fixed point that satisfies both earlier findings:
- Finding fix docs #6 (
89ea47e65c2): a brand-new open that fails must be dropped, so it isn't auto-retried. - Finding Error fetching data from materialized view #7 (
689aa6c75d1): a previously expanded database whose restore hits a transient failure must not be forgotten, or one blip would silently break the PR's contract ("restored databases survive").
else if (!was_remembered) is the single rule that satisfies both. Your suggestion — "drop on a failed explicit click, preserve only on background restore" — is implementable as a one-liner (else if (set_current) instead of else if (!was_remembered), since a restore is the only set_current = false open and only fires for already-remembered databases). It would satisfy #6, #7 and this finding.
I'm not taking it, for two reasons:
-
The residual harm is minimal. A background restore runs quietly (
8e0d7435a15:loadTablespassesquiet = !set_current), so a persistently-failing restore issues one wastedsystem.tablesquery per panel reopen with no visible error and no result-pane disruption. The only path that surfaces the error is an explicit click — which is user-initiated, so surfacing it is correct — and the entry is fully cleared on any connection change (resetConnectionScopedState). The scenario itself is narrow: a database that stays visible insystem.databaseswhilesystem.tablesthrows persistently (a privilege change or a broken remote database). -
set_current-based dropping reopens finding Error fetching data from materialized view #7 from a different angle. A remembered database on a flaky connection would be forgotten the first time the user clicks it during an outage, even though they never collapsed it — which is exactly the regression Error fetching data from materialized view #7 fixed.
Given the PR is already approved and this is the tenth iteration of the same open/panel-lifecycle staleness family, I'd rather ship the current fixed point than keep re-tuning a quiet, rare edge. Leaving the thread open for a maintainer to overrule if they prefer the set_current variant.
|
continue-pr: the AI review's tenth Rationale in brief:
The nine correctness findings before this one (highlight race, connection-generation staleness across This is the tenth round on the same open/panel-lifecycle staleness family; the marginal value of further re-tuning is near zero. I'd suggest a re-approval and merge over the AI loop, unless a maintainer prefers the |
…ntax-error-position Resolve conflicts in `programs/server/play.html` between this PR's syntax-error position highlight and the Web UI features that merged into `master` in the meantime (query tabs `#107826`, expanded-database restore `#108964`, and rainbow-bracket / matched-identifier highlighting `#109108`). - `postSingle` now takes both `params_restore_pending` (tabs feature) and `queryStart` (this PR); all call sites use the newer `my_request_num` ownership handling and pass both arguments. - The token render loop keeps `master`'s rainbow-bracket, bold matched-bracket, matched-identifier and per-digit-group number rendering, and additionally OR-s the `q-err-pos` class onto the token at the reported error position. The net diff of the branch over `master` is exactly this PR's syntax-error-highlight feature; no tabs / restore / bracket functionality was dropped.
Address review (ClickHouse#108964, commit 44b7e36): the `opened_databases` set that remembers which databases the user expanded was page-global, so it survived changes to `url` / `user` / `password`. Reopening the panel on a different server or as a different user would then auto-expand same-named databases and issue unintended `system.tables` queries there. `system.tables` (like `system.completions`) is connection-scoped, so clear `opened_databases` from the same input handlers that already invalidate the cached completions on a connection change. Renamed the handler `resetCompletions` -> `resetConnectionScopedState` to reflect that it now resets both pieces of connection-scoped state. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108964&sha=44b7e368c817e3a3873ae053193d99f8e6d6ddda&name_0=PR Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…anded-databases Web UI: restore expanded databases when reopening the database panel
…ntax-error-position Resolve conflicts in `programs/server/play.html` between this PR's syntax-error position highlight and the Web UI features that merged into `master` in the meantime (query tabs `ClickHouse#107826`, expanded-database restore `ClickHouse#108964`, and rainbow-bracket / matched-identifier highlighting `ClickHouse#109108`). - `postSingle` now takes both `params_restore_pending` (tabs feature) and `queryStart` (this PR); all call sites use the newer `my_request_num` ownership handling and pass both arguments. - The token render loop keeps `master`'s rainbow-bracket, bold matched-bracket, matched-identifier and per-digit-group number rendering, and additionally OR-s the `q-err-pos` class onto the token at the reported error position. The net diff of the branch over `master` is exactly this PR's syntax-error-highlight feature; no tabs / restore / bracket functionality was dropped.
In the Web UI (
play.html), closing the database panel removed all database elements from the DOM, so reopening it rebuilt the list with every database collapsed. This change remembers which databases were expanded and re-expands the ones that still exist when the panel is reopened.It also fixes a race condition when several databases are expanded in parallel (which happens during the restore above):
loadTablesused a single global staleness token, so when multiple loads ran concurrently all but the last were cancelled and their tables never appeared. The token is now scoped per container via aWeakMap, so a load is only superseded by a newer load of the same database. Additionally, restoring the expanded state no longer moves the current-database highlight away from the actualcurrentDatabase.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Web UI: when the database panel is reopened, the previously expanded databases are restored.
Documentation entry for user-facing changes
Version info
26.7.1.456(included in26.7and later)