fix(dashboard): trigger-user-auth IPC 落盘字符串导致所有 bot 启动崩溃循环 - #1377
Open
acllm wants to merge 1 commit into
Open
Conversation
…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。
There was a problem hiding this comment.
🟢 Approval recommended
修复点明确且与现有 /api/bot-env//api/bot-riff 的 coerce+apply 模式一致,并有针对性的回归测试验证写盘形态、错误透出与清除语义。
Pull request overview
本 PR 修复 dashboard 的 trigger-user-auth 配置保存路径:此前 IPC 路由把 JSON.stringify(policy) 的字符串直接传给 applyConfigField,导致 bots.json 中 triggerUserAuth 被落盘为字符串标量/空串,从而在 daemon 重启时被 parseTriggerUserAuthConfig 严格校验 fatal,造成所有 bot 进入启动崩溃循环。修复后对齐 /botconfig set 的共享解析/校验与清除语义,避免写入不可解析的形态,并补充回归测试覆盖线上踩坑场景。
Changes:
PUT /api/bot-trigger-user-auth:非空值先走coerceConfigValue(共享解析/校验),通过后再applyConfigField;null/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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Dashboard「按触发人身份调用 CLI」开关(PUT /api/bots/:id/trigger-user-auth → daemon IPC
PUT /api/bot-trigger-user-auth)保存后,bots.json里的triggerUserAuth变成字符串标量而非对象。daemon(重)启动时严格校验在parseTriggerUserAuthConfig处 fatal:每个 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,此路由跳过了这一步。附带两个次生问题:fallback: 'device')不被 400 拒绝,直接写盘(写完照样炸 daemon)null转成''原样写入空串,同样 fatal修复
对齐
/api/bot-riff、/api/bot-env的既有模式:非空值先coerceConfigValue共享解析校验(非法原因原样 400 透出),null走applyConfigField清除哨兵删除 key。测试
test/dashboard-ipc.test.ts新增 3 个回归用例(在 master 上先复现失败,修复后通过):相关测试面全绿(dashboard-ipc 254 用例 / bot-config-store / trigger-user-auth),
tsc --noEmit通过;全量 unit 套件其余失败经 stash 对照验证为 master 上预存的环境相关失败,与本次改动无关。