Repository navigation
perf(control-ui): avoid reparsing completed code while replies stream - #173264
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. |
7b44680 to
3c4db60
Compare
|
Codex review: needs maintainer review before merge. What this changesThis PR reuses completed Markdown containing code comparisons, skips unchanged DOM fragments, and extends the streaming benchmark. Example: A streamed TypeScript answer contains
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open as a maintainer-owned experiment addressing repeated streaming-render work still present on main; respect the explicit draft merge hold. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherControl UI receives cumulative assistant text, splits stable Markdown from the growing tail, parses and sanitizes rendered fragments, and reconciles them into retained chat DOM with separate media lifecycle handling. flowchart TD
A[Assistant text updates] --> B[Streaming Markdown owner]
B --> C[Code ownership parser]
B --> D[Stable prefix and live tail]
D --> E[Markdown parser and sanitizer]
E --> F[DOM reconciler]
F --> G[Chat content and media]
Technical reviewBest possible solution: Reuse completed code-bearing Markdown through the existing renderer and DOM owners while preserving conservative HTML handling and media refresh. Do we have a high-confidence way to reproduce the issue? Current-main source shows that a fenced comparison disables prefix reuse, and the PR reports a before-fix sanitizer-budget failure; this read-only review ran no target code. Is this the best way to solve the issue? The implementation addresses the conservative guard in its existing owner, reuses the established code parser, and preserves sanitization and media updates without adding a parallel rendering path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f1e5b8d4c831. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +27, Tests +244, Other +99. Total +370 across 6 files. Added test files: 1. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 15, 2026, 12:43 PM ET / 16:43 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. |
8369153 to
e186656
Compare
e186656 to
97cda72
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 97cda729f3
ℹ️ 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 hasHtml = append | ||
| ? previous.hasHtml || hasStreamingMarkdownHtml(stableMarkdown.slice(previous.markdown.length)) | ||
| : hasStreamingMarkdownHtml(stableMarkdown); |
There was a problem hiding this comment.
Reparse cross-block raw tags in progress cards
When toStreamingMarkdownParts is called with progressBars: true, treating every < inside code as safe breaks streaming/full-render parity. stripProgressCardRawContentBlocks scans the entire raw message without respecting Markdown code ownership and can pair an opener and closer across completed blocks—for example, fenced blocks containing <script> and later </script>. This cache path renders each block separately and retains both, while a full or final render removes the paired range. Disable this optimization for progress-card rendering or classify according to that whole-message preprocessor.
Useful? React with 👍 / 👎.
The benchmark added four production-suppression entries in a522893 (#173264), failing the main lint-suppressions gate. Keep the allowlist intact. Give captured native DOM functions explicit receiver contracts and accept native HTML inputs as unknown so TrustedHTML-like values are still coerced for character counts without changing the actual parser/setter inputs. No application imports or behavior change; the only consumer is the opt-in cold-load benchmark. There are no importing tests. Its serialized probe passed an isolated jsdom smoke for native receivers, HTML coercion, and exact finite counters. lint-suppressions.test.ts: 3 passed, 12.34s command wall (before: 1 failed/2 passed). UI and owning ui-other test types, type-aware/boundary oxlint, format, and P2 autoreview passed.
…s a literal < (openclaw#173264) The streaming Markdown renderer reuses completed blocks only when the stable prefix contains no raw HTML, but it tested for any '<' character, so a code span or fence with a comparison like `value < 100` disabled the cache and re-parsed/re-sanitized the whole growing reply on every delta. HTML detection now ignores '<' inside code spans and fences (tracked incrementally for appended text), and the DOM reconciler skips unchanged non-media nodes. Streamed and non-streamed output stay byte-identical (regression test). Seven interleaved AWS pairs with a long synthetic streamed reply (prose, fenced TypeScript, tables): late-stream JS 10.5 -> 8.4 ms per delta, LoAF blocking 5,231 -> 4,307 ms per stream, Markdown input parsed 4.32M -> 1.31M characters. Runtime +27 LOC; the rest is the streaming bench/probe. Full UI 3,500 tests passed; exact-head CI green.
The benchmark added four production-suppression entries in 913599c (openclaw#173264), failing the main lint-suppressions gate. Keep the allowlist intact. Give captured native DOM functions explicit receiver contracts and accept native HTML inputs as unknown so TrustedHTML-like values are still coerced for character counts without changing the actual parser/setter inputs. No application imports or behavior change; the only consumer is the opt-in cold-load benchmark. There are no importing tests. Its serialized probe passed an isolated jsdom smoke for native receivers, HTML coercion, and exact finite counters. lint-suppressions.test.ts: 3 passed, 12.34s command wall (before: 1 failed/2 passed). UI and owning ui-other test types, type-aware/boundary oxlint, format, and P2 autoreview passed.
What Problem This Solves
Streaming replies containing ordinary code comparisons repeatedly parse and sanitize completed Markdown as later blocks arrive.
User Impact
Less JavaScript work and long-frame blocking while an answer streams, with identical rendered output. Total renderer CPU remains nearly unchanged because style recalculation dominates; this does not eliminate all streaming jank.
Why This Change Was Made
The cold-load campaign originally measured 14 visual states over roughly 15 seconds for a signed-in dashboard deep-link reload. This lane measures subsequent streaming use.
The renderer already cached completed Markdown, but its HTML guard treated
<inside code as possible HTML. Once a comparison arrived, later completed blocks could re-render the entire prefix. The existing streaming owner now uses the shared Markdown code-ownership parser on newly completed text and retains its HTML classification in the existing bounded cache. Actual HTML retains its conservative fallback. The DOM owner also skips unchanged non-media fragments while preserving media lifecycle updates.The benchmark adds a 15,468-character answer with prose, code comparisons, and tables, delivered cumulatively in 645 deltas at a nominal 30 per second. It measures untraced streaming CPU by message-length quartile, parsing work, LoAF, frame gaps, and trusted composer input latency, and accepts the campaign's generic LoAF/mutation and WebSocket census probes. Native HTML hooks retain string conversion for TrustedHTML inputs omitted by lib.dom's types; the benchmark rejects non-finite character counts.
Evidence
Final-head comparison: seven interleaved baseline/candidate pairs on one quiet AWS Crabbox c7a.4xlarge, lease cbx_70beb3ceff7f: 16 CPUs, AMD EPYC 9R14, about 30.6 GiB RAM, startup load 1.04. Baseline runtime source:
e8633bd8930438e3ee165ad934d60e8a1ff9bd63; candidate:97cda729f353094dfb950a657e52129979b3f9f0. Both production bundles use identical fixture/probes and the repository's Playwright Chromium. Boot profiling ends before the streaming segment; no validation jobs run during the comparison.Values are median (IQR) across seven runs:
JavaScript CPU falls 20.1%, LoAF blocking falls 17.7%, and parsed input falls 69.6%. Input latency has overlapping IQRs: this is not a clear input-latency win. LoAF count increases while total blocking decreases. Geometry/style work also increases, and total CPU stays flat. Frame loss is estimated from rAF gaps; input-to-rAF is not a presentation timestamp. CPU counters include the benchmark/probes and native input. The first CPU quartile also includes fixture scheduling overhead.
JavaScript CPU across the four message-length quartiles is 12.44/11.59/10.76/10.50 ms per delta before and 11.83/10.74/9.34/8.38 afterward. Total CPU is 31.01/31.01/32.24/33.34 before and 30.12/31.07/32.22/33.28 afterward. Style work remains the dominant remaining cost. These counters do not prove a strict constant-time total renderer path.
All 14 captures have valid parsing counters, 645 delivered deltas, 24 headings, 24 code blocks, and 24 tables. Rendered HTML is identical across every capture after removing reconciler comments (SHA-256
5ecca9b6c7c28a6469d221875934598ef42efe24534f37fbe7a51140a35b9291). The focused regression separately checks byte-identical streamed/full renderer output at each completed section.Validation
pnpm test ui/src/components/markdown-streaming.test.ts --maxWorkers=1: 18 passed, final-head AWS wall time 10.58 s.pnpm test ui/src/components/markdown-dom-ref.test.ts --maxWorkers=1: 4 passed, final-head AWS wall time 4.92 s, covering DOM retention and media cleanup.pnpm tsgo:ui/pnpm tsgo:scriptspassed. Full UI e2e passed on the final head: 803 files / 3,500 tests passed, one existing file/test skipped, zero failures. Command:node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --maxWorkers=6; AWS wall time 3,978.19 s. The skipped file isui/src/e2e/desktop-resize.real-gateway.e2e.test.ts(existing platform-specific skip). All eight archived check exit codes are zero. The full pass/skip list is retained in the lane proof artifacts.97cda729f353.Scope and size
Runtime: +27 lines (31 added, 4 removed) across the three existing Markdown owners. The additional classification preserves the actual-HTML invalidation contract while allowing literal code to stay cached. No persistent state, server schema, configuration, dependency, or transport changes.
Benchmark/probe tooling: +369 net lines. The requested
git diff --stat origin/main...HEAD -- ':!*.test.ts' ':!*test-support*' ':!docs/*'includes that tooling: 402 added, 6 removed, +396 net lines. Six files total, including the one-line regression edit.Release-note context: Control UI keeps completed Markdown cached when streamed code contains comparisons, reducing repeated rendering work without changing the answer.
Synthetic before / after
The captures below show the completed baseline and candidate reply on the final-head comparison. Both were inspected in full and contain only the synthetic benchmark fixture.