Skip to content

refactor(ui): make streaming Markdown renderer-neutral - #168302

Merged
steipete merged 4 commits into
mainfrom
solid2/p1-16
Oct 10, 2026
Merged

steipete merged 4 commits into
mainfrom
solid2/p1-16

Conversation

@steipete

@steipete steipete commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Streaming Markdown depended on Lit's committed-value internals and nested rendering state, preventing the Control UI from sharing its retained-DOM behavior with another renderer.

User Impact

Internal refactor; no user-facing change. Parsing, sanitization, and existing test and performance limits are unchanged. No new dependencies.

Why This Change Was Made

A plain TypeScript MarkdownDomReconciler now owns the container's canonical tree. It preserves tail promotion without remounting, explicit generation resets, canonical strings rather than retained parsed nodes, reader-owned classes, repair of externally split text, and opaque completed subtrees, custom elements, and Mermaid. Media islands retain identity when moving between fragments and have explicit connection and disposal callbacks.

One thin Lit adapter drives streaming and standalone Markdown. The Markdown enhancement observer lifecycle is separated from its directive. The four-file production footprint initially changed from 956 to 1,169 LOC (+213); the exact-text correction leaves 1,168 LOC (+212). DOM ranges and canonical descriptors previously supplied by Lit now have an explicit framework-neutral owner, while duplicated driver code is removed.

Release-note context: internal refactor, no user-facing change.

Evidence

Final head: cd6d5ad7884c80cc859716df1bd33c8f63c02af5.

PR CI run 38035465764 completed successfully, including the CI gate, production/test typechecks, lint, guards, i18n, and the following UI jobs:

Job Result
checks-ui (1/3) 537 files; 7,448 passed, 1 skipped
checks-ui (2/3) 537 files; 7,161 passed, 3 skipped
checks-ui (3/3) 537 files; 7,672 passed, 2 skipped; all 35 streaming Markdown cases passed
checks-ui-e2e (1/2) Selected chat-containing E2E job: 14 files, 84 passed
control-ui-performance Build and performance job passed with the startup-JS warning below

The streaming cases cover zero removed nodes across 12 updates and retained details, wrap/copy controls, tables, highlights, media, and Mermaid. Local streaming proof also passed 35/35. Codex autoreview is clean through P2 for the extraction and both CI corrections; git diff --check passed.

Local stream-runtime A/B proof

CI did not select chat-stream-runtime-budgets.e2e.test.ts; the coordinator authorized this single-file local comparison after remote capacity failed. No extra CI workflow was dispatched. The selected CI E2E job remains a 14-file subset, not the entire chat suite.

Ran pnpm test ui/src/e2e/chat-stream-runtime-budgets.e2e.test.ts --maxWorkers=1 sequentially, first on detached origin/main (7c0d4070a293c644ededc6fc16dd1f6a52539e58) with its own frozen install, then on final head cd6d5ad7884c80cc859716df1bd33c8f63c02af5. Both passed 6/6; all existing budgets passed unchanged. No test or threshold was edited.

Measurement Base PR head Existing gate
Deltas 240 240 240
Host invalidations 2 2 2–180
Frame-scheduled invalidations 2/2 (100%) 2/2 (100%) ≥90%
Mutation batches / sampled animation frames 2 / 14 2 / 14 Diagnostic
Composer invalidations, steady / scroll-return ≤1 / ≤1 ≤1 / ≤1 ≤1 each; asserted bounds, counts not logged
Transcript load (400 messages + 150 rich chunks) 510 ms 480 ms ≤30,000 ms
Post-GC JS heap 26,280,196 B 26,297,776 B ≤100,663,296 B (96 MiB)
Idle long tasks / total duration 0 / 0 ms 0 / 0 ms ≤600 ms total
Idle task time over 4 seconds 28 ms 35 ms ≤600 ms
Complete command wall time 34.19 s 35.26 s Diagnostic
uptime load averages (1/5/15 min) 13.62 / 14.84 / 15.98 8.94 / 13.26 / 15.31 Recorded immediately before each run

Structural counts are identical. The heap difference is +17,580 B (0.067%), and idle task time differs by +7 ms; timings were sampled once under the recorded machine load and are not evidence of a performance improvement or a budget regression. The tool-stream retention contract also passed on both heads (50 retained cards after 60 complete lifecycles).

Measured asset budgets

Metric Base → candidate / candidate value
Chat boot JS gzip 1,536,033 → 1,537,114 B (+1,081 B)
Chat boot JS requests 32 → 32; limit 35
Chat boot CSS gzip 138,922 → 138,922 B
New-session boot JS gzip 1,296,397 → 1,297,379 B (+982 B)
New-session boot JS requests 26 → 26; limit 35
Startup JS 374,053 B gzip; 8 requests
Startup CSS 50,560 B gzip; 1 request; hard ceiling 51,200 B

The performance job reports startup JS 599 B above its 373,454 B enforcement threshold as an advisory CI warning. That warning is not a green runtime-budget result, and no limit or baseline was raised.

Earlier proof and CI corrections

  • Earlier head deeb2d39a18f9d8b556b0f1e1acd1f308479323c: Testbox Node and Bun Markdown selections each passed 649 tests in 23 files; production UI and nine test typecheck shards passed. These are earlier-head results. The dead-export guard then identified the redundant Lit driver, which was consolidated.
  • Initial PR CI caught incidental whitespace in .chat-text; the existing exact-text assertion was preserved and the template fixed.
  • Second PR CI caught a shadowed render import; the import is now named renderLit.

Remote attempts before PR CI

Attempt Result
Testbox tbx_01m4hz6pcdeevy598gygw6yyf6 Completed before accepting the candidate command; no remote proof
Testbox tbx_01m4j1tmqz7h7wfzwhjsds0q77 (run 38024919496) Earlier-head Node/Bun and typecheck evidence above
Testbox tbx_01m4j4bjx2kkx25akavgjfwt76 Timed out queued after 15 minutes
AWS run_3d022120abe974b9b1b1ade6e1e40a68 Provisioning refused by vCPU quota; no lease allocated
Hetzner cbx_8c051ef41fd0, final attempt run_d1b2c0a3921eb67faa645c906e73c4c7 Source transfer stalled after full resync; canceled before tests

All task-owned leases were stopped or released. The coordinator approved the design and authorized native landing after this A/B proof; merge admission remains subject to the required exact-head gates.

@clawsweeper

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

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR moves streaming Markdown reconciliation into a framework-neutral DOM owner and separates enhancement lifetimes from their Lit adapter.

Example: A reader expands and wraps an eight-line TypeScript block before its streaming fence closes.

  • Before: Lit-specific directives preserve the block and reader choices.
  • After: The framework-neutral reconciler preserves the same block and choices.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A coherent, supported extraction with passing exact-head checks and no actionable defect; direct reader-state evidence remains at the browser-component boundary.
Proof confidence 🦐 gold shrimp (3/6) The supplied MEMBER-author context exempts this PR from the external-contributor proof gate; final-head browser coverage exercises the changed production owners, and reported A/B tests exercise runtime budgets, while inspected screenshots belong to earlier fixes and the optional reader-state Chat-route demonstration remains unprovided.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Existing streaming continuity depends on Lit internals, complicating the planned renderer migration.
Reason: The existing area owner implements a recorded migration foundation without changing user behavior, configuration, dependencies, persisted data, or public APIs.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR provides a useful foundation for the planned renderer migration, with passing exact-head CI and no actionable introduced defect.

Priority: P3
Reviewed head: cd6d5ad7884c80cc859716df1bd33c8f63c02af5

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: An optional Chat-route demonstration retaining expanded code, wrapping, and media identity through fence closure would cover the earlier rank-up suggestion more directly.
Agent review details

How this fits together

The Control UI passes sanitized Markdown fragments and media bindings into the reconciler, which updates retained message DOM while separate owners enhance code, tables, and diagrams.

flowchart TD
 A[Chat message] --> B[Markdown parser and sanitizer]
 B --> C[Lit adapter]
 C --> D[Markdown DOM reconciler]
 D --> E[Retained message DOM]
 C --> F[Media renderer]
 F --> E
 G[Markdown enhancement lifecycle] --> E
Loading

Technical review

Best possible solution:

Land the renderer-neutral foundation while preserving the existing streaming, sanitization, media, and presentation contracts.

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

This is a behavior-preserving refactor rather than a bug report; source confirms the framework coupling, and no target code was executed during this review.

Is this the best way to solve the issue?

The extraction fits the recorded migration plan, removes the superseded directives, and keeps reconciliation and enhancement responsibilities explicit.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Active-tail DOM reconciliation and reader-owned state keeps the original intent (c2c5519: Preserve reader controls and untouched enhancements while growing Markdown updates in place.)
  • Streaming fragment promotion keeps the original intent (f7bd9a2: Keep the promoted fragment's existing renderer so closing a fence preserves code controls.)
  • Ordered media ownership keeps the original intent (1ea4fb7: Preserve text/media order, mounted media, and complete-document Markdown semantics.)
  • Markdown enhancement lifecycle keeps the original intent (2b45b18: Give Markdown enhancements one lifecycle owner while retaining transcript navigation and presentation teardown.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 81901bf adds ui/src/pages/chat/components/chat-message-text.ts:256 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 81901bfd217e; files: ui/src/pages/chat/components/chat-message-text.ts)

PR surface

Source +212. Total +212 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 567 355 +212
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 567 355 +212

Review metrics

Metric Value Why it matters
Production versus test LOC Production net +212; tests unchanged Explicit DOM ranges and canonical descriptors replace framework-provided reconciliation machinery; the body explains the growth and the diff removes duplicate Lit drivers.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This is an internal migration foundation with no intended user-visible change or demonstrated urgent regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Optionally show a Chat-route run retaining expanded code, wrapping, and media identity as a fence closes and later text arrives.

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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-10T07:12:28.333Z sha 995e13f :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T07:38:07.971Z sha 96c1e12 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T08:00:48.277Z sha cd6d5ad :: needs maintainer review before merge. :: none
  • reviewed 2026-10-10T08:17:37.000Z sha cd6d5ad :: needs maintainer review before merge. :: none

Reviewed October 10, 2026, 4:34 AM ET / 08:34 UTC (Revision 5).

@steipete
steipete merged commit 7bdba03 into main Oct 10, 2026
102 checks passed
@steipete
steipete deleted the solid2/p1-16 branch October 10, 2026 08:35
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
* refactor(ui): decouple streaming markdown from Lit

* refactor(ui): share the markdown Lit driver

* fix(ui): preserve exact markdown message text

* fix(ui): distinguish the Lit media renderer

Co-authored-by: Peter Steinberger <[email protected]>
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 P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L 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