fix(weixin): convert MSYS / Git-Bash drive paths to native Windows on send - #31472
Open
xxxigm wants to merge 3 commits into
Open
fix(weixin): convert MSYS / Git-Bash drive paths to native Windows on send#31472xxxigm wants to merge 3 commits into
xxxigm wants to merge 3 commits into
Conversation
Add ``normalize_msys_path`` and ``strip_file_url_prefix`` helpers and wire them into ``validate_media_delivery_path`` and the bare-local-path extraction inside ``extract_local_files``. Native Windows Python's ``pathlib.Path`` does not understand the Git-Bash / MSYS drive shape ``/c/Users/...`` — it joins it to the current drive's root and ends up at ``C:\\c\\Users\\...``, which never exists. Agents running under Git Bash routinely emit paths in that shape, so MEDIA: directives and bare local-file references are silently dropped on Windows even when the file is right there at ``C:\\Users\\...``. The helpers are no-ops on non-Windows hosts (``/c`` is a real POSIX filesystem path that we must never rewrite) and recognize both the modern ``/<drive>/...`` and legacy ``/cygdrive/<drive>/...`` shapes. Refs NousResearch#31457
``send_image`` previously stripped the ``file://`` prefix with a naive ``replace`` and trusted the result as a Windows-friendly path. When the caller passed ``file:///c/Users/.../cache/file.jpg`` (the shape an agent running under Git Bash routinely emits on Windows) the result ``/c/Users/...`` failed downstream with ``[Errno 2] No such file or directory`` because native Windows Python looked for a literal ``C:\\c\\Users\\...``. Route the URL through ``strip_file_url_prefix`` so the prefix removal and the MSYS-to-native rewrite happen together, and apply ``normalize_msys_path`` once more inside ``_send_file`` as a defense against any future caller that bypasses the validator. Refs NousResearch#31457
…tion * ``normalize_msys_path`` — Windows-only rewrite of ``/c/Users/...`` and the legacy ``/cygdrive/c/...`` shape to ``C:/Users/...``, ASCII-uppercased drive letter, no-op on POSIX hosts (so a real ``/c`` directory at the filesystem root is never corrupted). * ``strip_file_url_prefix`` — strips ``file://`` once, trims the synthetic third slash before a ``<drive>:`` segment so callers get a clean ``C:/foo`` rather than ``/C:/foo``, and routes the rest through the MSYS rewrite for the ``file:///c/Users/...`` shape the agent emits under Git Bash. * Source-level guards on ``validate_media_delivery_path``, ``BasePlatformAdapter.extract_local_files`` and the Weixin adapter's ``send_image`` / ``_send_file`` so future refactors cannot quietly drop the normalization wiring and re-open NousResearch#31457. * Behavioural smoke test that the existing happy-path validation (real file under an allowlisted root) still works after the new helper is threaded through. Also tightens the prefix regex to strip exactly the two-slash scheme delimiter rather than greedily eating every slash, which was masking the MSYS shape on the way to the rewrite step. Refs NousResearch#31457
Contributor
|
Thanks for tracing this Windows-specific delivery path. The underlying defect is still present on current main: Problems
Suggested changes
Automated hermes-sweeper review. |
This was referenced Jul 24, 2026
12 tasks
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.
Summary
Closes #31457.
On Windows, when the agent runs under Git Bash / MSYS the gateway
sees MEDIA paths like
/c/Users/.../cache/file.jpg(and the matchingfile:///c/Users/...URL). Native Windows Python'spathlib.Pathdoes not understand that drive shape — it joins the leading
/tothe current drive's root, so the canonical example resolves to a
non-existent
C:\c\Users\...andPath(path).read_bytes()reports[Errno 2] No such file or directory. The Weixin adapter thereforesilently drops every native attachment, even though Telegram and
Discord deliver the exact same path fine because they upload bytes
through a different code path that doesn't hit the MSYS quirk.
Approach
Two small, well-tested helpers in
gateway/platforms/base.py:normalize_msys_path(path)— Windows-only rewrite of/c/Users/...and the legacy/cygdrive/c/...shape toC:/Users/..., drive letter ASCII-uppercased, no-op on POSIX so areal
/cfilesystem path is never corrupted.strip_file_url_prefix(url)— strip exactly thefile://scheme delimiter, drop the synthetic third slash before a
<drive>:segment so callers getC:/fooinstead of/C:/foo,and route the remainder through
normalize_msys_pathso thefile:///c/Users/...shape (lowercase drive, no colon) survives.Wired in at the validation seam (
validate_media_delivery_path),the bare-path scanner (
extract_local_files) and the Weixinadapter's two file-touching call sites (
send_image's old naivereplace("file://", "")and_send_file'sPath(path).read_bytes()).Test plan
pytest tests/gateway/test_msys_path_normalization_31457.py—25 new tests covering both helpers, source-level guards on
the four wired call sites, and a behavioural smoke test that
the existing happy-path validation still works.
pytest tests/gateway/test_platform_base.py tests/gateway/test_media_extraction.py tests/gateway/test_weixin.py— 153 passed, 2 skipped (noregressions in the surrounding adapters).
MEDIA:/c/Users/.../cache/x.jpgunderGit Bash on Windows 11 → image is delivered natively to WeChat
(matching Telegram/Discord behaviour).
Made with Cursor