修复 s02 工具调用中的子进程输出解码问题#301
Open
WorkHaH wants to merge 1 commit into
Open
Conversation
|
Someone is attempting to deploy a commit to the crazyboym's projects Team on Vercel. A member of the Team first needs to authorize it. |
Collaborator
|
@WorkHaH |
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.
问题背景
s02_tool_use中的 bash 工具通过subprocess.run(..., text=True)捕获命令输出。在 Windows 上,
text=True会使用系统默认编码解码子进程输出,例如中文系统里通常是 GBK。如果子进程实际输出的是 UTF-8 字节,就可能在读取 stdout/stderr 时触发解码错误。
问题表现
执行
s02_tool_use/code.py时,某些命令输出包含 UTF-8 内容后会报错:随后因为 stdout 读取失败,
r.stdout可能变成None,继续拼接输出时又触发:最终导致 agent loop 中断。
修复方式
将子进程输出改为先按 bytes 捕获,再显式解码:
这样可以避免 Windows 默认编码和实际输出编码不一致时直接报错,同时保留对本地编码输出的兼容性。