fix(feishu): route tables and code blocks to CardKit 2.0 with post/text fallback#23861
Open
lqhl wants to merge 2 commits into
Open
fix(feishu): route tables and code blocks to CardKit 2.0 with post/text fallback#23861lqhl wants to merge 2 commits into
lqhl wants to merge 2 commits into
Conversation
Cherry-pick of PR 19038 plus fallback mechanism: - _TABLE_MARKDOWN_RE: detect GFM tables - _CODE_BLOCK_RE: detect fenced code blocks with 2plus content lines - _build_card_payload: CardKit 2.0 interactive card with tag:markdown - _build_outbound_payload: route tables and long code blocks to interactive - send() and edit_message(): fallback to plain text on interactive failure - _feishu_send_with_retry(): fail fast on interactive errors Fixes 19035 and 9549 (table and code block rendering in Feishu)
Author
Contributor
Minor: Comment/regex mismatch in
|
…drop redundant DOTALL
_CODE_BLOCK_RE uses {2,} to match 2+ content lines, but the comment claimed '3+ content lines'. Fix the comment to match the actual regex. Also remove re.DOTALL — the pattern already uses explicit \n, so DOTALL only adds unnecessary backtracking complexity.
Author
|
@liuhao1024 Thanks for catching this! Fixed in 8a60abe:
Both changes are comment/cosmetic — the regex behavior is unchanged, 209/209 feishu tests still pass. |
This was referenced May 12, 2026
Author
|
@teknium1 hi, can you take a look? |
huangyoje
pushed a commit
to huangyoje/hermes-agent
that referenced
this pull request
Jun 6, 2026
…ards Closes NousResearch#9549, NousResearch#19035. Supersedes NousResearch#23861. ## Problem Feishu's post-type 'md' element does not render GFM tables and truncates multi-line fenced code blocks. The current behaviour (force-text fallback, PR NousResearch#20275) avoids the blank-message symptom but leaks raw markdown source to the user — pipes, separators and code fences are visible as plain text. ## Approach Route content containing GFM tables or multi-line fenced code blocks to CardKit 2.0 interactive messages (schema: 2.0, tag: markdown), which render both natively. Plain markdown without tables/code stays in post/md as before. Falls back to plain text when the interactive card is rejected (bot lacks card permission, malformed payload, etc.) so failures degrade gracefully. ## ErrCode 11310: per-card table cap CardKit 2.0 caps the total number of GFM tables across an entire card at 5. Exceeding this triggers ErrCode 11310 ('card table number over limit') and the API rejects the whole card. The cap is per-CARD, not per-element — verified empirically against the live Feishu API on 2026-05-27. A single element with 6 tables fails. So do two elements with 4+2 tables, three elements with 2+2+2, and a layout with one table per element. Five tables in any layout pass. When content has more than 5 tables, _build_outbound_messages() splits it into multiple cards and send() iterates the resulting (msg_type, payload) list. Splits cut at section boundaries — the first paragraph break after the previous table block ends — so each table's heading and lead-in prose travel into the same card as the table itself, rather than being orphaned in the previous chunk. ## Tests tests/gateway/test_feishu.py::TestCardTableLimitSplitting - single card for ≤5 tables - two cards for 6 tables (5 + 1) - three cards for 12 tables (5 + 5 + 2) - non-table content keeps post/text routing untouched - prose between tables stays with the following table at split points ## Migration notes - Bots without card-send permission will silently fall back to plain text (existing fallback path, extended for the interactive case). - Edit_message remains on the single-payload path; streaming edits do not currently produce > 5 tables in a single chunk in practice.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Routes GFM tables and multi-line fenced code blocks to CardKit 2.0 interactive messages in Feishu, with automatic fallback to plain text when card delivery fails.
Problem
Feishu's
post/mdtag has two rendering limitations:| col1 | col2 |) is silently droppedSolution
Three new regex detectors + CardKit 2.0 builder + failure fallback:
_TABLE_MARKDOWN_RE— detects GFM tables (pipe-separated rows + alignment separator)_CODE_BLOCK_RE— detects fenced code blocks with 2+ content lines (short blocks stay in post/md)_build_card_payload()— wraps content in a CardKit 2.0 card withtag: markdownelement_build_outbound_payload()— routes detected content tointeractivemsg_typeFallback mechanism (not present in original PR #19038)
If the interactive card send fails (bot lacks card permission, API rejection, etc.), the message automatically falls back to plain text. Three layers of protection:
send()— catches send failures, retries as plain textsend()andedit_message()— catches API rejection without exception_feishu_send_with_retry()— interactive failures raise immediately (no retry loop)Testing
Changes
gateway/platforms/feishu.py: +62/-3 linestests/gateway/test_feishu.py: +114/-0 linesRelated
_should_send_as_card()trigger condition #9536, ## Problem When sending markdown table syntax (| col1 | col2 |) in Feishu, the message displays as plain text instead of being rendered as a table. This works correctly in OpenClaw. ## Environment - Hermes Agent version: [latest] - Feishu integration via WebSocket - Using native markdown table syntax in messages ## Expected behavior Markdown tables should render as formatted Feishu table messages, similar to how OpenClaw handles them. ## Screenshots [Attach screenshot comparing OpenClaw vs Hermes Agent rendering] ## Additional context The Feishu platform adapter usespostmsg_type with markdown, but the markdown hint regex may not be detecting table syntax properly. #7310