fix: cross-channel send_message failures (WeChat event loop + Telegram proxy)#18714
Closed
liuhao1024 wants to merge 2 commits into
Closed
fix: cross-channel send_message failures (WeChat event loop + Telegram proxy)#18714liuhao1024 wants to merge 2 commits into
liuhao1024 wants to merge 2 commits into
Conversation
Collaborator
|
Likely duplicate of #12370 — same dual-fix scope (WeChat event loop + Telegram proxy in send_message). |
1 similar comment
Collaborator
|
Likely duplicate of #12370 — same dual-fix scope (WeChat event loop + Telegram proxy in send_message). |
…m proxy)
Two fixes for cross-channel messaging via the send_message tool:
1. fix(weixin): prevent event-loop mismatch in send_weixin_direct()
- When called via _run_async from a different async context (e.g. cron
delivery or cross-channel Telegram→WeChat), the live adapter's aiohttp
session is bound to the gateway's main event loop.
- Using it from _run_async's new thread's loop causes
"Timeout context manager should be used inside a task".
- Added event loop compatibility check: if the session's _loop doesn't
match the current running loop, skip adapter reuse and fall through
to the fresh-session fallback path.
- Fixes NousResearch#17347, NousResearch#13099, NousResearch#13281, NousResearch#18014
2. fix(send_message): add proxy support for _send_telegram()
- send_message tool's _send_telegram() created Bot(token=token) without
proxy config, causing timeouts when TELEGRAM_PROXY is configured.
- Now uses resolve_proxy_url() + HTTPXRequest(proxy=...) matching
the gateway adapter's pattern.
When iLink returns ret=-2 (rate limited), the adapter exhausts its internal retries and raises. _send_weixin now catches rate-limit errors and retries up to 3 times with 10s/20s/30s backoff before giving up.
f9d112a to
0e80d90
Compare
13 tasks
Contributor
|
This appears to be implemented on current Evidence:
|
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.
What does this PR do?
Two fixes for cross-channel messaging via the
send_messagetool:1. fix(weixin): prevent event-loop mismatch in
send_weixin_direct()When
send_messagetargets WeChat from a different async context (e.g. cron delivery, cross-channel Telegram→WeChat, or TTS tool),_run_asynccreates a new event loop in a worker thread. The live adapter's_send_sessionis bound to the gateway's main event loop, so using it from the worker thread's loop causes:Fix: Check if
send_session._loopmatches the current running loop before reusing the live adapter. If they don't match, fall through to the fresh-session fallback path.Root cause: aiohttp's timeout context manager requires the session to be used within the same event loop it was created in. The original code didn't verify this.
2. fix(send_message): add proxy support for
_send_telegram()The
send_messagetool's_send_telegram()createdBot(token=token)without proxy config, causing timeouts whenTELEGRAM_PROXYis configured. The gateway adapter already handles this viaresolve_proxy_url()+HTTPXRequest(proxy=...), but the one-shot tool path didn't.Fix: Use
resolve_proxy_url('TELEGRAM_PROXY')and pass proxy toHTTPXRequestwhen available, matching the gateway adapter's pattern.Related Issue
Fixes #17347
Type of Change
Changes Made
How to Test
pytest tests/ -q— all tests should passChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture and workflows — or N/A