Repository navigation
feat(session): 完成 Virtual Actor 第二阶段运行时迁移 - #831
Closed
LucasIcarus wants to merge 19 commits into
Closed
LucasIcarus wants to merge 19 commits into
LucasIcarus wants to merge 19 commits into
Conversation
LucasIcarus
force-pushed
the
feat/virtual_actor
branch
from
August 12, 2026 05:54
fdfc8e9 to
1e72230
Compare
LucasIcarus
force-pushed
the
feat/virtual_actor_stage2
branch
from
August 12, 2026 06:05
791e545 to
2d214c9
Compare
LucasIcarus
force-pushed
the
feat/virtual_actor
branch
from
August 12, 2026 12:17
1e72230 to
c7ab587
Compare
评审确认的三个问题一并修复: 1.(critical)身份闸门把 bots.json 全文 sha256 当不变量:全仓 18+ 模块 会在运行时改写 bots.json(/config set、dashboard 默认值、setup add、 vcMeeting profile bootstrap 等),任何字节差异都触发 needsRepair 拒启, 且 bootstrap 在闸门之前写盘可在同一次启动内自触发死循环。现在 plan/receipt/status 只摘要「active 地址集合」的规范化投影(设计文档 明示:显示名、secret 等不改变 BotId),运行时配置写入不再影响身份态。 2.(critical)identity repair 用晋升时旧快照整体覆盖 bots.json,静默回 滚 allowedUsers/appSecret/新增 Bot。控制面现在结构性禁写配置权威: apply/repair/rollback 只收敛 registry + receipt,plan 不再嵌入完整 config 字节(顺带消除 appSecret 落入 bot-identity-ops 的泄漏面)。 3.(major)report --target-config 是绕过 src/setup/owner-identity.ts 的 bots.json 写入口(跨应用 ou_ 可直接落入 allowedUsers)。整条移除: 身份永远跟随配置权威,Bot 集合编辑归 setup/config 流程;report 现在 显式拒绝多余参数而非静默忽略。 4.(major)core-only 权威字节含 env 派生 cliId,换 BOTMUX_CORE_CLI 即 拒启且不可修复。授权字节收敛为地址字段(larkAppId+apiOnly)。 配套语义:新增 needsPromotion 状态——registry 完好但地址集合前进时, 启动闸门引导 report+apply(旧实现此场景既不能 repair 也不能 report, 彻底卡死);repair 遇损坏 registry 时回退到最新 receipt 选择操作; planned 状态按 createdAt 而非文件名字典序挑计划。 测试:控制面 12 用例(含运行时写入保持 ready、repair 不动 bots.json、 制品无 secret、needsPromotion 晋升链、report/apply 竞态 fail-closed、 core-only 换 cliId 保持 ready 五条新回归锁);command 3 用例(含 --target-config 拒绝与 repair/rollback 分派);cutover 4 用例全绿。 Claude-Session: https://claude.ai/code/session_01AjYRKcQeHGHFxWjKjRJsP6
评审确认的一 critical 两 major,都属于「隔离只有进入路径、没有对称 解除路径」同一家族: 1.(critical)restore 探测 unknown 被 05af681 改为 reconcile('unknown') → 激活 quarantine,而该隔离只有 Web 终端 exists 探测或完整 close 能 解除——herdr/tmux 服务端慢启动一次即让该 bot 全部持久后端会话在 daemon 生命周期内再也无法从飞书消息拉起 CLI,且与代码注释、旧测试 文件头declared的「保留待下条消息冷恢复」语义直接矛盾。恢复旧语义: unknown 只保留 worker-less active 记录不进隔离;持久后端按会话名 attach,幸存 pane 会被重入而非复制,冷恢复路径天然幂等。 2.(major)隔离记录绑定被取代的 DaemonSession 后永久锁死:resumeSession /relocate 换绑对象图后 sameQuarantinedBinding 永假,typed re-probe 解除逻辑不可达。改为把隔离状态重绑到当前活动绑定(pendingRetirements Set 按引用携带,在途 retirement 结算继续生效),fail-closed 语义保留 而解除路径恢复。 3.(major)unknownAfterEffect 围栏在 port.begin 之前被无条件消费: 一次以 rejected/quarantined 收场、未产出任何证据的 re-probe 也会 拆栅,后续 ordinary 激活可与结果未知的前次 fork 叠成双 CLI。改为 只在 begin 实际受理(active/effect)后才消费围栏。 审计 oracle 同步:A4 restore oracle 改钉「unknown 不 close 不 fork 且 不产生任何 reconcile 请求」的新不变量。 测试:restore-zombie-close 改写 unknown 用例锁恢复语义; current-session-activation 新增隔离重绑后仍可解除用例; session-activation-runtime 新增失败 re-probe 不拆栅用例; 激活相关 7 文件 240 用例全绿。 Claude-Session: https://claude.ai/code/session_01AjYRKcQeHGHFxWjKjRJsP6
评审确认的四个 major 逐一修复: 1. chat-rename 路由鉴权前置(dashboard-ipc-server):迁移时鉴权被下沉到 adapter execute 内部,未授权请求会先在 submit 落下永久 operation 收据 (攻击者可选 id + 无界内存)。恢复与 close/restart 兄弟路由一致的 路由层 sessionCliIpcAuth 前置,adapter 内部校验保留为纵深防御;新增 「未授权 403 后同 operationId 仍可被合法调用方使用」回归锁。 2. scheduler 结算消费 markRun 围栏返回值:definitionRevision 围栏返回 superseded 时 store 分文未写,但 producer 照常 publish schedule.fired 并发 hook——可观测台账与 store 发散,且 once 任务的关闭被误以为已 完成。现在只有 applied 才发布事件与 hook,superseded/missing 记日志 静默;新增编辑竞态静默回归锁。 3. 投影 boot 探针不再击杀 daemon:restore 后的 dashboardSnapshot 探针 一旦 notReady(单行 live/durable 漂移即触发)会让 startDaemon 直接 抛错退出。改为投影保持 fail-closed(不 markReady、读取持续拒绝)但 daemon 与非投影 IPC 正常服务,漂移行入日志供修复;恢复 restore 已 建立的 markIpcReady 释放。审计新增 oracle 钉住「探针只降级投影、 不得击杀 startDaemon」。 4. scratch 退役普查统一 canonical anchor 语义:普查用可见 route (chat=chatId/thread=rootMessageId)而 close 守卫用 sessionAnchorId (deferredScheduleRun 取隔离 routingAnchor),两套语义使 reopen 在 deferred 邻座场景误报 occupied。SessionView 新增 canonicalAnchor (由 directory row 的 ordinaryIngressBinding 透传),普查与守卫回答 同一问题;新增 deferred 邻座不被误判占位回归锁,「移走」模拟同步 补齐锚耦合。 验证:相关 8 测试文件 157 用例全绿,双审计 gate 通过,tsc 干净。 Claude-Session: https://claude.ai/code/session_01AjYRKcQeHGHFxWjKjRJsP6
major#9:stage2 新增的静态导入形成 worker-pool → session-manager → current-session-activation → worker-pool 运行时环,使 29 个测试文件的 partial vi.mock(worker-pool) 在 Current 激活路径上被 vitest 跳过、真实 forkWorker 抛 'WorkerPool not initialised'。断环方式: - session-manager 对 reconcileCurrentSessionActivation 改 import type, restore 的默认 activation 改为懒动态导入(daemon 生产路径本就显式注入) - current-session-activation 对 worker-pool 改 import type,execute 的 fork 兜底与 coordinator 的 bootId/registry 读取改为懒动态导入 静态图上不再存在任何经 current-session-activation 闭合的环。 major#10 及其余红测家族全部按同族已迁移样板清零(82 → 0): - daemon-rename-route(29)/initial-user-turn-opening(23):owner-strict 投影闸门夹具按 command-handler 样板补「live 注册表 JSON 投影」; forkWorker mock 补 boolean acceptance 契约 - lark-current-ordinary-ingress-production(14)/ current-ordinary-new-route-semantics(4):单轮 harness 改为与生产 runOrdinaryEffects 一致的 effect 循环(物化+激活两段) - group-join-shared-routing(6)/listener-foreign-bot-owner(2): registerBot 补稳定 BotId 绑定(对齐 daemon 启动路径); attachLiveWorker 补代际写穿(对齐 reserveWorkerGeneration)。 「外部 bot 发送者不得成为 owner」不变量恢复已验证状态 - doc-comment-daemon-concurrency(2):结构断言改钉激活 coordinator seam (代际守卫先于 dispatch 的不变量不变);共享失败用例改用生产真实的 「拒绝」失败形态(抛异常→隔离属激活端口合同,另有专测) - command-handler(1):C3 事件信封新增 projectionEpoch/sequence 断言跟进 - sessions-card-dispatch(1):close 夹具补 operation_id 写身份收据, 连带修复 non-200 用例此前因缺收据短路造成的假绿 验证:全量 pnpm test 15895 passed / 9 failed——其中 4 例为上游基线红 (纯 master 同样失败)、2 例为已知 codex/cost-calculator 负载 flake (隔离复跑通过)、3 例为本次审计 oracle 修改期间的中间态(复跑通过), 即本分支自有失败清零;pnpm build 双审计 gate + tsc 干净。 Claude-Session: https://claude.ai/code/session_01AjYRKcQeHGHFxWjKjRJsP6
LucasIcarus
force-pushed
the
feat/virtual_actor_stage2
branch
from
August 12, 2026 12:22
05cd17d to
a44a09e
Compare
I1 身份闸门此前要求操作员显式执行 identity report+apply 才放行 daemon 启动:存量部署升级或全新安装后,首次 restart 会让全部 bot daemon 以 BotIdentityStartupBlockedError 崩溃循环,restart CLI 的 handler-ready 校验随之失败,且报错误导向 --bootstrap-shutdown-protocol(照做也无法恢复)。 - 控制面新增 bootstrap():单次锁段内 statusOf→reportLocked→applyLocked, 仅处理锁内复核仍为 unmigrated 的 virgin root;planned(含 rollback 留下 的形态)、needsPromotion、needsRepair 原样返回,保持操作员显式决定。已有 plan 一律不自动 promote——否则会把操作员刚回滚的 plan 静默重新发布。 - daemon 闸门改走 ensureReadyDaemonBotIdentities:锁外采样只把 ready 当 快路径,其余状态一律进 bootstrap() 在锁内重判。若以锁外一次采样决策, 三 daemon 并发首启时兄弟进程会撞上 intent 中间窗口被误判 needsRepair 而启动失败(多进程压测约半数轮次复现),修后由控制锁串行化收敛。首启 完成时补一条 INFO 日志,便于区分「自动迁移」与「沿用既有身份」。 - report/apply/status 方法体原样抽为 reportLocked/applyLocked/statusOf (文件锁不可重入,bootstrap 需在单锁段内复用),逐行语义等价。 影响面:daemon 启动路径(全部 bot,含 core-only synthetic root)与身份 控制面公共接口;CLI identity 子命令、backend/适配器不受影响。已知固有 权衡:registry 与 bot-identity-ops 同时丢失的根与全新安装不可区分,首启 会重铸 BotId(改前同样重铸,只是显式执行);仅删 registry 仍判 needsRepair 挡住。 验证:pnpm build(含 session 台账审计)通过;identity 三个测试文件 27/27,新增覆盖多地址分配、core-only 首启、单 daemon 闸门只解析自身 config、锁外瞬时态路由回归、rollback 否决不被重放、daemon.ts 源码 deny-list 扩至 apply|report|repair|rollback|bootstrap;全量 unit 套件除 两处与本改动无关的存量红(slash-commands 文档缺 /introduce)与高负载 超时 flake 外全绿,flake 项在无负载下 91/91 复跑通过。未做 live 部署 验证——保留本机未迁移现场供备份后测试。 Claude-Session: https://claude.ai/code/session_01PpHQT8xDef3iKqq71xuAC8
I1 最初以分配式身份控制面交付(注册表 + report/apply promotion + 启动闸门 + botmux identity 命令 + 首启自动迁移)。复盘发现其唯一声称收益「换 App 保 身份」在没有 rebind 语义的现状下无法兑现(换址的唯一操作就是 retire+新铸, 身份照样断),而成本已实际发生:bots.json 与注册表双权威漂移出 needsPromotion 阻断日常增删 bot、升级/新装需要首启迁移、并发首启存在竞态、 加 bot 的操作序恶化为 stop→report→apply→start。当前没有任何落盘数据按 BotId 寻址(sessions/connector/groups 均按 larkAppId),推导与分配在 Target-B 首次落盘前可零成本互换,故按减负原则收敛为最简实现。 - core/bot-identity.ts 新增 deriveBotId / deriveBotIdForConfig: BotId = `bot_` + sha256(kind\0id) 前 32 hex,kind 分隔防 lark/coreOnly 同名互撞;展示名、secret、launch 参数不影响身份。若未来需要换址保身份, 届时以只记例外的显式映射引入(JSDoc 已记录该边界)。 - registerBot 注册时内部推导并绑定,BotState.botId 变为必填, requireBotId 不再存在「未绑定」失败态;cli riff 路径、vc-agent、 dashboard federation 等原先不经身份闸门的注册方现在同样天然获得 botId。 - daemon 启动移除身份闸门与控制面装配;删除 services/bot-identity-control-plane、core/bot-identity-startup、 cli/bot-identity-command 与 `botmux identity` 命令及其三个测试文件。 - 语义变化:同一地址删除后重新加回 → 同一 BotId(原为永久 retire+新铸); 同一 App 在不同数据根 → 同一 BotId(原为按根随机隔离)。运行时 BotId 类型与全部 ownerBotId 消费面不变。 - 设计文档 §1.3 增补减负修订记录,注明 Target-B 首次将 BotId 写盘前本 决策可零成本复议。 影响面:daemon/CLI/dashboard 全部 registerBot 调用方与 CLI 命令面; PtyBackend/TmuxBackend、IM 路由不受影响。~/.botmux 无需任何迁移(身份 注册表从未随正式版发布,未迁移现场直接照常启动)。 验证:pnpm build(含 session 台账审计)通过;npx tsc --noEmit 通过; 新增 test/bot-identity.test.ts 钉推导确定性/kind 分隔/knob 无关/ registerBot 绑定/跨重启稳定;ownerBotId 相关既有断言更新为推导值 (daemon-current-ordinary-ingress-one-cut、pending-repo-first-start-callers、 api-only-mode-wiring 源码钉);全量 unit 套件除 slash-commands 文档缺 /introduce 的存量红外全绿。 Claude-Session: https://claude.ai/code/session_01PpHQT8xDef3iKqq71xuAC8
Collaborator
Author
|
转轨了, no need anymore |
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.
改了什么
SessionRuntime。requireBotId贯穿 host/activation/lane/executor。remaining-control-bypass=86明示保留,Target-A 之外remaining-bypass=824台账如实标注。为什么
此前不同入口仍可能直接持有 SessionStore、active registry 或 worker lifecycle,并在 Runtime receipt/lane 之外执行副作用。响应丢失、owner/canonical 漂移、路由抢占或 backend 结果不明时,可能出现重复驱动、错误归属或旧 activation continuation 复活。
本变更把「谁有权推进一个 Session」收敛到单一 owner/epoch Runtime,并把无法证明结果的分支保持隔离,只有有类型的 readback/reconcile 才能继续。
基底与 rebase
feat/virtual_actor(其自身已 rebase 至 master f11c0c9,含 fix(report): 为主编排回注补充 IPC 鉴权 #779 report IPC 鉴权 / fix(dashboard): 软链/共享盘 HOME 下 token ensure/rotate 不再报 token_persist_failed #827 / fix(cli): 支持发现当前 ChatGPT 桌面端内置 Codex #828 / fix(worker): 修复首轮启动期卡片跳过工作中状态 #819 / fix(opencode): 斜杠命令原样透传(paste-line 送达 + 独立 Enter 提交) #822 / feat(vc-agent): 入会自动 provision lark-cli profile + 失败通知 owner + 沙盒改用户 opt-in #782 vc-agent 沙盒 opt-in)。17 个提交中 14 个逐字节等价重放,3 个台账提交仅重钉审计摘要(inventory sha256 / remaining-bypass digest),补丁间差异经 range-diff 证实只含摘要行;重叠源码文件(daemon.ts / worker-pool.ts / cli.ts / dashboard.ts / dashboard-ipc-server.ts)的净补丁与上游各补丁内容级逐行一致。评审与加固(后 4 个提交)
对本分支做了多维度独立评审(A4 激活生命周期 / C2 Dashboard / C3 投影 / C4 scheduler / Bot 身份边界 / Runtime 核心与台账 / 测试覆盖,逐条对抗性复核),确认 3 critical + 10 major,已全部修复:
fix(identity): 身份闸门收敛为地址集投影并禁写配置权威)identity report --target-config(绕过src/setup/owner-identity.ts的 bots.json 写入口,跨应用ou_可直落 allowedUsers 的红线路径);Bot 集合编辑归 setup/config 流程,身份永远跟随配置权威needsPromotion状态:地址集前进时引导 report+apply(原实现该场景 repair/report 双双拒绝,彻底卡死);core-only 权威字节剔除 env 派生 cliIdfix(session): 激活隔离态补齐对称解除路径并恢复 restore 懒恢复)fix(session): 收束四处控制面/投影/调度边界回归)markRundefinitionRevision 围栏返回值(superseded 不再发布与 store 发散的 fired 事件/hook)SessionView新增canonicalAnchor,deferredScheduleRun 邻座不再误报 occupied)fix(session): 消除激活模块静态循环依赖并清零遗留红测试)vi.mock(worker-pool)静默失效影响面
botmux identity report→apply --yes);地址集变更后 daemon 启动会以needsPromotion引导重新晋升/dashboard sessions详情卡不带 operation_id,升级后其 关闭/恢复 按钮会提示bad_operation_id,重新打开卡片即可(写身份收据按设计要求)实际验证
pnpm test:15939 passed / 37 skipped;余 5 例失败均与本分支无关——slash-commands-doc-sync×2 为上游基线红(纯 master 同样失败)、codex-app-runner×3 为已知负载 flake(隔离复跑 42/42 通过)。此前的worker-argv基线红已被上游 fix(worker): 修复首轮启动期卡片跳过工作中状态 #819 修复。本分支自有失败从 82 清零。pnpm build通过(含audit:domains/audit:session-state/audit:session-runtime三道 gate、TypeScript、Dashboard bundle、dist audit);pnpm exec tsc --noEmit干净。未执行
pnpm switch:here、daemon restart 或飞书 live 手测。稳定 Bot 身份切换需要显式 operator migration,本 PR 保持 Draft,合并前建议pnpm switch:here && pnpm daemon:restart后在飞书实测:普通消息收发、持久后端会话重启恢复、dashboard 关闭/恢复按钮、定时任务触发、botmux identity report/apply晋升链。🤖 Generated with Claude Code
https://claude.ai/code/session_01AjYRKcQeHGHFxWjKjRJsP6