Skip to content

[Bug] headless(-p/--resume)无法指定模型:会话存储的模型选择失效后 --resume 永久失败(Select a model before continuing) #856

Description

@txw778899-netizen

提交前确认 · Pre-submission checklist

  • 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate.
  • 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.

问题类别 · Category

模型设置 / 切换 · Model config

涉及的 Agent 框架 · Agent framework

ZCode Agent(自研)

严重程度 · Severity

阻塞使用 · Blocking (无法使用核心功能 / core function unusable)

复现频率 · Reproducibility

必现 · Always

问题描述 · Description

环境:ZCode CLI 0.16.9(apps/zcode-cli@0.16.9,仓库 HEAD 29628c9),Windows 11。调用方式:zcode --resume -p "…"(headless prompt)

现象:会话持久化的模型选择(runtime/model_selection entry)指向的 Provider 一旦失效(权益变化、账号切换、Provider 删除),该会话在 headless 下永久无法恢复,每次都报:

Error: Model creation failed
Cause: Error: Select a model before continuing

且 CLI 没有任何途径显式指定模型:

  • 无 --model(或类似)命令行参数(zcode --help 及参数解析中不存在);
  • /model 斜杠命令在 -p 模式下不被拦截,整段文本被当作 prompt 提交(实测 zcode -p "/model" 同样报上述错误);
  • intent.modelSelection 只有 TUI / Protocol 面能设置。

注意:全新 -p 会话不受影响(resolveInitialModelSelection 会用 configuredDefaultModelSelection 或注册表回退),只有 --resume 命中此问题。

根因(三段逻辑叠加,组合后 headless 无出口)

  1. packages/core/src/runtime/methods/turn.ts:103 —— 选择来源只有两个:

    const admittedModelSelection = options?.intent?.modelSelection ?? this.getSessionModelSelection();

  2. packages/bootstrap/src/app/create-app.ts restorePersistedModelSelection() —— 恢复时读取存储选择,registry.validateSelection 校验失败即置空,不回退全局默认(注释明确「恢复/配置刷新可以清除失效选择;未绑定不应借用默认模型」):

    getRuntime().setSessionModelSelection(validation?.ok ? selection : undefined);

  3. packages/core/src/runtime/methods/runtime-model.ts:18-23 —— 选择为空即抛 ConfigurationError。

TUI 下用户可用 /model 交互自救;headless 下 intent 无法注入、无回退、无提示,三条路全断。

修复方案

  1. 新增 --model <provider/model>(可选 --reasoning-level)参数并接入既有 intent 通道(turn.ts:103 已原生消费 intent.modelSelection,只需从 CLI 参数接线;provider/model 解析可复用 legacy-cli-model-config.ts 的 Hkt);

  2. 可选:非交互 surface 恢复且存储选择失效时,回退 configuredDefaultModelSelection 并 logger.warn;TUI 保持置空交给交互选择;

  3. 报错信息增强:附上会话存储的失效 providerId/modelId 与 --model 用法提示。

附注:与 #837(CLI 无法使用 bigmodel Coding Plan)、#839([1113] 报错)相关联——普通用户 CLI 登录后第一次 --resume 旧会话即命中,感知为「CLI 完全不能用」。相关:#842。

复现步骤 · Steps to reproduce

  1. 在桌面端创建会话(模型选择为某个账号侧 coding plan Provider X)
  2. 使 X 失效(例如该品牌权益到期 / 切换账号)
  3. 执行 zcode --resume <该会话> -p "hi"
  4. 每次都在 model creation 阶段报 Select a model before continuing,无任何自救手段

期望表现 · Expected behavior

headless 提供 --model 参数可显式指定模型;或恢复时对失效选择回退默认并给出警告;报错信息包含失效选择与可操作建议。

实际表现 · Actual behavior

zcode --resume -p "…" 固定报 Model creation failed / Select a model before continuing,无参数可绕过。

ZCode 版本 · ZCode version

3.14.3(apps/zcode-cli 0.16.9)

设备 / 系统 / 浏览器 · Device / OS / Browser

Windows 11 Pro 10.0.22631 x64

截图 / 录屏 / 日志 · Screenshots / Recordings / Logs

相关已有反馈:#837(CLI 无头执行无法使用 bigmodel.cn Coding Plan)、#839([1113] Insufficient balance 报错)。本 issue 提供源码级根因与最小修复路径。

Activity

  1. github-actions commented on Sep 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.
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