zai-org / zai-org/feedback

[Bug] 重启后模型供应商被重置回 OAuth 套餐,手动选择的 API Key 模式不持久

Open
#391 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: P2
Dominant language
No language data
Stars
22
Forks
1
PR merge metrics
No merged PRs in 30d

Description

提交前确认 · 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

影响体验 · Major(功能可用但体验受损)

复现频率 · Reproducibility

必现 · Always

问题描述 · Description

账号处于 OAuth 登录态时,用户在模型设置中手动切换到 API Key 模式(如 builtin:zai)后,每次重启 ZCode,该选择都会被重置回 OAuth 套餐modelProviderFamilyModes.zai 被写回 "oauth"modelProviderFamilySelectedKeys.zai 被写回 "coding-plan:builtin:zai-coding-plan"),需要每次手动切回。

从日志看,重置发生在启动流程中:主进程启动后读取 OAuth 账号 entitlement,将 preferred provider 解析为 builtin:zai-coding-plan,随后 settingService 即以该结果覆盖 setting.json 中用户上次的选择。用户显式保存的 provider 偏好没有被持久化尊重。

复现步骤 · Steps to reproduce
  1. 在 ZCode 中登录 Z.ai 账号(OAuth)
  2. 在模型设置中切换到 API Key 模式,填入 API Key(builtin:zai),确认可正常对话
  3. 完全退出并重启 ZCode
  4. 启动后模型供应商变回 OAuth 套餐,需再次手动切回 API Key 模式
期望表现 · Expected behavior

重启后保持用户上一次手动选择的供应商模式(API Key + preset:builtin:zai),OAuth 登录态不应在启动时静默覆盖用户选择。

实际表现 · Actual behavior

每次启动后 1~2 秒内,setting.json 被写回 OAuth 模式。当日日志中 5 次进程启动(09:29 / 09:31 / 09:49 / 13:35 / 20:19),每一次启动后均发生一次「自动重置为 oauth → 用户手动切回 apiKey」的循环:

时间 事件
09:29:19 进程启动
09:29:23 setting.json 写入 oauth + coding-plan:builtin:zai-coding-plan(自动重置)
09:29:41 用户手动切回 apiKey + preset:builtin:zai
09:31:29 进程重启,同样模式重复
09:49:52 进程重启,同样模式重复
13:35:28 进程重启,同样模式重复
20:19:07 进程重启,同样模式重复
20:19:26 用户手动切回 apiKey + preset:builtin:zai
ZCode 版本 · ZCode version

3.9.1(Windows 桌面版)

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

Windows 10 x64(10.0.26200),ZCode 桌面客户端

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

启动时触发重置的关键日志行(~/.zcode/v2/logs/,已脱敏裁剪):

[2026-08-27 20:19:11] [main] [host-log] [usage-stats] 读取 BigModel entitlement 已解析授权上下文
  {"preferredProviderId":"builtin:zai-coding-plan","providerId":"builtin:zai-coding-plan","scope":"personal","organizationId":null,"projectId":null}

[2026-08-27 20:19:11] [main] [host-log] [settingService] writing settings to: ...setting.json
  {...,"modelProviderFamilyModes":{"zai":"oauth"},
   "modelProviderFamilySelectedKeys":{"zai":"coding-plan:builtin:zai-coding-plan"},...}

[2026-08-27 20:19:26] [main] [host-log] [settingService] writing settings to: ...setting.json
  {...,"modelProviderFamilyModes":{"zai":"apiKey"},
   "modelProviderFamilySelectedKeys":{"zai":"preset:builtin:zai"},...}   ← 用户手动切回

两个额外观察,供定位参考:

  1. coding-plan-cache.json 中该 OAuth 账号的 builtin:zai-coding-plan 状态为 unavailablecoding_plan_not_entitled),即账号并无 coding plan 权益,但启动逻辑仍强制切换到该供应商。
  2. 退出账号登录、仅保留 API Key 后,重启不再发生重置——可作为临时规避手段,但会失去登录态相关功能。
临时规避 · Workaround

退出 Z.ai 账号登录,纯 API Key 模式使用;或每次启动后手动切回。

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the startup logs for entitlement resolution and settingService writes to setting.json, then compare the persisted API Key values with the OAuth values recorded in the issue. Check coding-plan-cache.json and the described OAuth entitlement path; done means restarting while logged in preserves the manually selected API Key mode and provider.

Written by the indexing model from the issue text.

Assessment

Domain
authentication, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.