Skip to content

perf(ui): preload the chat route's boot chunks on cold loads - #160293

Merged
steipete merged 8 commits into
mainfrom
perf/ui-cold-load-round-trips
Sep 29, 2026
Merged

steipete merged 8 commits into
mainfrom
perf/ui-cold-load-round-trips

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: the first Control UI load after a Gateway update (or on a new browser) is slow over remote connections, because the chat route's JavaScript is discovered in several sequential waves of small requests that HTTP/1.1's six connections per host drain one round trip at a time.

User Impact

Cold loads of a chat reach the transcript sooner over remote links: at 80 ms round-trip time, median time to visible transcript falls from 1,768 to 1,246 ms (−30%); at 200 ms, from 3,265 to 2,745 ms (−16%); locally 509 → 474 ms. Warm reloads (served by the service worker) are unchanged (80 ms RTT: 356 → 356 ms). Link favicons for the same host are requested once per page instead of five times. The startup entry shrinks by 424 bytes gzip. No behavior, config, or protocol changes.

Why This Change Was Made

Measured on main through a TCP delay proxy with the bundled UI and service worker: a cold chat load made about 90 requests. After the entry evaluated, about 45 more were discovered at once and drained in about 200 ms waves (one round trip each), and more small chunks followed in dependency order; chat.startup went out at about 3.1 s at 200 ms RTT. Many of those requests were about 1 KB per-page CSS facade modules. Warm reloads were already fine: the service worker serves about 94 of 95 requests.

  • Route-scoped boot preloads: a build plugin (ui/config/control-ui-boot-preloads.ts) emits one <template data-openclaw-route-preloads="…"> per boot route (chat, new) containing modulepreload and style-preload hints for that route's boot chunks. When serving index.html, the Gateway (src/gateway/control-ui-route-preloads.ts, control-ui.ts) activates only the requested route's template and drops the others, so the chat route's chunks are fetched in the first wave while other routes pay nothing. CSS is only preloaded; the lazy stylesheet owner keeps its cascade insertion order.
  • CSS consolidation: the per-page css-* JS facade grouping becomes one stylesheet group per measured boot route (control-ui-chunking.ts, boot manifest generator), removing a set of tiny sequential requests while keeping genuinely lazy features lazy.
  • Favicon dedupe: chat link favicons now go through the existing shared cache (which already owns in-flight sharing and the 15 s timeout), keyed per credential-scoped fetcher, and are skipped when the Gateway transport is not same-origin (the fetch would return nothing).
  • scripts/check-control-ui-performance.mts and its tests account for the route preload sets; docs updated.

Kept out deliberately: deduping the pre-hello control-ui-config.json request (its current ordering protects plugin asset grants and credential changes) and changing avatar projection (a participant-data change, not delivery).

Evidence

Four interleaved rounds per build, bundled UI, TCP delay proxy; medians in ms:

RTT Cold chat.startup send Cold transcript visible Warm reload visible
0 ms 299.5 → 264.5 509 → 474 367 → 364
80 ms 1,376.5 → 1,015.5 1,767.5 → 1,245.5 355.5 → 356
200 ms 2,662 → 2,392.5 3,265 → 2,744.5 580.5 → 582.5

At 200 ms RTT the cold request list falls from 89 to 76 requests, from 6 to 5 discovery waves, and from 15 to 12 send groups; favicon requests fall from 5 to 1. All warm reloads still make exactly one non-service-worker request.

  • 238 focused tests pass (chunking, boot preloads, Gateway route activation, favicon cache and loader, performance-check script), plus UI/core/scripts typechecks, CI oxlint on touched files, formatting, and independent Codex P2 review. Entry gzip 372,395 → 371,971 B against the unchanged 372,347 B limit; no limit or baseline was raised.
  • Not exercised: full declaration emission, and an in-place Gateway update transition (old tab, new build).

Per-file cost (node scripts/run-vitest.mjs <file> --maxWorkers=1 local wall on a heavily loaded host / summed per-test CI time from run 36588748117): control-ui.http.test.ts 169.9 s / 25.6 s (existing 128-case suite; this PR adds the route-preload cases), control-ui-performance.test.ts 18.3 s / 2.6 s, control-ui-performance-base.test.ts 11.4 s / 4.5 s, link-favicon-cache.test.ts 4.6 s / 0.2 s, link-favicon-loader.test.ts 3.1 s / 0.1 s, control-ui-chunking.test.ts 3.5 s / under 0.1 s. chat-sidebar-region-hosted-tabs.test.ts only moves a type import (0.8 s in CI). The first local control-ui.http.test.ts attempt failed before any assertion on a transient dist-runtime stat during concurrent runtime publication; the serialized retry passed 128/128 with nothing weakened.

Update and compatibility

No config, state, schema, protocol, or service-lifecycle change; the Gateway and the bundled UI ship together, and index.html is served no-cache (the service worker caches only hashed assets), so the served HTML always matches the running Gateway. The only cross-version surface is index.html template handling, covered for every skew combination with a live isolated Gateway (cold chat load through the real browser, seeded synthetic sessions):

Gateway UI build Route templates in served HTML Modulepreload links Cold chat load
main (before) this PR 2 (not activated; <template> content is inert per the HTML spec, so nothing extra is fetched) 6 active transcript visible, 75 requests
this PR main (before; no templates) 0 (nothing to strip; HTML unchanged) 6 transcript visible, 91 requests
this PR this PR 0 (chat template activated, others removed) 46 transcript visible, 77 requests

Custom gateway.controlUi.root builds of either version therefore keep working, and an in-place update needs no migration: the first reload after the update receives the new index.html together with the new hashed assets. (Timings from these compatibility runs are not comparable to the benchmark above; they ran on a heavily loaded host without the latency proxy.)

ui/config/control-ui-chunking.ts is build-time Vite/Rollup chunk grouping only: controlUiBootManifestKey() normalizes a module id to look it up in the committed boot-module list while the bundle is built. It writes no persisted, serialized, or user state, and nothing reads its output at runtime except as the hashed asset files the build emits, so there is no data model to migrate.

Inherited CI failures

The failing checks on head e9320a1 (run 36588748117, tested merge 2faf96f = this head + main ef1f568) are all in files this PR does not touch; security-fast passed. Each was checked on the unmodified main baseline:

  • Fail on main ef1f568 alone, replayed per file: lint-suppressions (allowlist 78 vs 77), agents/command/maintenance (missing resolvePluginMetadataSnapshotAsync mock export), agent-command.{compaction-rotation,embedded-maintenance,live-model-switch}, tts-summary.selection, session-history-worker-lifecycle, server-worker-placement-session-evidence.worker, config-model-validation.runtime, update-cli.service-authority, disk-budget.physical-usage.
  • Fail in main's own hourly CI (run 36591120570 on 42431b0) with the same files or signature: the four server-startup-* suites (worker-free fixture launching a worker) and the Doctor config-flow/preflight suites ("OpenClaw state database read admission is closed", 469 occurrences in main's hourly jobs).
  • Not independently reproduced: doctor-model-metadata-corruption.persistence (job small-9) passes alone on the baseline and does not appear in main's hourly failures. It tripped the Doctor settlement test fixture (doctor-maintenance.settlement.test-support.ts: "cannot start or inspect native processes") when the SQLite snapshot staging worker (src/infra/sqlite-snapshot-staging-owner.ts) started under it, a cross-test isolation failure in Doctor/infra code that this PR's UI and Control UI serving changes cannot reach. Recorded here as source-qualified, not proven pre-existing.

The earlier heads' failures (subagent-registry-queued-registration, chat.reset-visible-yield, session-accessor.sqlite-prepared-admission, gateway session/publication fixtures) were fixed on main by other changes (#161197, 9e4f201, 2fc693e, and the gateway fixture sweep); the claude-sessions and initial-connect-splash UI e2e failures passed repeatedly on this branch and on main locally (the splash test runs on the Vite dev server, where this PR's build-only plugin never runs).

HTTP/1.1 cold loads queued tiny CSS facades and discovered route boot
dependencies only after the entry executed. Group measured shared and
route styles, generate route preload templates from captured dynamic
entries, and activate only the requested route's hints in Gateway HTML.
Preserve lazy features, strict execution order, and snapshot isolation.

Use the scoped per-host favicon cache for transcript hydration, including
negative results. Keep all bootstrap/config scheduling and authority
behavior and all avatar projection/omission behavior unchanged from main.
The earlier config and avatar proposals are explicitly outside this change.

Rebuilt against pinned main 2b8c65c and ran four interleaved cold/reload
rounds at 0/80/200 ms RTT plus four paired 200 ms netlists:
- Cold visible medians: 509 -> 474, 1767.5 -> 1245.5, 3265 -> 2744.5 ms.
- 200 ms netlist medians: 89 -> 76 requests, discovery waves 6 -> 5,
  HTTP send groups 15 -> 12, startup 2814.5 -> 2382.5 ms,
  visible 3873 -> 2819 ms; first HTML discovery group 8 -> 54 resources.
- Config and avatar requests remain 2 -> 2; favicon requests 5 -> 1.
- Candidate warm reloads all retain one page-network response. Warm visible
  median differences are -3/+0.5/+2 ms; the prior 4-36.5 ms penalty did not
  reproduce. Warm startup sends remain 3.5-10.5 ms later, recorded separately
  from cached transcript visibility; no exact timing-parity claim.
- Initial-entry gzip: 372395 -> 371971 B, below unchanged 372347 B limit.
  Complete measured route boot bytes are reported separately.

Validation: 238 focused tests including restored config/credential tests,
UI/core/scripts typechecks, CI oxlint wrappers, formatting, diff check,
and scoped-clean P2 review. Runtime-only builds and postbuild stamps passed.
Gateway test preparation initially raced runtime publication; its missing
transient artifact was present after publication and the serialized run
passed 128/128 without weakening checks. Full declaration emission and
an in-place Gateway-update transition were not exercised.
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts size: L labels Sep 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 29, 2026, 12:29 PM ET / 16:29 UTC (Revision 10).

ClawSweeper review

What this changes

The branch adds route-specific preload hints for faster cold chat loads, shares chat favicon requests, and updates the Control UI build checks, tests, and documentation.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: current main and the latest release lack this improvement. The PR supplies measured real-browser gains and live Gateway/UI version-skew checks that address the previous compatibility concern. This review found no definite introduced defect.

Priority: P2
Reviewed head: e9320a143e603051b585cb05144e633df2f6ed7a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has focused tests and unusually specific runtime measurements, with no definite correctness finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The changed build and Gateway serving path was exercised with a real bundled browser UI through a TCP delay proxy, showing faster cold transcript visibility, and three live Gateway/UI version combinations all displayed a transcript. The boot manifest changes build inputs, not persisted user state, so data-model migration is not applicable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The changed build and Gateway serving path was exercised with a real bundled browser UI through a TCP delay proxy, showing faster cold transcript visibility, and three live Gateway/UI version combinations all displayed a transcript. The boot manifest changes build inputs, not persisted user state, so data-model migration is not applicable.
Evidence reviewed 8 items Introduced build behavior: The build plugin follows static dependencies of measured route entries and emits route-specific preload templates.
Gateway activation: The Gateway selects chat or new-session hints from the requested path before rewriting asset URLs.
Credential-scoped favicon sharing: Favicon cache entries are keyed by the fetcher, and the fetcher identity includes the Gateway URL, resource base path, and authorization candidates.
Findings None None.
Security None None.

How this fits together

The Control UI is a browser app bundled with the Gateway. Its build emits assets that the Gateway serves to browsers; the browser then fetches route code and renders the chat transcript.

flowchart LR
A[Measured boot modules] --> B[Control UI build]
B --> C[Route preload templates]
C --> D[Gateway route selection]
D --> E[Browser asset requests]
E --> F[Chat transcript]
F --> G[Shared favicon requests]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +188, Tests +246, Docs +12, Other +49. Total +495 across 24 files.

View PR surface stats
Area Files Added Removed Net
Source 14 283 95 +188
Tests 7 288 42 +246
Docs 2 13 1 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 1 65 16 +49
Total 24 649 154 +495

Review metrics

Metric Value Why it matters
Cold chat visibility at 80 ms RTT 1,767.5 → 1,245.5 ms median The reported real-browser measurement directly tests the intended user benefit.
Code growth production +198, tests +246 net lines The production growth has a stated performance rationale and focused validation.

Stored data model

Persistent data-model change detected: serialized state: ui/config/control-ui-chunking.ts, unknown-data-model-change: ui/config/control-ui-chunking.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Preserve route-limited fetching and lazy stylesheet order while landing the measured cold-load improvement through the normal exact-head validation workflow.

Do we have a high-confidence way to reproduce the issue?

Yes: current main lacks the route preload path, and the PR specifies a real bundled-UI cold-load comparison through a TCP delay proxy. This read-only review did not rerun the benchmark.

Is this the best way to solve the issue?

Yes: build-generated hints and Gateway route selection use the existing build and serving owners; the reported version-skew runs support the upgrade path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5ce29782b78f.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a measured Control UI cold-load improvement with limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed build and Gateway serving path was exercised with a real bundled browser UI through a TCP delay proxy, showing faster cold transcript visibility, and three live Gateway/UI version combinations all displayed a transcript. The boot manifest changes build inputs, not persisted user state, so data-model migration is not applicable.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed build and Gateway serving path was exercised with a real bundled browser UI through a TCP delay proxy, showing faster cold transcript visibility, and three live Gateway/UI version combinations all displayed a transcript. The boot manifest changes build inputs, not persisted user state, so data-model migration is not applicable.

Evidence

What I checked:

  • Introduced build behavior: The build plugin follows static dependencies of measured route entries and emits route-specific preload templates. (ui/config/control-ui-boot-preloads.ts:37, e9320a143e60)
  • Gateway activation: The Gateway selects chat or new-session hints from the requested path before rewriting asset URLs. (src/gateway/control-ui.ts:766, e9320a143e60)
  • Credential-scoped favicon sharing: Favicon cache entries are keyed by the fetcher, and the fetcher identity includes the Gateway URL, resource base path, and authorization candidates. (ui/src/pages/chat/link-favicon-loader.ts:20, e9320a143e60)
  • Current main and release check: The route-preload build and Gateway files are absent from fetched current main; the same files are absent from the latest release tag v2026.9.6. (5ce29782b78f)
  • Route test coverage: The Gateway test covers chat, new-session, nested, unrelated, and base-path requests, and checks that inactive templates are removed. (src/gateway/control-ui.http.test.ts:1156, e9320a143e60)
  • Real behavior and upgrade evidence: The captured PR body reports four interleaved real-browser rounds per build through a TCP delay proxy: median cold transcript visibility fell from 1,767.5 to 1,245.5 ms at 80 ms RTT. It also reports visible transcripts for old Gateway/new UI, new Gateway/old UI, and new Gateway/new UI combinations. The earlier completed review requested upgrade evidence and recorded no findings.

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-28T09:34:40.955Z sha e8e5c93 :: blocked before merge. :: none
  • reviewed 2026-09-28T10:00:22.543Z sha 1988c88 :: blocked before merge. :: none
  • reviewed 2026-09-28T10:40:18.198Z sha fc6c16e :: blocked before merge. :: none
  • reviewed 2026-09-28T11:11:17.806Z sha fc6c16e :: blocked before merge. :: none
  • reviewed 2026-09-29T12:29:26.133Z sha 96fe5f0 :: blocked before merge. :: none
  • reviewed 2026-09-29T13:31:07.407Z sha 96fe5f0 :: blocked before merge. :: none
  • reviewed 2026-09-29T13:53:17.322Z sha ee7450c :: blocked before merge. :: none
  • reviewed 2026-09-29T15:22:20.705Z sha e9320a1 :: blocked before merge. :: none

@steipete
steipete enabled auto-merge (squash) September 28, 2026 09:00
@steipete
steipete disabled auto-merge September 29, 2026 16:35
@steipete
steipete merged commit a5690b3 into main Sep 29, 2026
200 of 214 checks passed
@steipete
steipete deleted the perf/ui-cold-load-round-trips branch September 29, 2026 16:39
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…w#160293)

* perf(ui): reduce cold-load delivery round trips

HTTP/1.1 cold loads queued tiny CSS facades and discovered route boot
dependencies only after the entry executed. Group measured shared and
route styles, generate route preload templates from captured dynamic
entries, and activate only the requested route's hints in Gateway HTML.
Preserve lazy features, strict execution order, and snapshot isolation.

Use the scoped per-host favicon cache for transcript hydration, including
negative results. Keep all bootstrap/config scheduling and authority
behavior and all avatar projection/omission behavior unchanged from main.
The earlier config and avatar proposals are explicitly outside this change.

Rebuilt against pinned main cc0fae4 and ran four interleaved cold/reload
rounds at 0/80/200 ms RTT plus four paired 200 ms netlists:
- Cold visible medians: 509 -> 474, 1767.5 -> 1245.5, 3265 -> 2744.5 ms.
- 200 ms netlist medians: 89 -> 76 requests, discovery waves 6 -> 5,
  HTTP send groups 15 -> 12, startup 2814.5 -> 2382.5 ms,
  visible 3873 -> 2819 ms; first HTML discovery group 8 -> 54 resources.
- Config and avatar requests remain 2 -> 2; favicon requests 5 -> 1.
- Candidate warm reloads all retain one page-network response. Warm visible
  median differences are -3/+0.5/+2 ms; the prior 4-36.5 ms penalty did not
  reproduce. Warm startup sends remain 3.5-10.5 ms later, recorded separately
  from cached transcript visibility; no exact timing-parity claim.
- Initial-entry gzip: 372395 -> 371971 B, below unchanged 372347 B limit.
  Complete measured route boot bytes are reported separately.

Validation: 238 focused tests including restored config/credential tests,
UI/core/scripts typechecks, CI oxlint wrappers, formatting, diff check,
and scoped-clean P2 review. Runtime-only builds and postbuild stamps passed.
Gateway test preparation initially raced runtime publication; its missing
transient artifact was present after publication and the serialized run
passed 128/128 without weakening checks. Full declaration emission and
an in-place Gateway-update transition were not exercised.

* fix(ui): keep link favicon cache as the leaf module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant