Skip to content

fix(chat): skip embed shortcodes in indented code blocks - #153579

Merged
obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/canvas-embed-indented-code-077
Sep 20, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
SunnyShu0925:fix/canvas-embed-indented-code-077

Conversation

@SunnyShu0925

@SunnyShu0925 SunnyShu0925 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

extractCanvasShortcodes scans assistant replies for [embed ...] shortcodes to render them as canvas previews. It used parseFenceSpans to skip [embed] tags inside code blocks (so literal examples stay visible text), but parseFenceSpans only 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 (from src/shared/text/code-regions.ts) is the canonical code-region scanner that covers all three CommonMark code shapes: fenced, indented, and inline. Replacing the parseFenceSpans + manual binary-search skip logic with isInsideCode(start, codeRegions) is both more correct and simpler — it removes the fence-span iteration loop entirely. This is the same findCodeRegions migration that #146361 applied to parse-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 → extractCanvasShortcodes at 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.

Before fix: Control UI chat — indented [embed] stripped, code block content missing

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.

After fix: Control UI chat — indented [embed] preserved as literal text, no canvas preview

Terminal proof (normalizeMessage path, before/after matrices):

# Before (main):  canvas previews: ["https://example.com/image.png"]  code block preserved: false
# After (fix):     canvas previews: []  code block preserved: true
# After (fix): real [embed] outside code → canvas previews: ["https://real.com/img"]  (still works)
# After (fix): fenced code [embed] → canvas previews: []  (no regression)

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 parseFenceSpans gap by scanning its callers (the same anchor that #146361 migrated in parse-output.ts). The fix applies the existing findCodeRegions/isInsideCode pattern. Proof uses the Control UI e2e test infrastructure to render a real chat page with before/after screenshots, plus terminal before/after matrices through the normalizeMessage path.

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.
@clawsweeper

clawsweeper Bot commented Sep 20, 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 P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 20, 2026
@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 20, 2026, 7:04 AM ET / 11:04 UTC (Revision 5).

ClawSweeper review

What this changes

The 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
Reviewed head: b02c4f8fba416d88784eddbb340691c9934e30c7

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful regression coverage and convincing app screenshots; no blocking correctness or security finding remains.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): Inspected actual Control UI before/after screenshots show the production normalization and embed-extraction path preserving indented and inline examples without previews. The maintained mocked-Gateway setup is appropriate for this visible rendering change and resolves the earlier standalone-page concern.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): Inspected actual Control UI before/after screenshots show the production normalization and embed-extraction path preserving indented and inline examples without previews. The maintained mocked-Gateway setup is appropriate for this visible rendering change and resolves the earlier standalone-page concern.
Evidence reviewed 7 items Introduced change: The verified merge-base-to-head diff changes only the extractor and its tests. It replaces the fence-only exclusion with the existing Markdown code-region owner while retaining attribute parsing and preview construction.
Still necessary on main: Fetched main still uses parseFenceSpans, which excludes fenced examples but does not protect indented or inline code.
Latest release comparison: The supplied latest release, v2026.9.5, also contains the fence-only extractor; this repair is not already present there.
Findings None None.
Security None None.

How this fits together

Control 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
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -7, Tests +8. Total +1 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 12 -7
Tests 1 8 0 +8
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 13 12 +1

Review metrics

None.

Technical review

Best 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.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. Inspected actual Control UI before/after screenshots show the production normalization and embed-extraction path preserving indented and inline examples without previews. The maintained mocked-Gateway setup is appropriate for this visible rendering change and resolves the earlier standalone-page concern.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): Inspected actual Control UI before/after screenshots show the production normalization and embed-extraction path preserving indented and inline examples without previews. The maintained mocked-Gateway setup is appropriate for this visible rendering change and resolves the earlier standalone-page concern.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This fixes disappearing code examples and unintended previews in Control UI chat, with a limited rendering scope.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): Inspected actual Control UI before/after screenshots show the production normalization and embed-extraction path preserving indented and inline examples without previews. The maintained mocked-Gateway setup is appropriate for this visible rendering change and resolves the earlier standalone-page concern.
  • proof: sufficient: Contributor real behavior proof is sufficient. Inspected actual Control UI before/after screenshots show the production normalization and embed-extraction path preserving indented and inline examples without previews. The maintained mocked-Gateway setup is appropriate for this visible rendering change and resolves the earlier standalone-page concern.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. Inspected actual Control UI before/after screenshots show the production normalization and embed-extraction path preserving indented and inline examples without previews. The maintained mocked-Gateway setup is appropriate for this visible rendering change and resolves the earlier standalone-page concern.

Evidence

What I checked:

  • Introduced change: The verified merge-base-to-head diff changes only the extractor and its tests. It replaces the fence-only exclusion with the existing Markdown code-region owner while retaining attribute parsing and preview construction. (src/chat/canvas-render.ts:277, b02c4f8fba41)
  • Still necessary on main: Fetched main still uses parseFenceSpans, which excludes fenced examples but does not protect indented or inline code. (src/chat/canvas-render.ts:277, 6d3ed6db7f1a)
  • Latest release comparison: The supplied latest release, v2026.9.5, also contains the fence-only extractor; this repair is not already present there. (src/chat/canvas-render.ts:277, ec9c1a13db89)
  • Canonical parser and production caller: The shared helper delegates to Markdown Core, whose parser collects code and inlineCode source ranges. Control UI expandTextContent calls the changed extractor before constructing text and canvas content. Existing parser tests cover fences, inline code, tabs, indentation, and nested containers. (packages/markdown-core/src/reasoning-tag-parser.ts:276, b02c4f8fba41)
  • Actual app proof resolves earlier request: Inspected all four locally prepared screenshots from the linked proof comment: the running Control UI shows unintended previews before the repair and intact indented/inline code afterward. The captured body reports a maintained mocked Gateway feeding the real router, normalizer, and chat components, plus passing ordinary-embed and fenced controls. This proves the visible UI boundary, not a live Gateway or external provider. The two ordinary-embed images were absent from the prepared manifest and browser retrieval returned Cache miss; those controls remain supported by the recorded report and source tests. The reported replay SHA d8369533f2a957608dd5db07f77c9fb48ff4e1ae was unavailable locally and through GitHub, so the body's final-file equivalence assertion was not independently verified.
  • Re-review continuity: GitHub's current commit patch confirms the follow-up preserves the prior production repair, updates two comments, and consolidates regression coverage into indented and inline cases. The previous review had no code findings. The captured proof comment reports 100 focused passing tests and both regressions failing before the fix; this review did not execute target code. (src/chat/canvas-render.test.ts:122, b02c4f8fba41)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-20T08:48:56.497Z sha eec8bed :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-20T09:09:58.764Z sha eec8bed :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-20T09:30:14.670Z sha eec8bed :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-20T09:53:20.990Z sha eec8bed :: needs real behavior proof before merge. :: none

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review.

@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added the proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. label Sep 20, 2026
@obviyus obviyus self-assigned this Sep 20, 2026
@obviyus

obviyus commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

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 2889a999b1eb12393cedb2813df1b8a3376dfd08. After: tested repair d8369533f2a957608dd5db07f77c9fb48ff4e1ae. The final contributor branch will retain the same production repair and is bound separately before review.

Indented code — before

The literal shortcode disappears and an unintended preview is shown.

Actual Control UI before: indented literal embed becomes an unintended preview

Indented code — after

The complete example remains a code block, with no preview extracted.

Actual Control UI after: indented literal embed stays visible code

Inline code — before and after

Actual Control UI before: inline literal embed becomes an unintended preview

Actual Control UI after: inline literal embed stays visible code

Ordinary supported embed — before and after

The real chat canvas iframe still loads the same inert, same-origin asset in both phases. Fenced-code controls also passed unchanged.

Actual Control UI before: ordinary supported embed still renders

Actual Control UI after: ordinary supported embed still renders

All eight browser cases passed. Both indented/inline regression cases failed on the original extractor; the candidate passed 100 focused extractor and normalizer tests.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 20, 2026
@obviyus
obviyus merged commit 11eb00c into openclaw:main Sep 20, 2026
234 checks passed
@obviyus

obviyus commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

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.

@SunnyShu0925

Copy link
Copy Markdown
Contributor Author

@obviyus Thanks for merging the PR!

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 21, 2026
…#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

2 participants