Skip to content

feat(assistant-mode): 开放私聊 bot 的个人助理模式,每个会话归一个主人、按主人隔离 - #3652

Merged
deepcoldy merged 15 commits into
deepcoldy:masterfrom
xu4wang:feat/assistant-mode-v2
Nov 21, 2026
Merged

deepcoldy merged 15 commits into
deepcoldy:masterfrom
xu4wang:feat/assistant-mode-v2

Conversation

@xu4wang

@xu4wang xu4wang commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

依赖 #3649(sandboxWithholdBotSecret)。本分支包含 #3649 的提交;本 PR 自己的改动是 96946e9ee..HEAD(10 个提交,已 rebase 到 #3649 当前 head 96946e9)。请先审/合 #3649,合后我 rebase,diff 只剩本 PR 部分。

背景

开放私聊的 Bot(谁都能私聊它)所有用户共用一个 cwd、一个 CLI 记忆目录、一份沙盒可写面:A 让 agent 写下的文件、A 的对话记录,B 私聊同一个 Bot 时都能让 agent 读出来。

做了什么

新增 bot 配置 assistantMode(默认关),把这类 Bot 变成「每个人自己的助理」:

  • 每个会话恰好一个主人:私聊 = 发送者;/group 会话群 = 创建者;普通群 = 认领者(/assistant claim,管理员可 /assistant owner @某人 指定;主人退群后群进入待认领、停止服务)
  • 按主人收窄:USER_HOME = <BOT_HOME>/users/<open_id>,cwd 固定在 USER_HOME/work;CLAUDE_CONFIG_DIR / codex home、fs-policy 授权、附件桶(attachments/<appId>/u/<open_id>,只读)、宿主侧读命令都只给本人的那份;可选模板目录 assistantTemplateDir 首次初始化(不跟随软链)
  • 不放 Bot 密钥:assistantMode 隐含 feat(sandbox): 新增 sandboxWithholdBotSecret,沙盒不放 Bot 密钥,send/history/quoted 走宿主中转 #3649 的 sandboxWithholdBotSecret——沙盒里没有 App Secret、没有 lark-cli 密钥库;botmux send / history / quoted 走宿主中转(宿主指定 session、quoted 核对本会话所在群);会话 lark-cli 不给 bot 身份令牌(凭证接口按实时 bot 配置判,开模式前的存量会话也拿不到),--as user 不受影响。list 在助理模式下不可用(会列出别人的会话),文档已写明
  • 准入闸(最后一道):decideAssistantAdmission(core/assistant-spawn.ts),在 worker 启动(forkWorkerPrepared)和向活 worker 投递输入(sendWorkerInput)两处都判:
    • 主人与当前解析出的主人一致 → 放行
    • 还没跑过 CLI、没记主人的新会话 → 认领给当前主人并把 cwd 改到主人 work/(这样各条建会话路径不必各自记得填主人)
    • 开模式前跑过的存量会话、主人已变、群未认领、沙盒形态在开模式前已冻结(没冻结「不放密钥」)→ 拒绝、回一条「这条没处理,请重发」、退役会话;退役被拒(如远端 runner 拒绝取消)时后续输入照样拒收
  • 各条建会话路径显式带主人:普通消息、话题回复与话题延续(不复活主人不对的旧会话)、fork / 干净恢复 / 独立任务(继承)、新话题定时任务、会议接收、看板任务、卡片点击、HTTP/webhook 触发器(不建 worktree);群未认领时直接拒绝
  • 不对助理会话开放的能力:v3 工作流(快照生成时 + 启动时按实时配置拒绝,暂停后才开模式的运行恢复时也拦得住)、决策看板 IPC(按 bot 汇总、不按主人隔离,回 403)、按发言人分道(principal lane;群里会话都归群主人)
  • 开关即时生效:/botconfig assistantMode on 挂起/关闭该 bot 现有 worker,存量会话在下一条消息时由准入闸退役;认领 / 改绑主人时退役前主人的会话
  • /assistant 命令、i18n、文档(docs-site/docs/{zh,en}/assistant-mode.md、docs/file-sandbox.md、设计文档 docs/design/2026-11-20-assistant-mode.md)

刻意不做

  • 不改默认:未开 assistantMode 的 bot 行为不变(下载调用参数、关闭点、IPC 路由都有测试钉住;准入闸和输入闸在模式关时直接放行)
  • 助理模式要求 sandbox: "oncall",其他沙盒档拒绝启动
  • 不做跨主人共享(同一群里多人用同一个助理时,会话都归群主人)

测试

npx tsc --noEmit -p tsconfig.json                 # 通过
npm run build                                      # 通过
npx vitest run --project unit <下列 24 个文件>
#  assistant-command / assistant-mode / assistant-mode-withhold-secret / assistant-spawn /
#  assistant-mode-input-gate / card-click-turn-bind / dashboard-create-session /
#  trigger-session-root-message / principal-lane-live-acceptance / close-consumer-matrix /
#  fs-policy / event-dispatcher / sandbox-relay-watcher / session-sandbox-freeze / fork-session /
#  session-store / model-pin / workflow-sandbox-paths / workflow-v3-ephemeral-pool /
#  daemon-ordinary-ingress-failure-notice / session-lifecycle-start / crash-loop-diagnostic /
#  test-hygiene / bot-registry
#  → 24 files, 2309 passed / 9 skipped;满载下 event-dispatcher(dedupe_fixture_timeout)与
#    sandbox-relay-watcher 4 条计时用例偶发失败,单独重跑两次均 774 passed
bun test ./test/<文件>  # 本 PR 改动的 13 个测试文件中可跑 bun 腿的 5 个(其余用 vi.hoisted,被 run-bun-tests 判为 deferred):
#  assistant-command 17/17、assistant-mode 15/15、close-consumer-matrix 14/14、fs-policy 134/134 通过;
#  ipc-lark-tool-identity 75 pass / 5 fail —— 同样 5 条在 master 上也失败(本机环境),新增用例通过

全量单测对照(npx vitest run --project unit,本机):本分支失败的 65 个文件里,59 个在干净 master 上同样失败(本机环境:HOME / 工具链相关);其余 6 个中 2 个是本分支引入的回归、已修(会话关闭点登记进关闭点矩阵;未开助理模式时下载调用参数不变),4 个单独重跑通过(满载偶发)。修完后没有再跑一遍全量,只跑了上面的定向集合。

变异验证:新增判定逐条删掉/取反后对应测试都会失败——归属判定(认领条件、主人相等、冻结形态)、话题延续、fork 继承、工作流快照与启动两处检查(含未注册 bot 回落读配置)、按发言人分道旁路、看板/卡片/触发器三条路径的主人与未认领拒绝、活 worker 输入闸(含模式关时不生效)、凭证接口按实时配置拒绝。未被单测直接覆盖的是 forkWorkerPrepared 里把 adopt 结果写回会话的几行(判定本身有测试)。

追加修复:换主时序与凭证隔离

在 bfe25009e 后追加 c6f22ca26,覆盖跨 owner 隔离链的四个问题:

  • 附件下载前移:现有会话已跑过或已带 owner 时,在任何下载 / prepared-attachments 交接之前按实时 owner 复核;归属失效直接提示重发并退役,不再先把新主人的文件写进旧主人桶。
  • 队列与实际投递统一判定:所有 admitQueuedActivationTail 写入在 journal / FIFO 计数变化前接受统一 live-input 检查;promotion 在推进 journal 前复查;tracked IPC 与 standalone bootstrap 后的 init 在实际发送前再复查。覆盖 double-fork、protected-egress、opening follower、ACK 合并写入等入口。
  • token 等待后复核:getTenantAccessToken() 返回后重新读取实时 bot 配置,并重跑会话冻结标志 + 实时 assistantMode 的 withholding,慢请求跨模式切换不再发放凭证。
  • 删除失效逃生阀:移除 assistantLarkBotIdentity 配置、IPC gate2、init 透传、类型、/botconfig 项及中英文文档;助理模式不提供 app 身份凭证例外。

回归与变异证据

  • 换主 + close 未完成的实际路由:旧桶无下载、旧 worker 无输入。
  • double-fork 换主:tail 不写入、FIFO 计数不推进、worker 无输入。
  • 已落盘 tail 换主:promotion 不改变 journal、worker 无输入。
  • standalone cold-init:tracked 与 nontracked 两条路径在 bootstrap 期间换主后均不发送旧 prompt。
  • 慢 token lookup:等待期间开模式且 legacy worker 已停,响应仍为 403,正文不含 token。
  • 上述六处守卫逐一失效后,对应测试均咬红;恢复后全绿。所有变异/时序探针经 fenced-run 执行。

追加验证

  • bun run build:通过。
  • 相关 vitest:1786 passed(含 command-schema / oracle 14、配置与测试卫生 423、配置路由 162)。
  • Bun 逐文件:268 passed(ipc-lark-tool-identity 88/88、close-consumer-matrix 14/14、assistant-command 17/17、assistant-mode 15/15、fs-policy 134/134)。

对抗复核覆盖

对抗复核未发现新的行为缺陷,实际攻击与验证场景包括:

  • owner 改绑且 close 长期未结算:附件不写旧桶,后续 admission 不依赖 close 成功仍持续拒绝。
  • double-fork tail 写入与改绑交叠:返回 rejected,tail 与 FIFO order 不变,旧 worker 无输入。
  • tail 已落盘、ACK promotion 前改绑:promotion 返回 false,journal 不推进,prompt 不发送。
  • standalone bootstrap 与改绑交叠:tracked / nontracked 两条 init 路径均不发送旧 prompt。
  • tenant-token 长等待与开模式交叠:即使 legacy worker 已停,迟到 token 仍被 403 拦截。
  • promotion 中途 sessionStore.updateSession 注入失败:首次不发送 IPC,tail / FIFO / activation / ledger / pendingPrompt 恢复;随后精确重试仅发送一次,不重复推进 journal。
  • 普通 IPC 超时与改绑交叠:真实 retry 重新检查 owner,不执行第二次 worker.send,pending delivery 清除;迟到 callback 后也不补发、不误报普通投递失败。

未做真实飞书、真实 worker/CLI 与 daemon 重启后的 live 验证;上述结论来自真实组件、可控 Promise / 假时钟与故障注入。

Rebase 后增量修复:密钥库与内容 IPC

在 14a401555 后追加 276cd2f5d、cb62cf743、06a96d212、acaacde67(最终 head acaacde67),处理增量审查发现的四项问题:

  • Seatbelt 最终隔离:finalDenyPaths 与 sealLarkKeyStore 统一,并覆盖全部 session-stores、bots/dashboard 配置秘密;finalReadOnlyPaths 统一过滤 bot homes、session-stores、附件及其祖先授权,owner USER_HOME 与本人附件桶不受影响。
  • no-transport 数据库:carve-out 排除助理模式的 session-stores/<appId>,但保留 bots-info.json、bin 等合法最小授权;最终 deny 同时覆盖其它 app 的 DB/WAL/SHM。
  • 内容 IPC 实际边界:message、raw_input、inject_command 在同步发送及 bootstrap 后均复核 owner;transfer replay 也在实际发送前复核。term_action、display、refresh 等控制 IPC 不增加 registry 查询。
  • ordinary-delivery 夹具:function-harness 按需加载 live/transfer 两级归属判定;两个 ordinary-delivery scope 与 deployment-continuation 手写 scope 均接入真实判定,修复 Vitest/Bun 的 assistantLiveInputAdmission is not a function 与 assistantTransferInputDeliveryAllowed is not defined。

新增回归与变异证据

  • assistant-only + 最终 ancestor read-only:Seatbelt 编译后的 keystore deny 位于最终 allow 之后。
  • no-transport + assistant:sessions.db 为 deny,bots-info/bin 保持 readOnly;最终 deny 覆盖所有 session-stores。
  • 标准与外部 BOT_HOME:其它 app DB、bots.json、dashboard secret、其它 owner 附件均不被 final allow 回授,owner 工作目录与自有附件保持 allow。
  • 同步 stale-owner:raw_input、inject_command、message 全部拒绝且不发送。
  • standalone bootstrap 换主:raw_input 不再释放到旧 worker。
  • 真实 transferSession:目标 owner 改变后 replacement 不 replay raw_input;退役失败也不放行。
  • 控制 IPC 在 registry 未注册时仍正常发送。
  • 各处守卫逐一变异均咬红,恢复后全绿;变异均经 fenced-run。

验证

  • bun run build:通过。
  • 最终 head CI:44833385089 全部 job 成功;Sandbox network boundary 44833385107 成功。
  • 29 个相关 vitest 文件:2032 passed。
  • Bun 逐文件:343 passed(含 fs-policy 138/138、ipc-lark-tool-identity 88/88、worker-managed-origin-contract 11/11、codex-app-capacity-adversarial 21/21、daemon-deployment-continuation 30/30、codex-app-capacity-recovery 9/9)。

对抗复核覆盖

对抗复核先复现了 final allow 的同类回授,修复后按三种布局逐项解析真实 buildFsPolicy + compileToSeatbelt 的最后匹配规则,未再发现问题:

  • 标准 BOT_HOME;
  • 外部 BOT_HOME、botmuxHome 仍在 /Users/u;
  • BOT_HOME、botmuxHome、sessionDataDir 全部外置,保留 /Users/u final allow。

核验结果:本应用及其它应用的 sessions.db/WAL/SHM、bots.json、dashboard secret、其它 owner 附件/HOME、共享 bot 凭证、lark-cli 密钥库均为 deny 或 deny-default;owner 工作目录与自有附件保持 allow。第三种布局中最终顺序明确为 ancestor allow 在前、密钥库与全部 session-stores deny 在后。

同步内容输入、bootstrap、transfer replay、控制 IPC 不读 registry 的定向用例也已复跑通过。未执行真实 macOS Seatbelt 内核或 live worker 端到端验证。

🤖 Generated with Claude Code

@deepcoldy

Copy link
Copy Markdown
Owner

你好,这个 PR 的自动评审群已建,麻烦点击链接加入群聊、查看评审意见并跟进后续修改:
https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=87cs4f52-23fe-45e1-ada3-e0dc83767d91

另外你暂时不在自动拉群名单里,也可以把 GitHub 账号和飞书信息补进名单文档,补好后后续评审会自动拉你进群:https://bytedance.larkoffice.com/wiki/WJ1nwWbtxi89erkNGNbcgkt9nUe

(本条为自动流程发出的提示消息)

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

审查基线:本地 rebase 后 5f799b85b。当前仍有 3 个跨 owner 隔离问题与 1 个配置缺陷,不建议合并。

P1-1|换主窗口内,B 的附件会先落进 A 的附件桶

位置:src/daemon.ts:31003-31007,后续准入拒绝发生在 src/daemon.ts:31962。

现有会话存在时,下载器无条件优先使用 ds.session.assistantOwnerOpenId,而附件下载早于 worker 准入检查。A→B 改绑后,只要退役尚未完成或消息处理器已捕获旧 ds,B 的文件就会写入 attachments/<appId>/u/<A>/<messageId>/;之后即使输入被拒绝并提示重发,文件已经持久化在 A 可读的桶中。

**真实路由探针:**以 A 的旧 chat-scope 会话开始,改绑 B 并让 close Promise 保持未完成,再由 B 发送文件调用真实 handleThreadReply。观察到 downloadResources 的 owner 参数为 A,随后日志才是 assistant-mode: refusing input;旧 worker 未收到 message,但 bucketOwners === [A]。

**建议:**任何下载或 prepared-attachments 交接之前重新解析当前 owner;旧 ds 归属已过期时先拒绝/退役并要求重发,不得先持久化附件。回归用例应同时断言“旧桶无写入”和“旧 worker 无输入”。

P1-2|queued activation 与冷启动 init 都绕过了双准入闸

位置:

  • src/core/worker-pool.ts:19320-19348:double-fork 分支在助理归属检查之前直接 admitQueuedActivationTail;src/core/worker-pool.ts:18802 的 protected-egress 排队入口同类。
  • src/daemon.ts:23327-23337:opening follower 也可直接写 tail。
  • src/core/worker-pool.ts:18230-18268:promotion 在持久化 journal 后直接 worker.send,没有按当前 owner 复核。
  • src/core/worker-pool.ts:20519-20528:standalone IPC bootstrap 等待结束后直接发送首个 init,也不经过 sendWorkerInput。

**可控时序探针 1:**当前 owner 从 A 改为 B 后,对照 decideAssistantAdmission 返回 {kind:'reject', have:A, expected:B};同一状态下调用真实 forkWorker 再触发 promotion,结果为 {queuedOwnerB:true, sentOwnerB:true},即 B 的输入进入 A 的 tail 并发给 A 的 worker。

**可控时序探针 2:**standalone fork 在 worker_ipc_probe 后暂停,改绑 owner 再发出 worker_ipc_ready;包含原 prompt 的 init 仍被发送(探针观测 initSent === true)。远端关闭准备存在 await,且关闭失败会保留 active row,因此“换主已发生、退役尚未完成”不是不可达状态。

**建议:**统一覆盖三层,而不是只补普通消息入口:① 所有 tail 写入前;② promotion 修改 journal 前及实际发送前;③ bootstrap/重试后的 init 与 message 实际投递前。归属不符时不能把输入留在旧会话 journal 中,需退役并提示重发。保留上述两条时序作为回归用例。

P1-3|慢速 bot-token 请求跨模式切换后仍返回 app 身份凭证

位置:src/core/dashboard-ipc-server.ts:4451-4473。

getTenantAccessToken() 之前检查了实时 assistantMode,但 await 之后只复核 session/binding,没有重新读取身份策略。legacy 会话在模式关闭时发起慢请求,等待期间开启助理模式,仍可在最后收到 tenant token。

**真实 HTTP 探针:**用受控 Promise 挂起 token lookup,请求开始后令 assistantMode=true,并将 legacy ds.worker 置空模拟 worker 已停;释放 lookup 后响应仍为 200,正文包含 credential:'late-bot-token'。现有 stillValidSession 不检查 worker,也不重跑 withholding,因此停止 worker 本身不能堵住这个响应。

**建议:**token 返回前重新读取实时 bot 配置,并重复完整的 withholding/assistant-owner 判定;任何一项不再满足都返回 403。补“lookup 挂起→开模式/换主→释放 lookup”的回归用例,并断言响应正文不含 token。

P2-1|assistantLarkBotIdentity: true 的文档承诺确实失效;不建议只删第一道 403 来修

位置:src/core/dashboard-ipc-server.ts:4432-4445、src/bot-registry.ts:4543-4544、src/adapters/cli/sandbox-mode.ts:128-137。

真实路由探针设置 assistantMode:true、assistantLarkBotIdentity:true 后,mode:'bot' 仍固定返回 403 lark_tool_bot_identity_withheld,与配置 hint 和中英文文档承诺不符。

需要精确限定“死开关”的含义:是文档所述的助理模式逃生阀失效,不宜仅凭 gate2 推断所有异常/历史状态下代码都绝对不可达。并且问题不止 gate1 的实时 assistantMode 条件:配置归一化会无条件把助理模式的 sandboxWithholdBotSecret 固化为 true,所以仅给 gate1 加例外,正常助理会话仍会被冻结标志挡住。

修法取向:

  • 推荐删除 assistantLarkBotIdentity knob、gate2、worker init 字段及文档/hint,与“沙盒不持任何 app 身份凭证”的隔离模型保持一致。
  • 若产品必须保留逃生阀,则需要把它定义为对 #3649 凭证模型的显式例外,区分“用户显式配置 withhold”与“assistantMode 隐含 withhold”,同时调整 live/frozen 两层判定并补真实配置归一化 + token 路由测试;只改 gate1 不足。

本地验证

  • bun run build:通过。
  • 13 个相关 vitest 文件:459 passed。
  • 上述探针均通过 bun scripts/fenced-run.ts -- bunx vitest ... 执行;失败输出即文中观测值。探针代码已移除,工作树保持干净。

@xu4wang

xu4wang commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

感谢 c6f22ca 的修复,评审里的 4 条(附件先于准入、排队/提升/首个 init 绕闸、慢 token 请求、删开关)都看过了,没有异议。

我这边在同一主题(换主时序)上又排查了一轮,在 c6f22ca 之后仍能复现下面几类「A 名下进来的输入落到 B 的会话 / 桶 / ask」的场景。补丁放在单独分支,没有推到本 PR 分支,要不要合、怎么合由你决定:

仍可复现的场景

# 场景 结果
1 消息在 dispatcher 队列里排着(前一条在下大附件),期间 /assistant owner 改给另一人 出队时按新主人解析,附件进新主人的桶、内容进新主人的会话
2 已有会话、对它发 /compact <说明> 这类原生斜杠命令(raw_input / inject_command 直送) 不经过 assistantLiveInputAdmission,直接写进 worker
3 还没有会话时下载附件期间换主 后面自动建会话按新主人建,把旧主人那条交给新主人
4 注册竞争失败后的两处改投、activeSessions.has 递归重入、级联期间暂存消息的回放 改投/回放都没带「这条按谁准备的」,到目标处按当前主人放行
5 旧主人会话里带超时的 botmux ask,会话退役后仍挂着 新主人的纯文字被当成它的答复;且它排在前面会挡住新主人自己的 ask
6 新话题入口在准备群背景/提示钩子期间换主;新话题里 /schedule 等预建会话的斜杠命令;冷启动 /goal 透传;/workflow run 都在建会话/执行命令前没核对到达时的主人
7 配对模式下种子消息在旧主人时到达、跟新主人时的追问配对 种子的文本与附件并进新主人的轮次
8 关掉 assistantMode 后仍在跑的会话(沙盒冻结了原主人) 附件改落共享桶,worker 读不到

补丁做法

不再逐条路径补,而是统一一个「到达时主人」:

  • im.message.receive_v1 一进来(排队、durable inbox 持久化之前)就把当时的主人记在事件上(__botmuxAssistantArrivalOwner),随消息带进 RoutingContext.assistantPreparedOwnerOpenId;PreparedThreadReply 也带上它。
  • 所有消费输入/建会话的点(斜杠命令、Saved Workflow、ask 答复、重下附件、改投、回放、新话题/自动建会话/冷启动透传建会话)之前比对「到达时主人」与当前主人,不同就拒收并提示重发(复用 worker.assistant.session_retired,并 markIngressAdmitted)。模式关闭(当前无主人)不算漂移。
  • sendWorkerSessionInput 对 raw_input / inject_command 复用你的 assistantLiveInputAdmission,bootstrap 等待之后再复核一次。
  • 挂着的 ask 先按其会话的 assistantOwnerOpenId 过滤再挑选。

验证

  • 新增 test/assistant-mode-owner-change-route.test.ts(走真实 handleThreadReply / handleNewTopic,15 条)和 assistant-mode-input-gate.test.ts 里 1 条 raw_input 用例;每条都做过变异验证:去掉对应检查后该用例变红。
  • npx tsc --noEmit -p . 通过。
  • 相关测试集(约 240 个文件)在 c6f22ca 与补丁上各跑一遍对比:两边失败的文件集合完全相同(12 个,都是本机环境相关的既有失败,例如 ipc-lark-tool-identity 的 5 条平台凭证用例),补丁没有引入新失败;其中 worker-traex-question-page.integration 并发跑时偶发多 1 条,单独重跑两边均为 1 failed。

没覆盖的

  • dispatcher 里「事件到达即记主人」这一步本身没有单测(路由测试是直接构造带戳的事件)。
  • 第 6 条里 /workflow run 的拒收没有单独用例,冷启动 /goal 透传里那道检查也只能靠前面的入口检查间接覆盖。

🤖 Generated with Claude Code

@xu4wang

xu4wang commented Nov 20, 2026

Copy link
Copy Markdown
Contributor Author

补充说明优先级:上面这些都是低概率的边角情况,仅供参考,不阻塞本 PR 合并。

私聊不存在换主;群里认领后只有管理员手动改派才会换主,而且要恰好落在某条消息排队、下载或改投的几秒窗口内,影响也只是那一条消息。c6f22ca26 已经保证换主后旧会话退役、后续输入不再进旧会话,主路径是够的。

补丁要合、要改,还是不管,都由你决定。如果想用更省事的兜底,可以只改一处:换主时丢弃该群还在排队的消息并提示重发,不必在每条路径上核对。

🤖 Generated with Claude Code

@deepcoldy
deepcoldy force-pushed the feat/assistant-mode-v2 branch from c6f22ca to 14a4015 Compare November 20, 2026 21:00

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

增量审查发现 3 个 P1 隔离问题与 1 个 P2 测试接线问题,当前 head 不宜 squash。以下均已在 14a401555 上用行为探针复现,临时探针已删除,工作树干净。

P1-1|assistant-only 时,macOS 最终 Seatbelt allow 会重新打开 lark-cli 密钥库

位置:src/adapters/cli/fs-policy.ts:1314(编译出口在 :1432-1437)。

sealLarkKeyStore = withholdSendCredential || assistantMode 已接入普通规则,但 finalDenyPaths 仍只由 withholdSendCredential 决定。assistantMode:true 且未显式设置 withhold 时,如果 mandatoryReadOnlyPaths 含 HOME 或 /,最终 ancestor allow 会出现在普通 keystore deny 之后,重新打开 master.key.file 与 appsecret 密文。

**探针:**构造 assistant-only、mandatoryReadOnlyPaths:['/Users/u'] 并调用真实 buildFsPolicy + compileToSeatbelt。最终 /Users/u allow 位于 16155,而 keystore deny 位于 12261;没有最终 deny 在 allow 之后,探针按预期失败。

修法:finalDenyPaths 与 sealLarkKeyStore 使用同一条件,并补 assistant-only 的编译后顺序断言:keystore deny 必须位于最终 ancestor allow 之后。

P1-2|no-transport 助理会话重新获得整个 bot 的 sessions.db

位置:src/adapters/cli/fs-policy.ts:1237-1256,尤其是 :1249。

前面的 !ctx.assistantMode 已禁止 session-store 授权,但 no-transport carve-out 又无条件加入 session-stores/<currentAppId> 的 readOnly。更深的 internal grant 覆盖 authority deny,使该目录(含其它 owner 的会话正文)重新可读。

探针:assistantMode:true + larkTransportEnabled:false 调用真实 buildFsPolicy,accessForPath(.../session-stores/cli_self/sessions.db) 实际为 readOnly,而隔离要求为 deny。

**修法:**no-transport carve-out 同样排除助理模式的 session-stores/<currentAppId>;保留其余合法的 routing/bin 等 carve-out。补 no-transport + assistant 的回归用例。

P1-3|non-ordinary IPC 与 transfer replay 仍可跨 owner 投递

位置:

  • src/core/worker-pool.ts:15511-15515:sendWorkerSessionInput 在 bootstrap 回调里直接 worker.send(annotated)。
  • src/core/worker-pool.ts:15927-15935:replacement worker 对非 ordinary 消息直接 replay。

**探针 1(raw_input + bootstrap):**A 的会话在 worker_ipc_probe 后排队 raw_input,改绑 B 再发 worker_ipc_ready。即使 init 路径已有闸,/model opus 的 raw_input 仍被发送。

**探针 2(真实 transferSession):**transfer 期间缓存 raw_input,目标 chat owner 为 B 后完成 detach/exit。replacement worker 仍收到 /model opus。

**修法:**在这两个实际投递边界复用 assistantLiveInputAdmission。注意 sendWorkerSessionInput 的既有轻量 guard 语义:不要给 term_action、display 控制等无内容 IPC 增加 registry 查询;应对 message / raw_input 等内容输入复核,ordinary tracked 消息继续走现有 ordinary 闸。保留上述两条时序回归。

P2-1|两个 function-harness scope 缺少新依赖,当前 CI 因此失败

位置:test/worker-managed-origin-contract.test.ts:66-72、test/ordinary-im-contract-delivery.test.ts:46-58。

新增 assistantLiveInputAdmission 是 sendOrdinaryImDeliveryAttempt 的自由变量,但两个 fixture scope 都未提供它:

  • ordinary-im-contract-delivery.test.ts:Vitest 29 个失败(CI test (1/4))。
  • worker-managed-origin-contract.test.ts:Vitest 6 个失败(CI test (4/4)),Bun 同样 6 个失败(bun-test (4/4))。
  • 错误统一为 TypeError: assistantLiveInputAdmission is not a function。

**已验证修法:**每个 fixture 提供非助理 getBot: () => ({ config: {} }),并用同一个 loadWorkerPoolFunction('assistantLiveInputAdmission', fixtureScope) 抽取真实闸函数。临时应用后分别得到 35/35 与 11/11 通过。直接注入 workerPool.assistantLiveInputAdmission 不够:它仍会读取真实 registry,并因测试 appId 未注册而失败。

已确认的结构与验证

  • range-diff:8 个 =、3 个 !,48 文件,diff --check 通过。
  • 本地 bun run build 通过;冲突/隔离相关 6 个 vitest 文件 1159 条通过。
  • CI run 44816421763 已结束:build、binary 与其余 shards 成功;test (1/4)、test (4/4)、bun-test (4/4) 及聚合 job 因上述夹具问题失败。

@deepcoldy
deepcoldy force-pushed the feat/assistant-mode-v2 branch from acaacde to 509ecd3 Compare November 21, 2026 00:19

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

同步增量审查结论:代码层面未发现新的语义共存问题,但当前 head 仍不能 squash,因为 CI 首跑未全绿。

零改写已独立确认

  • git range-diff 5d3d802489...acaacde67 83328b7a78...509ecd379:15/15 提交全部 =,没有 !。
  • git merge-tree --write-tree acaacde67 origin/master 重新计算的树为 a9d61624b0e1744db15a9a3afa74fd674db38be2,与 HEAD tree 完全相同,证明 rebase 没有静默改动。
  • 语义检查覆盖:worker-pool 投递闸与 Antigravity 生命周期改动、/stop 与 /cd//repo、worker.ts 的 USER_HOME/模板/stripRefreshToken、Session/init 字段,以及 function-harness 的新依赖键。

本地验证

  • bun run build:通过。
  • 5 个核心隔离文件:785 passed。
  • 全部 29 个助理相关文件:2032 passed。
  • 单独复跑 CI 失败文件 traex-auto-model.integration.test.ts:30/30 通过(约 469 秒)。因此这不是稳定回归,而是高负载下出现的时序失败。

CI 阻塞不是 #3674 的豁免形状

CI run 44843071008 的最终状态是:

  • build、darwin/glibc/musl binaries、其余 Vitest/Bun shards:test (3/4)、test (4/4) 等全部成功。
  • bun-test (1/4) 失败:test/traex-auto-model.integration.test.ts 的 keeps a successive input queued after the preceding write changes Working to capacity 在约 39 秒后出现 timeout: correction submitted;日志末尾为 structured-turn-unfinished。
  • 聚合 bun-test 因该 shard 失败而失败。

#3674 是 botmux-update-notify-delivery 的真实文件锁 ioUntil 等待,与这次 TraeX 集成用例不是同一测试或同一失败机制,不能套用“已知 #3674 偶发不重跑”的例外,也不应仅以同 SHA 重跑掩盖。需要把该 TraeX 等待问题作为独立的时序问题处理并同步出 CI 首跑全绿的新 head,之后再 squash。

本 PR 的 diff 未触碰该失败等待逻辑或该集成测试;本地同文件 30/30 通过。代码增量审查没有发现问题,但 G4 当前不满足。

xu4wang and others added 14 commits November 21, 2026 16:49
A bot anyone can DM shares one cwd, one CLI memory bucket and one sandbox
writable surface across all users. `assistantMode: true` turns it into
"everyone's own assistant": every session has exactly one owner (DM = sender,
/group session group = creator, regular group = whoever added the bot), and
cwd, CLAUDE_CONFIG_DIR, fs-policy grants, attachments and host-side read
commands are all narrowed to that owner.

- bots.json / /botconfig: assistantMode, assistantTemplateDir,
  assistantLarkBotIdentity
- core/assistant-mode.ts: open_id shape gate, USER_HOME/work/attachments
  paths, template overwrite-sync, refreshToken stripping, owner resolution
- services/assistant-owner-store.ts: <dataDir>/assistant-owners/<appId>.json
- im/lark/assistant-command.ts: pre-routing `/assistant status|claim|owner @x`
- daemon: resolveAssistantSpawn before all six createSession entry points,
  owner recorded on bot-added, owner-left → suspend + unclaimed notice,
  assistantWorkDir wins in resolvePinnedWorkingDir, no role-library schedules
- worker: fail-closed (needs oncall sandbox + BOT_HOME redirect, cwd must be
  owner's work/, template sync), CLI data dir = USER_HOME/claude with junk RT,
  fs ctx botHome = USER_HOME, no roleLibrarySubtree, per-owner attachmentsBucket
- worker-pool: re-resolve ownership at every fork; mismatch/none → refuse
- fs-policy: attachmentsBucket ctx; session-manager/attachment-path per-owner
  bucket; IPC role-switch and lark-tool bot identity → 403 for owned sessions;
  /cd /repo locked; botmux history/quoted/list scoped to the same owner
- docs: docs-site assistant-mode.md (zh/en), slash-commands rows,
  docs/file-sandbox.md section, design doc

Tests: assistant-mode (8), assistant-command (17), fs-policy (+4),
event-dispatcher (+1); mutation-checked; vitest + bun legs.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
- fs-policy: in assistant mode do not grant the bot-wide session-stores
  (sessions.db carries lastUserPrompt) nor this bot's lark-cli
  appsecret/master key (would let a user mint the tenant token and bypass
  the bot-identity gate); grant the real BOT_HOME send-cred.json read-only
- template sync never follows destination symlinks (unlink planted links,
  O_EXCL temp + rename)
- owner resolution: the owner store wins over the /group session-group
  creator, so a `left` record stops service there too; owner-left falls back
  to killWorker when suspend is refused
- owner changes (claim / admin rebind) and `/botconfig assistantMode on`
  retire mismatched live sessions; forkWorker retires a session it refuses
- bot-added owner recording runs before the autoStart gating
- `/assistant owner @x` reads raw mention `id.open_id`, ignores the bot itself
- thread-reply and quoted attachment downloads use the owner bucket
- CLI peer gate resolves the caller's own session via daemon IPC (fail-closed)

Co-Authored-By: Claude Fable 5.1 <[email protected]>
- fs-policy: send-cred.json (plaintext larkAppSecret) is not granted in
  assistant mode either; `botmux send` goes through the outbox relay and
  needs no credential. history/quoted/list are unavailable there (documented)
- worker: before provisioning, unlink owner-planted symlinks at the top of
  USER_HOME/claude and USER_HOME/codex; the credential copy is written
  O_NOFOLLOW + rename so the host never writes through a link into ~/.claude
- daemon: bot re-added by a different person retires the previous owner's
  live sessions (same path as claim/rebind); suspend refusal falls back to
  closeSession (works for non-suspendable backends) instead of killWorker;
  thread-reply attachments resolve the owner before download when no live
  session exists

Co-Authored-By: Claude Fable 5.1 <[email protected]>
- assistantMode 隐含 sandboxWithholdBotSecret:bot-registry 解析时补上该标志,
  sandboxWithholdsBotSecret() 也认 assistantMode(冻结、会议接收、工作流快照都走它)
- 于是助理会话的 send / history / quoted 都由宿主代执行:history 只读本会话,quoted 只读本会话
  所在群;quoted 附件在宿主落 relay-attachments/<appId>/u/<open_id>/ 再回传
- owner 的附件桶对沙盒只读、owner USER_HOME 与 outbox 在 macOS 上 pin 住(沿用开关的既有行为)
- 文档:history / quoted 不再标为不可用,list 仍不可用

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 新增 core/assistant-spawn.ts:resolveAssistantSpawn 从 daemon 挪出,定时任务、会议接收共用
- fork 子会话与干净恢复继承 assistantOwnerOpenId;新话题定时任务、冷启动会议接收按 chat 的主人建会话、
  cwd 固定在主人 work/,群未认领时拒绝(定时任务记为失败)
- 话题延续:旧会话主人不是当前主人时不复活,直接按当前主人新建(否则准入闸关掉后下一条又复活它)
- v3 工作流拒绝 assistantMode bot(工作流 worker 没有按主人的会话,会拿到整个 BOT_HOME)
- 决策看板 IPC 对带主人的会话回 403(看板按 bot 汇总,不按主人隔离)
- 助理模式退役会话改用 closeSessionForBackgroundCleanup 并登记到关闭点矩阵;未开助理模式时下载调用参数不变

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 工作流 worker 启动前按实时 bot 配置检查 assistantMode:暂停后才开模式的运行从存储的快照恢复,
  不经过快照生成那道检查
- 独立任务(cloneIndependentLaunchPosture)复制 assistantOwnerOpenId,否则子会话被准入闸拒掉、任务不执行

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 源会话已归属主人时不走按发言人分道(分道会话没有主人、cwd 是 worktree,会被准入闸拒掉、消息丢失)
- 工作流启动前的助理模式检查:本进程未注册该 bot(独立运行 / 其他 daemon 的 bot)时回落读 bots 配置

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 准入判定抽成 decideAssistantAdmission:还没跑过 CLI、未记主人的新会话直接认领给当前主人并把 cwd
  改到主人 work/,不再要求每条建会话路径(文档会话、headless、工作流节点投递等)各自填主人;
  开模式前跑过的存量会话、主人已变、群未认领仍拒绝并退役
- 看板任务、卡片点击、HTTP/webhook 触发器建会话时解析主人;群未认领直接拒绝(不建空会话);
  触发器在助理模式下不建 worktree

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 准入判定:会话沙盒形态已冻结但没冻结「不放 Bot 密钥」(开模式前冻结的)→ 拒绝并退役,不认领也不放行,
  否则这个会话的沙盒会缺少进程信息限制
- 退役会话时回一条提示(这条没处理、请重发),不再静默丢消息

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- sendWorkerInput:助理模式下,会话不归当前主人(开模式时没能退役的存量会话、主人已变)或没冻结「不放 Bot 密钥」
  → 拒收、提示重发、再尝试退役;退役被拒时后续输入照样拒收
- IPC lark-tool 凭证:bot 已开 assistantMode 时一律不给 bot 身份令牌,不只看会话冻结的标志

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- 在队列写入、promotion、bootstrap/IPC 实际投递前按实时 owner 复核
- 附件下载前退役失效会话,token 等待后重跑 withholding
- 删除无效的 assistantLarkBotIdentity 配置与文档
- 补充换主竞态回归及关闭点分类

Co-Authored-By: Claude Code <[email protected]>
- finalDenyPaths 与 sealLarkKeyStore 统一,no-transport 不再回授 sessions.db
- message/raw_input/inject_command 在同步及 bootstrap 投递前复核 owner,控制 IPC 不读 registry
- transfer replay 在实际发送前复核 owner
- 补齐两个 ordinary-delivery 夹具依赖及 Seatbelt/no-transport/时序回归

Co-Authored-By: Claude Code <[email protected]>
- finalDenyPaths 纳入助理会话库,保护 DB/WAL/SHM
- finalReadOnlyPaths 过滤真实 BOT_HOME 及其祖先授权,owner 子树不受影响
- 覆盖标准与外部 BOT_HOME 的 Seatbelt 编译顺序及变异验证

Co-Authored-By: Claude Code <[email protected]>
- finalReadOnlyPaths 统一过滤 bot homes、会话库、附件与配置秘密及其祖先
- finalDenyPaths 保护全部 session-stores 与 bots/dashboard 配置秘密
- 补齐外部 BOT_HOME 下其它应用、其它 owner 与配置秘密的编译后回归

Co-Authored-By: Claude Code <[email protected]>
- function-harness 按需加载 live/transfer 两级归属判定
- deployment-continuation 手写 scope 同样接入真实判定
- 覆盖 capacity、session-contract、ordinary delivery 与 deployment 双腿回归

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy
deepcoldy force-pushed the feat/assistant-mode-v2 branch from 509ecd3 to 0db8b42 Compare November 21, 2026 08:52

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

最终 rebase 增量复审 head 0db8b42083d4cd781e1b267c179bd79c147cb326:确认 15 个提交只是原样移动到含全部修复的新 master,没有夹带额外逻辑变化。

独立复算与验证:

  • git merge-tree --write-tree 1eb362ec5 509ecd3795 与 git rev-parse 0db8b4208^{tree} 完全一致,均为 4e092c2b6270b4b391ea3be3911c046e227050b5。
  • range-diff 中 13 个 =、2 个 !(第 8、11 提交)。两个 ! 的 hunk 均只涉及 worker-pool.ts import 行:cli-execution-mode 的既有导入上下文,以及 assistant admission import 的添加/替换;没有 admission 判定、调用参数或控制流变化。
  • 最终 diff 仍为 53 个文件,全部属于助理模式实现、文档和对应测试,没有夹带 TraeX、runner teardown 或其它 master 修复。
  • detached head 上运行归属闸、fs-policy、会话时序、附件换主、transfer replay、ordinary delivery、managed-origin、deployment 共 8 个测试文件:1037/1037 通过。

因此 rebase 增量没有新的代码阻塞。最终合入仍以 run 44886933638 的 attempt=1 全绿为准,不沿用旧 head、#3687 或 #3684 的绿灯。G9 macOS Seatbelt / live worker 验证继续保留为后续事项。

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

#3652 的最终 head 首跑门禁已满足:run 44886933638(attempt=1,0db8b42083d4cd781e1b267c179bd79c147cb326)全部 job 成功。

  • 四个 bun-test shard、四个 test shard 全部通过;
  • build、三个 binary job、聚合 test/bun-test 全部通过;
  • Sandbox network boundary / network-boundary 也为 SUCCESS。

结合 merge-tree / range-diff 的零逻辑变化确认、53 文件范围核对及 8 个相关测试文件 1037/1037 的验证,#3652 已具备按既定流程 squash 合入的条件。G9 macOS Seatbelt / live worker 验证继续作为后续事项,不以本次 CI 替代。

@deepcoldy
deepcoldy merged commit 98b3a8b into deepcoldy:master Nov 21, 2026
15 checks passed
@github-actions

Copy link
Copy Markdown

@xu4wang @deepcoldy 合入 master 后的 Midscene E2E 失败:Feishu live Midscene 失败。

这次运行覆盖 1eb362e…371ad146a(4 个提交),同批合入的还有 #3684 #3685 #3690,失败不一定由本 PR 引起。

用例 跑道 状态 失败信息
Claude group reply mode topic answers in topics that share one session feishu-core-group-modes failed Node "feishu.runScenario" timed out after 1800000ms.

@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.27

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