Skip to content

fix(gemini,acp): sanitize Gemini tool names and decode Windows taskkill errors#1828

Merged
piorpua merged 1 commit intomainfrom
fix/issue-1635
Mar 29, 2026
Merged

fix(gemini,acp): sanitize Gemini tool names and decode Windows taskkill errors#1828
piorpua merged 1 commit intomainfrom
fix/issue-1635

Conversation

@kaizhou-lab
Copy link
Copy Markdown
Collaborator

Summary

  • Sanitize MCP tool names before sending to Gemini API to prevent 400 Invalid function name errors. Gemini requires ^[a-zA-Z_][a-zA-Z0-9_]*$ — characters like -, ., /, : are replaced with _.
  • Decode Windows taskkill failure output from GBK encoding so Chinese error messages remain readable in log files instead of appearing as garbled characters.
  • Add regression tests for both Gemini tool-name sanitization and Windows error decoding.

Related Issues

Closes #1635

Test Plan

  • Unit tests pass (15 new tests)
  • Type check passes
  • Lint and format pass

…ll errors

Sanitize MCP tool names to comply with Gemini's function_declarations.name
rule (^[a-zA-Z_][a-zA-Z0-9_]*$) by replacing invalid characters with underscores.

Decode Windows taskkill stderr from GBK encoding for readable Chinese log output
instead of garbled replacement characters.
@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 29, 2026

Code Review:fix(gemini,acp): sanitize Gemini tool names and decode Windows taskkill errors (#1828)

变更概述

本 PR 修复了两个独立问题:1) 在将 MCP 工具名称发送给 Gemini API 前进行清洗,解决因工具名含 -./: 等非法字符导致的 400 Invalid function name 错误;2) 对 Windows taskkill 命令的 stderr 输出进行 GBK 解码,解决中文系统下日志出现乱码的问题。两个修改均位于正确的模块,并附有回归测试。


方案评估

结论:✅ 方案合理

两个修复均直接定位问题根因,改动最小化。sanitizeGeminiFunctionName 正确地放在 OpenAI2GeminiConverter.ts 中,与转换逻辑内聚;decodeWindowsError 作为工具函数放在 acp/utils.ts 中合理,只在 Windows 分支被调用。两处均未引入不必要的抽象层。


问题清单

🔵 LOW — 工具名清洗后可能产生同名冲突

文件src/common/api/OpenAI2GeminiConverter.ts,第 189–193 行

问题代码

functionDeclarations: params.tools.map((tool) => ({
  name: sanitizeGeminiFunctionName(tool.function.name),
  ...
})),

问题说明:若两个 MCP 工具名清洗后映射到同一字符串(如 read-fileread.file 都会变成 read_file),Gemini API 会收到含重复 namefunctionDeclarations,可能导致未定义行为或 API 错误。当前实现不做去重处理。实际场景中碰撞概率较低,但属于已知边界情况。

修复建议:本次 PR 不强制要求修复,建议后续以 issue 跟踪,必要时在 sanitizeGeminiFunctionName 下游添加去重逻辑(如为冲突名追加序号后缀)。


汇总

# 严重级别 文件 问题
1 🔵 LOW OpenAI2GeminiConverter.ts:189 清洗后工具名可能碰撞,无去重处理

结论

批准合并 — 无阻塞性问题

两个修复均正确、简洁,测试覆盖边界情况完整,CI 全绿。名称碰撞属低概率边界情况,不阻塞本次合并。


本报告由本地 pr-review skill 生成,包含完整项目上下文,无截断限制。

@piorpua
Copy link
Copy Markdown
Contributor

piorpua commented Mar 29, 2026

✅ 已自动 review,无阻塞性问题,正在触发自动合并。

@piorpua piorpua merged commit 4ac9c05 into main Mar 29, 2026
17 checks passed
@piorpua piorpua deleted the fix/issue-1635 branch March 29, 2026 08:28
@piorpua piorpua added bot:done Auto-merged by bot and removed bot:reviewing Review in progress (mutex) labels Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:done Auto-merged by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ppt 生成工具名触发400以及日志乱码

2 participants