Skip to content

fix: support dingtalk-stream >= 0.20 async SDK changes#9828

Closed
nightq wants to merge 1 commit into
NousResearch:mainfrom
nightq:fix/issue-9752-dingtalk-stream-compatibility
Closed

fix: support dingtalk-stream >= 0.20 async SDK changes#9828
nightq wants to merge 1 commit into
NousResearch:mainfrom
nightq:fix/issue-9752-dingtalk-stream-compatibility

Conversation

@nightq

@nightq nightq commented Apr 14, 2026

Copy link
Copy Markdown

Summary

Fixes the DingTalk adapter for dingtalk-stream >= 0.20 which made three breaking async changes.

Root Cause

  1. start() changed sync → async: asyncio.to_thread() fails on coroutines with "coroutine was never awaited"
  2. process() changed sync → async: SDK now awaits the return value, but (STATUS_OK, "OK") tuple can't be awaited
  3. Message type changed: Handler now receives CallbackMessage with data in .data dict instead of ChatbotMessage with direct attributes → _extract_text() got nothing → "Empty message, skipping"

Fix

  • Runtime detection: Use inspect.iscoroutinefunction() to detect sync vs async start()
  • Dual handler: Added async_process() for new SDK while keeping process() for backward compat
  • Message extraction: Added _extract_chatbot_message() to reconstruct a ChatbotMessage-like object from CallbackMessage.data dict (handles both dict and JSON string)

Test Plan

  • Added 4 unit tests for _extract_chatbot_message(): dict data, JSON string data, missing data, invalid JSON
  • All tests pass
  • Backward compatible with dingtalk-stream < 0.20

Closes #9752

Fixes NousResearch#9752

Root cause: dingtalk-stream >= 0.20 made three breaking changes:
1. start() changed from sync to async — asyncio.to_thread() doesn't work
2. process() changed from sync def to async def — SDK awaits return value
3. Callback message is now CallbackMessage with data in .data dict,
   not ChatbotMessage with direct attributes

Fix:
- Detect start() sync/async at runtime with inspect.iscoroutinefunction()
- Add async_process() handler for new SDK while keeping process() for old
- Add _extract_chatbot_message() to reconstruct ChatbotMessage from
  CallbackMessage.data dict for new SDK versions
@teknium1

Copy link
Copy Markdown
Contributor

Closing as superseded by #11471 (#11471) which salvaged @kevinskysunny's minimal fix (#11257) and added a follow-up for the broken _extract_text() path found during E2E testing.

Thanks for the fix — a lot of contributors hit this SDK break at the same time. Your investigation helped confirm the root cause.

@teknium1 teknium1 closed this Apr 17, 2026
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.

[Bug]: DingTalk adapter broken with dingtalk-stream >= 0.20 (async process/start)

2 participants