fix(wechatcom): read a locally generated image instead of fetching it by Lesereingrape · Pull Request #3312 · zhayujie/CowAgent · GitHub
Skip to content

fix(wechatcom): read a locally generated image instead of fetching it - #3312

Merged
zhayujie merged 1 commit into
zhayujie:masterfrom
Lesereingrape:fix/wechatcom-local-image
Sep 29, 2026
Merged

zhayujie merged 1 commit into
zhayujie:masterfrom
Lesereingrape:fix/wechatcom-local-image

Conversation

@Lesereingrape

Copy link
Copy Markdown
Contributor

Fixes #3311

An image the agent generates itself is handed to the channel as a local path — bridge/agent_bridge.py:1902-1908 returns Reply(ReplyType.IMAGE_URL, "file://<path>"), and channel/chat_channel.py:417-422 does the same for a media item it found on disk. The 企业微信应用 branch only knew how to fetch an IMAGE_URL, so download_bytes raised InvalidSchema: No connection adapters were found for 'file://…', its own except Exception logged one line, and the picture vanished while the caption text stayed.

What changed

channel/wechatcom/wechatcomapp_channel.py — the IMAGE_URL branch now resolves the value the way the wechatmp sibling already does (channel/wechatmp/wechatmp_channel.py:190-195): strip a file:// prefix, read the file when the path exists, otherwise keep using the bounded downloader. The network path, the size guard, the compression and the webp conversion are untouched.

tests/test_wechatcom_file_reply.py — extends the fixture that file/video replies already use instead of adding a new harness: _Recorder.upload now accepts the BytesIO an image upload passes (file replies hand it a (name, body) tuple), records send_image, and three cases are added:

  • a file:// image is uploaded and delivered;
  • a plain local path is treated the same way;
  • a remote https:// image is still downloaded before uploading, so the network path is pinned too.

A missing local file is not swallowed by the new branch: it falls through to the existing download error log, which keeps this change to the one case it needs to fix.

How it was verified

  • Redone on pristine master 37879dd3 with no channel lifecycle: send(Reply(ReplyType.IMAGE_URL, "file://" + png)) records an empty call list. With the fix the stub records ("upload", "image", …, b"\x89png-body") followed by ("image", "media-1").
  • pytest tests/test_wechatcom_file_reply.py — 2 failed, 8 passed before the change, 10 passed after.
  • Whole suite, same tip, twice (pytest tests/ -q): pristine master 32 failed, 2277 passed; this branch 32 failed, 2280 passed. The FAILED lines are byte-for-byte the same set of 32, so nothing regressed — those 32 are pre-existing environment-dependent failures on Windows, not caused by this diff.
  • ruff check channel/wechatcom/wechatcomapp_channel.py tests/test_wechatcom_file_reply.py --select F --ignore F403,F405 — clean.

An IMAGE_URL reply is how the agent hands over an image it wrote on disk
(bridge/agent_bridge.py, channel/chat_channel.py), but this branch only
knew how to fetch a URL, so requests raised "No connection adapters were
found" and the picture disappeared with one error line beside the text
the user kept receiving.
@zhayujie
zhayujie merged commit 66fcc0b into zhayujie:master Sep 29, 2026
3 checks passed
@zhayujie

Copy link
Copy Markdown
Owner

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.

wechatcomapp drops a locally generated image: the IMAGE_URL branch only fetches URLs

2 participants