Skip to content

fix(lark): 补齐文档评论轮的请求用户身份关联 - #2315

Merged
deepcoldy merged 4 commits into
deepcoldy:masterfrom
chengweiv5:fix/doc-comment-request-user-20261025
Oct 25, 2026
Merged

deepcoldy merged 4 commits into
deepcoldy:masterfrom
chengweiv5:fix/doc-comment-request-user-20261025

Conversation

@chengweiv5

@chengweiv5 chengweiv5 commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

改了什么

仅修复文档评论轮的请求用户身份关联,不修改授权策略、权限配置或其它功能。

  • 已合入身份切换上游 70abe2726(fix(auth): 修复排队与定时任务的执行身份切换 #2015)。保留上游 trustedCaller 三态判定:当前执行者优先,显式 null 不允许回退成评论作者或其它身份。
  • 将 currentGatewayCallerOpenId 抽为可直接测试的纯函数,并保留 worker-pool 原导出与调用点。仅旧 worker 未提供权威调用者时,按精确 turnId 从评论目标恢复作者;不借用 session/subscription owner 或其它轮作者。
  • 为非 adopt 的评论 live/refork 输入补齐当前作者的 trustedCaller,让最新 worker 从真实输入中冻结执行身份,而不是仅把作者展示给模型。保留 bot/user 类型,不将机器人标成真人;无作者、无 turnId 和 legacy adopt 输入保持无身份。
  • 存活 worker 的评论分支显式通过 sendWorkerInput 第四参数转发 cliInput.trustedCaller,保证身份到达真实 IPC,而不只停留在构建出的 payload 上。
  • 共新增 32 个回归用例,覆盖评论作者关联、排队轮身份隔离、上游 callerless 安全边界、执行者与评论落点分离、Codex/Claude 输入、live/refork/adopt,以及真实 daemon 到 worker IPC 和用户凭证接口的衔接。

为什么

原评论入口正确保存了作者,但请求者解析遗漏评论 per-turn 作者,lark-cli --as user 在读取既有授权前返回 No current requesting user; --as user requires their authorization(exit 77)。

上游 #2015 进一步以真实输入的 trustedCaller 冻结执行身份,缺少该字段会明确发布 trustedCaller:null。因此本次上游同步既保留显式 callerless 的安全边界,也补齐评论输入的身份传递,不能仅消除文本冲突。

影响范围

  • 仅评论输入的执行身份和请求者解析;不修改凭证接口、真人校验、应用隔离、授权策略或权限配置。
  • 普通消息、恢复、定时与只读续跑分支保留上游原逻辑;legacy adopt 行为不变。
  • 不修改 CLI 适配器、PTY/Tmux、sandbox 或 workflow 的生命周期实现。Linux 本机验证,覆盖 Codex 与 Claude 的输入构建,未声称全部 CLI/后端组合端到端验证,也未进行 macOS 真机验证。
  • 相对身份切换上游仅 8 个文件有差异:4 个源码、4 个测试文件。

最新上游版本的实际验证

评论反馈修复后的验证(8db9e6e5f)

  • 增加真实 daemon 边界回归后,修复前 4 个场景中 2 通过、2 失败,失败实际看到 worker IPC 缺少评论作者身份。
  • 修复后执行下列命令,13 个文件、810 个用例全部通过(Bun 1.4.3):
    timeout 300s bun run test test/daemon-rename-route.test.ts test/gateway-turn-caller.test.ts test/doc-comment-prompt.test.ts test/ipc-lark-tool-identity.test.ts test/session-lifecycle-start.test.ts test/identity-storage-model.test.ts test/active-turn-authority.test.ts test/turn-cli-identity.test.ts test/doc-comment-ask.test.ts test/reply-target-fallback.test.ts test/doc-comment-event-identity.test.ts test/doc-comment-daemon-concurrency.test.ts test/test-hygiene.test.ts
    bun run build
    git diff --check
  • 构建与产物审计、diff 检查通过;没有重新部署或重启。

上游同步时的验证(1bee62402)

  • 同步适配前:timeout 120s bun run test test/gateway-turn-caller.test.ts test/doc-comment-prompt.test.ts,32 个用例中 27 通过、5 失败;失败准确复现评论输入没有执行者身份。
  • 适配后,Bun 1.4.3:
    timeout 300s bun run test test/gateway-turn-caller.test.ts test/doc-comment-prompt.test.ts test/ipc-lark-tool-identity.test.ts test/session-lifecycle-start.test.ts test/identity-storage-model.test.ts test/active-turn-authority.test.ts test/turn-cli-identity.test.ts test/doc-comment-ask.test.ts test/reply-target-fallback.test.ts test/doc-comment-event-identity.test.ts test/doc-comment-daemon-concurrency.test.ts test/test-hygiene.test.ts
    12 个文件、637 个用例全部通过,包含上游执行身份/定时生命周期测试和测试规范检查。
  • 最终输入到凭证接口验证:timeout 120s bun run test test/ipc-lark-tool-identity.test.ts test/doc-comment-prompt.test.ts test/gateway-turn-caller.test.ts,78/78 通过。
  • bun run build:完整构建和产物审计通过;新增 gateway/comment 输入测试的独立 TypeScript 检查通过;git diff --check 通过。
  • 本次同步在独立 worktree 完成,未覆盖当前 live 构建,未重新部署或重启。

先前版本的 live 验证

初版修复 9d034f05a 曾执行 bun run switch:here && bun run daemon:restart;11 个 bot 和 Dashboard 在线。随后飞书评论实测及日志确认:lark-cli contact +search-user --as user 返回 ok:true、identity:user、exit 0,IAM 查询成功并回复原评论,未再出现 exit 77。

此 live 结果属于初版,不作为本次上游适配版本已部署的证明。本次上游适配以以上本地回归和构建结果为准。

验证环境说明

复用本机依赖视图,未在 worktree 执行 install,未修改 package.json/锁文件或主仓库共享依赖。原依赖视图缺少的 [email protected] 已隔离在初版 worktree 的本地依赖视图。

整个旧 IPC 测试文件的额外独立类型检查此前发现既存 SDK cache mock 类型错误,未扩大范围修复。实际 IPC 测试和项目完整构建通过。

@deepcoldy

Copy link
Copy Markdown
Owner

自动评审的初步意见(最终以维护者审阅为准):

整体方向正确,refork 路径与上游三态语义的保留都没问题,但 live worker 路径的执行身份没有真正送到 worker,这个 PR 要修的 exit 77 在常见场景下仍然会出现,需要补一处一行转发和一条守护测试。

P1:live 分支构建了 trustedCaller,但没转发到 worker IPC

src/daemon.ts:29306(文档评论、worker 存活分支):

if (!sendWorkerInput(ds, cliInput, turnId)) {

sendWorkerInput 构造发给 worker 的 message 时,trustedCaller 只取自第 4 个参数 opts.trustedCaller(src/core/worker-pool.ts:13127),不会从 payload(cliInput.trustedCaller)里拿。本 PR 在 buildDocCommentTurnInput 里给 live 输入补的 trustedCaller,在 live 分支因此被丢弃。

后果(上游 #2015 之后):

  1. worker 收到的 message 没有 trustedCaller,在轮次发布时按三态语义显式发布 trustedCaller: null(src/worker.ts:5093-5095);
  2. daemon 据此冻结 callerless origin;
  3. currentGatewayCallerOpenId 遇到 origin.trustedCaller === null 直接返回 undefined——本 PR 新增的 docCommentTargets 恢复分支永远走不到(你们自己的新用例 "preserves an explicit callerless execution even with a recorded comment author" 正好固化了这个提前返回)。

而 live 恰恰是主路径:doc-watch 会话会预热并长期存活,评论到达时 worker 通常是活的。refork 分支是好的(forkWorker 的 initTrustedCaller = promptPayload.trustedCaller,src/core/worker-pool.ts:14102)。

参照普通消息(daemon.ts:6136)、异步 ask 答复(daemon.ts:8733)、xpi(daemon.ts:21897)的既有写法,建议改为:

if (!sendWorkerInput(ds, cliInput, turnId,
  cliInput.trustedCaller ? { trustedCaller: cliInput.trustedCaller } : {})) {

我用 fake-worker harness 实测验证过:当前形状下 worker 收到的 message 无 trustedCaller 字段;改成上面的形状后字段正确到达,且无作者时保持不带身份。

P2:新增 IPC 用例的 fixture 形状与真实链路不符

test/ipc-lark-tool-identity.test.ts 新用例手动构造了:

session.managedTurnOrigin = { ..., trustedCaller: cliInput.trustedCaller ?? null, callerOpenId: ... }

这等于假设 daemon live 路径会把 cliInput.trustedCaller 发布成 origin——但如上所述它不会。这个用例因此在 live 路径实际损坏时依然全绿。建议补一条 daemon 边界测试:worker 存活时驱动评论 live 分支,断言 worker 实际收到的 IPC message.trustedCaller 是评论作者;并覆盖无作者 / adopt 输入不带身份。

其余观察(不阻断)

  • gateway-turn-caller.ts 的 docCommentTargets 恢复分支没有像 failedTurnRecovery / continuation 那样做 appId + senderType === 'user' 校验。考虑到该记录由 daemon 在本 app 会话内写入、且 IPC 凭证路由还会经 resolveVerifiedUserIdentity 复核,可以接受,建议加一行注释说明这一前提。
  • 预热轮(warmup)保持 callerless 符合设计,无需改动。
  • 本地已跑:bun run build、12 个相关测试文件 637/637 通过;新增两层的删除式变异均按预期变红。

@chengweiv5

Copy link
Copy Markdown
Contributor Author

已修复评论指出的 live worker 身份转发缺口。

  • handleDocCommentAdmitted 的 live 分支现在把 cliInput.trustedCaller 显式传给 sendWorkerInput 第四参数;不改变共享发送函数或上游 callerless 判定。
  • 新增 4 个 daemon 边界场景,直接驱动真实 handleDocComment / sendWorkerInput,检查 fake worker 实际收到的 message.trustedCaller:已识别作者、未知作者、legacy adopt,以及同会话不同轮作者切换。
  • 修复前定向执行:2 个场景通过、2 个失败,失败实际看到 IPC 的身份字段为 undefined;修复后 13 个相关测试文件、810 个用例全部通过。
  • 评论目标由当前应用 daemon 写入、凭证路由仍复核真人的前提已补注释。
  • bun run build、git diff --check 通过。未部署或重启;先前初版 live 结果不作为本次更新版已实测的证明。

验证命令(Bun 1.4.3):

timeout 300s bun run test test/daemon-rename-route.test.ts test/gateway-turn-caller.test.ts test/doc-comment-prompt.test.ts test/ipc-lark-tool-identity.test.ts test/session-lifecycle-start.test.ts test/identity-storage-model.test.ts test/active-turn-authority.test.ts test/turn-cli-identity.test.ts test/doc-comment-ask.test.ts test/reply-target-fallback.test.ts test/doc-comment-event-identity.test.ts test/doc-comment-daemon-concurrency.test.ts test/test-hygiene.test.ts
bun run build
git diff --check

@deepcoldy
deepcoldy merged commit f71291d into deepcoldy:master Oct 25, 2026
10 checks passed
@github-actions

Copy link
Copy Markdown

🚀 Released in v3.52.0

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