Repository navigation
feat(trigger): owner 续轮支持 actorUnionId,单人白名单默认识别主人 - #3954
Conversation
- 管理员名单只有一个人(所有条目都解析到同一人)且未显式指定主人时,默认此人为主人;多人名单仍需显式指定,否则 403 owner_unresolved - 新增 bots.json `ownerUnionId`(on_,须同时是 allowedUsers 条目),与 ownerOpenId 同时配置时必须是同一人 - `/api/trigger` 在 actor=owner 时接受可选 `actorUnionId`,不是该 bot 主人时 403 owner_mismatch;格式非法或缺 actor 时 400 - Dashboard 把带 actorUnionId 的请求转发到新的 `/api/trigger/owner-union`,旧 daemon 404 时返回 daemon_upgrade_required,不会静默忽略该字段 - 会话 turns 的 capabilities 新增 ownerUnionId Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
left a comment
There was a problem hiding this comment.
复审结论(head 680802f0)
发现 1 个需要修复的正确性问题,建议修复后再合入。除下述 core-only 边界外,未发现有待阻断的改动。
[P2] apiOnly bot 带 actorUnionId 时抛出 500,而不是受控拒绝
位置:src/core/trigger-session.ts:992(src/im/lark/client.ts:699 是异常冒泡点)。
当 core-only(apiOnly: true)bot 以单个字面 ou_ 条目配置 allowedUsers 时,getStrictOwnerOpenId 可以认定主人,ownerUnionIdVerdict 随后返回 lookup。refuseOtherUnionId 调用 resolveUnionIdFromOpenIdStrict,但后者在进入自己的 try 之前执行 getBotClient;core-only bot 因此抛出 LarkTransportDisabledError。该异常穿过 triggerSessionTurn,最终由 IPC 外层转成 500 trigger_failed,而不是契约内的 403 owner_unresolved。
已在围栏内用真实 triggerSessionTurn 复现:
{"outcome":"threw","name":"LarkTransportDisabledError","message":"Feishu transport is disabled for core-only bot local_pr3954_probe (attempted: getBotClient)"}同一请求去掉 actorUnionId 的对照组正常返回结构化错误,没有抛异常:
{"outcome":"control-returned","result":{"ok":false,"errorCode":"bad_request","error":"apiOnly bot requires an HTTP response mode (waitForFinalOutput or asyncReturnSessionId)"}}建议将 strict lookup 的 client 构造纳入异常分类,或在该调用边界显式接住 transport-disabled 并返回 owner_unresolved;同时补一条从 trigger 入口进入的 apiOnly + actorUnionId 回归用例,断言不抛出、不派发且返回受控 403。
本地验证
运行时为项目钉版 Bun 1.4.4:
bun run build:通过,含 typecheck、domain / dist / embedded-assets 审计。- PR 直接改动的 5 个测试文件:688 passed / 3 skipped。
- owner 身份恢复、turn CLI 身份、Webhook、bot 配置编辑/克隆等关联回归:255 passed。
git diff --check:通过;复审后工作区干净。
CI 状态核对
当前唯一代码测试红项仍是 bun-test (4/4) 的 test/loopback-fetch.test.ts 未处理 ECONNRESET,与开放的 #3287 现象一致;本 PR 未触碰该文件。其余 vitest 分片、build、三平台 bun-binary、network-boundary 均绿。该检查目前尚未重跑成功,合并闸仍需按项目流程处理。
在 union_id 查询边界仅将 LarkTransportDisabledError 转为 owner_unresolved,其它异常继续抛出。补充 typed、跨模块副本与未知异常的入口回归。 Co-Authored-By: Claude Code <[email protected]>
|
P2 修复已追加提交并推送: 修复内容
验证结果
|
Refs nwverse#17649 botmux answers 403 with {ok:false, errorCode:"owner_mismatch", error:"<words>"} (deepcoldy/botmux#3954): the node read the code from error, so a real refusal still looked like a stale token. It now reads errorCode, falling back to a bare code in error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
#109 合并树背书:可合(绑定 master
|
|
已合并,感谢贡献! 评审与验证小结
非阻断 follow-up(不影响本次合入)
本次为自动评审,最终以维护者审阅为准。欢迎继续贡献。 |
…on suggestions and worded owner refusals (#17691) Fixes #17649 Companion BotMux change: deepcoldy/botmux#3954 (`actorUnionId`, the `ownerUnionId` capability, 403 `owner_unresolved` / `owner_mismatch`). This PR works with any BotMux: without that change the node sends `actor: "owner"` alone, and before 3.59.23 it sends the plain external trigger. ## What changed and why #10770 sent every botmux turn as `actor: "owner"` whenever BotMux advertised `ownerActor`. Persona never said whose turn that was, and a BotMux owner refusal looked like an expired token. This PR makes the owner an explicit, hub-wide choice. - **Setting (manager, `server/internal/assistant/agents_display.go`, `agents_botmux_owner.go`).** Agents display settings gain `botmux_owner_union_id`, stored as `agents.botmux_owner_union_id` beside `show_botmux`. On save the value is trimmed and checked with `proto.ParseBotmuxOwnerUnionID` (`^on_[A-Za-z0-9_-]+$`, at most 128 bytes); `""` clears it, anything else is a 400, and only full access may save. A save hands the value to every computer online with `node.configure {"botmux_owner_union_id"}`; each push sends what is stored when it goes out, so the last of two quick saves wins. Every new connection also gets it through `nodeConnectCalls`. Another manager reads it through `agents.display.get`, and when that read fails the node is handed nothing, so a failed read can never clear the node's value. - **Suggestions, never silent (`node/hostbotmux_owner.go`, `GET /api/v1/agents/botmux-owner-candidates`).** The new read-only node method `botmux.owner_candidates` is registered through `nodeRPC`. It reads the bots.json BotMux loads (`BOTS_CONFIG`, else `~/.botmux/bots.json`, at most 8 MiB) and decodes only `ownerUnionId` and `allowedUsers`. It returns deduplicated `on_…` ids, the ids that are a bot's only person first. It never returns secrets, tokens, open_ids, e-mail addresses or the path, and it writes nothing. The manager asks every computer online, waits at most 3 s, merges the answers, and lets only full access read them. Nothing is saved by the suggestion. - **Sending (`node/hostbotmux.go`, `hostbotmux_turns.go`).** The node keeps the id in memory and hands it to the botmux host, including a host made later (`syncBotmuxOwner`). | Owner Union ID | capabilities | `/api/trigger` | composer | | --- | --- | --- | --- | | empty | any | external trigger, no `actor` | `botmux_external_trigger_reason: "owner_unset"` | | `on_…` | `ownerActor` + `ownerUnionId` | `actor: "owner"` + `actorUnionId` | — | | `on_…` | `ownerActor` only | `actor: "owner"` (no unknown field for that BotMux) | — | | any | neither | external trigger | `"upgrade"` (the existing 3.59.23+ notice) | - **Clear refusals (`node/sendsafe.go`, `apierr`, `devices/held.go`).** A 403 whose `errorCode` (or bare `error`) is `owner_…` is no longer treated as a stale token, so the node does not refresh the token or retry. It becomes `not_delivered` with `delivered: "none"` and a reason: `botmux_owner_unresolved`, `botmux_owner_mismatch`, or `botmux_owner_refused` for any other `owner_…` code. The hub words the reason in the viewer's language, in en / zh-Hans / ja, held messages included. A 403 without an owner code is still refreshed and retried once, as before. - **Session wire (`proto`).** `botmux_external_trigger_reason` is stored sparsely on `SessionHierarchy`, so `TestSessionFitsItsSizeClass` still holds. The hand-written encoder writes it (new `hierarchyWireLayout`), and the list key includes the reason, so a change is pushed. - **Web (`views/settings/BotmuxOwnerField.tsx`, lazy).** Under **Show botmux sessions in Agents** (only while it is on, and only from a hub that sends the field) there is a text field with Save and Clear, a format check before sending, and **Use suggestion**, which only fills the field. The words explain what the setting does and where to find the id. `AgentStatusLine` picks the composer line by reason. The decoded and raw botmux display and the botmux chip are unchanged and do not read the setting. - **Docs.** `docs/protocol/protocol.md` ("Agents display settings", "BotMux messages"), `docs/integrations/engines.md` ("botmux"), `docs/web/web.md` ("Shared botmux visibility"). The mock hub serves the setting and a made-up candidate for screenshots. ## Verification Run on Linux at `cb1803f804` (merged with `upstream/main` `8dfd576f87`), unless noted. - Go - `go build ./...` and `go vet` on `proto`, `transcript`, `node`, `assistant`, `assistantwire`, `apierr`, `devices`, `hub` and `i18n`: clean. - `go test -race -run 'TestBotmux|TestToolView' ./internal/node/`: ok. New tests: - `TestBotmuxOwnerUnsetSendsExternalTrigger` - `TestBotmuxOwnerUnionIDNeedsItsCapability` - `TestBotmuxOwnerRefusalIsClearAndNotRetried`: one POST, no token refresh; a plain 403 is still retried once. - `TestBotmuxTriggerAnswerCode` - `TestBotmuxOwnerConfigure` - `TestBotmuxOwnerCandidatesScan`: no secret, open_id, e-mail address or path in the answer, and the file is unchanged. - `TestBotmuxOwnerCandidatesMethod` - `TestBotmuxBotsPath` The #10770 owner tests were updated to set an owner id. - `go test -race -run 'TestBotmuxOwner|TestAgentsDisplay|TestAgyIdleCompact' ./internal/assistant/`: ok. New tests: - `TestBotmuxOwnerUnionIDSetting`: validation, roles, push to online computers only, clearing. - `TestBotmuxOwnerUnionIDOnConnect`: own value, shared value, and a failed read hands nothing. - `TestBotmuxOwnerCandidates`: merge, invalid ids dropped, older or offline nodes, full access only, nothing saved. - `go test -race ./internal/proto/ ./internal/transcript/`: ok, including `TestSessionWireMatchesReflect`, `TestSessionFitsItsSizeClass`, `TestSessionBotmuxExternalTriggerWire` and `TestParseBotmuxOwnerUnionID`. `go test -race -run 'Held|Localize|Bridge' ./internal/devices/ ./internal/apierr/`: ok. - `route_scopes`: `PERSONA_UPDATE_ROUTE_SCOPES=1` adds one row, `- GET /api/v1/agents/botmux-owner-candidates` (full credentials only). `TestRouteScopes` and the hub architecture guard pass. - Domain model: `go test ./internal/archguard/` gives the same rule lines on this branch and on clean `upstream/main` (`diff` empty, 28 lines). Its failures (`TestCentralListsTakeNoNewName`, `TestDomainHookScope`, `TestDomainLayers`) are pre-existing. The first version of this branch added a `handleMethod` case; that was moved to a `nodeRPC` registration. - Full packages `./internal/node/`, `./internal/assistant/` and `./internal/devices/` on this machine: 8, 20 and 4 failures. Rerun with the same `-run` on clean `upstream/main`, they are the identical sets (tmux/worktree/git-environment tests, prompt goldens). `./internal/i18n` `TestHardcodedChineseBaseline` fails on files this PR does not touch (`assistant/attachments.go`, `memory_entity.go`, `title_guard.go`, `extension/source.go`), which came from `upstream/main`. - Web - `npx tsc -b` and `npm run lint`: pass. - `npx vitest run src/views/settings/BotmuxOwnerField.test.tsx src/lib/agents-display.test.tsx src/views/chat/botmux-messages.test.tsx src/i18n`: 17 files, 98 tests passed. - Before the merge, `src/views/settings/` plus the botmux, agents-display, status-line and i18n suites: 172 of 173 files passed. The failure is `Labs.test.tsx`, which fails identically on clean `upstream/main`. - `npm run build` after the merge: `first screen en 485,034 B, ja 487,522 B, zh-Hans 486,044 B; 164 B left under FIRST_SCREEN_BUDGET (ja)`. The field and its words are in the lazy Settings chunk. Before the merge, the same build left 691–733 B against 152 B on `main`, so the first screen did not grow. - Repository checks - `git diff --check upstream/main..HEAD`: clean. - `python3 scripts/privacy_check.py` and `--range upstream/main..HEAD`: clean. - `python3 scripts/ci/wire_types_ratchet.py --base upstream/main`: none above the baseline (new ids are the named `proto.BotmuxOwnerUnionID`). - `test_doc_paths`, `test_doc_go_paths` and `test_doc_wire`: OK. - `test_doc_sections` fails only on `ExecutionChannelsCard.tsx` / `RuntimesCard.tsx` "Engines and channels", which is the same on clean `upstream/main`. - `web_font_ratchet.py` fails only on `web/src/views/session/files/empty.tsx`, the same on `upstream/main`; this PR adds no px font sizes. - `scripts/mock/test_mock_hub.py` fails only on the pre-existing `MOCK_BOT_GROUP`; this PR adds no `MOCK_*` switch. - Not run: the full web suite (`npm test`), Apple / Android / HarmonyOS / Desktop builds, hosted CI, and a live BotMux end to end (the BotMux side is the open #3954, so the 403 shape was checked against its diff). Screenshots are synthetic mock hub data, `vite preview` of this branch, 1280×900. Not taken at the largest text size. | | light | dark | | --- | --- | --- | | Suggestion found, nothing set |  |  | | Suggestion filled (not saved) |  |  | | Saved (Clear appears) |  | | | zh-Hans, and a value that is not a union_id |  |  (light) | ## Apple performance Not applicable (no `apple/` changes). ## Design principles self-check - [x] 1 Defaults first: with nothing set, BotMux messages go the usual way, and the composer says so in one line. Fresh installs behave as before for older BotMux. Evidence: `TestBotmuxOwnerUnsetSendsExternalTrigger` and the web notice test. - [x] 2 Progressive disclosure: the field appears only under **Show botmux sessions in Agents** while it is on, is lazy-loaded, and the first screen did not grow. Evidence: `BotmuxOwnerField.test.tsx` and the build output above. - [x] 3 User control: the value is visible, saved explicitly, and cleared with one button; a suggestion only fills the field. Evidence: `BotmuxOwnerField.test.tsx` and `TestBotmuxOwnerCandidates`. - [x] 4 Consistency first: reuses `Row`, `SettingsHint`, `settingsInputClass`, `Button`, the display-settings store and the existing composer notice line. No new component or token, so `DESIGN_SYSTEM.md` is unchanged. - [x] 5 Model and product separate: touches features only (who BotMux sends speak for). Speed, model and presentation are unaffected; decoding and the botmux chip do not read the setting. - [x] 6 Checkable: each acceptance item in #17649 is backed by the tests named above. - [x] 7 Fast, local-first and stateful: saving shows **Saving…** at once, and the answer is the hub's stored value. A failed save keeps the draft and shows the existing retry row. Owner refusals arrive with `delivered: "none"`, so they are safe to resend after fixing. - [x] Other platforms: not applicable here. iOS and Android do not read `botmux_external_trigger` today, and older clients keep the boolean. - [x] Parity list row updated: not applicable (no parity row for BotMux). UI change self-check (rules): - Only tokens and design-system components; the token and font ratchets did not go up for these files. - Existing styles are unchanged. - Every control has a spoken label (`aria-label` on the field; buttons have text), and the format error is an `alert`. - Clearing is reversible, since the value can be entered again, so there is no confirmation. - New copy is in en, zh-Hans and ja. - Screenshots are shown here in light and dark, not committed. Deviation: no largest-text-size capture. - No new problem of a kind listed in `HIG_AUDIT.md`. - Primary screens show no raw ids except the setting's own value. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
🚀 Released in v3.59.37 |
背景
#3599 让本机 Dashboard 管理员可以在
/api/trigger用actor: "owner"以 bot 主人身份续轮,但主人只认bots.json里显式配置的ownerOpenId。多数个人部署的 bot 的allowedUsers只有一个人(写的是on_或邮箱),没配ownerOpenId就全部 403owner_unresolved。另外,同一个人在不同飞书应用下的open_id各不相同,客户端没法用跨应用稳定的union_id说明「我要以这个人的身份发」,也没法在 owner 是别人时被拒。改了什么
主人认定(
getStrictOwnerOpenId,同步纯函数)ownerOpenId(ou_)或新增的ownerUnionId(on_)。ownerUnionId必须同时是allowedUsers条目,并经现有解析映射rawAllowedUserResolution落到本 app 的ou_。显式主人必须仍在解析后的管理员名单内,两者都配时必须是同一人,否则视为无法认定,不会退回默认。resolvedAllowedUsers去重后恰好 1 人),这个人就是主人。名单为空、多人,或有条目没解析出来(可能是另一个人)时,不认定主人,返回 403owner_unresolved。getOwnerOpenId保持「显式优先,否则取第一个ou_」的旧语义,只是显式来源多了ownerUnionId。这样lark-cli --as user的 owner fallback 和 owner actor 认的是同一个人。请求字段
actorUnionIdactor: "owner"一起出现,格式为on_…,否则 400bad_request。非管理员通道(公开只读 token、H5、平台身份、webhook)带了这个字段,就和actor/runAs一样返回 403actor_not_allowed。on_条目时直接比对映射;声明了ownerUnionId而请求值不同时直接拒绝;其余情况用本 app 凭证查主人的union_id(复用现有resolveUnionIdFromOpenIdStrict)来比对。不是主人一律 403owner_mismatch;查不到或暂时失败返回 403owner_unresolved。actorUnionId,同一个 key 换了身份声明会判为冲突。deliverToExisting会再复核一次主人,daemon 重启 / reattach 时的身份恢复(validateBeforeWrite)调用的也是同一个函数,所以中途改名单或改主人都会在发出前被拒。路由与能力宣告
actorUnionId的请求转发到新的 IPC 路由/api/trigger/owner-union(必须是宿主签名请求,并且必须带actorUnionId)。旧 daemon 没有这条路由会返回 404,Dashboard 转成 503daemon_upgrade_required。旧 daemon 的 validator 会原样放行未知字段,如果复用老路由,actorUnionId这道限制会被静默忽略、照样以主人身份发出。这里沿用了 feat(trigger): API 任务触发支持指定工作目录与按指定用户身份执行 #3746/api/trigger/host的做法。/api/trigger/owner和/api/trigger/host这两个受信端点也会校验actorUnionId。GET /api/sessions/:id/turns的capabilities改为["ownerActor", "ownerUnionId"]。ownerUnionId加进CLONE_IDENTITY_KEYS,克隆 bot 时不会带上源 bot 的主人声明。docs/session-turns.md、docs/lark-tool-identity.md、docs-site 中英文 bots.json 字段表、CHANGELOG。影响面评估
bot-registry.ts(getOwnerOpenId/getStrictOwnerOpenId)、core/trigger-session.ts、core/dashboard-ipc-server.ts、dashboard/trigger-api.ts、services/trigger-types.ts。trg_owner_*):单人名单的 bot 从拒绝变为放行。普通 trigger、runAs、webhook 都不受影响,这些路径的测试全部通过。getOwnerOpenId只有在 bot 新配置了ownerUnionId时结果才会变;没配新字段的 bot 结果不变(已有单测覆盖)。测试验证
本机(Linux)实测:
bun run build(含 tsc、typecheck、audit:domains、dist / 嵌入资源审计)[domain-audit] no private deployment hostnames foundgit diff --check upstream/master..HEADnpx vitest run --project unit test/owner-actor-strict-owner.test.ts(新增)npx vitest run --project unit test/trigger-session-root-message.test.tstest/trigger*、webhook-routes、plugin-webhook-routes、test-hygiene、session-turns、bot-config-editor、dashboard-clone-prefill、event-dispatcher、dashboard-ipc等 52 个文件)event-dispatcher.test.ts「为慢插件先 ACK 再更新原卡片」这条失败用例与本改动无关:它起一个慢插件子进程,靠 1000ms 挂钟截止来断言,对整机负载敏感。在不含本改动的
upstream/master临时 worktree 上,同一条用例同样是 3 次里 1 败 2 过,本分支也是 3 次里 1 败 2 过。本地 bun 为 1.3.11,比项目钉的 1.4.4 旧,构建时只告警、不拦截。上面的测试都通过 vitest 运行。
用例覆盖
on_/ 邮箱 / 字面ou_)默认识别主人;不带actorUnionId放行,带本人 union 也放行;他人 union 返回owner_mismatch,不派发。owner_unresolved,即使带的是名单里某个人自己的 union 也拒绝。显式ownerOpenId或ownerUnionId匹配时放行,他人返回owner_mismatch。ownerOpenId与ownerUnionId冲突时拒绝;ownerUnionId不在名单条目里时拒绝;格式非法的ownerUnionId被忽略。owner_mismatch;查不到或暂时失败返回owner_unresolved;查询期间名单变化时拒绝派发。/api/trigger/owner-union;公开只读 token / H5 / 平台身份带actorUnionId(不论有没有actor)一律 403;缺actor或格式非法返回 400;旧 daemon 404 时返回 503daemon_upgrade_required。/api/trigger/owner-union未签名请求 401;签名但不带actorUnionId返回 403actor_not_allowed;普通/api/trigger带 owner actor 返回 403。capabilities为["ownerActor", "ownerUnionId"]。变异复验:逐个摘掉新增守卫后跑对应测试,10 处全部变红。这 10 处是:单人判定的「全部条目解析到同一人」检查、「去重后恰好一人」检查、trigger 入口的 union 校验、声明了
ownerUnionId时直接判不匹配、显式主人冲突检查、IPC owner-union 必带字段检查、Dashboard 路由选择、validator 400 检查、非管理员通道的身份声明拦截、union 查询结果比对。对抗复核(持久身份语义)
尝试交给独立上下文复核,但没有成功执行,所以下面的探针由实现者自己完成。每项都用真实组件跑出了复现序列:
turnIdempotencyKey,第一次用主人 union,结果 ok;换成他人 union 重放,得到idempotency_conflict;同一 union 重放,得到idempotent: true。worker 总共只收到 1 次派发。owner_mismatch,0 次派发,key 没有被占用。ownerUnionId指定另一个人,结果owner_unresolved,0 次派发;只往单人名单里加一个人,同样owner_unresolved,0 次派发。getStrictOwnerOpenId,规则与触发时一致;名单在重启后变成多人时,恢复同样会被拒。🤖 Generated with Claude Code
配套客户端
Persona 侧:nwverse/persona#17691(设置「BotMux Owner Union ID」,探测到
ownerUnionId时随actor: "owner"携带actorUnionId,并把 403owner_unresolved/owner_mismatch原样转成清晰的拒收原因)。