Skip to content

perf(console): the chat UI, the auth pages and qrcode leave the first load - #38384

Merged
objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-ciejge
Nov 28, 2026
Merged

objectstack-fleet[bot] merged 5 commits into
mainfrom
claude/project-thread-ciejge

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Fixes #37572
Requested by Tesla · project thread

Part of #37444

Clause-②: no (load order only)
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:控制台每个页面在画出来之前要下载的脚本少了约 326 KB(压缩后),聊天助手改为第一次打开聊天面板时才下载,登录等账号页面改为打开该页时才下载,二维码改为第一次显示时才下载;界面和数据都不变。
  • 为什么做:属于首屏加载提速专项;聊天界面因打包分组漏列两个文件,又回到了每个页面的首次加载里,这次补上,并加了守卫,再漏会直接报错。
  • 出错会怎样:最坏情况是访客打开登录页、第一次打开聊天面板或显示两步验证二维码时多等片刻,或看到加载失败的提示;不涉及保存的数据,可以直接撤回这次合并。
  • 要你做什么:无。

What changes

The chunks every Console page fetches before it can draw drop from 2,226,792 to 1,893,160 bytes gzipped (147 to 134 eager chunks), measured on production builds of main at eef1cbfe4 and of this branch at 686c9993. Three cuts, as amendment 7243947617 on the card lists them:

  1. The chat UI leaves the first load again (ui/apps/console/vite.config.ts). packages/plugin-chatbot/src/core.ts re-exports hitlContinuation and chat/questionSkip, and the plugin-chatbot-core chunk group did not list them. They landed in plugin-chatbot, which the eager core chunk then imported statically, and that pulled in plugin-chatbot (236,909 gz) and plugin-markdown (69,180 gz) on every page. The group lists both now.
  2. The 9 public auth pages and the 4 dev harness pages load with their routes (ui/apps/console/src/App.tsx). Each page now uses lazy(). The dev pages sit behind ProtectedRoute and get their own Suspense boundary, as DevRowActions already did. The auth pages get no boundary of their own. They suspend into ConsoleShell's boundary, which also holds NativeShellRouting, so the mobile shell's ready() still waits until /login is on screen (see Acceptance notes).
  3. qrcode is imported on demand at its two call sites: TotpQr in RemediationOverlay.tsx and QrcodeBlock in ActionResultDialog.tsx. If the import fails, the message goes to the error slot that an encoding error already used.

Guard. ui/scripts/check-eager-closure-budget.mjs gains a sixth half, evaluateLazyChatChunks. It fails when a plugin-chatbot or plugin-markdown chunk is in the eager closure, whatever the aggregate says. It returns error when the report has no files, or when its counter-probe finds no module of either package in a chunk of that name, so a renamed chunk cannot pass by default. Unit tests cover pass, fail for each chunk, the counter-probe, an unreadable report, and main going from exit 0 to 1. A static case also checks that every export ... from in core.ts is matched by the group regex parsed out of vite.config.ts.

Re-pin. I re-pinned by the gate's documented formula at the measured head, as the seat ruled. The ceiling is MAX_EAGER_CLOSURE_GZIP_BYTES = 1,893,160 + 711,680 / 2 = 2,249,000 (it was 2,407,237). BASELINE = 1,893,160 / 134 / 2653 at 686c9993, with squashMerge null until a back-fill. The four per-chunk ceilings did not move. Changeset: patch for @object-ui/app-shell, @object-ui/console and @objectstack/console.

Tests

Every reading in this section was taken at head 809cfb890. Commit 809cfb890 changes only the gate script and its test, and vite.config.ts does not import that script, so no bundler input differs from 686c9993, where the bundle was built.

  • Eager closure gate on the head build: node scripts/check-eager-closure-budget.mjs (in ui) exits 0. Every half is ✅, including "Chat chunks stay lazy". The same gate on the main build exits 1 on that half.
  • Ablation of cut 1, recorded earlier in this round (literal anchor, blob hashes checked, restore verified equal to HEAD): the unit static case goes red naming ./hitlContinuation and ./chat/questionSkip. The rebuilt bundle reads 2,201,929 gz in 148 eager chunks. The gate exits 1 from the chat half alone, while the aggregate half stays ✅ (2150.3 KB under the 2196.3 KB budget). Without the new half, the gate would not have caught this regression.
  • pnpm --dir ui exec vitest run scripts/: 172 files passed, 2 skipped; 5159 tests passed, 2 skipped.
  • Console: App.docsPortalLazy, App.nativeShellMode-29039 and App.nativeShellOpenSet-29330: 2 of 3 files passed on the first run, 1 test failed (see Acceptance notes, "a timing-dependent assertion"). Re-run of App.nativeShellMode-29039 4 times on an idle box: 17/17 each, then 3 more times under synthetic CPU load: passed each time.
  • app-shell RemediationOverlay* and ActionResultDialog tests: 7/7 files, 48/48 tests.
  • type-check exits 0 for @object-ui/console and for @object-ui/app-shell (its script also runs tsconfig.test.json).
  • Not run locally, declared: the full @object-ui/app-shell and @object-ui/console suites (CI Test UI runs them).
Derived gates (dispatch-gates --commands, 47 families, at 809cfb8)

node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --ran with the exit-coded record: "47 derived famil(ies) accounted for — 45 run, 2 NOT-MEASURED". 45 exited 0. NOT MEASURED: pnpm check:dual-build-cjs-loads (exit 3, PREREQUISITE NOT MET: the @objectstack/* packages are not built in this worktree; Build Core builds them in CI), and pnpm check:type-check-debt (its re-measure needs a full-repo package build; CI Lint & Repo Gates runs it). overlap-check.mjs --branch=claude/project-thread-ciejge: "VERDICT clean exit 0", merges cleanly onto origin/main 61cde6dc7.

Acceptance notes

  • Mobile shell ready signal. My first version of cut 2 gave each auth route its own Suspense boundary. App.nativeShellMode-29039 and App.nativeShellOpenSet-29330 then caught ready() being posted over the loading fallback (ready:nothing) instead of the login page. Removing those boundaries fixes it. The native shell drops its cover only once the first route is on screen, as before.
  • A file outside the amendment's list. App.docsPortalLazy.test.tsx used LoginPage as its live positive control for an eager import. Cut 2 makes that page lazy, so the control moves to FormPage, which is still static. This is the same move objectui#13410 made when SharedRecordPage went lazy. The test file is not on the amendment's file list. It is in this PR because cut 2 made its assertion false. It is in commit 686c9993.
  • Out of scope, not fixed here. On a two-factor-armed boot (OS_AUTH_TWO_FACTOR=true), the "Enable Two-Factor Auth" button does not render on the user's own record in Setup (Users, Security tab). This happens on the main build and on this branch alike. The browser console says: [ActionEngine] action "enable_two_factor" hidden: its visible predicate threw — CEL predicate failed to evaluate: (has(record.id) && record.id == ctx.user.id && has(record.two_factor_enabled) && record.two_factor_enabled != true) && features.twoFactor == true. The record shows "Two-Factor Enabled: No", and /api/v1/auth/config reports features.twoFactor: true. It is in the report for the seat to file. Because of it, the QR reading below goes through the other call site, the MFA remediation overlay.
  • The Console has no assistant button on the open framework, because discovery reports services.ai unavailable and GET /api/v1/ai/agents returns an empty list. For the chat-panel reading, the browser stubs that one endpoint with a single agent so the button and the drawer render. What the reading measures is which chunks the browser fetches. It does not measure a reply.
  • A timing-dependent assertion, found at this head and NOT fixed in this PR. The first local run of App.nativeShellMode-29039 failed once in "posts ready once, after the first route rendered": expected [] to deeply equal [ 'ready:login-page', 'route:/login' ]. With the auth pages lazy, the first route commits after a chunk resolves, and ready() and routeChanged run in that commit's passive effects. These effects can land after findByTestId returns, so the synchronous expect(events) right after it can read an empty list. On main the page was eager, so the first route committed inside render's act (inferred from the code, not measured). Measured: 1 failure in 9 runs, on a cold and loaded box. The fix is five waitFor wraps in that file and in App.nativeShellOpenSet-29330. Both files are outside the amendment's file list, so the fix is left to the seat to add to the file list, not pushed here.

Verification

Read first, by risk:

  1. ui/apps/console/src/App.tsx: the comment above the lazy pages and the 9 auth routes without their own boundary. A boundary added back there would bring back the early ready().
  2. ui/scripts/check-eager-closure-budget.mjs: evaluateLazyChatChunks, and the chat-lazy entry in main's fold.
  3. ui/packages/app-shell/src/views/ActionResultDialog.tsx: the import('qrcode') path that writes to the error slot.

Two-minute check: run pnpm --filter @object-ui/console build and then, in ui, node scripts/check-eager-closure-budget.mjs. Expect "✅ Chat chunks stay lazy" and about 1848.8 KB eager against a 2196.3 KB budget.

Readings

Eager closure before and after (production builds, same container, same instrument)

Both builds were measured with emitEagerClosureReport (dist/eager-closure.json). Control: main at eef1cbfe4. Head: 686c9993. Commit 809cfb890 changes only the gate script and its test.

chunk eef1cbfe4 686c9993 delta
plugin-chatbot 236,909 not eager -236,909
plugin-markdown 69,180 not eager -69,180
index 135,874 117,803 -18,071
browser (qrcode) 8,804 not eager -8,804
everything else 1,776,025 1,775,357 -668
aggregate (gz) 2,226,792 (147 of 2633) 1,893,160 (134 of 2653) -333,632

The per-chunk rows are unchanged: vendor-objectstack -392, framework -18, ui-components +583, i18n-locale-en 0.

Earlier readings, kept as recorded: at 483eaa34, 1,893,147 in 134 of 2653. With cut 1 ablated, 2,201,929 in 148 of 2653.

Gate at head: exit 0
✅ Console eager closure is 1848.8 KB gzipped across 134 of 2653 chunks (budget: 2196.3 KB, headroom: 347.5 KB).
✅ Per-chunk eager budgets (4 chunks weighed)
✅ Chunk membership: 5 budgeted package(s) each landed exactly where declared
✅ Ceiling sensitivity (5 ceilings): aggregate headroom 347.5 KB = 0.50x the 695.0 KB regression
✅ Chat chunks stay lazy: `plugin-chatbot` and `plugin-markdown` hold modules in this build and none of them is in the eager closure.

The ablation build (cut 1 reverted) gives:

✅ Console eager closure is 2150.3 KB gzipped across 148 of 2653 chunks (budget: 2196.3 KB, headroom: 46.0 KB).
❌ Chat chunks are in the EAGER closure, so every console page downloads the chat UI before it draws: `plugin-chatbot` 231.4 KB, `plugin-markdown` 67.6 KB.

The gate exits 1.

Browser readings: real Chromium 1243 through Playwright 1.63, production builds, HTTP/2 TLS front

Setup: objectstack start with NODE_ENV=production, OS_AUTH_TWO_FACTOR=true and OS_TRUSTED_ORIGINS set to the front, the showcase app and a SQLite file database. The main and PR dists were served in turn by the same server behind the same HTTP/2 front. Each check used a fresh browser context, and every document was served over h2.

reading main build PR build
signed-out /login renders the e-mail and password inputs yes yes
/login fetches a LoginPage-*.js chunk no (inlined in index) yes, LoginPage-TuUOOWNS.js
chat chunks fetched by /login plugin-markdown, plugin-chatbot none
chat chunks fetched by a signed-in page before the chat opens plugin-markdown, plugin-chatbot none
chat chunks fetched by the first click on Ask AI none (already loaded) plugin-markdown-z1wyxXLS.js, plugin-chatbot-eTgo7l4P.js
the chat drawer opens with its composer yes yes
2FA QR: qrcode chunk fetched before enrolment (eager) none
2FA QR: fetched on submit browser-jSiDnjdN.js (the qrcode chunk, not eager)
2FA QR: canvas drawn 184x184, 16,206 dark and 17,650 light pixels, no error text

The QR was read on the MFA remediation overlay (TotpQr) for a second account, with auth.mfa_required set to everyone and a grace period of 0. The setting was restored to off afterwards. Notes on why: the record-page "Enable Two-Factor Auth" button does not render on either build (Acceptance notes), and the agent catalog is stubbed for the chat reading because the open framework has no AI service.

LCP medians by the #37444 method

Method: production builds, HTTP/2 TLS front, Lighthouse 13.6.0 desktop-config (simulated throttling, storage reset on), signed in through the Console login form, Chromium 1243 headless. I ran the arms back to back in blocks main-1, pr-1, pr-2, main-2 of 5 runs per page each, so each arm has 10 runs. Every document and script was served over h2, and no run recorded a runtime error.

page main median LCP (ms) PR median LCP (ms) delta
home (/_console/home, landing on the showcase capability map) 2,214 2,068 -147 (-6.6%)
list (/apps/com.example.showcase/showcase_task) 2,734 2,562 -172 (-6.3%)
record (.../showcase_task/record/GYPAOUBLX6JfK5c_) 2,510 2,310 -200 (-7.9%)

Home caveat. /_console/home redirects to the last app opened. In block main-1 it landed on the Setup dashboard, because the browser checks before it had last opened Setup. Those 5 runs measure a different page (2,473 to 2,707). They are excluded from the home row and kept in the raw data. To give main 10 runs on the same landing page, I appended a block main-3 of 5 home runs; it ran right after main-2, not interleaved with a PR block. The unfiltered home medians are main 2,378 and PR 2,068.

Scripts fetched per load: home 180 on main and 167 on the PR, list 285 and 274, record 217 and 206.

Runs (ms):

  • main home: 2.1=2277 2.2=2283 2.3=2219 2.4=2233 2.5=2227 3.1=2208 3.2=2209 3.3=2189 3.4=2192 3.5=2201 (main-1, on the Setup dashboard: 2661 2707 2703 2473 2662)
  • pr home: 1.1=2140 1.2=2099 1.3=2007 1.4=2035 1.5=2062 2.1=2060 2.2=2073 2.3=2102 2.4=2000 2.5=2082
  • main list: 2751 2668 2771 2731 2672 2736 2740 2663 2834 2706
  • pr list: 2540 2607 2634 2559 2564 2424 2585 2557 2630 2514
  • main record: 2510 2518 2485 2510 2536 2604 2478 2489 2511 2490
  • pr record: 2351 2311 2303 2276 2288 2385 2310 2331 2301 2357

These are shared-box readings. The runs held the verify lock, which excludes other locked runs but not other unlocked work.

Appended after the session restart: the gate re-read at head 809cfb8

Commit 809cfb890 changes only ui/scripts/check-eager-closure-budget.mjs and its test (git diff --stat 686c99934 809cfb890: 2 files). ui/apps/console/vite.config.ts does not import that script, so no bundler input differs from 686c9993, and the eager closure was not rebuilt. The dist/eager-closure.json on disk is byte-identical (cmp) to the 686c9993 reading recorded above. node scripts/check-eager-closure-budget.mjs at committed head 809cfb890 exits 0, and its output is byte-identical (diff) to the "Gate at head" block above: 1848.8 KB across 134 of 2653 chunks against a 2196.3 KB budget (2,249,000 bytes), and "Chat chunks stay lazy". No recorded number changes.


Generated by Claude Code

… load

The plugin-chatbot-core chunk group now takes the two modules core.ts
re-exports that it did not list (hitlContinuation, chat/questionSkip), so the
plugin-chatbot and plugin-markdown chunks are lazy again. The nine auth pages
and four dev pages load with their routes, and qrcode loads when a QR first
draws. The eager-closure gate gains a half that fails when a chat chunk is in
the eager closure.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM
…ceiling

The eager-closure gate's chat half gets unit cases, a main-level exit-1 case
and a static case that matches every module plugin-chatbot/src/core.ts
re-exports against the plugin-chatbot-core group. MAX_EAGER_CLOSURE_GZIP_BYTES
and BASELINE are re-pinned by the gate's formula to the reading on the branch
commit 483eaa3: 1,893,147 + 355,840 = 2,248,987.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM
The auth routes drop their own Suspense, so the mobile shell's ready() still
waits for the first route to be on screen. The docs-portal laziness test moves
its eager positive control from LoginPage to FormPage. The changeset carries
the claim's Clause-② line verbatim.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM
The build of 686c999 reads 1,893,160 gz across 134 of 2653 chunks, so the
ceiling is 1,893,160 + 355,840 = 2,249,000 and BASELINE names 686c999.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM
With the auth pages lazy, the first route commits after a chunk resolves,
and ready() and routeChanged run in that commit's passive effects, which can
land after findByTestId returns. The five event assertions now wait for the
events; the ready: prefix still records what was on screen when ready() came.

Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L9qibx7DSQZnugnuX8CpCM
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#3 · os-tesla · session_01L9qibyUSf2nKJWW6qBemSU

Landing · 2026-11-28T21:21Z · zone o3-ux (seat card thread)
Head-sha: ebc4922962b8319143f005c5672df01d92664438

  • L1-a ACCEPT 7245956643 at this head. No contract review owed: Clause-② no (verified: no export moved, TotpQr and QrcodeBlock module-private), Metadata-protocol none, no spec, governed or narrowing path. Changesets patch for @object-ui/console and @objectstack/console. N1 (the "(load order only)" parenthetical) left as is, per L1-a.
  • Claim 7243573945, amendments 7243947617 (threshold, cap by formula, chat-lazy guard) and 7245569343 (two nativeShell test files for the lazy-LoginPage flake).
  • Readings: eager closure 2,226,792 → 1,893,160 gz (−333,632), cap 2,249,000, gate exit 0 (ablating cut 1 gives exit 1); LCP medians by the Console first screen: home, object list and record page miss the 2.5 s LCP threshold (baseline 3.6 / 4.6 / 4.2 s); re-measure on a production build first #37444 method 7245504380: home −147, list −172, record −200 ms.
  • check-governed-merges.mjs --pr 38384: NOT governed. Size +421 / −70, 10 files.
  • K: 3 < 15.
  • Checks at this head: 47 success, 11 skipped, 0 failed. mergeable_state clean.
  • Action: mark ready for review and enable auto-merge (queue).

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 28, 2026 21:22
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 2efcedd Nov 28, 2026
59 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-ciejge branch November 28, 2026 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Console first screen: the eager JS closure (1.95 MB, same 120 chunks on every page) is ~2 s of LCP; slim what the shell imports eagerly

2 participants