Skip to content

perf(control-ui): reuse versioned assets and uploaded avatars - #167993

Merged
steipete merged 1 commit into
mainfrom
steipete/coldload-immutable-assets
Oct 9, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/coldload-immutable-assets

Conversation

@steipete

@steipete steipete commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A returning Control UI operator can revalidate an unchanged uploaded profile avatar, and redownload already retained build assets after the browser's separate HTTP cache is evicted.

The cold-load campaign's EVIDENCE.md recorded a signed-in reload of a dashboard deep link with 14 visible states over roughly 15 seconds, dashboard content at 11.75 seconds, and repeated avatar/asset requests costing about 1.0–1.4 seconds each. This PR addresses the cache paths below; it does not claim to fix that complete waterfall.

User Impact

Uploaded profile avatars whose URL matches the exact uploaded content revision can stay in the private browser cache. Build-versioned fonts, themes, and the web manifest reuse the service-worker copy before making a fetch. Unversioned or mismatched avatar revisions, host photos, and external avatar fallbacks continue to revalidate.

No visual layout, configuration, durable schema, or authentication changes. Credential changes remain distinct through Vary: Origin, Authorization, Cookie. Errors are not added to the service-worker cache.

Why This Change Was Made

The avatar HTTP owner already has the uploaded content revision but always returned private, max-age=0, must-revalidate. Only an exact URL/revision match now receives private, max-age=31536000, immutable, on both 200 and 304 responses.

The worker already validates public asset URLs against the current/retained build inventories and retains at most three build caches. Those URLs now share the hashed-asset cache-first path. This removes the redundant network-first/fallback branch; asset versions remain the invalidation key and activation still prunes old builds.

Production delta: 16 additions, 27 deletions, net −11 lines, across user-profiles-http.ts and ui/public/sw.js (excluding tests and docs).

Remaining campaign work: native plugin bundles are explicitly authorized by per-plugin, expiring cookie grants and current policy. They are not public assets. Putting them into the public URL-only service-worker cache would change that security contract; simply varying a private cache by the renewed cookie would still miss after renewal. This PR leaves that decision to the campaign lead. Workspace icon URLs are unversioned, and the session projection does not advertise icon absence. The server's 32-root LRU already avoids repeated scans, but the HTTP 404 remains. A complete follow-up needs authoritative icon presence/revision, or a separately scoped disposable miss cache with root/placement and lifetime invalidation; guessing from workspace existence is incorrect.

Evidence

Synthetic headless Chromium, actual Gateway handleControlUiHttpRequest static route, actual baseline/current workers, and normal build-inventory substitution:

Scenario Before After
Ordinary second reload, warm HTTP + worker caches 0 network requests / 0 bytes 0 network requests / 0 bytes
Reload after clearing only HTTP cache, retaining worker CacheStorage 4 requests / 42,110 response bytes 0 requests / 0 bytes
Same HTTP-cache-evicted reload, local elapsed time 10.72 ms 8.58 ms

The byte figure includes 38,552 body bytes and 3,558 response-header bytes. Local timing is noise-scale; the meaningful proof is removal of requests and bytes. This is an asset-route boundary measurement, not a full authenticated Gateway/dashboard benchmark, and uses no injected latency or private capture.

  • Testbox tbx_01m4h9a2r89fxgqakytz3nhcpv: 358 tests passed across user-profile HTTP, agent-avatar HTTP, Control UI conditional HTTP, worker cache, and worker lifecycle tests. Initial missing dependency installation was repaired with the frozen install before validation.
  • Regression proof: four worker-cache cases fail against the original worker; the avatar HTTP file fails against the original owner on immutable/credential-Vary expectations, then passes with the fix.
  • Measured pnpm test <file> --maxWorkers=1 wall time: src/gateway/user-profiles-http.test.ts 22.29 s (27 tests), ui/src/app/service-worker-cache.test.ts 1.89 s (36 tests).
  • Fresh post-rebase Testbox tbx_01m4ha5vdhtk0k94kn49qrn0kj: core, all 27 core-test graphs, and UI typechecks passed. The changed-file gate then stopped on an inherited deprecated-API violation: src/gateway/server-methods/agents.ts:2 (direct config writes). Reproduced the identical guard failure in a separate checkout of main commit a0ca02fc31df0aa03f63a4a3618b22a7af722641 on the same lease. Subsequent checks in that command were not run; this is not a green full-gate claim.
  • Detached Codex autoreview: scoped clean through P2. No accepted/actionable findings.
  • Public-asset and agent-avatar immutable HTTP headers were already present on the baseline; their HTTP tests remain in the proof set.

CI on 0ef8425bf4d32f2c0c34281bf4603a8aaf08a705 completed successfully: 58 checks passed, 49 skipped, no failures, including openclaw/ci-gate. CI run. Shared-job wall time: changed Node tests 255 s; UI test shards 275 / 289 / 320 s; UI E2E shards 193 / 222 s. These are whole-job timings, not individual test-file execution times. No CI reruns or unrelated changes were made. Both Testbox leases and the synthetic browser/HTTP servers have been stopped. No merge requested; campaign lead owns landing.

Serve exact uploaded-avatar content revisions with private immutable caching and credential-aware Vary. Reuse build-inventory public assets from the service-worker cache before fetching, removing the redundant network-first fallback.
@clawsweeper

clawsweeper Bot commented Oct 9, 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 size: S labels Oct 9, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The Control UI reuses retained build assets and privately caches uploaded avatars whose URLs match their content revisions.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and appears correct, with browser asset measurements and narrower handler-level avatar validation.
Proof confidence 🦐 gold shrimp (3/6) The supplied MEMBER author classification exempts ordinary contributor proof. Recorded Chromium output exercises the actual static route and workers after HTTP-cache eviction, eliminating four asset requests; uploaded-avatar policy is supported by handler-level regression coverage. No stored format or migration changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes
User problem: Returning operators can wait for unchanged profile images and retained interface assets to be requested again.
Reason: The recorded request reduction supports a focused optimization with less production code. The supplied maintainer-authored direction explains the cache-policy change and its boundaries.

Merge readiness

✅ Ready for maintainer review

This PR remains a useful, focused optimization absent from current main. No actionable correctness defect was identified.

Priority: P2
Reviewed head: 0ef8425bf4d32f2c0c34281bf4603a8aaf08a705

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The recorded browser comparison covers public assets; uploaded-avatar reload and credential-change behavior is covered by handler tests rather than a full browser run.
Agent review details

How this fits together

The Gateway serves the Control UI's static files and authenticated profile images. The browser's service worker retains public build assets, while its HTTP cache follows the avatar response policy.

flowchart TD
  B[Browser requests] --> W[Asset service worker]
  W --> C[Retained build cache]
  C -->|Cache miss| S[Gateway static files]
  B --> A[Profile avatar route]
  A --> H[Current authentication check]
  H --> R[Uploaded content revision match]
  R --> P[Private browser cache]
Loading

Technical review

Best possible solution:

Keep cache reuse in the existing HTTP and service-worker owners, with content revisions providing invalidation.

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

Not applicable as a correctness bug; current-main source confirms the redundant cache paths, and the recorded Chromium comparison demonstrates additional requests after HTTP-cache eviction.

Is this the best way to solve the issue?

Yes. The patch reuses existing content revisions and build inventories, removes the redundant network-first branch, and adds no competing cache owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Verified introduced scope: The pinned introduction delta changes only the avatar HTTP policy, service-worker reuse, their tests, and the accompanying documentation. (0ef8425bf4d3)
  • Still necessary on current main: Fetched main retains network-first handling for versioned public assets and must-revalidate responses for uploaded avatars; neither optimization is already present. (src/gateway/user-profiles-http.ts:208, 87d3db2aea6a)
  • Narrow avatar cache policy: Only an exact uploaded-content revision receives private immutable caching. Host photos and Gravatar responses omit that revision argument and continue revalidating; authentication and current-state assertions remain in place. (src/gateway/user-profiles-http.ts:209, 0ef8425bf4d3)
  • Existing revision producer: Profile display already advertises the uploaded SHA-256 and MIME suffix used by the ETag formatter, so uploads select new URLs without changing stored data or protocol fields. (src/state/user-profiles-internal.ts:414, 0ef8425bf4d3)
  • Public asset admission preserved: Cache reuse still requires hashed assets or exact current/retained build-inventory membership. Private responses, credential-varying responses, login redirects, and errors remain excluded. (ui/public/sw.js:343, 0ef8425bf4d3)
  • Recorded browser boundary measurement: The fully inspected PR body records headless Chromium using the actual static HTTP handler and baseline/current workers: clearing only HTTP cache changed retained-asset reloads from four requests and 42,110 response bytes to zero requests and bytes. Avatar verification is handler-level coverage. Captured body identity: d05ca48bca545ead7597616b43393967276c34802b768a30ebb883bdb123bbde. (0ef8425bf4d3)

PR surface

Source -11, Tests +60, Docs +6. Total +55 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 16 27 -11
Tests 2 66 6 +60
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 88 33 +55

Review metrics

Metric Value Why it matters
Uploaded-avatar cache lifetime Exact content revisions: 0 → 31,536,000 seconds Long-lived private caching is restricted to URLs matching the uploaded content.

Labels

Label changes:

  • add P2: This reduces avoidable Control UI reload traffic with a bounded change to existing cache owners.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This reduces avoidable Control UI reload traffic with a bounded change to existing cache owners.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 9, 2026, 6:28 PM ET / 22:28 UTC.

@steipete
steipete merged commit 286fff8 into main Oct 9, 2026
130 of 132 checks passed
@steipete
steipete deleted the steipete/coldload-immutable-assets branch October 9, 2026 22:38
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…aw#167993)

Serve exact uploaded-avatar content revisions with private immutable caching and credential-aware Vary. Reuse build-inventory public assets from the service-worker cache before fetching, removing the redundant network-first fallback.
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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S 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