fix(weixin): Windows 微信连接自动选用桌面版维护的标准 CLI,零配置跑通全链路 (issue #2028/#1879) - #2276
Merged
BigPizzaV3 merged 2 commits intoSep 22, 2026
Merged
Conversation
BigPizzaV3#1879) Store 版桌面应用把可独立执行的 CLI 维护在 %LOCALAPPDATA%\OpenAI\Codex\bin\<哈希>\codex.exe, 随桌面版一起更新、在系统保护目录之外;旧探测链(find_bundled_codex_cli → WindowsApps 包内路径)拿到的是第三方进程无法执行的死路径,Windows 上微信连接必然 os error 5。 - app_paths: 新增 find_desktop_managed_codex_cli(bin 哈希子目录取最新,兼容平铺布局); is_windows_store_cli_path 提为公共检测 - app_server: 路径留空时 Windows 自动选用标准 CLI;启动预检拦截 WindowsApps 路径; spawn 失败提示按类别区分,文案统一指向「留空自动查找 / 点按钮」两个动作 - manager: 「使用桌面版内置 CLI」在 Windows 只返回标准路径,不再把死路径写进设置 - settings: 归一化时把存量 WindowsApps 坏路径置空,升级即自愈 - connect: 处理消息前预检本地模型代理(openai_base_url → 127.0.0.1), 桌面版未运行时直接报明确原因,不再只剩一句「处理失败」; 非白名单消息从静默丢弃改为状态栏提示 附带修复本次调试发现的两个缺口:standalone 探测漏掉 bin 哈希子目录层级、 白名单静默丢弃无任何提示。macOS 行为不变。
用 wiremock 假微信网关驱动真实 run_weixin_connect 循环: 非白名单消息被丢弃的同时,状态栏必须出现「已忽略来自非白名单发送方的消息」。 此前该行为改动只有编译级确认,无测试覆盖(注意快照须在停止循环前取, 正常退出会覆盖状态文案)。真机事件路径已实际核验。
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.
Closes #2028
Refs #1879
问题
Windows + Microsoft Store 版 Codex 的用户启用「个人微信连接」后,微信发消息必然失败。#2028 的报错原文(本 PR 修复前可在任何 Store 版机器上稳定复现):
配套还有三个持续困扰(均为真机调试中确认):
codex.cmdshim 不被CreateProcess的裸命令名解析命中(只补.exe),PATH 回退同样是 NotFound([Bug] 处理微信消息失败:无法启动 Codex app-server(codex),请检查 Codex CLI 路径 —— 应该填哪个路径? #1879 里「直接填 codex 也失败」的成因);openai_base_url指向本地代理127.0.0.1:57321,该代理只随 launcher 启动的桌面版存在。桌面版不在线时 turn 失败,用户只看到一句模糊的「处理失败」,无从定位。根因
三层叠加:
WindowsApps目录受系统保护,第三方进程无法直接CreateProcess其中的 exe,改权限也不生效;.app/Contents/Resources/codex是普通可执行文件,探测/直启全部成立——find_bundled_codex_cli的 Windows 分支照搬了这个假设,把包内resources\codex.exe当成可用路径返回;%LOCALAPPDATA%\OpenAI\Codex\bin\<哈希>\codex.exe维护一份可独立执行的完整 CLI(本机实测约 316MB,含 sandbox 等组件,随桌面版一起更新)。旧代码只探测bin\codex.exe平铺层,够不到哈希子目录。一个支撑事实:CLI 与桌面版共享同一个
~/.codex(登录态、config.toml、会话库),因此改用这份 CLI 不产生第二套配置,桌面版里登录一次即可。方案:一条标准路径,零选择
不给用户多方案罗列,全链路围绕单一标准路径自动化:
Windows 标准 CLI 路径 =
%LOCALAPPDATA%\OpenAI\Codex\bin\<哈希>\codex.exe.cmdshim 裸名解析不到修复(5 文件,+349/−37,约半数为测试/文案;另附 1 个回归测试提交)
find_desktop_managed_codex_cli():扫bin一级子目录,取含codex.exe的最新一份,兼容平铺布局;is_windows_store_cli_path提为公共检测app_paths.rsconnect/app_server.rscommands.rsconnect/app_server.rssettings.rsopenai_base_url,若指向127.0.0.1:<端口>且 300ms 内 TCP 连不通,直接报明确原因,不再让 turn 失败后只剩「处理失败」connect/mod.rsconnect/mod.rsmacOS 行为不变(
find_bundled_codex_cli原逻辑保留在非 Windows 分支)。报错文案(前 → 后)
验证(全部真机,Windows 11 + Store 版 Codex 26.915.4065.0)
单测:新增 10 个(哈希目录选最新/平铺兼容/误伤用例、空路径解析、文案断言、坏路径迁移、localhost 端点判定、白名单循环回归);全量
cargo test -p codex-plus-core37 个测试组全部通过,0 回归。核心层真机(临时集成测试,真实
LOCALAPPDATA/ 真实 codex 二进制):bin\247581e40ee272fb\codex.exe;UI 层 E2E(管理器 CDP 9330 驱动真实界面):坏路径经真实保存链路被归一化置空;按钮填入并落盘标准路径;清空保存后连接以空路径正常轮询。
端到端:真机微信发消息 → 收到回复,全程 CLI 路径为空(空路径 → 自动解析 → app-server → 57321 代理 → 模型 → 回微信)。
分支行为补验:
run_weixin_connect循环,状态栏得到上述明确文案;codex且 PATH 无 codex 时,报错带指向性提示;已知边界
bin\<哈希>布局系对桌面版行为的逆向观察(无官方文档):若上游改布局,解析落空后退回 PATH + 通泛报错指引,不会崩,但主路径失效;.cmd不被裸名解析,历史问题非本次引入),文案将其引导至「安装桌面版」这条标准路径;#[cfg]隔离完全未动,但未在 mac 真机回归(探测/按钮/留空路径建议合并前在 mac 顺手过一遍)。