Repository navigation
perf(ui): construct live Markdown tails directly as DOM - #182875
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. What this changesThis PR constructs ordinary chat Markdown as DOM nodes and passes them to the existing reconciler to avoid repeated HTML parsing. Example: A streamed reply contains TypeScript fences, tables, and links.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: the optimization has owner support, but the direct renderer introduces a session-link regression. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherChat message preparation passes parsed Markdown through rendering and sanitization into the framework-neutral DOM reconciler, which retains interactive transcript content. flowchart TD
A[Chat Markdown] --> B[Markdown parser]
B --> C[Allowlisted DOM construction]
B --> D[HTML renderer and DOMPurify]
C --> E[Prepared content]
D --> E
E --> F[Existing DOM reconciler]
F --> G[Chat transcript]
Technical reviewBest possible solution: Preserve sanitized inline-token metadata within the existing construction path while retaining one sanitizer policy and one reconciler. Do we have a high-confidence way to reproduce the issue? Source tracing establishes both repeated HTML parsing on main and the introduced inline-session metadata loss; no target code was executed. Is this the best way to solve the issue? Carrying prepared DOM through the existing reconciler follows the performance guidance, but inline code must preserve the metadata already produced by parser plugins. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against aaecd52e6bff. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +483, Tests +66, Other +1. Total +550 across 13 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 24, 2026, 5:14 PM ET / 21:14 UTC. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dfd261d696
ℹ️ 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".
| if (token.type === "code_inline") { | ||
| parent.append( | ||
| element("code", {}, [token.content.replaceAll("\0", "").replace(/\r\n?/gu, "\n")]), |
There was a problem hiding this comment.
Preserve session-link attributes on inline code
When a message contains a backtick-wrapped session URL on the configured public origin rather than the current browser origin, this branch discards the token's data-session-href attribute. installMarkdownSessionLinks deliberately adds that attribute to code_inline tokens in markdown-session-links.ts:112–118, and both session-title registration and session navigation use it to recognize these references. Consequently, the new chat rendering path leaves these URLs as inert code instead of providing the existing session title, hovercard, and navigation behavior. Preserve allowlisted token attributes here, or fall back to the existing renderer for attributed inline-code tokens.
Useful? React with 👍 / 👎.
# Conflicts: # config/control-ui-startup-budget-baseline.json
# Conflicts: # config/control-ui-startup-budget-baseline.json
|
Merged via squash.
|
) * perf: render ordinary chat Markdown directly to DOM * test(ui): type Markdown content mocks and serialize prepared prose * perf(ui): ratchet Markdown budgets to the refreshed build * perf(ui): refresh Markdown budgets after main merge * perf(ui): limit token DOM construction to live Markdown tails
What Problem This Solves
Live chat tails repeatedly serialize Markdown to HTML, parse it through DOMPurify, then parse it again for reconciliation. This change constructs supported Markdown syntax directly as allowlisted DOM only for the mutable streaming tail and carries that fragment through the existing reconciler.
User Impact
Settled messages, reload, history load, session switch, completed prefixes, and completion retain the existing HTML + DOMPurify path and string cache. Raw HTML, unsupported plugin tokens, and specialized renderers keep the full sanitizer boundary. Prepared fragments are cloned before consumer mutation. Appearance, links, reader controls, and lazy boundaries remain unchanged.
Peter accepted the additional code and chat bytes after the original experiment measured streaming script CPU −8.6% and HTML assignments 2,129 → 178. The broad direct-rendering candidate was rejected after a reload p95 regression, so this revision restricts direct construction to streaming. Three base and three broad-candidate diagnostic profiles did not establish per-node construction as the cause of that tail; no causal claim is made from those samples.
Evidence
Security proof is against the original pipeline at main
368b9dc52b98985dda08c2579fa1bff3e1809485; the newer fetched main has identical Markdown owners and budget inputs. All differential inputs match the current source hashes.tsconfig.ui.jsonci:fullf01cc6fd4d3a66ba00d8a4ad63b7e89958a8ea0fStartup raw bytes are identical; its gzip movement is build variation, not a causal win. The supported
--update-baseline --reasoncommand records the accepted CPU/bytes tradeoff and measured startup baseline. Chat's cap is 1,274,861 B: measured head plus the existing 811 B headroom.Final same-machine timing uses 20 serial base/base/head triplets (60 cells). Values below are median / nearest-rank p95 / min–max, in milliseconds unless noted.
Streaming script median improves 6.87% (A/A −0.83%) and p95 improves 12.08%. HTML assignments fall 88.81%. Reload script median changes +0.34%; its p95 is +6.42%, while the unchanged A/A p95 is +9.85%. Reload total-task median is +3.22% and p95 −4.95%. The shared host's one-minute load ranged 35.14–77.36; wall readiness is noisy (A/A median +30.26%) and is not treated as a speedup or regression. The raw p95 increase is disclosed: the unchanged control has a larger tail, so it does not establish a candidate-specific reload regression. Bulk source/cache behavior is restored, and reload script/task medians remain inside the 5% band. Reload style CPU is a disclosed exception among subphases: median +6.26%, p95 −2.08%; there is no CSS change and the bulk DOM path is unchanged. This is not a claim that every CPU submetric improved.
Touched UI production source: 1,999 → 2,444 lines (+445). All touched production/config/scripts: 2,795 → 3,241 (+446). Tests/support: 3,527 → 3,599 (+72). The simplification removes static prepared caching and the obsolete string-streaming production API; string assertions now serialize the real streaming result in test support. Effects 1 → 1, listeners 0 → 0, DOM queries 2 → 2, cleanup 1 → 1; owner APIs and reactive state counts unchanged. No Worker or dependency added.
Synthetic-only before/after captures were inspected. Both show the final streamed reply with identical code blocks, tables, and links.
Workload, acceptance, and limits
The final acceptance run uses a 400-message synthetic chat and 645 deltas at 30/s: 20 serial base/base/head triplets, untraced renderer thread CPU, host load recorded. The second base copy is an A/A control. Reload uses persisted state and HTTP cache; it does not model a cold-network first visit. Acceptance requires streaming improvement and reload median regression ≤5% with no real p95 regression. On a noisy host, A/A and CPU over 20 pairs take precedence over wall timing. The original −40% / ≤1.0 s streaming and −40% settled targets are not achieved or claimed.
The corpus includes transcript Markdown, DOMPurify historical XSS/mXSS payloads, hostile attributes/language labels, URL schemes and decoded control bytes, generated links/favicons, nested grammar, deterministic prefixes, and syntax-boundary/random streaming splits. Raw authored HTML still uses DOMPurify.
Reproduce with
scripts/bench-control-ui-cold-load.ts --bundle-dir <base> --compare-bundle-dir <base-copy> --compare-bundle-dir <head> --runs 60 --streaming-reply --transcript-messages 400 --face chat --untraced --thread-cpu-time. Builds usepnpm ui:build; strict asset comparison uses both same-machine bundles. No broad local E2E, Docker, or remote lease was used.The first lint attempt used the editor UI graph and timed out in unrelated SDK declarations; the corrected documented lint graph passes. Knip's four inherited files are
extensions/codex/src/app-server/protocol-validator-schemas.ts,src/gateway/mcp-app-standalone-host.ts,src/gateway/worker-environments/repository-node-requirement.ts, andsrc/sessions/runtime-context.ts.