Skip to content

feat(webhook): 支持平台传递调用人身份并按轮隔离工具凭据 - #4055

Open
ACEVERYDAY wants to merge 6 commits into
deepcoldy:masterfrom
ACEVERYDAY:feat/webhook-user-identity
Open

ACEVERYDAY wants to merge 6 commits into
deepcoldy:masterfrom
ACEVERYDAY:feat/webhook-user-identity

Conversation

@ACEVERYDAY

Copy link
Copy Markdown

背景

多个用户通过同一个 Webhook 调用 Bot 时,连接器可以验证请求来源,但受管 CLI 还需要知道本轮应使用谁的权限。本变更让支持用户鉴权的平台把已验证的调用人传给机器,并将个人工具凭据限定在该用户发起的轮次。

改动与兼容性

  • 机器通过已绑定的平台隧道接收短时签名声明,核对机器、请求内容、有效期和一次性标识。连接器继续校验令牌或 HMAC,目标群或会话复用现有 runAs 权限检查。用户身份验证通过后,事件正文仍按连接器原有的信任规则处理。
  • 在启用 bytecloud 能力的 trigger-user 模式下,daemon 在派发前向绑定平台的 /v1/machine/webhook-tool-credential 兑换本轮凭据。bytedcli 和 Bits 使用调用人的凭据,Codebase 复用 Bot 的 gitTokenExchangeUrl 换票,Git 继续使用已有的 gitHost 配置。凭据过期或轮次结束时清理。
  • 遵循 feat(bytedcli): 支持混合执行身份、逐命令权限配置和插件权限预设 #3971 的严格模式边界。Bot 当前使用 read-machine-write-actor,或目标会话仍保留严格模式标记时,会在兑换前拒绝带工具凭据的轮次。派发后策略收紧时会重新核对,逐命令 broker 也会校验轮次,防止个人凭据绕过权限规则。
  • 既有连接器继续使用原投递入口。个人 JWT 会从交给 Agent 的请求头中移除,包括显式列入请求头白名单的情形。公开端仅依赖平台签名协议和 Bot 换票配置,部署方负责校验入口用户 JWT。

验证

  • 在 macOS 上运行 bun x vitest run test/webhook-tool-credential.test.ts test/webhook-routes.test.ts test/trigger-session-root-message.test.ts test/ipc-current-execution-route.test.ts test/bytedcli-broker-authority.test.ts -t 'webhook|Webhook|strict policy',5 个文件中选中的 54 项用例全部通过。覆盖调用人和轮次隔离、严格模式拒绝、换票中途策略变化,以及请求头过滤。
  • bun run build 和 bun run audit:domains 通过。两端用相同的合成测试向量核对签名协议。Linux 进程识别路径待上游 CI 验证。

webhook-user.ts 的 Ed25519 断言校验是整条调用人身份链的密码学入口,
此前只有 webhook-routes 的端到端向量覆盖合法签名与内容篡改,没有
伪造签名/异密钥等负向用例:把 verify 守卫短路后,webhook-routes
41 项仍全绿(变异存活)。

新增 test/webhook-user.test.ts 11 例,直接钉住:合法签名断言的声明
解析、伪造签名、异平台密钥、aud 不匹配、过期与超长 exp、畸形三段式/
错误 header/超长/非字符串、非法 email 与 jti、method/target/路由头/
body 的摘要绑定、无注册密钥与畸形注册 fail-closed、connection 级
清理隔离、credential 标志缺省。

变异复验:短路 verify 后本文件 2 个签名用例咬红(2 failed / 9 passed),
恢复后 11/11 通过;与 webhook-routes 合计 52/52。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@deepcoldy

Copy link
Copy Markdown
Owner

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

已先同步最新 origin/master(e2cf6d3696)并在本地把本 PR 单提交 rebase 到最新主干复核:无冲突,diff 相对最新主干不变。rebase 仅在本地评审 worktree 进行,未 force-push、未改写本 PR 已有提交。

结论:未发现 P0/P1/P2 阻断问题,信任链完整且各失败路径闭合,进入独立复审。

复核过的关键链路:

  • 入口与传输边界:/__botmux/webhook-user/v1/... 仅接受平台隧道桥接的 loopback 对端(isPlatformTunnelPeer 按桥接 TCP 连接的源端口登记,连接关闭即注销),非隧道直连一律 403;连接器自身的 token/HMAC 校验仍在用户断言校验之前执行。Ed25519 验签公钥只来自已认证控制通道的 registered 消息且校验 machineId 匹配;未注册或注册畸形时绑定为空,验签 fail-closed。
  • 断言协议:固定 header {"alg":"EdDSA","typ":"botmux-webhook+jwt"};签名覆盖 header.payload;claims 校验 aud=机器、exp 为安全整数且硬过期、有效期窗口 ≤35s、sub 邮箱格式、jti 恰为 22 字符,并把 method、target(含 query)、12 个路由头与 body 的 SHA-256 摘要绑定进 request。jti 经 claimNonce 一次性消费,重放返回 409。
  • 身份解析边界:dashboard 验签后把 verified email 经可信主机 IPC 跳(/api/trigger/webhook-user,isTrustedHostIpcRequest)传给 daemon,并在代理体里用该 email 覆盖 runAs;daemon 的 resolveRunAs 用本 bot 应用把邮箱解析为同 app 的 openId/unionId 并实时 canOperate 校验目标群,不存在跨应用复制 ou_。原始事件 payload 仍按不可信外部事件构造 prompt(envelope.trusted=false),断言头与 rpc-persist-jwt-token 不会进入请求体、审计日志或连接器头白名单(pickAllowedHeaders 无条件跳过该头)。
  • 按轮凭据隔离:凭据轮 ID 为 trg_runas_webhook_<uuid>(复用 trg_runas_ 前缀的 runAs 严格 marker 失效逻辑);daemon 用 machine token 向平台 /v1/machine/webhook-tool-credential 兑换(仅 https,loopback http 例外,4s 超时,校验 JWT 形状与过期),凭据存于按 turnId 的内存 Map,到期定时器清理;worker turn_terminal 处理在当前 attempt 终态撤销凭据与 Git 快照锚点(陈旧 dispatchAttempt 终态不触发)。
  • 逐命令授权:/api/current-execution-identity 的 webhook 分支要求谱系证明、turnId===identityTurnId、无 BOTMUX_AS、bytecloud 能力开启;异步 Codebase 换票前后两次用 executionStillCurrent 复检 worker 代际/轮次 origin/策略与 canOperate(app, chat, callerOpenId, unionId),换票 URL 中途变化即 403;strict export 围栏在渲染后再查一次。既有 bytedcli-broker-authority 显式拒绝 webhook 轮,机器/存量授权 broker 不能为本轮兜底。
  • Git 路径:新增 --git-webhook-turn 分类:注册后台任务、或谱系证明 Git 调用属于派发前已存在的普通任务祖先时返回 legacy(沿用原 gitHost/askpass 凭据);当前 webhook 轮返回本轮 ID,git wrapper 才挂专用 host-scoped helper。证明失败时导出 trg_runas_webhook_unverified,helper 取不到票即输出 quit=true,普通 askpass 脚本也加了同前缀守卫;仓库内用真实 git credential fill 的 shell 集成测试覆盖了后台任务、跨轮身份不匹配、host 大小写/端口归一、其他 host 不串票等场景。
  • 幂等身份隔离:webhook-idempotency 条目记录 userEmail,同 key+body 但身份不同的重试拿不到 firstTriggerId,in-flight waiter 的 ran 结果也按邮箱剥离 triggerId,避免一个身份的轮次 ID 泄露给另一个身份的投递。
  • 生效条件:仅当 triggerUserAuth.enabled 且 bytecloud 能力开启、bytecloudExecution=trigger-user、会话为 proven 身份模型且 Linux loopback 谱系可用时,受管 bytedcli/Bits/Codebase 命令才使用本轮个人凭据;read-machine-write-actor 严格模式或会话残留严格标记时,在兑换前即返回 webhook_tool_credential_unavailable(HTTP 503)。单快照模型下 wrapper 与 publishToolIdentity 对 webhook 轮明确拒绝并给出引导。

我追加的测试提交 f3298ebe

首审变异复验发现:src/platform/webhook-user.ts 的 Ed25519 验签门没有专属负向测试——把 verify(...) 守卫短路后,原有 test/webhook-routes.test.ts 41 项全部通过(签名伪造无牙)。因此追加 test/webhook-user.test.ts(11 例,纯行为测试),覆盖伪造签名、异密钥、aud 不符、过期/超长 exp、畸形 token/错误 header/超长/非字符串、非法 email/jti、method/target/路由头/body 摘要绑定、无注册密钥与畸形注册 fail-closed、connection 级清理隔离、credential 标志缺省。同一变异下新文件 2 个签名用例咬红(2 failed / 9 passed),恢复后 11/11 通过。该提交为纯测试新增,基于本 PR 原 head 59ba97c 快进推送,未改动作者任何提交。

本地验证

  • bun install --frozen-lockfile(本 PR 专属 worktree 独立 node_modules,未软链其他 checkout)
  • bun run typecheck(tsc -p tsconfig.typecheck.json)通过
  • 改动及直接相关的 12 个测试文件:762/762 通过(vitest run,--maxWorkers=4)
  • 新增 test/webhook-user.test.ts:11/11;与 webhook-routes 合计 52/52
  • 变异复验:签名守卫短路 → 新测试 2 项咬红;恢复 → 全绿

待 CI 与平台侧

  • 本 PR 来自外部 fork,pull_request 工作流首次运行处于 action_required(需维护者批准);Linux 进程谱系/peer scan 路径作者仅在 macOS 验证,最终以 CI Linux 全量结果为准。
  • 平台侧签名协议的两端合成向量一致性由作者说明已核对;本机未含平台实现,未做跨服务联调。

@deepcoldy

Copy link
Copy Markdown
Owner

你好,这个 PR 的自动评审群已建,麻烦点击链接加入群聊、查看评审意见并跟进后续修改:
https://applink.larkoffice.com/client/chat/chatter/add_by_link?link_token=e1bn5b99-9a98-4bab-8fcc-803b065a46e9

另外你暂时不在自动拉群名单里,也可以把 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.

复审结论:要求修改(1 项测试可靠性阻断)

[P2] 伪造签名用例可能只改变 Base64URL 填充位,并未改变签名字节

位置:test/webhook-user.test.ts:75-79,失败断言在 test/webhook-user.test.ts:107-110。

Ed25519 的 64 字节签名编码为 Base64URL 后,末字符只有高 2 位参与解码。当前变异在原末字符为 A 时将其改成 B;A / B 的解码字节相同,所以该用例约 1/4 概率没有把签名改坏。在 Node 下它会误通过,在 Bun 下则直接暴露为随机失败。

在当前 head f3298ebe38a51b507feb895393c8ed6eb9134458、Linux、Bun 1.4.4 实测:

$ bun test test/webhook-user.test.ts
10 pass
1 fail
verifyWebhookUserProof (platform Ed25519 assertion gate) > rejects a forged signature even when every claim and the request digest are valid

另用真实 Ed25519 签名做了最小探针:选取末字符为 A 的签名并替换为 B,结果为 sameBytes: true、originalVerified: true、mutatedVerified: true。这证明问题在测试变异方式,不是验签守卫接受了不同的签名。该文件会被 Bun 测试选择器纳入 bun-test (2/4),因此当前形态会让 CI 随机失败。

建议先解码、翻转一个真实签名字节,再重新编码,例如:

const signatureBytes = Buffer.from(signature, 'base64url');
signatureBytes[0] = signatureBytes[0]! ^ 1;
signature = signatureBytes.toString('base64url');

这样每次都会改变参与 Ed25519 校验的字节,同时保留合法的三段式与 Base64URL 外形。

除这项新增测试问题外,本轮未发现生产路径的新阻断:平台密钥注册、请求摘要绑定与 nonce、可信 IPC 的 runAs 覆盖、按轮凭据兑换/复检/撤销,以及 Git 的 legacy / 当前轮 / 证明失败分类均已复核。

其余验证结果:

  • bun run typecheck:通过。
  • 本 PR 改动的 13 个测试文件经 Vitest:773/773 通过。
  • git diff --check 44a1554a43...HEAD && bun run build:通过。
  • bun test test/webhook-user.test.ts:如上,存在可复现失败;需修复后再判定可合。

复审 review 6110642345 指出:Ed25519 签名 64 字节编码为 86 字符
base64url,末字符只有高 2 位参与解码;原变异把末字符 A 换成 B,
A/B 解码出的字节相同,约 1/4 概率没有真正改坏签名,导致 bun test
随机失败(本机 Bun 1.4.4 对缺陷版本连跑 12 轮有 5 轮 10 pass/1 fail;
2000 个签名探针实测末字符 A 占 520、A→B 字节相同率 26%)。

改为先 Buffer.from(signature,'base64url') 解码,翻转首字节最低位
(XOR 0x01)后重新编码,确定性破坏签名字节。

验证:修复后 bun test test/webhook-user.test.ts 连跑 12 轮均
11 pass/0 fail;vitest(Node)11/11;对 src/platform/webhook-user.ts
验签守卫短路的变异下,本文件仍恰有「伪造签名」「异密钥」2 例咬红;
bun run typecheck 通过;git diff --check 干净。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@deepcoldy

Copy link
Copy Markdown
Owner

针对复审 review 6110642345 的 P2(新增签名测试的末字符变异约 1/4 概率没有真正改变签名字节),已修复并推送到新 head edff4349d8(在我上一个测试提交 f3298ebe 之上快进,未改写作者任何提交;两个追加提交均只动测试文件)。

独立复现,确认问题成立

  • 机制探针:对 2000 个 Ed25519 签名(64 字节 → 86 字符 base64url)统计末字符,A/Q/g/w 各约 1/4;原变异「末字符为 A 时改成 B」在 520/2000(26%)样本上解码出的签名字节与原签名完全相同——末字符的 6-bit 索引只有高 2 位参与最后一个签名字节,A(索引 0) 与 B(索引 1) 的差异落在不参与解码的低 4 位。
  • 测试级复现:在缺陷版本上用 Bun 1.4.4 跑 bun test test/webhook-user.test.ts(经仓库 bunfig.toml 的 fence preload)连跑 12 轮,其中 5 轮结果为 10 pass / 1 fail,失败用例正是 rejects a forged signature even when every claim and the request digest are valid。

修复方式

test/webhook-user.test.ts 的 mutateSignature 改为先 Buffer.from(signature, 'base64url') 解码,翻转签名首字节最低位(signatureBytes[0] ^= 0x01)后再 toString('base64url')。任何一个签名字节改变都会使 Ed25519 验签失败,变异不再有概率空转。

修复后验证

  • bun test test/webhook-user.test.ts 连跑 12 轮:每轮均 11 pass / 0 fail,失败轮数 0/12。
  • Vitest(Node)test/webhook-user.test.ts:11/11 通过。
  • 变异有效性复验:把 src/platform/webhook-user.ts 的 verify(...) 守卫短路后,该文件仍恰有「伪造签名」「异平台密钥」2 个用例咬红(2 failed / 9 passed);还原源码后 11/11 全绿。
  • bun run typecheck 通过;git diff --check 干净。

复审补充核对的后台任务 Git 分类边界(registerScheduledBackgroundExecution 只接受 schedule:<taskId>:<uuid> 且持久任务 authority、运行身份、callerOpenId 全部匹配;trg_runas_webhook_* 无法通过 parseScheduledTurnId;已注册任务仍须通过实际进程祖先证明)与首审链路核实一致,该分类没有新增权限绕过。

请对新 head edff4349d8 复审。fork PR 的 CI workflow 首次运行仍需维护者批准;批准后 bun-test 分片会跑到本文件,以 CI 结果为准。

@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 均为 edff4349d8aa597ad78477c751581f421b4f13b7。相对上一轮 f3298ebe,本提交只修改 test/webhook-user.test.ts,没有生产代码漂移。

修复方式成立:先解码签名,再翻转首字节最低位并重新进行 Base64URL 编码。这样每次都会改变实际交给 Ed25519 校验的签名字节,不再受末字符填充位影响;断言的三段式和 Base64URL 外形仍保持合法。上一轮指出的概率性空转已消除。

本地独立验证:

  • bun test test/webhook-user.test.ts 连跑 12 轮:每轮均 11 pass / 0 fail。
  • bunx vitest run test/webhook-user.test.ts --maxWorkers=1:11/11 通过。
  • bun run typecheck:通过。
  • git diff --check f3298ebe38..HEAD:通过。
  • 临时短路 src/platform/webhook-user.ts 的验签守卫后,Bun 下恰好“伪造签名”和“异平台密钥”两例咬红,结果为 2 failed / 9 passed;还原源码后恢复 11/11,工作区干净。

本轮未发现新的 P0/P1/P2 问题,上一轮测试可靠性阻断已解除。

流程备注:外部 fork 的首跑工作流仍需完成维护者审批,且所有必需检查全绿后才满足合入门禁;本结论针对当前 head 的代码与测试内容。

@github-actions
github-actions Bot requested a review from deepcoldy November 30, 2026 11:20
CI run 46402612811 四个失败分片(test 1/4、bun-test 1/2/4)的根因
均为本次 PR 的测试接线缺口,无其他真实失败:

1. test/helpers/worker-pool-message-harness.ts 从 worker-pool.ts 切出
   turn_terminal 等 case 子句在 with(scope) 中执行,PR 新增的
   clearWebhookToolCredential / forgetWebhookGitPreDispatchProcesses
   模块导入不在切片作用域内,导致 failed-queued-turn-reply-card
   (vitest 6 例 / bun 6 例)与 merged-turn-reply-card(vitest 7 例 /
   bun 7 例)全部 ReferenceError。按 harness 既有约定注入两个真实导出。

2. close-consumer-matrix 的 CONSUMERS 键按 AST 扫描的
   file::enclosingFunction::symbol 登记:PR 把原
   triggerSessionTurnAdmitted 大函数体改名为 dispatchSessionTurn
   (新薄包装沿用旧名承载 webhook 凭据逻辑),其中 4 个
   closeSessionForBackgroundCleanup 调用点随改名迁移,旧键变为
   stale、新键 dispatchSessionTurn 未分类。将矩阵键更新为
   core/trigger-session.ts::dispatchSessionTurn::closeSessionForBackgroundCleanup,
   category/count(4)/why 不变。

验证:vitest 跑 close-consumer-matrix + 两个 reply-card 文件共 55 例
全绿(含矩阵 classified/count/stale 全部 15 例);bun 同三文件复核中。
git diff --check 干净。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@deepcoldy

Copy link
Copy Markdown
Owner

CI 四个失败分片的测试适配修复已推送:新 head 1bfbca593a(在 edff4349d8 之上快进;本提交仅改 2 个测试/测试辅助文件,生产代码无变化)。

核对 run 46402612811 的 test (1/4) 与 bun-test (1/2/4) 失败日志,根因只有两处,均为本 PR 新增生产接线后测试侧未同步,四个分片没有其他真实失败:

  1. test/helpers/worker-pool-message-harness.ts:该 harness 把 src/core/worker-pool.ts 的 case 子句切出后在 with(scope) 中执行,worker-pool 的模块级导入不在切片作用域。本 PR 在 turn_terminal 分支新增的 clearWebhookToolCredential / forgetWebhookGitPreDispatchProcesses 调用未注入 scope,导致 test/failed-queued-turn-reply-card.test.ts(vitest 6 例、bun 6 例)与 test/merged-turn-reply-card.test.ts(vitest 7 例、bun 7 例)全部报 ReferenceError: clearWebhookToolCredential is not defined。按 harness 既有约定注入这两个真实导出;二者对未知 turnId 或无快照状态的 session 都是安全 no-op。

  2. test/close-consumer-matrix.test.ts:矩阵键按 AST 扫描的 file::enclosingFunction::symbol 登记。本 PR 把原 triggerSessionTurnAdmitted 大函数体改名为 dispatchSessionTurn(新的薄包装沿用旧名承载 webhook 凭据派发逻辑),其中 4 个 closeSessionForBackgroundCleanup 调用点随函数改名迁移,使旧键变为 stale、新键 core/trigger-session.ts::dispatchSessionTurn::closeSessionForBackgroundCleanup 未分类(bun-test 2/4 的矩阵 2 个用例失败,vitest 对应分片同样会命中)。已将 CONSUMERS 键更新为新键,category: 'background'、count: 4 与 why 说明保持不变。

修复后本地双引擎验证:

  • Vitest(Node):vitest run test/close-consumer-matrix.test.ts test/failed-queued-turn-reply-card.test.ts test/merged-turn-reply-card.test.ts → 3 文件 55/55 通过(矩阵 15 例含 classified / exact-count / stale 全部通过;两个 reply-card 文件各 20 例)。
  • Bun 1.4.4(经仓库 bunfig fence preload):同三文件分别 15 pass / 0 fail、20 pass / 0 fail、20 pass / 0 fail。
  • bun run typecheck 通过;git diff --check 干净。

新 head 的外部 fork workflow 已重新批准(CI run 46440333723、Sandbox network-boundary run 46440333759),合码门禁以新 head 全量分片首跑结果为准。本次增量纯属测试适配,不涉及业务语义取舍。

@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 均为 1bfbca593a11b896a6ac03a55d2863626e6f59c5。相对已通过的 edff4349d8,增量只修改两个测试文件,生产代码没有漂移。

两处适配均成立:

  1. test/helpers/worker-pool-message-harness.ts 注入的是 src/core/webhook-tool-credential.ts 的两个真实导出,并保留调用方已提供的 scope 实现;没有用空桩掩盖 turn_terminal 行为。对普通未知 turnId、没有快照的 session,这两个函数本身即为安全 no-op,而 webhook 轮仍能执行真实清理。
  2. test/close-consumer-matrix.test.ts 的新键与 AST 的实际 enclosing function 一致:dispatchSessionTurn 直接包含 4 个调用点;另一个 reuseExistingWinner 内嵌调用仍由原有独立键覆盖。category=background、count=4 和 why 的语义没有放宽,旧 stale 键也已移除。

本地验证:

  • bunx vitest run test/close-consumer-matrix.test.ts test/failed-queued-turn-reply-card.test.ts test/merged-turn-reply-card.test.ts --maxWorkers=1:3 个文件、55/55 通过。
  • Bun 1.4.4 分别复跑上述三个文件:15/15、20/20、20/20,全部通过。
  • bun run typecheck:通过。
  • git diff --check edff4349d8..HEAD:通过,工作区干净。

本机高负载并行首轮曾触发未改动的 60ms 固定等待和 Bun 默认 5 秒矩阵扫描超时;延长等待/超时的诊断探针均通过,随后按原配置串行复跑也全部通过,探针改动已还原。这两处不是本次增量引入的行为回归。

本轮未发现新的 P0/P1/P2 问题。合入仍以当前 head 的所有必需 CI 检查全绿为准。

@deepcoldy

Copy link
Copy Markdown
Owner

G7 合并树复核:可合(按 #109 例外)

复核输入为 master=eb446991ddc2186bb980c8495d649e23bbb76f99、PR head=1bfbca593a11b896a6ac03a55d2863626e6f59c5。GraphQL 回读远端 master 仍为上述提交。

独立重算结果:

  • merge-base 为 44a1554a4388c42d973a1889d3333d93c0f2359b。
  • git merge-tree --write-tree eb446991dd 1bfbca593a 退出 0、无冲突,结果确为 60baf984dc4a02d69bd81f2d9d854801266b7027。
  • 验证提交 9dafd17318d82019da9d39d7f1cda0fb74f53432 的 HEAD^{tree} 与该 OID 一致,父提交为 PR head 与上述 master。
  • 整段 delta 的文件交集只有 src/core/dashboard-ipc-server.ts。合并后该文件 16056 行;会话历史结构化 import / 薄路由与本 PR 的 import、current-execution、trigger IPC 区段均不相邻,且路由方法与路径没有语义交叠。
  • 分别比较两侧文件清单:merge 结果相对 master 恰好只增加 PR 的文件 delta,相对 PR 恰好只增加 master 的文件 delta,没有额外或丢失文件。
  • 两个方向的 git diff --check 均通过。

在同一验证检出 /tmp/pr4055-merge-verify 上独立执行:

  • bun run --cwd /tmp/pr4055-merge-verify build:通过,包含 tsc、typecheck、dashboard 打包和产物审计。
  • close-consumer-matrix、failed-queued-turn-reply-card、merged-turn-reply-card、webhook-tool-credential、session-history-pagination、card-json-export:83/83 通过。
  • 另行覆盖 webhook-user:11/11 通过。原先 90/90 的计数对应 webhook-user(11 例),而不是 webhook-tool-credential(4 例);前五者中的其余五个文件合计 79 例,因此该口径同样为 90/90。两份相关文件都纳入后,共 7 个文件、94/94 通过。
  • 构建与测试后检出的 HEAD^{tree} 仍为上述预测 tree,工作区无 tracked 改动。

结论:这棵合并树满足本处文件交集的 #109 验证条件,无需仅因该交集改为同步 master 重跑。实际合入仍以 PR head 1bfbca593a 的必需 CI 首跑全绿为准;若 master 在合入前继续前进,应对新 master 重新执行 G7。

…ldy#4082 CI speedup)

Conflict resolution combining PR deepcoldy#4055 webhook per-turn git credentials
with master's deepcoldy#4040 mixed-mode push authorization in renderGitCommitWrapper:
- unified signature (realGit, resolver, webhook?, refusePush, pushClient?)
  and a single run_git choke point; the needs_actor dispatch preserves
  deepcoldy#4040's push restriction/exit-2 pushClient while passthrough and
  attributed commits route through run_git so deepcoldy#4055's marker classification
  still applies; webhook and strictBroker modes are mutually exclusive.
- prepareTriggerUserCliEnv installs the git wrapper when any of
  gitResolver/webhookGitHost/strictBroker is active and wires both the
  webhook credential helper and the strict pushClient.
- test/bytedcli-broker-authority.test.ts keeps both new authority tests;
  test/bytedcli-strict-runtime.test.ts call adapted to the unified signature.

Local verification on the merged tree: typecheck pass; conflict-adjacent
suites 325/337 with the only 12 failures being deepcoldy#4040 git-push-adversarial/
git-push-host real-process tests that fail identically on clean master
af916a9 in this shared host environment (environmental; GitHub CI is gate);
bytedcli-strict-runtime 7/7 after the call adaptation; cli-identity,
webhook-tool-credential, close-consumer-matrix, broker-authority and
git-push-client/operation all green.
@deepcoldy

Copy link
Copy Markdown
Owner

已按维护流程把最新 master 合入本 PR 并解决冲突,新 head 为合并提交 ecd62c24ef(普通 merge,未 force-push,作者原有提交全部保留;合入内容含 #4082 CI 分片提速与同期批次 #4040/#4042/#4020/#4027/#4033 等)。

冲突仅 2 个文件,均为两个 Git 身份特性在同一函数上的并行演进, resolution 为保留双方语义的合并:

  1. src/core/cli-identity.ts 的 renderGitCommitWrapper:feat(webhook): 支持平台传递调用人身份并按轮隔离工具凭据 #4055 增加了 webhook 按轮凭据的 webhook 配置与 run_git 统一执行入口(marker 分类 + host 级 helper);master 上 feat(git): 支持混合模式按触发者授权推送并自动发送授权卡片 #4040 增加了混合模式的 refusePush / pushClient(push 受限提示或转交授权客户端,needs_actor 退出码 2 分派)。合并后使用统一签名 (realGit, resolver?, webhook?, refusePush=false, pushClient?):needs_actor 保留 feat(git): 支持混合模式按触发者授权推送并自动发送授权卡片 #4040 的 push 分支与 action 分派,退出 1 的透传和提交归因路径都改走 run_git,使 feat(webhook): 支持平台传递调用人身份并按轮隔离工具凭据 #4055 的 webhook marker 分类在所有真实 git 执行路径上仍然生效;prepareTriggerUserCliEnv 的安装条件合并为 gitResolver || webhookGitHost || strictBroker,同时接线 webhook helper 与 strict pushClient。webhook 模式(!strictBroker 且 bytecloud+gitHost)与 strictBroker 模式按构造互斥,两条 push 逻辑不会同时生效。
  2. test/bytedcli-broker-authority.test.ts:双方在同一位置各新增一个用例(本 PR 的 webhook 轮 broker 拒绝、feat(git): 支持混合模式按触发者授权推送并自动发送授权卡片 #4040 的 gitHost 冻结/变更),两个用例都保留。
  3. test/bytedcli-strict-runtime.test.ts 中 feat(git): 支持混合模式按触发者授权推送并自动发送授权卡片 #4040 的直接调用按统一后的参数位置适配(webhook 位传 undefined),断言不变。

本地合并树验证:

  • bun run typecheck 通过;git diff --check 干净。
  • 冲突直接相关套件在合并工作树全绿:test/cli-identity.test.ts、test/bytedcli-broker-authority.test.ts(含两个新用例)、test/bytedcli-strict-runtime.test.ts 7/7、test/webhook-tool-credential.test.ts、test/close-consumer-matrix.test.ts、test/git-push-client.test.ts、test/git-push-operation.test.ts、test/bytedcli-actor-authorization.test.ts 等共 325/337 通过。
  • 同一次运行中 test/git-push-adversarial.test.ts 与 test/git-push-host.test.ts 的 12 个失败(真实 git 子进程/本地 HTTP 适配器用例,含 30s 超时)在干净的 af916a9 master 临时 worktree 中以完全相同的 12 项复现,属本机共享环境对这类真实进程对抗用例的环境问题,非本次合并引入;这些用例以 GitHub runner 上的新 head CI 结果为准。

新 head 的 fork workflow 已批准:CI run 46488916180(将使用 #4082 后的新分片布局)与 Sandbox run 46488916134。合并增量(冲突 resolution)已请复审人复核;合码以新 head 必需 CI 首跑全绿为准。

@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.

合并增量复审:要求修改(1 个 P2)

[P2] strict 初始 PATH 无 Git 时,空 real_git wrapper 阻断后补 PATH 的真实 Git

位置:src/core/cli-identity.ts:2889-2915。

#4040 在 strict 模式下只有找到 realGit 才创建 Git wrapper;找不到时不写 wrapper。当前合并版为了满足 webhook 的动态 PATH 查找,在 gitResolver || webhookGitHost || strictBroker 成立后无条件写 wrapper;当 strict 且初始 PATH 没有 Git 时,生成脚本里的 real_git=''。该 wrapper 随后进入 session PATH,导致登录 shell 后补入的真实 Git 也被它截获,普通只读命令同样执行空路径。

已用两侧真实的 prepareTriggerUserCliEnv 做对照探针:strict、初始 PATH 为空目录,准备环境后把包含真实替代 git 的 late PATH 加入,再执行 git --version:

merged: {"wrapperExists":true,"status":126,"stdout":"","stderr":".../git: 5: exec: : Permission denied"}
master: {"wrapperExists":false,"status":0,"stdout":"late-real-git","stderr":""}

这是 #4040 既有可用性语义的回归,不是本次需要的安全收紧。webhook 无 realGit 时需要写 wrapper 做动态查找,strict 无 realGit 时则应保留 master 的不安装行为,或另行实现 strict 的 late-PATH 解析;不能直接 exec 空串。最小方向是把 wrapper 的创建条件细化为 realGit || webhookGitHost(gitResolver 缺失 Git 本来就会抛错),并增加上述 late-PATH 行为回归用例。

其余合并内容已核对,无需返工:

  • 五参签名及生产/测试调用点一致;webhook 普通透传与提交归因都走 run_git,strict push 的 exit 2 / pushClient 分派保留,webhook 与 strict 构造互斥。
  • 额外真实 shell 探针验证 webhook + commit 归因、legacy、strict + resolver 的 push/commit 组合均通过。
  • bun run typecheck 与两个方向的 git diff --check 通过。
  • 12 个相关测试文件中,10 个文件共 353 项通过;git-push-adversarial / git-push-host 的 12 项失败,在干净第二父 108c2f7ac3 用同一依赖复跑得到逐项相同的 12 项失败,因此不是本合并引入。上述 12 项环境失败不是本次 request-changes 的理由。

修复这一个 strict 无初始 Git 的边界后,再进行最终 CI 门禁即可。

合并 deepcoldy#4055 与 deepcoldy#4040 时,git wrapper 写入被改成无条件执行:strict 模式下
初始 PATH 找不到 git(realGit 为空)也会生成 real_git='' 的 wrapper,
它截获登录 shell 后补 PATH 找到的真实 git,连 git --version 都以
126(: Permission denied)失败,回归了 deepcoldy#4040「仅在找到 realGit 时
安装 wrapper」的行为(Kimi 合并增量复审 P2,对照探针复现)。

将写入条件细化为 realGit || webhookGitHost:strict 无初始 git 时不
安装 wrapper,后补 PATH 的真实 git 直接可达;webhook 模式保留
run_git 的运行时 PATH 重查(无初始 git 也安装动态查找 wrapper)。

补两个 PATH 边界回归用例(test/cli-identity.test.ts):strict 无 git
经 Bun TS eval 调 prepareTriggerUserCliEnv 断言不生成 git wrapper 且
后补 late-bin/git 可执行(变异为无条件写入时该用例咬红);webhook
无初始 git 仍安装 wrapper 与 helper 且运行时能找到后补 git。
typecheck 与 git diff --check 通过;strict-runtime 7/7。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@deepcoldy

Copy link
Copy Markdown
Owner

合并增量复审 P2(strict 初始 PATH 无 Git 时空 real_git wrapper 阻断后补 PATH 真实 Git)已修复,新 head de94602aa9(在合并提交 ecd62c24ef 之上的修复提交,普通推送,未 force)。

修复内容(src/core/cli-identity.ts 的 prepareTriggerUserCliEnv):git wrapper 写入条件由无条件改为 realGit || webhookGitHost——

回归测试(test/cli-identity.test.ts 新增 describe「git wrapper install PATH boundary」2 例):

  1. strict + 无 git 的初始 PATH:经 Bun TS eval(strict broker 入口仅在该上下文可解析,与 test/bytedcli-strict-runtime.test.ts 同 harness)调用 prepareTriggerUserCliEnv,断言 sessionIdentityBinDir 下不生成 git wrapper,且把 identity bin 目录与后补 late-bin 放入 PATH 后 git --version 输出 late-real-git。变异验证:把写入条件临时改回无条件(if (true || ...)),该用例以「strict mode installed an empty-real_git git wrapper」咬红;还原后通过。
  2. webhook(trigger-user + bytecloud + gitHost)+ 无 git 初始 PATH:断言仍安装 git 与 botmux-webhook-git-credential,且生成的 wrapper 运行时能经 PATH 重查找到后补的 webhook-late-git(git --version 退出 0)。

验证:新用例 2/2 通过;bun run typecheck 通过;git diff --check 干净;test/bytedcli-strict-runtime.test.ts 7/7(含此前因统一签名位置适配的 push 委托用例)。

新 head 的 fork workflow 已批准:CI run 46493493529、Sandbox run 46493493579。请复审该修复增量;合码仍以新 head 必需 CI 首跑全绿为准。

@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.

P2 修复复审结论:代码可合

已核对线上与本地 head 均为 de94602aa9121f0d5c2815c62f4e908c5a064fcc。增量只修改 src/core/cli-identity.ts 的 wrapper 安装条件,并在 test/cli-identity.test.ts 增加两个 PATH 边界行为用例。

修复正确:

  • strict 且初始 PATH 无 Git 时不再写 real_git='' wrapper,恢复 #4040 的既有行为。
  • webhook 无初始 Git 时仍安装 wrapper,保留 run_git 在调用时重查 PATH 的能力。
  • gitResolver && !realGit 的既有抛错不变;strict + realGit 的五参 push 分派不变。

独立复验:

  • 重跑上一轮同一 late-PATH 复现,结果为 {"wrapperExists":false,"status":0,"stdout":"late-real-git","stderr":""},原 126 失败已消除。
  • cli-identity、bytedcli-strict-runtime、webhook-tool-credential 三个文件合计 219/219 通过,包含新增 strict / webhook 两个 PATH 用例。
  • bun run typecheck:通过。
  • git diff --check ecd62c24ef..HEAD:通过,工作区干净。

上一轮 P2 已解除,本轮未发现新的 P0/P1/P2 问题。实际合入仍以当前 head 的必需 CI 首跑全绿为准。

This branch has not been deployed

No deployments
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.

3 participants