Skip to content

fix(gateway): DingTalk adapter compat with dingtalk-stream >= 0.20#9764

Closed
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/dingtalk-async-compat-9752
Closed

fix(gateway): DingTalk adapter compat with dingtalk-stream >= 0.20#9764
konsisumer wants to merge 1 commit into
NousResearch:mainfrom
konsisumer:fix/dingtalk-async-compat-9752

Conversation

@konsisumer

Copy link
Copy Markdown
Contributor

Summary

Fixes the DingTalk adapter which broke with dingtalk-stream >= 0.20 due to three API changes:

  • process() is now async — SDK awaits the return value, causing "object tuple can't be used in 'await' expression". Fixed by making _IncomingHandler.process() async.
  • start() is now asyncasyncio.to_thread() on a coroutine doesn't work. Fixed by detecting async start() via inspect.iscoroutinefunction and running it in a fresh event loop on a worker thread.
  • Messages are now CallbackMessage with data in a JSON dict, not ChatbotMessage with direct attributes. Fixed by adding _normalize_message() that handles both formats.

Backward compatible with dingtalk-stream < 0.20.

Closes #9752

Test plan

  • All 25 existing + new DingTalk adapter tests pass
  • New tests for _normalize_message covering both CallbackMessage (dict data, JSON string data) and legacy ChatbotMessage
  • New test for _run_stream_sync helper

dingtalk-stream 0.20+ changed three things that broke the DingTalk adapter:

1. ChatbotHandler.process() is now async — the SDK awaits its return value,
   causing "object tuple can't be used in 'await' expression"
2. DingTalkStreamClient.start() is now async — asyncio.to_thread() on a
   coroutine doesn't work, causing "coroutine was never awaited"
3. Messages arrive as CallbackMessage with data in a JSON dict, not as
   ChatbotMessage with direct attributes — _extract_text() got nothing

Fix: make process() async, detect async start() and run it in a fresh
event loop on a worker thread, and normalize both message formats through
_normalize_message() before processing.

Closes NousResearch#9752
@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