Skip to content

fix: Windows 本地 agent 的 execute 工具现在能继承宿主环境,正常调用 python/curl/edge-tts 等外部命令 - #246

Open
chujieHong wants to merge 5 commits into
TencentCloud:developfrom
chujieHong:fix/windows-local-shell-inherit-env
Open

fix: Windows 本地 agent 的 execute 工具现在能继承宿主环境,正常调用 python/curl/edge-tts 等外部命令#246
chujieHong wants to merge 5 commits into
TencentCloud:developfrom
chujieHong:fix/windows-local-shell-inherit-env

Conversation

@chujieHong

Copy link
Copy Markdown
Contributor

deepagents LocalShellBackend defaults inherit_env=False, so every agent execute() subprocess starts with an empty environment (no PATH/SystemRoot) and external tools (python/curl/ffmpeg/edge-tts) are unfindable. POSIX sh fills in a default PATH, so the breakage is effectively Windows-specific.

Inject inherit_env=True into the Windows default agent backend spec (default_agent_backend_spec) and, via setdefault, into windows_neutralize_host_root for configured local_shell specs. An explicit inherit_env=false (empty-env sandbox) is preserved. Filesystem backends are skipped: no execute tool, and its constructor rejects the kwarg.

Adds unit tests covering local_shell injection, filesystem skip, and explicit-override preservation. Verified end-to-end: a fresh agent thread now runs venv edge-tts via execute and delivers a valid MP3.

Summary

deepagents LocalShellBackend 默认 inherit_env=False,agent 每次 execute() 的子进程都从空环境启动(无 PATH/SystemRoot),外部工具 python/curl/ffmpeg/edge-tts 全部不可查找。POSIX 的 sh 会补一个默认 PATH,所以这个问题实际上只影响 Windows。

在 Windows 默认 agent backend spec(default_agent_backend_spec)中注入 inherit_env=True,并通过 setdefault 注入到 windows_neutralize_host_root 中已配置的 local_shell spec。显式的 inherit_env=false(空环境沙箱)会被保留。filesystem backend 跳过注入:它没有 execute 工具,且其构造器不接受该 kwarg。
image

新增单测覆盖:local_shell 注入、filesystem 跳过、显式覆盖保留。端到端验证:新建 agent 会话线程现在能经 execute 调用 venv 内的 edge-tts 并交付有效 MP3。

修复 Windows 上本地 agent execute 工具因子进程继承空环境(inherit_env=False)而无法运行任何外部命令的问题:在默认 backend spec 与 Windows 归一化中注入 inherit_env=True,使 python/curl/ffmpeg/edge-tts 等工具开箱即用;同时保留显式 inherit_env: false 的沙箱出口,并跳过无 execute 的 filesystem backend。

Target branch

  • Base is develop (feature / fix — default)
  • Base is main (release/* or hotfix/* only)

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactor / chore
  • Release / hotfix

Test plan

PYTHONUTF8=1 /Scripts/python.exe -m pytest tests/unit/backend/test_resolver.py tests/unit/agents/test_agent_manager.py → 70 passed, 2 skipped
ruff check + mypy → 均 clean
端到端(WebSocket 真实会话):新 agent 线程经 execute 调用 venv 内 edge-tts,产出有效 MP3 并 send_file_to_user 交付

  • make all passes locally
  • Added/updated tests

Checklist

  • Updated CHANGELOG.md (if user-facing)
  • README / docs updated (if needed)

deepagents LocalShellBackend defaults inherit_env=False, so every agent
execute() subprocess starts with an empty environment (no PATH/SystemRoot)
and external tools (python/curl/ffmpeg/edge-tts) are unfindable. POSIX sh
fills in a default PATH, so the breakage is effectively Windows-specific.

Inject inherit_env=True into the Windows default agent backend spec
(default_agent_backend_spec) and, via setdefault, into
windows_neutralize_host_root for configured local_shell specs. An explicit
inherit_env=false (empty-env sandbox) is preserved. Filesystem backends are
skipped: no execute tool, and its constructor rejects the kwarg.

Adds unit tests covering local_shell injection, filesystem skip, and
explicit-override preservation. Verified end-to-end: a fresh agent thread
now runs venv edge-tts via execute and delivers a valid MP3.
…cute

Two Windows-only defects in the harness stack made agent shell commands
unusable on Chinese Windows:

1. deepagents LocalShellBackend.execute runs subprocesses with text=True
   (strict UTF-8). Under PYTHONUTF8=1 the pipe reader crashes with
   UnicodeDecodeError when native tools (dir, git, ffmpeg, curl) emit
   GBK/CP936, dropping the entire output and returning a spurious exit
   code - the confusion that sent agents into endless self-diagnosis
   loops. Fixed with a bytes-mode reader + errors=replace decode.

2. harness_agent's virtual-path rewrite treats the / after a drive
   letter as a virtual path start, so C:/Users/... became
   C:'<root>'\Users\... and every absolute Windows path failed with
   file not found. Tightened the bare-token lookbehind to also exclude
   : and backslash.

Patches applied idempotently at import (Windows only) via
octop.infra.backend.windows_execute.
@chujieHong
chujieHong force-pushed the fix/windows-local-shell-inherit-env branch from 267be61 to 3559881 Compare August 12, 2026 10:18
@chujieHong chujieHong closed this Aug 12, 2026
@chujieHong chujieHong reopened this Aug 12, 2026
The CI-failing test asserted inherit_env unconditionally, but the resolver
injects it only on Windows (on POSIX sh supplies a default PATH from the
empty env, so nothing is added). Make the assertion platform-aware so the
test passes on both linux and windows CI jobs.
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