Skip to content

fix: avoid reading unused Control UI asset bodies - #179190

Merged
steipete merged 2 commits into
mainfrom
solid2/w-perf-coldload
Oct 21, 2026
Merged

steipete merged 2 commits into
mainfrom
solid2/w-perf-coldload

Conversation

@steipete

@steipete steipete commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A cold Control UI request for a Brotli script or stylesheet read, returned from the file worker, and cached the original, Brotli, and gzip bodies. Only one body was sent to the browser.

User Impact

Cold visits do less file work and retain fewer asset bytes. The rendered UI, lazy boundaries, startup bundle, compression negotiation, custom roots, conditional requests, and HEAD responses keep their existing behavior.

Why This Change Was Made

Parse encoding preferences once, retain the canonical source metadata, and prepare only the first acceptable available body in the existing bounded root cache. Missing sidecars still fall through in preference order; selected errors retain their existing behavior. HTML aliases still obtain source HTML before document rewriting and compression.

The build already emits Brotli/gzip sidecars. Rewritten HTML already uses a bounded compression cache with Brotli quality 4, so this change adds no compression cache. The cold-load benchmark now supports real Gateway HTTP, first navigation without warm-up, network/CPU throttling, a resource waterfall, and DOM presentation milestones. Its bootstrap, RPCs, and media are synthetic; the terminal policy follows the real document to avoid a policy-reconciliation reload.

Evidence

Acceptance recorded before the measured series: five interleaved baseline/candidate pairs per profile; fresh browser/context and disabled HTTP cache; identical production UI bundle and fixed synthetic team-scale fixture; warm Gateway with cold prepared-asset cache; investigate any median/p95 regression above 20%. The profiles are loopback and 35 ms / 10 Mbps / 4× CPU. RPC delay is 35 ms on both. Document compression is warm in the main series. The initial loopback pair, which also includes first HTML compression, is reported separately; a sixth loopback pair preserves five warm-HTML samples per side. Process startup is outside these navigation timings.

The two isolated source Gateways differ at the asset-reader implementation: the baseline pins the original reader from 04e83824bca, while the candidate uses this change. Both use the same handler and production UI build. The normal gateway.controlUi.enabled lifecycle resets the asset cache between samples. Reader source hashes and raw sample artifacts were retained locally. Visibility is a DOM/rAF milestone, not a compositor-paint timestamp; neither side autofocuses the composer.

Every measured visit reduced asset body-read attempts 158 → 58 (−63.3%) and body bytes 9,069,965 → 1,647,418 (−81.8%). Browser transfer bytes stayed approximately 1.66 MB. This is a demonstrated file-work reduction; these small samples do not establish a general navigation-latency improvement.

Profile / metric Baseline median / p95 Candidate median / p95
loopback: document TTFB (ms) 40.6 / 65.7 41.7 / 104.1
loopback: request-to-first-byte (ms) 32.4 / 57.4 21.6 / 49.2
loopback: visible transcript DOM (ms) 1162.2 / 1241.1 1093.7 / 1824.6
loopback: enabled composer (ms) 710.4 / 792.9 591.0 / 1460.0
throttled: document TTFB (ms) 33.2 / 124.4 42.8 / 79.2
throttled: request-to-first-byte (ms) 18.2 / 22.8 18.1 / 61.4
throttled: visible transcript DOM (ms) 6324.7 / 7482.7 6492.5 / 6817.1
throttled: enabled composer (ms) 2999.0 / 3828.1 2804.9 / 3023.2

Five samples per side/profile; p95 is the nearest-rank maximum. All raw samples are retained. Host one-minute load ranged 57.5–148.7 during loopback and 58.8–100.9 during throttled runs. The initial, separate first-HTML pair had transcript/composer readiness 1757.7/1251.6 ms before and 1568.5/1032.0 ms after; it is diagnostic, not part of the five-sample cohorts.

The >20% regressions were investigated: loopback candidate p95 TTFB/transcript/composer rose, and throttled median TTFB rose 33.2→42.8 ms. Throttled pre-request time rose 10.4→18.0 ms while median request-to-first-byte remained 18.2→18.1 ms; the candidate also had one 61.4 ms request-to-first-byte outlier. No asset starts before HTML response completion. /chat performs the same missing-path and source-HTML reads, and emits the same 6,928-byte compressed document. Five additional interleaved direct HTTP controls, with fresh TCP connections and warm exact /chat compression, measured header TTFB median/p95 13.2/53.5 ms → 14.9/56.6 ms and identical body hashes. This does not reproduce the browser's >20% median shift, but does not prove all tail-latency movement is host noise; latency remains inconclusive on this loaded host. No negative sample was discarded.

Startup is byte-for-byte unchanged: 329,060 B JS gzip, 304,879 B JS Brotli, 990,291 B raw JS, 7 startup JS requests; 40,346 B CSS gzip and 1 startup CSS request. The separate strict check fails on both base and head against the current 325,000 B JS limit; this PR neither raises the budget nor grows startup.

Check Result
Original-reader regression Fails as expected: first Brotli request performs 3 body reads instead of 1
Three directly changed test files 79 tests pass, including negotiation, alternating preferences, conditional/HEAD responses, custom roots, HTML aliases, and root lifecycle
pnpm tsgo:ui Pass
Targeted core/script type-aware lint and formatting Pass; initial broad lint setup timed out generating unrelated Plugin SDK declarations
pnpm ui:build on baseline and candidate Pass
Strict startup performance check Same inherited failure on both: 329,060 B JS gzip exceeds the current 325,000 B budget; 7 JS requests and 1 CSS request on both
Production Knip Pass, no ignores added
Independent review No actionable P0–P2 findings

Separate candidate-only 4× CPU diagnostic (excluded from A/B timings): 21,181 frames mapped and 266 asset frames unmapped. Largest application self-time samples were chat-pane-header.tsx (307.7 ms), scroll-state-observer.ts (287.0 ms), and chat-details position/measurement (170.6/126.5 ms). These are client rendering owners outside this lane. The waterfall already discovers 34 startup/route assets within approximately 2 ms, and the existing preload generator walks static dependencies while retaining CSS ordering. No additional eager imports or preload expansion was justified. The diagnostic filmstrip independently brackets visible transcript pixels: frame 331 at 7067.6 ms still shows skeletons; frame 332 at 7089.5 ms contains the transcript (expected display time 7095.8 ms), following DOM readiness at 6924.3 ms. These are captured-frame observations, not exact physical-display timing, and this profiled run is excluded from A/B medians.

Reproduction command (run against each isolated Gateway; reset its prepared-asset cache between samples):

node --import ./scripts/tsx.mjs scripts/bench-control-ui-cold-load.ts \
  --bundle-dir dist/control-ui --gateway-url http://127.0.0.1:19451 \
  --face chat --first-load --runs 1 --cold-http-cache --untraced \
  --fixture-now-ms 1792560000000
# Throttled profile additionally uses:
# --network-latency-ms 35 --download-kbps 10000 --cpu-throttle 4

LOC across touched files against integrated main: 4,308 → 4,636 (+328). Production serving code: 1,551 → 1,576 (+25); tests +34; benchmark +236; docs +33. The added benchmark code makes the serving path and measurement boundary reproducible. No UI feature files or dependencies changed.

The attached before/after captures contain only the synthetic fixture and show the unchanged rendered UI.

Before: synthetic cold-load chat fixture

After: identical synthetic cold-load chat fixture

Profiled diagnostic: last skeleton and first transcript frames

Main integration and final CI

Final head 395db5e241a6 merges main at d35934e0a02b after a real benchmark conflict prevented admission. The resolution keeps main’s dashboard-menu selector inside the warmed path and preserves first-load’s warm-up bypass. Fresh independent review is clean through P2; frozen install, UI typecheck, script lint, and formatting pass. Serving files and focused tests are identical to measured commit bf81c02c03c0; the same-bundle startup and timing measurements above belong to that original controlled comparison, not a repeated benchmark after integration.

Final full CI 39568696562, attempt 1 completed with one inherited root failure; security-fast, real-Gateway E2E, and every other selected job passed. Control UI Markdown table interactions > contains content-sized tables after restoring a percentage reading width fails with the same false-versus-true assertion at line 214 on the latest completed scheduled main run 39563487228. The newer scheduled main run was still queued when qualified.

The tested merge 873c3abaa5fc has ordered parents 7f6d2b75845e and 395db5e241a6, and matches a reconstructed merge tree. Its effective changes are this PR’s eight paths. The entire UI source tree, failing test, and table CSS have identical Git objects in the CI main parent and tested merge. Native inherited-failure recovery retains the red CI result; it does not claim green. No CI rerun was used.

Cold bundled asset requests read and cache only the first acceptable available representation. Preserve canonical source checks, conditional responses, and rewritten HTML aliases. Extend the cold-load benchmark to real Gateway HTTP with first-load, waterfall, presentation, and throttling measurements.
@steipete steipete added the ci:full Keep ordinary native-locale CI selection on the next PR run. label Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T08:36:19.102216Z 395db5e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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 Oct 21, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. and removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 21, 2026
@clawsweeper clawsweeper Bot added the clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. label Oct 21, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 395db5e241

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +566 to +570
const terminalEnabled = gatewayUrl
? await fetch(new URL("/control-ui-config.json", gatewayUrl)).then(async (response) => {
if (!response.ok) {
throw new Error(`Gateway bootstrap returned ${response.status}`);
}

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.

P2 Badge Avoid requiring an unauthenticated bootstrap request

When --gateway-url targets a normal token- or password-authenticated Gateway, this credential-free fetch receives 401 and aborts the benchmark before Chromium starts. Gateway authentication defaults to token mode, and this new mode neither accepts credentials nor needs the real bootstrap payload because the browser route is replaced with a synthetic one later. Derive the terminal policy from an unauthenticated surface or provide an explicit authenticated/configured input so the documented command works without weakening Gateway auth.

Useful? React with 👍 / 👎.

@steipete
steipete enabled auto-merge (squash) October 21, 2026 08:39
@clawsweeper

clawsweeper Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR reads only the negotiated Control UI asset body and extends the cold-load benchmark to measure real Gateway HTTP delivery.

Example: A cold browser visit requests a bundled script with Accept-Encoding: br, gzip.

  • Before: The worker reads and caches the original, Brotli, and gzip bodies while sending only Brotli.
  • After: The worker reads source metadata and only the selected Brotli body.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Production-path evidence supports the serving optimization, but the introduced authenticated-Gateway benchmark failure blocks the patch.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied browser measurements exercise the changed asset reader through real isolated Gateway HTTP servers with an identical production bundle and synthetic RPC/media fixtures, demonstrating fewer body reads and bytes; inspected screenshots show preserved rendering, and latency remains inconclusive.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Cold Control UI visits perform unnecessary file reads and retain asset bodies the browser never receives.
Reason: The maintainer-authored direction removes measured waste without adding another cache, changing rendered UI, or claiming an established navigation-latency improvement.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: the asset-reader optimization has demonstrated value, but the new benchmark aborts against normally authenticated Gateways.

Priority: P2
Reviewed head: 395db5e241a608f7803cc436aa549e86fe1d28dd

Before merge

  • Read terminal policy without requiring anonymous bootstrap access (P2) - With a token- or password-authenticated Gateway, this fetch sends no credentials to /control-ui-config.json, whose handler calls authorizeControlUiReadRequestOrReply. The resulting 401 throws before Chromium launches, so the newly documented --gateway-url command cannot measure a normal authenticated installation. The later Playwright bootstrap interception cannot affect this Node fetch. Read the existing data-openclaw-terminal-enabled attribute from the public document instead, preserving Gateway authentication.

Findings

  • [P2] Read terminal policy without requiring anonymous bootstrap access — scripts/bench-control-ui-cold-load.ts:566-570

Tests

  • Missing end-to-end proof: The new Gateway benchmark has no supplied successful run against a token- or password-authenticated Gateway.
Agent review details

How this fits together

The Gateway HTTP handler negotiates static representations, delegates safe file preparation to the root-owned worker cache, and sends assets or rewritten HTML to browsers.

flowchart LR
Browser --> GatewayHTTP
GatewayHTTP --> EncodingSelection
EncodingSelection --> RootAssetCache
RootAssetCache --> FileWorker
FileWorker --> BundledFiles
RootAssetCache --> HTTPResponse
HTTPResponse --> Browser
Loading

Technical review

Best possible solution:

Retain the negotiated-body optimization and derive benchmark terminal policy from the existing public document attribute.

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

Current-main source eagerly reads all three asset bodies, and the PR supplies matching before/after Gateway measurements; the benchmark authentication failure is independently traceable from its credential-free fetch to the protected endpoint.

Is this the best way to solve the issue?

Selecting the first acceptable representation within the existing worker/cache owner is a focused fix that preserves conditional responses and HTML preparation; the benchmark should consume the document's existing terminal-policy contract.

Full review comments:

  • [P2] Read terminal policy without requiring anonymous bootstrap access — scripts/bench-control-ui-cold-load.ts:566-570
    With a token- or password-authenticated Gateway, this fetch sends no credentials to /control-ui-config.json, whose handler calls authorizeControlUiReadRequestOrReply. The resulting 401 throws before Chromium launches, so the newly documented --gateway-url command cannot measure a normal authenticated installation. The later Playwright bootstrap interception cannot affect this Node fetch. Read the existing data-openclaw-terminal-enabled attribute from the public document instead, preserving Gateway authentication.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against ec4420b78882.

Provenance checked

  • Worker-owned asset preparation and root caching keeps the original intent (9ee2b0b: Move safe file admission and reads off the Gateway event loop while sharing bounded prepared responses.)
  • Encoding preference ordering and missing-sidecar fallback keeps the original intent (897583a: Prepare encoding preferences once and preserve quality ordering, sidecar fallback, and rejection behavior.)
  • Logical asset names and physical HTML aliases keeps the original intent (f48206d: Preserve MIME selection and document preparation for encoded filenames and contained symlinks.)
  • Cold-load benchmark warm setup changes intended behavior with a stated reason (test(control-ui): reproduce Team boot queries and warm snapshots #175672: Preserve realistic synthetic boot queries and persisted warm snapshots; the new first-load mode explicitly bypasses warm-up while retaining the default warmed path.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • Run the documented --gateway-url --first-load --runs 1 benchmark against a token-authenticated isolated Gateway and confirm metrics are produced without bootstrap 401.
  • Repeat with gateway.terminal.enabled false and confirm synthetic bootstrap agrees with the document policy without a reconciliation reload.
  • node scripts/run-oxlint.mjs --tsconfig tsconfig.json scripts/bench-control-ui-cold-load.ts
  • pnpm exec oxfmt --check scripts/bench-control-ui-cold-load.ts
  • git diff --check

What I checked:

PR surface

Source +25, Tests +34, Docs +33, Other +236. Total +328 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 61 36 +25
Tests 3 46 12 +34
Docs 1 34 1 +33
Config 0 0 0 0
Generated 0 0 0 0
Other 1 322 86 +236
Total 8 463 135 +328

Review metrics

Metric Value Why it matters
Serving code versus tests Serving code +61/-36 lines; tests +46/-12 lines The serving growth carries encoding preferences through the existing owner and selects one body; regression coverage exercises alternating preferences and rewritten HTML aliases.
Benchmark options 6 new developer CLI flags The flags select Gateway HTTP, first navigation, disabled HTTP cache, network latency, download throughput, and CPU throttling.

Labels

Label changes:

  • add P2: The optimization addresses measurable excess file work, while the introduced defect blocks a developer benchmark rather than normal Control UI operation.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: The optimization addresses measurable excess file work, while the introduced defect blocks a developer benchmark rather than normal Control UI operation.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Verify the repaired benchmark completes against an authenticated isolated Gateway with both terminal-enabled and terminal-disabled documents.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 21, 2026, 4:40 AM ET / 08:40 UTC.

@steipete
steipete disabled auto-merge October 21, 2026 08:56
@steipete
steipete merged commit 2fb9f04 into main Oct 21, 2026
154 of 157 checks passed
@steipete
steipete deleted the solid2/w-perf-coldload branch October 21, 2026 09:15
@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 Oct 22, 2026
…#179190)

Cold bundled asset requests read and cache only the first acceptable available representation. Preserve canonical source checks, conditional responses, and rewritten HTML aliases. Extend the cold-load benchmark to real Gateway HTTP with first-load, waterfall, presentation, and throttling measurements.
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 ci:full Keep ordinary native-locale CI selection on the next PR run. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant