Skip to content

fix(feishu): correct fence boundaries, expand fallback, and force text mode for tables#13723

Closed
WuTianyi123 wants to merge 2 commits into
NousResearch:mainfrom
WuTianyi123:fix/feishu-fence-boundary-and-fallback
Closed

fix(feishu): correct fence boundaries, expand fallback, and force text mode for tables#13723
WuTianyi123 wants to merge 2 commits into
NousResearch:mainfrom
WuTianyi123:fix/feishu-fence-boundary-and-fallback

Conversation

@WuTianyi123

@WuTianyi123 WuTianyi123 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes two distinct classes of Feishu message delivery failures where markdown content causes messages to be swallowed or appear blank on the client.

Problem 1: Fenced code block boundary mis-detection

_build_markdown_post_rows used naive regex ^```\s*$ to detect open/close fences. This fails for:

  • Code blocks with 4+ backticks (e.g. ``````) — inner ``` lines were mistaken for close fences
  • Tilde fences (~~~) — not recognized at all
  • Language tags with backticks (e.g. ``` `) — close regex didn't match

Result: Code blocks truncated early or never closed, corrupting post JSON → "消息类型不合法" or blank messages.

Problem 2: Markdown tables sent as post appear blank

When a message contains both **bold** (matching _MARKDOWN_HINT_RE) and a markdown table, the entire content is sent as post type. Feishu's md tag does not render markdown table syntax — the message appears completely blank on the client.

Result: Users cannot see anything for table-containing messages.

Changes

  1. Fence boundary detection — replaced naive regex with fence_char + fence_len state tracking (CommonMark compliant). Open/close fences must use the same character and closing length must be ≥ opening length.

  2. Post→text fallback — ty-agent lacked fallback logic entirely; hermes only caught English errors. Expanded _POST_CONTENT_INVALID_RE to cover Chinese error messages and added robust fallback to plain text.

  3. Table detection — added _MARKDOWN_TABLE_RE to detect markdown table syntax (|...| + separator line). Forces text type for table content, ensuring it displays as plain text instead of being swallowed.

Test Plan

  • Unit tests for fence boundary (6 cases including 4-backtick nesting, tilde fences)
  • Verified _MARKDOWN_TABLE_RE correctly identifies tables while avoiding false positives on non-table markdown
  • Confirmed text payload format for table content is valid JSON
  • Live test: table message successfully delivered and visible on Feishu client
  • Restarted gateway and verified running code has fence_len + _MARKDOWN_TABLE_RE

Backwards Compatibility

No breaking changes. Messages without tables or code blocks behave identically. Table messages now consistently use text type instead of unreliable post type.

Related Issues

Fixes message-swallowing bugs in Feishu adapter when sending markdown tables or nested fenced code blocks.

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery platform/feishu Feishu / Lark adapter labels Apr 21, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #12512 (merged) which first split fenced code blocks into post rows — this PR fixes edge cases in that logic.

1 similar comment
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #12512 (merged) which first split fenced code blocks into post rows — this PR fixes edge cases in that logic.

WuTianyi added 2 commits April 22, 2026 08:31
…fallback coverage

- Replace simple regex fence matching with char+length tracking to avoid
  mis-interpreting inner fences (e.g. a  ended the code block prematurely,
        causing malformed post payloads and silent message drops.
Feishu post-type 'md' elements do not render markdown tables.
When table content is sent as post (triggered by **bold** matching
_MARKDOWN_HINT_RE), the message appears blank on the client.

Add _MARKDOWN_TABLE_RE to detect markdown table syntax and force
text mode for table content, ensuring it is visible as plain text.
@WuTianyi123 WuTianyi123 force-pushed the fix/feishu-fence-boundary-and-fallback branch from 0b96f24 to b76b1af Compare April 22, 2026 00:38
@WuTianyi123 WuTianyi123 changed the title fix(feishu): correct fenced code block boundary detection and expand fallback coverage fix(feishu): correct fence boundaries, expand fallback, and force text mode for tables Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery platform/feishu Feishu / Lark adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants