Skip to content

[Bug] 无头 CLI -p 模式从不发起工具调用:工具定义在系统提示中但未真正装载,模型编造执行结果(必现) #1276

Open

Description

@Alidadei

English TL;DR

Headless CLI mode (zcode -p) never emits any tool calls in v0.17.0 on Windows: the tool definitions appear in the system prompt (the model can list all 16 of them), but no structured tool invocation ever happens. The model then fabricates execution results ("file created", "bash output: ...") while nothing actually runs. Verified via the shared session database: headless sessions contain zero tool parts while GUI (app-server) sessions on the same machine record tool calls normally. 5/5 repro rate.

问题描述 · Description

无头 CLI 模式(zcode.cjs -p "<prompt>")下,模型从不发起任何工具调用。工具定义确实进入了系统提示(让模型自报工具清单,它能完整列出 16 个:bash、write、read_file、multi_edit、glob_file_search、web_fetch 等),但整个会话没有任何一次真实的工具执行。后果是模型大量编造执行结果:声称"已创建文件"(磁盘上不存在)、声称"Bash 返回 xxx"(命令从未运行),甚至编造运行环境(自称在"Linux 虚拟机 /root/projects/mcopilot-frontend-init(Catpaw NoCode)")来解释失败——实际进程在 Windows 本机,无任何虚拟机。

初步定位方向:工具描述以文本形式进了 prompt,但 API 请求很可能没有携带结构化的 tools 参数(或工具执行通道未接通),导致模型"知道"工具却无法调用。

复现步骤 · Steps to reproduce

环境:Windows 11 x64(10.0.26200),bigmodel provider(anthropic 兼容端点 open.bigmodel.cn),模型 GLM-5.3 系列,node v24.20.0。无头 CLI 与桌面版共用安装(resources\glm\zcode.cjs)。

  1. node "D:\TOOLS\ZCode\resources\glm\zcode.cjs" -p "在当前目录创建文件 test.txt,内容写 ok"(在任意临时目录下执行;--cwd 指定目录同样复现)
  2. 等待返回,模型回复"已创建 test.txt"
  3. 检查当前目录:文件不存在
  4. 再试 --json、--verbose、--surface terminal、--mode build 等变体,同样复现
  5. 对照测试:-p "列出你当前可用的所有工具名称",模型能列出全部 16 个工具名

期望表现 · Expected behavior

-p 模式与 GUI/app-server 模式行为一致:模型发起工具调用(write/bash 等),工具真实执行,文件真实落盘、命令真实运行,--json 输出中包含工具事件。

实际表现 · Actual behavior

  • 5 次测试(写文件 ×3、跑命令 ×2)全部编造结果,0 次真实工具执行,必现。
  • --json 返回中无任何工具相关事件,usage.cacheReadTokens: 0。
  • 模型在无工具可用的状态下持续编造"成功",对用户有实际危害(以为任务完成,实际什么都没发生)。

证据(会话数据库)

无头会话与 GUI 会话共用 ~/.zcode/cli/db/db.sqlite,对比 part 表:

  • 无头 -p 会话的 part 类型序列全部为 [text, text, step-start, text, step-finish],零 tool part(抽查 3 个会话)。
  • 同机 GUI 会话(app-server --stdio --surface desktop 通道)的 part 分布:tool: 13,工具调用正常。
  • 说明执行层/记录层本身工作正常,问题特定于 -p 单发路径的工具装载。

版本与环境

  • zcode CLI bundle:0.17.0(桌面版安装目录内 resources\glm\zcode.cjs,node zcode.cjs --version 输出 zcode 0.17.0;doctor 输出 process: zcode-cli, node: v24.20.0, platform: win32/x64)
  • OS:Windows 11 x64(10.0.26200)
  • Provider:bigmodel(anthropic 兼容,https://open.bigmodel.cn/api/anthropic),GLM-5.3 系列;同模型在 GUI 模式下工具调用完全正常
  • 已验证无头模式可正常工作的部分:纯文本问答、-c/--resume 跨进程续会话、会话与 GUI 共库共享

补充

Activity

  1. github-actions commented on Oct 28, 2026

    @github-actions

    👋 感谢你的反馈,我们已经收到。

    • 维护者看到后会尽快回复你。
    • 状态保持为 status: 待评估,你可以随时补充信息。
    • 信息不全时我们会打上 needs: 更多信息 标签并 @ 你。

    👋 Thanks — we've received your issue.

    • A maintainer will get back to you as soon as we can.
    • Status stays at status: 待评估 (Triage); feel free to add context.
    • If we need more details, we'll add needs: 更多信息 and ping you.
  2. Alidadei commented on Oct 28, 2026

    @Alidadei
    Author

    补充诊断(修正与深化)

    继续排查后发现根因比我最初描述的更精确,原判断"工具未装载"需要修正为两层问题:

    事实修正:工具定义确实装载了(41 个)

    通过 app-server --stdio 原始 JSON-RPC 通道(不经 GUI)建会话并发任务,session/event 事件显示 toolCount: 41。工具定义已进入会话。但无论 -p 还是裸 app-server,模型都只回文本、从不发起工具调用——工具调用环(tool-call loop)在无头路径上从未触发。

    新发现的第 2 个 bug:无头模式默认模型解析错误

    model_usage 表显示:

    • GUI 会话(正常):account:bigmodel-individual-coding-plan / GLM-5.3-Flash,工具调用数百次
    • 全部无头会话(-p 与裸 app-server):new-provider / ng-flash(用户自定义的第三方 provider,0 次工具调用,且大量编造结果)

    即:无头路径没有沿用 coding plan 的主力模型,而是回落到了某个自定义 provider。已尝试 session/setModel 修正,但无头服务器的 Provider Registry 中既无 account:bigmodel-individual-coding-plan 也无 builtin:bigmodel(报 "Provider Registry 中不存在 Model"),客户端无法纠正。

    关键交叉验证:换上正确模型后工具调用依然断裂

    用 --surface desktop --mode yolo -p "..." 强制会话落到 GLM-5.3-Flash(model_usage 可证),返回仍声称"已用 write 工具创建文件",part 表仍为零 tool part,磁盘无文件。同一模型在 GUI 正常调用工具、在无头模式从不调用——排除了单纯"模型不配合"的解释,指向无头路径的 provider 请求构造或工具执行回路缺陷(仍怀疑结构化 tools 参数未随请求发出)。

    给修复的两点建议

    1. 无头模式(-p / 裸 app-server)应默认使用与 GUI/coding plan 相同的主力模型,或在 Provider Registry 中暴露完整 provider 列表让 session/setModel 可用。
    2. 排查无头路径的 provider 请求是否缺失 tools 参数(模型能"报菜名"却不能调用,与该假设吻合)。

    环境补充

    Windows 11 x64、zcode CLI bundle 0.17.0、bigmodel anthropic 兼容端点、GLM-5.3-Flash(GUI 侧)。无头会话与 GUI 会话共用 ~/.zcode/cli/db/db.sqlite,以上证据均可用 SQL 复查。

  3. Alidadei commented on Oct 28, 2026

    @Alidadei
    Author

    结案更正:主因是未登录状态下的静默降级,登录后无头完全正常

    用户完成了 zcode login bigmodel(CLI 自己的 OAuth)之后,重新实测:

    • 无头 -p 默认模型变为 account:bigmodel-individual-coding-plan / GLM-5.3-Flash(不再回落自定义 provider)
    • Write 工具真实执行并落盘(文件内容验证通过),工具调用环正常工作
    • 会话与 GUI 共享同一 credential store,但登录前的无头进程既不回落到 plan 模型、也无法通过 session/setModel 修正(注册表中无 plan provider),且模型不发起工具调用时以"已成功"话术收场——这一静默降级链路才是危险所在

    建议保留的两个改进点

    1. 无头进程未登录/无可用凭据时,应在启动时明确报错或警告,而不是回落到任意自定义 provider 并让模型以编造结果收场;
    2. 登录前 session/setModel 无法看到 plan provider(注册表不含),客户端无自救手段;建议注册表对已共享凭据的 plan provider 可见,或提示"请先 zcode login"。

    感谢,本 issue 的核心现象随登录解决,剩余为上述鲁棒性建议。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions