Skip to content

fix(tui): degrade Moonshot tool schema failures per tool - #22

Merged
h3c-hexin merged 2 commits into
Pinvou:pinvou3-cleanfrom
qiuYliangM:fix/moonshot-mcp-tool-degrade
Aug 27, 2026
Merged

fix(tui): degrade Moonshot tool schema failures per tool#22
h3c-hexin merged 2 commits into
Pinvou:pinvou3-cleanfrom
qiuYliangM:fix/moonshot-mcp-tool-degrade

Conversation

@qiuYliangM

@qiuYliangM qiuYliangM commented Aug 23, 2026

Copy link
Copy Markdown

Background

A third-party MCP server can expose a tool schema that Moonshot's MFJS validator cannot accept (for example, a schema containing pattern). Because the complete active tool surface is sent with each model request, failing the whole request on one incompatible tool makes unrelated Moonshot/Kimi turns unusable.

Changes

  • Degrade per tool: retain compatible tools and omit only the incompatible tool from the current Moonshot request.
  • Omit tools and tool_choice when no compatible tool remains.
  • Reject a named tool_choice locally when it targets an omitted tool, instead of sending a dangling choice. The user-visible error includes the tool name but never schema values.
  • Emit one typed projection warning per affected streaming request. The TUI shows a localized warning toast; embedding runtimes receive a status item with the stable provider_tool_projection_warning code.
  • Keep projection warnings outside content accounting so transparent stream retry behavior is unchanged.
  • Preserve preview/send parity through the shared build_chat_wire_body preparation seam.

Verification

  • cargo fmt --all -- --check
  • cargo test -p codewhale-tui --lib forkguard_moonshot -- --nocapture — 3 passed
  • cargo test -p codewhale-tui --lib --locked forkguard_ -- --test-threads=1 — 45 passed
  • cargo test -p codewhale-tui --lib drops_ — 48 passed
  • cargo test -p codewhale-tui --lib localization::tests:: — 32 passed

Known limits

  • This remains a narrow Moonshot stopgap. A general route-specific tool projection layer should reconcile tool catalogs, deferred tool search, tool_choice, request preview, diagnostics, and dispatch validation in one upstream-owned seam.
  • An omitted tool still exists in the canonical catalog/tool-search haystack; the full cross-surface design is intentionally not implemented in this fork PR.

No-Issue: issues are disabled on this fork repository. The general design will be tracked in the upstream repository.

@github-actions

Copy link
Copy Markdown

Thanks @qiuYliangM for taking the time to contribute.

This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered.

Please read CONTRIBUTING.md for the expected contribution shape. A maintainer can grant recurring PR access by commenting /lgtm on a pull request.

qiuYliangM and others added 2 commits August 27, 2026 10:01
Upstream sanitize_moonshot_chat_tools failed the whole request before
transport when any tool's parameters failed MFJS compatibility
validation. One third-party MCP server whose schema uses keywords
outside the MFJS whitelist (e.g. $schema, pattern) therefore broke
every Moonshot-routed turn, including turns that never called the tool.

Change the sanitizer to per-tool degradation: a tool whose parameters
cannot pass validation is dropped from the current request with a
tracing warning that names the tool but, like the error Display,
carries no schema values. When every tool is dropped, the tools and
tool_choice keys are omitted so an empty array or a dangling choice
cannot trigger a fresh 400. Preview and actual sends stay consistent
because both go through build_chat_wire_body.

The two upstream fail-before-transport tests are rewritten to assert
the new behavior (request sends, offending tool absent from the wire
body, private schema values never leak), and a new
forkguard_moonshot_drops_only_incompatible_tool locks the per-tool
degradation contract.

Agent-assisted change (Kimi Code CLI); root-cause analysis and fix
plan: docs/mcp-schema-moonshot-mfjs-analysis.md in the parent repo.

Signed-off-by: Lfanxing <1461574375@qq.com>
当具名 tool_choice 指向被 MFJS 兼容性检查淘汰的工具时,在发送前返回不含 schema 内容的明确错误,避免生成悬空选择。

对普通按工具降级请求,在流开始前发出一次结构化警告;TUI 通过本地化 warning toast 展示,runtime 记录带稳定诊断码的 status item,且诊断事件不改变透明重试的内容判定。

新增具名选择和单次可见警告回归测试,并补齐完整语言包。

Signed-off-by: hexin <372726039@qq.com>
@h3c-hexin
h3c-hexin force-pushed the fix/moonshot-mcp-tool-degrade branch from 70befd8 to 8f49fb8 Compare August 27, 2026 02:15
@h3c-hexin
h3c-hexin merged commit 04e109a into Pinvou:pinvou3-clean Aug 27, 2026
7 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.

2 participants