Skip to content

fix(dashboard): trigger-user-auth IPC 落盘字符串导致所有 bot 启动崩溃循环 - #1377

Open
acllm wants to merge 1 commit into
deepcoldy:masterfrom
acllm:fix-trigger-user-auth-ipc-stringify
Open

fix(dashboard): trigger-user-auth IPC 落盘字符串导致所有 bot 启动崩溃循环#1377
acllm wants to merge 1 commit into
deepcoldy:masterfrom
acllm:fix-trigger-user-auth-ipc-stringify

Conversation

@acllm

@acllm acllm commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

问题

Dashboard「按触发人身份调用 CLI」开关(PUT /api/bots/:id/trigger-user-auth → daemon IPC PUT /api/bot-trigger-user-auth)保存后,bots.json 里的 triggerUserAuth 变成字符串标量而非对象。daemon(重)启动时严格校验在 parseTriggerUserAuthConfig 处 fatal:

Fatal error: Error: Bot config [0]: triggerUserAuth must be an object (file: ~/.botmux/bots.json)

每个 bot 进程启动即崩,重启 10 次耗尽后卡在 errored。线上实测:通过 dashboard 配置该开关后,新加的 3 个 bot 全部崩溃循环起不来(本机 v3.21.0 复盘)。

根因

src/core/dashboard-ipc-server.ts 的该 IPC 路由把 JSON.stringify(policy) 得到的字符串直接传给 applyConfigField,而后者契约只接受「已解析」的值——kind: 'json' 原样落盘。路由注释声称“与 /botconfig set 共用校验”,但 /botconfig set 实际先走 coerceConfigValue,此路由跳过了这一步。附带两个次生问题:

  • 非法 policy(如 fallback: 'device')不被 400 拒绝,直接写盘(写完照样炸 daemon)
  • 清除路径把 null 转成 '' 原样写入空串,同样 fatal

修复

对齐 /api/bot-riff/api/bot-env 的既有模式:非空值先 coerceConfigValue 共享解析校验(非法原因原样 400 透出),nullapplyConfigField 清除哨兵删除 key。

测试

test/dashboard-ipc.test.ts 新增 3 个回归用例(在 master 上先复现失败,修复后通过):

  1. 落盘为对象而非字符串标量
  2. 非法 policy 400 且磁盘不动
  3. null 清除 key 而非写空串

相关测试面全绿(dashboard-ipc 254 用例 / bot-config-store / trigger-user-auth),tsc --noEmit 通过;全量 unit 套件其余失败经 stash 对照验证为 master 上预存的环境相关失败,与本次改动无关。

…daemon 崩溃循环

PUT /api/bot-trigger-user-auth 把 JSON.stringify 后的字符串直接交给
applyConfigField,而后者契约只接受「已解析」的值(kind: 'json' 原样落盘),
导致 bots.json 里 triggerUserAuth 变成字符串标量;daemon 严格校验在
parseTriggerUserAuthConfig 处 fatal(must be an object),所有 bot 进程
启动即崩、重试耗尽后卡在 errored。清除路径同样中招:null 被转成空串 ''
原样写入而非删除 key。

修复对齐 /api/bot-riff、/api/bot-env 的既有模式:先 coerceConfigValue
共享解析校验(非法 policy 原样 400 拒绝),null 走 applyConfigField 的
清除哨兵删除 key。
Copilot AI lite review requested due to automatic review settings September 12, 2026 15:31
@acllm
acllm requested a review from deepcoldy as a code owner September 12, 2026 15:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

修复点明确且与现有 /api/bot-env//api/bot-riff 的 coerce+apply 模式一致,并有针对性的回归测试验证写盘形态、错误透出与清除语义。

Pull request overview

本 PR 修复 dashboard 的 trigger-user-auth 配置保存路径:此前 IPC 路由把 JSON.stringify(policy) 的字符串直接传给 applyConfigField,导致 bots.jsontriggerUserAuth 被落盘为字符串标量/空串,从而在 daemon 重启时被 parseTriggerUserAuthConfig 严格校验 fatal,造成所有 bot 进入启动崩溃循环。修复后对齐 /botconfig set 的共享解析/校验与清除语义,避免写入不可解析的形态,并补充回归测试覆盖线上踩坑场景。

Changes:

  • PUT /api/bot-trigger-user-auth:非空值先走 coerceConfigValue(共享解析/校验),通过后再 applyConfigFieldnull/undefined 使用 applyConfigField(..., null) 清除 key。
  • 新增 dashboard IPC 回归用例:验证落盘形态为对象、非法 policy 400 且不写盘、null 清除 key 而非写空串。
File summaries
File Description
src/core/dashboard-ipc-server.ts 修复 trigger-user-auth IPC 写盘流程:引入共享 coerce 校验并用 null 哨兵清除,避免将字符串/空串写入 triggerUserAuth
test/dashboard-ipc.test.ts 增加 3 个回归测试,覆盖“落盘字符串导致 daemon fatal”“非法 policy 原样 400 且磁盘不变”“null 清除 key”三类场景。
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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