Skip to content

fix: 启动 AutoCAD 前补齐 Windows 登录环境变量,消除许可代理崩溃弹窗 - #10

Merged
luomufanye-cloud merged 2 commits into
codex/luomu-cad-v1.0.0from
fix/acad-launch-windows-env
Nov 26, 2026
Merged

luomufanye-cloud merged 2 commits into
codex/luomu-cad-v1.0.0from
fix/acad-launch-windows-env

Conversation

@luomufanye-cloud

@luomufanye-cloud luomufanye-cloud commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

问题

由 agent 通过 luomu-cad 启动 AutoCAD 时,会弹出 "Autodesk Error Report",或者干脆启动失败。具体表现跟发起启动的 agent 宿主有关。

根因

  • DispatchEx 由 DCOM 启动 AutoCAD 时,会把 MCP 服务端进程的环境传给 AutoCAD;这个环境又来自启动 MCP 服务端的 agent 宿主。
  • 很多宿主不会传完整的 Windows 登录环境:
    • Codex 的 shell_environment_policy inherit = "core" 会删掉 ALLUSERSPROFILE 等变量。
    • 官方 MCP SDK 客户端默认只传十来个变量,同样没有 ALLUSERSPROFILE。
  • 缺少 ALLUSERSPROFILE 时,Autodesk 许可代理 AdskLicensingAgent.exe 一启动就抛出 std::runtime_error,每次重试都弹一个错误报告。在 MCP SDK 默认环境下,未修复的代码甚至连 AutoCAD 都启动不了(COM 返回 0x80080005 "服务器运行失败")。

修改

  • cad.py 新增 _complete_windows_environment()。它在 DispatchEx 之前运行,按白名单从当前用户的默认登录环境(CreateEnvironmentBlock)补回缺失的 Windows 登录变量。
  • 已有的值不会被覆盖,白名单以外的变量也不会被复制,所以宿主特意去掉的密钥之类的变量仍然不会传给 AutoCAD。
  • 这一步放在服务端唯一的 AutoCAD 启动路径上。Skill 规定只能通过 cad_start 启动,所以不管哪个 agent 宿主调用,都会经过这里。
  • 新增三个测试:补变量逻辑的单元测试;Windows 上检查登录环境里确实有这几个前置变量;以及真实启动路径测试,断言调用 DispatchEx 时 ALLUSERSPROFILE 已经存在。最后这个测试在去掉修复后会失败。

验证

本机 AutoCAD 2024,经真实 stdio MCP 服务端调用 cad_start,每种环境各启动一个新实例,等待 45 秒后检查:

宿主环境 修复前 修复后
MCP SDK 默认环境(通用 MCP 宿主) AutoCAD 启动失败 启动成功,许可注册成功,弹窗 0 个,崩溃报告 0 个
Codex inherit=core 许可代理崩溃,弹出 3 个窗口 启动成功,许可注册成功,弹窗 0 个,崩溃报告 0 个
完整环境(Claude Code 这类) 正常 正常

pytest:1013 passed,18 skipped。

本 PR 叠加在 #9(1.0.0 候选)之上;main 上的同一修复是单独的 PR。如果 #9 先合并,需要先把本 PR 的目标分支改成 main,再删除 #9 的分支。

🤖 Generated with Claude Code

luomufanye-cloud and others added 2 commits November 25, 2026 18:49
Agent shells that inherit only a core environment (Codex with
shell_environment_policy inherit="core") drop ALLUSERSPROFILE and other
logon variables. DCOM hands the caller's environment to the AutoCAD it
launches, and Autodesk's licensing agent throws std::runtime_error at
startup without ALLUSERSPROFILE. Every retry then raised an
"Autodesk Error Report" dialog.

Before DispatchEx, fill in missing variables from an allowlist using the
user's default logon environment. Existing values are never overwritten,
and nothing outside the allowlist is copied.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@luomufanye-cloud
luomufanye-cloud merged commit d23638d into codex/luomu-cad-v1.0.0 Nov 26, 2026
6 checks passed
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.

1 participant