fix(feishu): render markdown tables as native Feishu tables - #57566
fix(feishu): render markdown tables as native Feishu tables#57566neilwong89 wants to merge 2 commits into
Conversation
- edit_message(): when Feishu API rejects post payload with 'content format of the post type is incorrect', send a NEW post message instead of falling back to plain text. This keeps table formatting intact for streaming responses. - _build_outbound_payload(): remove _MARKDOWN_TABLE_RE workaround that forced tables to text mode. Feishu post 'md' elements DO render GFM tables; routing tables to post type restores rendering. - _MARKDOWN_HINT_RE: add (^\s*\|) to detect table rows and route them to post type correctly. Closes: tables degrade to plain text during streaming.
When Feishu API rejects a post payload (e.g. incomplete GFM table during streaming), send() previously fell back to plain text via _strip_markdown_to_plain_text(), destroying table formatting. Now send() retries the same post payload instead of downgrading to text, preserving markdown tables across both exception and response-error fallback paths. This mirrors the fix already applied to edit_message(). Tests: added test_send_post_rejected_retry_as_post_on_exception and test_send_post_rejected_retry_as_post_on_response (18/18 passing)
2a652d8 to
1627b25
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused Feishu table-routing work. The underlying routing issue is still present on current main, but this revision needs correction before it is salvageable.
Problems
tests/test_feishu_fallback.py:11importsgateway.platforms.feishu, which no longer exists on current main; the adapter is atplugins/platforms/feishu/adapter.py, so the new test file cannot collect as written.plugins/platforms/feishu/adapter.py:1918and:1931resend the same post payload after Feishu has rejected that payload as invalid. Current main deliberately falls back to text in this case (plugins/platforms/feishu/adapter.py:1913-1936), as documented inwebsite/docs/user-guide/messaging/feishu.md:419and tested intests/gateway/test_feishu.py:2862-2950. Removing that fallback can turn an unsupported-post rendering failure into a dropped message.tests/test_feishu_fallback.py:275-321only checks call counts, not the retry message type or payload.
Suggested changes
- Import the migrated plugin adapter in the new tests.
- Keep table detection/routing to
postseparate from the generic invalid-post fallback; retain a delivery-preserving text fallback when Feishu rejects a post payload. - Capture and assert each retry's type and payload.
This is an automated hermes-sweeper review.
| → same fallback behavior as edit_message | ||
| 3. _build_outbound_payload correctly routes markdown tables to post type | ||
| 4. _strip_markdown_to_plain_text correctly strips markdown | ||
| """ |
There was a problem hiding this comment.
gateway.platforms.feishu no longer exists on current main after the platform-plugin migration; the adapter is plugins.platforms.feishu.adapter. This import will fail test collection, so please update the test to use the current module path.
| chat_id=chat_id, | ||
| msg_type="text", | ||
| payload=json.dumps({"text": _strip_markdown_to_plain_text(chunk)}, ensure_ascii=False), | ||
| msg_type="post", |
There was a problem hiding this comment.
Feishu has already rejected this exact post payload as invalid, and this retry resubmits it unchanged. That removes the current post→text delivery fallback for unsupported Markdown; preserve the text fallback here and in the response-error branch, while routing valid tables to post on the normal path.
| result = await adapter.send(chat_id="test_chat", content=table_content) | ||
|
|
||
| assert result.success is True | ||
| assert call_count[0] == 2 |
There was a problem hiding this comment.
This proves only that the fake was called twice. Record the msg_type and payload for both calls and assert the intended fallback explicitly; otherwise a retry with the wrong message type still passes.
|
Closing — this was fixed on main by #68121, which removes the |
Summary
Rewrite the Feishu markdown table rendering pipeline so that GFM table syntax is sent as Feishu post/md content (native table rendering) instead of being forced to plain text.
Problem
When Hermes Agent sends a markdown table to Feishu,
_MARKDOWN_TABLE_REdetected it and forced a plain text fallback. But_strip_markdown_to_plain_text()does not cleanly strip tables — the separator line survives, producing a mangled mix.Solution
_MARKDOWN_HINT_REso tables are routed to post type_MARKDOWN_TABLE_REforced-text branchChanges
plugins/platforms/feishu/adapter.pytests/gateway/test_feishu_fallback.pyAll 18 tests pass.
Closes #27922. Based on upstream 88b720e.