Repository navigation
fix(chat): skip embed shortcodes in indented code blocks - #153579
Conversation
extractCanvasShortcodes used parseFenceSpans (only fenced code) to skip [embed] examples inside code blocks, so literal [embed] tags in 4-space indented code blocks were mis-extracted as real shortcodes and stripped from the delivered text. Switch to findCodeRegions which covers fenced, indented, and inline code.
|
🦞👀 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. Reviewed September 20, 2026, 7:04 AM ET / 11:04 UTC (Revision 5). ClawSweeper reviewWhat this changesThe PR preserves literal embed examples in indented and inline Markdown code by reusing the shared code-region parser and adding regression coverage. Merge readiness✅ Ready for maintainer review This remains a useful fix: current main still has the defect. No blocking findings remain, and the new Control UI screenshots address the previous proof request. Priority: P2 Review scores
Verification
How this fits togetherControl UI chat normalizes assistant text into visible text and canvas previews. The embed extractor decides which shortcodes become previews and which remain literal code. flowchart TD
A[Assistant message] --> B[Chat normalization]
B --> C[Embed extractor]
D[Markdown code regions] --> C
C --> E[Literal code and surrounding text]
C --> F[Supported canvas previews]
E --> G[Control UI chat]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -7, Tests +8. Total +1 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep Markdown code detection centralized while preserving literal examples, surrounding text, and ordinary supported embeds. Do we have a high-confidence way to reproduce the issue? Yes: an assistant message containing an indented or inline embed example reaches the fence-only extractor on current main and is consumed as a preview. Source inspection and supplied before/after app captures support this; no new execution was performed. Is this the best way to solve the issue? Yes: reusing the existing Markdown owner is a narrow repair that removes duplicate scanning logic and preserves the established preview path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 6d3ed6db7f1a. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
|
@clawsweeper re-review. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Actual Control UI chat proof, using the application router, maintained mocked Gateway handshake/history, production normalization and chat/widget components. These are screenshots of the running app, not a standalone rendering of normalized text. All data, model labels and canvas assets are synthetic; no external asset requests were permitted. Before: trusted main Indented code — beforeThe literal shortcode disappears and an unintended preview is shown. Indented code — afterThe complete example remains a code block, with no preview extracted. Inline code — before and afterOrdinary supported embed — before and afterThe real chat canvas iframe still loads the same inert, same-origin asset in both phases. Fenced-code controls also passed unchanged. All eight browser cases passed. Both indented/inline regression cases failed on the original extractor; the candidate passed 100 focused extractor and normalizer tests. |
|
Merged as 11eb00c. Literal embed examples now remain visible in indented and inline Markdown code; ordinary embeds still render. Verified all eight actual Control UI before/after cases, the two pre-fix regression failures, 100 passing focused tests, green exact-head CI and a clean review. Inspected screenshots are in the body-linked proof comment: #153579 (comment). No CI or screenshot exception was used. Thanks @SunnyShu0925 for the original repair. |
|
@obviyus Thanks for merging the PR! |
…#153579) ## What Problem This Solves Fixes literal `[embed]` examples disappearing from indented and inline code in Control UI chat and becoming unintended canvas previews. ## User Impact Code examples remain visible as code. Ordinary supported embeds still render, fenced examples remain literal, and surrounding prose is preserved. No configuration, schema, permission, dependency, or iframe-policy change is introduced. ## Why This Change Was Made The existing extractor now uses the canonical Markdown code-region scanner instead of a separate fence-only walk. The contributor's production repair is preserved. Regression coverage is consolidated into two distinct cases for indented blocks and inline code; production code is seven lines smaller. ## Evidence [Inspected actual Control UI before/after screenshots and ordinary-embed controls](openclaw#153579 (comment)). - Drove the real Control UI app/router through the maintained mocked Gateway handshake and session history, then the production normalizer, chat bubble and widget iframe. This is not a handcrafted page displaying normalizer output. - Four browser cases per phase: indented and inline examples were stripped and generated previews on pinned main; the candidate preserves both with no preview. Fenced examples and ordinary supported embeds pass unchanged. - Used synthetic model/session labels and inert same-origin canvas assets. External HTTP was blocked. Both tabs and owned Vite servers were settled after capture. This is UI boundary proof, not a claim about a real Gateway or external embed provider. - The two regression cases failed on the original extractor. The candidate passed 10 extractor tests and 90 UI normalizer tests, scoped lint/formatting, and both structural line checks. - Both final changed files match the tested current-main replay. The six published PNGs were inspected, attached in the originating task, and verified decoded and visible in the actual GitHub comment. The linked comment records the exact before/after source revisions. ## AI Assistance Original contributor note, retained for attribution: > AI-assisted. Discovered the `parseFenceSpans` gap by scanning its callers (the same anchor that openclaw#146361 migrated in `parse-output.ts`). The fix applies the existing `findCodeRegions`/`isInsideCode` pattern. Proof exercises the Control UI `normalizeMessage` normalization path that the chat renderer calls, with before/after Playwright screenshots. Co-authored-by: Ayaan Zaidi <[email protected]>






What Problem This Solves
extractCanvasShortcodesscans assistant replies for[embed ...]shortcodes to render them as canvas previews. It usedparseFenceSpansto skip[embed]tags inside code blocks (so literal examples stay visible text), butparseFenceSpansonly detects```/~~~fenced code. An[embed]tag inside a 4-space indented code block (CommonMark standard) was mis-extracted as a real shortcode, stripping the code example from the delivered message and replacing it with a canvas preview.Why This Change Was Made
findCodeRegions(fromsrc/shared/text/code-regions.ts) is the canonical code-region scanner that covers all three CommonMark code shapes: fenced, indented, and inline. Replacing theparseFenceSpans+ manual binary-search skip logic withisInsideCode(start, codeRegions)is both more correct and simpler — it removes the fence-span iteration loop entirely. This is the samefindCodeRegionsmigration that #146361 applied toparse-output.ts.User Impact
When an LLM reply contains an indented code block with a literal
[embed]example (e.g. documentation showing how to use the embed syntax), the example is no longer extracted as a real preview. The code block arrives intact as visible text.Evidence
The Control UI renders assistant messages via
ui/src/lib/chat/message-normalizer.ts:464(normalizeMessage→expandTextContent→extractCanvasShortcodesat line 395). The proof below uses the Control UI e2e test infrastructure (startControlUiE2eServer+installMockGateway) to render a real Control UI chat page with an assistant message containing an indented[embed]example.Before fix (main,
origin/main):The indented
[embed]is mis-extracted as a canvas preview. The code block content is stripped — only"Here is how to embed:"and"That was an example."remain in the chat bubble. The e2e test assertion fails (text does not contain[embed url=...]), confirming the bug.After fix (this branch, head
eec8bed):The indented
[embed]is preserved as literal text. The full code block ([embed url="https://example.com/image.png"]/some content/[/embed]) is visible in the chat bubble. No canvas preview is generated. The e2e test passes.Terminal proof (normalizeMessage path, before/after matrices):
Test suite: 9/9 passed (
src/chat/canvas-render.test.ts), including 1 new regression test for indented code block embed extraction.AI Assistance
AI-assisted. Discovered the
parseFenceSpansgap by scanning its callers (the same anchor that #146361 migrated inparse-output.ts). The fix applies the existingfindCodeRegions/isInsideCodepattern. Proof uses the Control UI e2e test infrastructure to render a real chat page with before/after screenshots, plus terminal before/after matrices through thenormalizeMessagepath.