Repository navigation
refactor(ui): make streaming Markdown renderer-neutral - #168302
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 maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Refactor · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherThe 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
Technical reviewBest 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
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +212. Total +212 across 4 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 HistoryReview history (4 earlier review cycles)
Reviewed October 10, 2026, 4:34 AM ET / 08:34 UTC (Revision 5). |
|
Merged via squash.
|
* 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]>
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
MarkdownDomReconcilernow 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:
checks-ui (1/3)checks-ui (2/3)checks-ui (3/3)checks-ui-e2e (1/2)control-ui-performanceThe 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 --checkpassed.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=1sequentially, first on detachedorigin/main(7c0d4070a293c644ededc6fc16dd1f6a52539e58) with its own frozen install, then on final headcd6d5ad7884c80cc859716df1bd33c8f63c02af5. Both passed 6/6; all existing budgets passed unchanged. No test or threshold was edited.uptimeload averages (1/5/15 min)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
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
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..chat-text; the existing exact-text assertion was preserved and the template fixed.renderimport; the import is now namedrenderLit.Remote attempts before PR CI
tbx_01m4hz6pcdeevy598gygw6yyf6tbx_01m4j1tmqz7h7wfzwhjsds0q77(run 38024919496)tbx_01m4j4bjx2kkx25akavgjfwt76run_3d022120abe974b9b1b1ade6e1e40a68cbx_8c051ef41fd0, final attemptrun_d1b2c0a3921eb67faa645c906e73c4c7All 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.