Repository navigation
fix(onboarding): make managed MOSA bot activation recoverable - #572
Conversation
deepcoldy
left a comment
There was a problem hiding this comment.
这版方向对,权限/事件回读、owner 扫码、PM2 错误与空列表分离也都值得保留;但当前实现仍有两个会破坏“失败即锁死 + 可恢复”的阻塞问题,建议修完再合。
-
activationPending在启动 ACK 前已经从持久配置删除,Dashboard 崩溃或启动结果不确定时无法 fail-closed。src/dashboard/bot-onboarding.ts:871-900先写回不带activationPending的bots.json,再await runLiveStart();只有 Promise 正常返回失败时才补回标记。我用一个不 resolve 的startBotLive复现了这段窗口:启动尚未 ACK 时,磁盘行已经没有 marker。此时新建 Manager 模拟 Dashboard 重启,账本会把任务恢复成failed / permission_recovery_interrupted,内存快照显示activationPending:true,但它不会把 marker 重写回bots.json,所以 fleet restart 仍可启动该 bot。同一问题在不确定启动结果下更明显:CLI 超时/异常可能发生在 PM2 已经创建进程之后;当前 rollback 只补 marker,不会精确 stop + 回读确认当前进程已消失,因而可能出现“磁盘 pending、daemon 仍在线”。需要让 activation transition 本身可恢复:例如持久化
activating阶段并在启动/重启时 reconcile,或让 daemon 持一次性 activation receipt 启动后再提交 ACK;任何 ambiguous/failed start 都必须 stop exact row 并回读 absence 后才能声称重新锁死。 -
“精确 PM2 启动 ACK”和原始下标 fence 目前都只做了一半。
src/cli.ts:2581-2589在pm2 start --only返回 0 后直接返回state:'started',没有重新jlist验证 exact process 仍为 online(更没有核对该 row 的BOTMUX_BOT_INDEX/ app identity)。这不足以作为上面状态机依赖的启动 ACK;PM2 子进程随即崩溃或命令超时后的部分成功都会被误分类。src/daemon.ts:16284-16303首次确实用loadBotConfigAtIndex(idx),但 profile bootstrap 后又用 compact 后的loadBotConfigs(),找不到原 App 时 fallback 到botConfigs[idx]。并发配置变化时这仍可能选到别的 App;如果 bootstrap 因目标刚被标 pending 返回bot_not_in_config,当前代码也只是 warn,然后继续用标记前读到的 stalecfg注册。建议在registerBot前再次按 raw index 解析并断言 appId 未漂移;pending/missing 必须致命退出,不能 fallback 到 compact index,也不能继续 stale config。
本地验证:
- 相关 5 个 suite:178/178 通过
pnpm exec tsc --noEmit:通过pnpm build(含 public-domain/dist audit):通过- 全量 unit:10039/10039 通过(显式设
BOTMUX_SCHEDULE_TIMEZONE=America/Los_Angeles,避免本机全局 Asia/Shanghai 配置污染时区用例) - diff 未发现私有部署域名或密钥;未改隧道协议,因此不需要 platform 镜像改动
另外,MOSA 在 master 中此前没有出现;它是否属于可公开术语仍请 maintainer 单独确认,这不替代上面两个代码阻塞项。
|
Addressed the requested-change blockers in ab2bd31:
Verification:
Please re-review the current head. |
deepcoldy
left a comment
There was a problem hiding this comment.
复核新 head ab2bd319:activationStarting + gated daemon、start 后 PM2 jlist 精确回读,以及 success 分支的 raw-index 重载,方向都对;但 crash-safe 状态机仍有 3 个阻塞空窗,原 review 的 stale-config 分支也还没完全关掉,因此继续 CHANGES_REQUESTED。
-
恢复开始的“deactivation”阶段没有持久化/重启 reconcile,旧 daemon 仍可能在
activationPending:true时在线。runPermissionRecovery()先调用holdRecoveryActivation()把activationPending:true写入bots.json,随后才await runLiveStop()(src/dashboard/bot-onboarding.ts约 1670 行)。如果 Dashboard 在 stop ACK 前退出,现有 daemon 不会因为磁盘 marker 改变而自行断开长连接。新 Manager 的reconcileInterruptedManagedActivations()只扫描activationStarting,不会检查activationPending,所以重启后也不会补 stop。我用 never-resolving
stopBotLive卡在这个精确 crash-point,再创建第二个 Manager 模拟 Dashboard 重启,结果是:{"pendingOnDisk":true,"restartStopCalls":0}也就是磁盘声称 pending,但旧 daemon 仍可能收消息。需要把 deactivating intent 也纳入 durable state/reconcile;重启看到这类 managed pending 必须 exact stop + absence readback,成功前不能进入扫码/完成路径。
-
当前 PM2 “精确 ACK”没有证明进程是本次 gated/quiescent activation daemon。
isExactPm2BotApp()只核对 process name、raw index、BOTMUX_LARK_APP_ID和 online;BotmuxPm2App也没有暴露BOTMUX_MANAGED_ACTIVATION_APP_ID/ job receipt。于是一个同 App/index 的旧普通 daemon 会走already-online,即使它没有等待activationStarting、早已在飞书长连接上。这个场景会被问题 1 直接触发:旧 daemon 未停 → complete 写activationStarting→start-bot把旧进程当 ACK → Dashboard 清 marker。managed activation 的 ACK 至少要区分“普通 online”和“本次 gated online”(最好绑定 jobId/nonce);遇到旧普通 row 应先 exact stop + absence,再从带 receipt 的 ecosystem entry 重建,不能返回
already-online。 -
commit 后、ledger completed 落盘前仍有一个不可恢复窗口。
commitManagedActivation()先原子删除activationStarting,返回后activateRecoveredBot()才patch(liveStarted:true)并持久化 completed ledger。若在两者之间退出,磁盘已经是 ready/daemon 已获放行,但 ledger 仍是 propagation-pending。重启后没有activationStarting可 reconcile;再次completeScopePropagation()会因为beginManagedActivation()要求activationPending:true而固定失败。我用真实生成的 pending ledger,构造“刚清 marker 就退出”的精确磁盘状态,重启后结果:
{"result":{"ok":false,"error":"permission_recovery_activation_failed"},"startCalls":0}需要一个 durable committing/completed receipt,或在 restore 时能够无歧义地 reconcile “config 已 commit、ledger 未 commit”;并补这个 instruction-boundary crash test。
-
原 review 的 bootstrap failure 分支仍会用 stale config 注册。
src/daemon.ts中只有profileBootstrap.ok时才按 raw index 重新加载并断言 appId;bot_not_in_config/config_unavailable/validation_failed仍只是 warn,随后直接registerBot(cfg)。目标在 bootstrap 期间变为 pending/missing 时,parseBotConfigsFromText()会过滤它并返回bot_not_in_config,这里仍会继续使用 marker 之前读到的 stalecfg。显式BOTMUX_BOT_INDEX路径应在 所有 bootstrap 结果之后、registerBot 之前 再做一次 raw-index load + appId fence;pending/missing/drift 必须致命退出。
验证结果:
- 新增针对性 3 suite:118/118 通过
- 全量 unit:10167/10167 通过
pnpm exec tsc --noEmit:通过pnpm build:通过(含 public-domain/dist audit)git diff --check:通过
因此这些仍是 crash 时序与 ACK 语义的测试盲区,不是现有断言失败。请补 deactivation/commit 两端的 crash-point 测试、gated receipt 校验,以及 bootstrap failure fence 后再 re-review。未合并。
|
Addressed the second review in 304cd0b:
Validation: pnpm exec tsc --noEmit, focused activation tests (129 passing), and pnpm build pass. Full unit retains the pre-existing four failures in test/vc-meeting-daemon-session.test.ts; the activation paths are covered by the focused regression tests. |
deepcoldy
left a comment
There was a problem hiding this comment.
复审 304cd0b:前两轮 CHANGES_REQUESTED 的 4 个阻塞项(deactivation 持久化/reconcile、gated PM2 receipt 校验、commit/completed 崩溃窗口、bootstrap failure 后 stale-config fence)已全部修复并配套崩溃点测试。针对性 129/129、typecheck、公有域名审计通过;全量 unit 仅 3 个既有环境相关 suite 失败(master 同样失败,与本 PR 无关)。放行。
ec146a4(deepcoldy#572)把 foreign-bot 授权门扩大到所有 scope(含 native topic)并删掉 了 ownsSession 豁免,导致「同机兄弟 bot 首次 bot→bot 直连、接收侧 cross-ref 尚未学到对方 receiver-scoped open_id」被误判为未知外部 bot,弹 /grant 卡。 根因:cross-ref(bot-openids-<appId>.json)是被动从 mentions[] 学习,第一次直连 存在冷启动窗口;飞书 open_id 按接收应用隔离,不能靠自报 open_id 判断同伴。 修复:在判定 unknown、发授权卡前,新增一次 live sibling 补全: - 新增 client.ts resolveSiblingBotBySenderOpenId:用当前群 live /members/bots roster,仅当 sender open_id 命中唯一同名本机配置 sibling、且该 app 独立 is_in_chat 确认时才认(复用 auth-grade resolveCurrentChatBotOpenIdsByLarkAppIds 做严格再校验)。任何 API 失败/歧义/同名冲突/真外部 bot 一律 fail-closed 回 授权卡——绝不放行自报名字。 - event-dispatcher.ts gate:命中 sibling 则 updateBotOpenIdCrossRef 回填 cross-ref(后续同一对 bot 直接命中 isKnownPeerBot,且同条消息下游 daemon evaluateTalk 的 peer 腿也随之放行),再 route;否则维持原授权卡逻辑。 影响面:仅收窄「配了 allowlist 的受限态 + foreign-bot @mention」这一门,未动 oncall/grant/team-peer/open-mode 其它腿。真外部 bot 授权语义不变(负向用例覆盖)。 已有 native-topic 授权卡回归测试仍绿(resolver 默认 fail-closed)。 测试:pnpm build 绿;新增 event-dispatcher 4 例(冷 sibling 自愈+回填、真外部 bot 仍弹卡、known-peer 不走 live、granted-bot 不走 live)+ list-chat-bot-members 7 例(resolver 正/负/歧义/roster 缺失/API 失败/空 open_id/不在群);定向 event-dispatcher(236)/list-chat-bot-members(32)/exact-chat-grant/peer-bot-operate/ team-peer-trust/grant-gates/bot-routing/grant-card 全通。 Co-Authored-By: Claude <[email protected]>
Summary
Why this belongs in botmux
MOSA owns Space/owner ACLs, durable commands, leases/fences, and Workboard projection. botmux owns the Feishu Open Platform setup and daemon activation data plane. The failure happened between permission application and botmux startup, so the runtime must fail closed and expose a recoverable receipt to MOSA.
Verification
Safety