Skip to content

fix(feishu): sanitize markdown in streaming cards to prevent truncation#1433

Open
BingqingLyu wants to merge 3 commits intomainfrom
fork-pr-54899-fix-26708-streaming-truncation
Open

fix(feishu): sanitize markdown in streaming cards to prevent truncation#1433
BingqingLyu wants to merge 3 commits intomainfrom
fork-pr-54899-fix-26708-streaming-truncation

Conversation

@BingqingLyu
Copy link
Copy Markdown
Owner

@BingqingLyu BingqingLyu commented Apr 27, 2026

Summary

Closes openclaw#26708

When an LLM response streamed via Feishu Card Kit contains unmatched backticks or bare angle brackets, the message gets truncated. This is because Card Kit's incremental markdown parser treats unmatched opening backticks as starting a code span/block that never closes, and bare < as unclosed HTML tags.

Changes

  • New sanitizeCardKitMarkdown function in streaming-card.ts:
    • Balances triple-backtick fences (appends closing fence if odd count)
    • Balances inline backticks outside fenced blocks
    • Escapes bare angle brackets outside code spans that don't look like valid HTML/Feishu tags
  • updateCardContent calls sanitizeCardKitMarkdown before sending to Card Kit
  • truncateSummary strips backticks and angle brackets from notification summary

Test plan

  • Stream a response with unmatched backticks — verify no truncation
  • Stream a response with bare angle brackets (e.g. if x < 10) — verify no truncation
  • Stream a response with properly matched code blocks — verify unchanged behavior
  • Verify notification summary renders cleanly

Rebased onto current main. Adds sanitizeCardKitMarkdown() to balance
unclosed backtick fences/spans and escape bare angle brackets that cause
Card Kit streaming to truncate output.

Also strips leaked reasoning tags from streaming text and falls back to
post format when replying to avoid older clients showing upgrade prompt.
The oxlint no-control-characters rule flags \x00 as unexpected control
characters. Switch to Unicode Private Use Area codepoints \uE001/\uE002
which serve the same sentinel purpose without triggering the linter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feishu: message truncated when containing backticks or angle brackets in streaming mode

2 participants