fix(channels): skip empty text blocks in DingTalk rich text parsing#1554
Conversation
When DingTalk sends richText messages, empty or whitespace-only text
items created empty TextContent blocks that caused LLM API errors
("text content blocks must be non-empty"). This filters empty text
in _parse_rich_content, matching the approach used in the Feishu
channel. Also changes the base channel empty-content fallback from
an empty string to a single space to prevent the same error class.
Fixes agentscope-ai#1303
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where DingTalk rich text messages containing empty or whitespace-only text items led to LLM API errors and corrupted session history. The changes prevent these invalid text blocks from being processed by stripping text content and skipping empty results in the DingTalk handler, and by providing a more robust fallback for empty content parts in the base channel utility. This ensures message integrity and prevents API failures. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a crash caused by empty text blocks from DingTalk rich text messages. The fix in dingtalk/handler.py to filter out empty or whitespace-only text items is correct and well-implemented. The addition of regression tests in test_dingtalk_rich_text.py ensures this issue won't reappear. The defensive change in base.py to use a single space as a fallback for empty content is a pragmatic solution that avoids API errors while integrating well with the existing debouncing logic. I have one minor suggestion for code simplification.
|
Thank you for your contribution! Please remove the test files. And run |
Welcome to CoPaw! 🎉Thank you @mvanhorn for your first contribution! Your PR has been merged. 🚀 We'd love to give you a shout-out in our release notes! If you're comfortable sharing, please reply to this comment with your social media handles using the format below:
Thanks again for helping make CoPaw better! |
…gentscope-ai#1554) Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Co-authored-by: xieyxclack <yuexiang.xyx@alibaba-inc.com>
Summary
DingTalk richText messages can contain empty or whitespace-only text items. The current
_parse_rich_contentmethod createsTextContent(text="")blocks from these, which causes LLM API errors:The error persists because corrupted messages are stored in session history, requiring manual session file deletion to recover.
Changes
dingtalk/handler.py: Strip text before appending and skip if empty, matching the guard pattern already used in the Feishu channel (as suggested in #1303 comment)base.py: Change the emptycontent_partsfallback fromtext=""totext=" "as a defensive measure against the same error classtest_dingtalk_rich_text.py: Add regression tests verifying empty text items are filtered while valid text is preservedScope
This fix is intentionally scoped to the DingTalk handler and base fallback. The prior attempt (#1331) moved filtering into the shared
build_agent_request_from_user_content, which was broader than needed. This PR keeps the change minimal and channel-specific.Fixes #1303
This contribution was developed with AI assistance (Claude Code).