Skip to content

improve(ui): reduce image and browser code loaded on chat boot - #181062

Open
steipete wants to merge 1 commit into
mainfrom
perf/chat-media-boot
Open

steipete wants to merge 1 commit into
mainfrom
perf/chat-media-boot

Conversation

@steipete

@steipete steipete commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Chat boot loads image retrieval and browser operation code before either feature is used.

User Impact

Chat boot downloads 9,324 fewer gzip JavaScript bytes, with unchanged image opening, media rendering, and browser annotation behavior. No migration or user action is required.

Why This Change Was Made

Move the existing synchronous image-open helpers and browser annotation event contract into lightweight modules. Load browser screenshot operations inside the existing serialized thumbnail capture operation. The existing owners still publish pending work and admit annotations synchronously; no new cache, loading state, renderer, or compatibility path is introduced.

Evidence

Production builds compared against 722ad802bc2801eadd83c8b484cd9715480b1f97: Chat JavaScript gzip 1,417,590 → 1,408,266 bytes (−9,324); Shell 315,959 → 315,985 (+26); New Session 953,504 → 953,516 (+12). Shell/New differences meet the campaign's ≤64-byte build-variance allowance. JavaScript request counts remain 7/24/18. Chat CSS gzip increases 204 bytes without a new first-paint request.

130 focused test cases passed across thumbnail serialization, image gallery/custody/handoff, annotation admission/lifecycle, browser panel suites, and caught lazy-chunk recovery. UI typecheck, scoped lint, production build, and generated boot manifest checks passed. Independent review found no actionable defects. Production Knip reports the same out-of-scope cron/gateway, approval presentation, X OAuth, and session cleanup findings already confirmed on the campaign baseline; no finding involves these changes.

Timing acceptance, recorded before the run: compare this exact candidate and the pinned base on one focused Blacksmith Testbox, recording observed CPU/RAM and load. Run ten alternating samples per variant for signed-in Chat reload and New Session first load, with cold HTTP cache. Chat first nonempty transcript and enabled composer, and New Session enabled composer, must each have median ≤ base × 1.05 and p95 ≤ base. Four allocations entered capacity queues and were stopped without running samples; all four are reconciled. The second reached hydration while its stop was in flight. Timing remains a required, unproven gate before landing; results will be added when capacity is available.

Exact-head CI run 39869744663 completed with one inherited native-plugin UI failure (plus its aggregate CI gate): all 48 footer assertion signatures match scheduled main run 39865398397. The obsolete pseudo-element expectations are repaired on main by a68d0eb2525; none of those assertions or production paths is changed here.

@steipete steipete added the ci:full Keep ordinary native-locale CI selection on the next PR run. label Oct 22, 2026
@clawsweeper

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

@steipete
steipete marked this pull request as ready for review October 22, 2026 23:07
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 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-22T23:11:27.160411Z fcd00a8 Draft marked ready
ℹ️ 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.

@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: fcd00a843f

ℹ️ 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".

const pending = (entry.pending ?? Promise.resolve()).then(async () => {
try {
const { bindBrowserRequestClient, captureBrowserScreenshot, fetchBrowserScreenshotDataUrl } =
await import("../../components/browser/browser-client.ts");

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 Route lazy browser chunk failures through recovery

When the first thumbnail is requested after a deployment replaces the hashed assets, or when this chunk request fails transiently, the new dynamic import rejects inside the broad catch; the revision remains recorded as attempted, the memo resolves to undefined, and the same card never retries or invokes the existing stale-chunk recovery flow. Handle import failures separately with retryControlUiImport (while retaining the current capture/fetch failure policy) so browser previews recover rather than disappearing silently.

AGENTS.md reference: AGENTS.md:L76-L77

Useful? React with 👍 / 👎.

@steipete steipete Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing global stale-chunk owner handles this caught lazy-surface failure. main.ts:52 synchronously installs installStaleChunkReloadListener, before the queued thumbnail callback can attempt its import, and this production build transforms the browser import through Vite's preload helper, which dispatches vite:preloadError before rejecting. The listener schedules guarded document recovery even when the thumbnail catch returns undefined (stale-chunk-reload.ts:413–428).

I verified the generated browser-client import and reran the existing recovers caught lazy-surface failures when the document is reachable, not evaluation errors test successfully. Adding retryControlUiImport here would put the error in routeImportErrors, suppressing that global recovery; the thumbnail catch would then consume a persistent retry failure instead of the route error surface handling it. Keeping the existing lazy-surface recovery owner avoids that regression, so I am not applying this suggestion.

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR separates lightweight image and annotation helpers from heavier modules and loads browser screenshot operations on demand.

Example: Cold-loading signed-in Chat in the reported production-build comparison.

  • Before: Chat loads 1,417,590 gzip JavaScript bytes.
  • After: Chat loads 1,408,266 gzip JavaScript bytes, saving 9,324 bytes.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation is focused and source-consistent; build measurements provide partial evidence, while the explicitly required runtime timing acceptance remains incomplete.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Opening Chat downloads image-retrieval and browser-operation code before those features are used.
Reason: The maintainer-authored direction has a measured byte benefit and a small, behavior-preserving implementation.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: the maintainer-directed optimization is focused and preserves existing behavior, with no actionable code defect found.

Priority: P3
Reviewed head: fcd00a843fbe1cd7f78b05fd1f13d21336255299

Before merge

  • Complete next step - The PR owner should resolve the reported merge conflict while preserving current main's changes.

Findings

None.

Tests

  • Missing end-to-end proof: The declared alternating cold-cache Chat and New Session timing campaign has no completed results.
Agent review details

How this fits together

The Control UI renders chat media and browser previews using shared image helpers, synchronous annotation events, and a serialized screenshot queue backed by Gateway requests.

flowchart TD
  A[Chat boot] --> B[Lightweight image helpers]
  A --> C[Annotation event contract]
  A --> D[Thumbnail queue]
  D --> E[Lazy browser client]
  E --> F[Gateway screenshot and media]
  C --> G[Composer admission]
Loading

Technical review

Best possible solution:

Retain the lightweight extraction and existing recovery owners, then complete the declared timing acceptance before landing.

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

Current-main static imports establish the eager-loading path; the reported byte reduction was not rerun during this read-only review.

Is this the best way to solve the issue?

The smallest complete change is to separate the existing synchronous helpers and event contract, migrate their callers, and defer screenshot imports inside the existing queue; this diff follows that approach without adding state or parallel implementations.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

PR surface

Source -3, Tests +4. Total +1 across 21 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 15 77 80 -3
Tests 6 11 7 +4
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 88 87 +1

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is a modest startup-byte optimization without an established urgent user-facing failure.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 22, 2026, 7:56 PM ET / 23:56 UTC.

This branch has not been deployed

No deployments
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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant