Skip to content

fix(chat): preserve Markdown image examples in native chat - #113904

Merged
steipete merged 1 commit into
mainfrom
codex/fix-native-markdown-image-code-rendering-4d8e89
Jul 28, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/fix-native-markdown-image-code-rendering-4d8e89

Conversation

@steipete

@steipete steipete commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Native iOS/macOS chat already supports inline data-image rendering and safely flattens remote Markdown images into alt text. The remaining implementation used a document-wide regular expression, so image examples inside fenced code, inline code, indented code, and escaped Markdown were still mistaken for real images. That changed rendered text and the sanitized user-history copy.

Why This Change Was Made

This rewrite keeps the landed image feature and the current provenance-marker metadata sanitizer intact. It replaces only image recognition with the repository-pinned swift-markdown 0.8.0 CommonMark AST, then maps structural image source ranges back to the original UTF-8 text.

The mapping follows the dependency contract directly:

  • SourceLocation.column is 1-based UTF-8 bytes.
  • ranges are end-exclusive after swift-markdown adjusts cmark's inclusive end column.
  • swift-cmark treats only CR/LF as source-position line endings and replaces NUL with U+FFFD before calculating columns.
  • empty image destinations surface as nil, so they are still collected and safely flattened.

Unsupported/remote image alt text is emitted as escaped literal Markdown. Decoded entities therefore cannot synthesize a second image or link when native chat parses the cleaned text again.

User Impact

  • Real inline data images continue to render in document order.
  • Real remote images remain non-fetching alt text.
  • Literal image examples remain byte-preserved in fenced, inline, indented, and escaped code/text.
  • CRLF, CR, Unicode, empty destinations, balanced destination parentheses, optional titles, and NUL input follow the same safe behavior.

Evidence

Exact rewritten head: d141b3e16281e14af56da734619f537ea3dcf840.

  • Direct dependency inspection: swift-markdown 0.8.0 revision 3c6f9523da3a1ec2fd829673e472d95b8097a3b8 and transitive swift-cmark 0.8.0 revision 924936d0427cb25a61169739a7660230bffa6ea6.
  • Regression coverage now includes actual data/remote images, document ordering, Unicode, LF/CRLF/CR, Unicode separators, fenced/inline/indented code, escaped syntax, balanced parentheses, titles, empty destinations, NUL normalization, and decoded-alt recursive parsing.
  • scripts/format-swift.sh macos: 0 files require formatting.
  • git diff --check: passed.
  • Final Codex autoreview (gpt-5.6-sol, high): clean, no accepted/actionable findings.
  • Source-blind behavior contract: all 4 user tasks and all 4 anti-cheat groups passed from the exact-head native log.
  • Exact-head CI: run 30393194911, attempt 2 passed.
    • macos-swift: Swift lint, release build, OpenClawKit tests, and macOS app tests passed.
    • ChatMarkdownPreprocessor passed; OpenClawKit finished with 1,239 tests in 95 suites, and the macOS app/shared run finished with 1,522 tests in 166 suites.
    • ios-build, native i18n, macOS Node, Android builds/tests/lint, security, and the aggregate openclaw/ci-gate passed.

The first CI attempt had one unrelated Android coroutine test timeout after 5 seconds; all other 1,939 Play tests passed. The permitted single retry passed without code changes.

Provenance

The over-broad regex came from #38895 (4bf902de5851304cae53c57889b5ae90fa7367a8, follow-up d25b493c7f79d13e7dca0278f66aeeb6c05f4d72), authored and merged by @obviyus on 2026-03-07. That PR correctly established remote-image flattening; this change preserves that security behavior while moving recognition to the CommonMark owner boundary.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 25, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 25, 2026
@clawsweeper

clawsweeper Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 25, 2026, 6:51 PM ET / 22:51 UTC.

ClawSweeper review

What this changes

The PR replaces regex-based Markdown image preprocessing in native iOS/macOS chat with structural CommonMark image parsing so code examples, escaped syntax, and persisted chat text are not mistaken for images.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 5 items remain

Keep this PR open for human maintainer review. The maintainer label is a protected signal under repository policy, and the provided evidence does not include inspectable after-fix native runtime proof beyond test claims.

Priority: P2
Reviewed head: 7034bc2e7618306111169df21b49fc7df042567a
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has a focused, plausible implementation and tests, but merge confidence is capped by missing inspectable real native behavior proof and required protected-owner review.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The PR body reports extensive native test results, but the supplied evidence does not include an inspectable after-fix native app, simulator, terminal, recording, log, or artifact showing the repaired behavior. Please provide redacted real runtime evidence; updating the PR body should trigger another review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body reports extensive native test results, but the supplied evidence does not include an inspectable after-fix native app, simulator, terminal, recording, log, or artifact showing the repaired behavior. Please provide redacted real runtime evidence; updating the PR body should trigger another review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 3 items Protected maintainer signal: The supplied PR context shows the maintainer label, which repository policy treats as requiring explicit maintainer handling rather than automated cleanup.
Patch scope: The supplied diff changes the shared native Markdown preprocessor and its focused Swift tests, with no indicated workflow, dependency, lockfile, migration, or generated-artifact changes.
Proof gap: The PR body reports native test runs, but the supplied review context contains no inspectable after-fix device, simulator, terminal, recording, log, or linked runtime artifact demonstrating that literal Markdown examples remain unchanged in native chat.
Findings None None.
Security None None.

How this fits together

Native iOS/macOS chat preprocesses Markdown before the text reaches rendering and persisted history. It extracts embedded data images while converting actual remote-image syntax to safe non-fetching text.

flowchart LR
  A[Chat Markdown input] --> B[Native Markdown preprocessor]
  B --> C[CommonMark image parsing]
  C --> D[Data image extraction]
  C --> E[Safe remote image text]
  D --> F[Chat rendering and history]
  E --> F
Loading

Decision needed

Question Recommendation
Should this protected native-chat parser change proceed after an owner verifies the Swift-Markdown source-range contract and reviews real native runtime evidence? Review and merge with runtime proof: Confirm the parser source-range behavior and accept a redacted native app, simulator, terminal, or runtime-log demonstration of the repaired Markdown cases.

Why: The protected maintainer label and shared persisted-chat preprocessing boundary require explicit owner judgment; supplied test claims alone cannot establish merge readiness.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body reports extensive native test results, but the supplied evidence does not include an inspectable after-fix native app, simulator, terminal, recording, log, or artifact showing the repaired behavior. Please provide redacted real runtime evidence; updating the PR body should trigger another review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The structural parser and byte-offset conversion alter text preprocessing for both rendering and persisted native-chat history; maintainer review should verify source-range handling on Unicode and LF/CRLF/CR input before merge.
  • Resolve merge risk (P1) - The PR has no inspectable after-fix real native-chat artifact in the supplied context, so its reported test coverage does not satisfy the external real-behavior proof gate.
  • Complete next step (P2) - The protected maintainer label and missing inspectable native runtime proof require owner review rather than automated repair or cleanup.
Agent review details

Security

None.

PR surface

Other +184. Total +184 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 213 29 +184
Total 2 213 29 +184

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Verify parser and persisted-text compatibility (recommended)
    Before merge, confirm source-range replacement preserves literal Markdown and existing history text across Unicode and LF, CRLF, and CR inputs.
  2. Pause for native owner review
    Keep the PR open if the shared native-chat owner cannot validate the Swift-Markdown range contract and an after-fix runtime artifact.

Technical review

Best possible solution:

Retain the structural CommonMark approach if native review confirms its source-range contract, then add redacted after-fix native runtime evidence showing literal Markdown examples remain text while genuine data and remote images retain their intended handling.

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

No high-confidence live reproduction was independently established. The supplied PR description and focused test diff identify a plausible current native preprocessing path, but no executable source inspection or after-fix runtime artifact was available in this review environment.

Is this the best way to solve the issue?

Unclear. Structural CommonMark parsing is a plausible maintainable replacement for a document-wide image regex, but its exact source-range and newline behavior needs native owner and dependency-contract verification before it can be called the best fix.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against bfc8c89c3573.

Labels

Label changes:

  • add P2: This is a focused but user-visible native chat and history text-preservation fix.
  • add merge-risk: 🚨 compatibility: Replacing the established regex preprocessor changes how existing Markdown input is interpreted across native chat clients.
  • add merge-risk: 🚨 session-state: The PR description states that the same preprocessing path modifies persisted user-history text, so an incorrect replacement can alter stored conversation content.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports extensive native test results, but the supplied evidence does not include an inspectable after-fix native app, simulator, terminal, recording, log, or artifact showing the repaired behavior. Please provide redacted real runtime evidence; updating the PR body should trigger another review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: This is a focused but user-visible native chat and history text-preservation fix.
  • merge-risk: 🚨 compatibility: Replacing the established regex preprocessor changes how existing Markdown input is interpreted across native chat clients.
  • merge-risk: 🚨 session-state: The PR description states that the same preprocessing path modifies persisted user-history text, so an incorrect replacement can alter stored conversation content.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports extensive native test results, but the supplied evidence does not include an inspectable after-fix native app, simulator, terminal, recording, log, or artifact showing the repaired behavior. Please provide redacted real runtime evidence; updating the PR body should trigger another review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Protected maintainer signal: The supplied PR context shows the maintainer label, which repository policy treats as requiring explicit maintainer handling rather than automated cleanup. (7034bc2e7618)
  • Patch scope: The supplied diff changes the shared native Markdown preprocessor and its focused Swift tests, with no indicated workflow, dependency, lockfile, migration, or generated-artifact changes. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatMarkdownPreprocessor.swift:1, 7034bc2e7618)
  • Proof gap: The PR body reports native test runs, but the supplied review context contains no inspectable after-fix device, simulator, terminal, recording, log, or linked runtime artifact demonstrating that literal Markdown examples remain unchanged in native chat. (7034bc2e7618)

Likely related people:

  • steipete: The provided PR metadata identifies this person as the author of the current focused native-chat change; no current-main history pass was available to establish stronger ownership routing. (role: recent area contributor; confidence: low; commits: 7034bc2e7618; files: apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatMarkdownPreprocessor.swift, apps/shared/OpenClawKit/Tests/OpenClawKitTests/ChatMarkdownPreprocessorTests.swift)

Rank-up moves

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

  • Add a redacted after-fix native runtime artifact covering fenced, inline, indented, and escaped image examples plus a real image case.
  • Have the native owner verify the Swift-Markdown source-position contract for Unicode and LF/CRLF/CR input.

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.

@steipete steipete self-assigned this Jul 28, 2026
@steipete
steipete force-pushed the codex/fix-native-markdown-image-code-rendering-4d8e89 branch from 7034bc2 to d141b3e Compare July 28, 2026 19:43
@steipete
steipete merged commit 49f4942 into main Jul 28, 2026
95 of 97 checks passed
@steipete
steipete deleted the codex/fix-native-markdown-image-code-rendering-4d8e89 branch July 28, 2026 20:12
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 28, 2026
…etwork-none

* origin/main: (74 commits)
  fix(ui): make Control UI ownership and permissions reliable (#115364)
  feat(system-agent): host memory import in Ask OpenClaw (#115376)
  fix(chat): preserve literal Markdown image examples (#113904)
  refactor(chat): keep web and terminal sessions synchronized (#115377)
  fix(ui): order model picker by provider strength (#115380)
  feat(ui): make Memory settings a destination page with live overview and dreams (#115383)
  docs(security): fix warning line wrap (#115388)
  fix(memory-core): avoid cubic MMR similarity rescans (#113359)
  fix(discord): preserve code-leading reasoning chunks (#103166)
  fix(slack): protect outbound hooks from previews
  fix(ui): keep explicit navigation ahead of chat canonicalization (#115366)
  fix(exec): safely cancel pending node approvals (#115373)
  fix: make Code Mode reliable across gateway and provider lifecycles (#115379)
  perf(ui): debounce event-driven session list refreshes and right-size child paging (#115374)
  feat(talk): support GPT-Live realtime voice over ChatGPT OAuth (#115226)
  feat(system-agent): guide gateway configuration in Ask OpenClaw (#115363)
  fix(agents): make overflow recovery append-only via branch-and-reappend (#115271) (#115310)
  fix(macos): bound websocket ping so a dropped pong cannot orphan its continuation (#115362)
  fix(codex): isolate native hook relay startup (#115078)
  fix(ci): stop reviving superseded pull request workflows (#115378)
  ...

# Conflicts:
#	CHANGELOG.md
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant