Repository navigation
fix(auth): allow same-principal consecutive turns and continue device-code authorization on the live turn - #1911
Conversation
triggerUserAuth 的 lark-cli/bytedcli wrapper 在 turn id 不一致时一律 exit 77, 即使用户只是自己发了跟进消息(旧轮尾部命令、auth wait 期间的新一轮)也被拦, 表现为「这条命令属于上一轮对话」反复出现、文档一直读不到。 - 凭证与 live-turn 标记各盖 openId(turn.caller / .env 新增 BOTMUX_IDENTITY_OPEN_ID), wrapper 仅在双方都指名且为同一人时放行,缺任一侧仍 fail closed,跨人安全语义不变 - worker 经 IPC 透传 turnCallerOpenId(init/message/raw_input/排队/接管全路径) - auth-status 设备码授权在轮次轮转到同一人时把新 token 回灌当前轮; 发起人冻结在授权请求记录里,异人仍严格 auth_turn_changed Co-Authored-By: Claude <[email protected]>
|
你好 @47seek,PR 的评审群已建好,自动评审(首审 + 交叉复审)已在群里开始,结论稍后会同步到本 PR。 你目前不在我们的自动拉群名单里,机器人暂时无法直接把你拉进群,请点击下面的链接自行加入(一年有效): 也欢迎把你的 GitHub 账号和飞书信息补进这份名单文档,补好后后续评审群会自动把你拉进去: (本条为自动流程发出,最终评审结论以维护者审阅为准。) |
|
初步自动评审意见(最终以维护者审阅为准)。 整体方向认可:仅在双方都具名同一人时放宽 turn 绑定、跨人仍然 exit 77(fail closed);设备码轮询冻结 approver、批准后改发到 live turn、marker 未翻转时保持 409 让 CLI 重试的设计都正确。wrapper 四态测试与 IPC 同人/异人用例齐备,本地 tsc / build / 相关测试及 CI 10 腿均绿,关键分支做变异核验有牙。 但发现 1 个会让主要场景在自然时序下间歇性失败的问题,建议修改: P2|
触发链路:设备码批准后 token 已落库 → 用户的跟进消息 t2 被 accept, 建议:
P3 备忘(不阻塞)
验证记录:评审基于最新 master(20e5f32cf,PR 0 behind、无冲突);本地 tsc、 |
|
补充一条勘误与双审收敛后的修改清单(接续上条初步意见,仍以维护者审阅为准)。 勘误:请撤回上条 P3-2 的「调换两个文件的写入顺序」建议——那个改法会更不安全。 复审用真实 wrapper 对两种顺序各自的单文件交错窗口做了实测(我也独立复现一致):两次
实测两种一致态(turn/caller 同人同轮)都正确拒绝;只有各自的混合态放行。所以请勿调换顺序。若要彻底消掉这个竞态(可作为本 PR 或后续 followup),正解是把 turn 与 caller 放进同一次原子写:例如 双审收敛后的修改清单 必修(P2,双审均用真实代码实证;复审还穿过真实 HTTP 路由端到端复现):
P3(不阻塞,建议顺手):
验证基线不变:head bfcfec4 对最新 master 0 behind、CI 10 腿绿。改完我们会重 fetch 新 head 重新核验。 |
|
再补一组「单文件原子写」正解的实现约束(双审用真实 /bin/sh 实测过),避免改出「看着对、实则坏」的版本: 若采纳「turn + caller 合并进
如果觉得单文件改造面偏大,也可以选择本 PR 只修必修 3 条(CAS 按行匹配 + openId 透传 + 真实文件测试),两文件交错窗口(当前顺序需要 A→B→A 交替 accept 的窄窗口)另开 followup 用上面的方案收口——两种范围都可接受,但不要采用「调换两个文件写入顺序」的改法(上一条勘误已说明)。 |
|
补充一份最终实现核对清单(与复审方逐处对齐,供修改时逐项勾): 若本 PR 一并落「单文件原子写」(推荐)——同一 commit 四处同步:
若本 PR 只修必修 3 条、交错窗口另开 followup: 即使当前 其余 P3(wrapper 开头清空继承的 OPEN_ID/TURN、PID marker 持久化 caller + adoptInitialActiveTurn 兜底、promoteQueuedActivationTail 的 caller 改取冻结的 trustedCaller、悬空注释归位)不阻塞,可随本 PR 或 followup。 |
在 deepcoldy#1911 的同一人连续轮次放行基础上,修复双审发现的必修问题,并消除 turn 与 caller 两文件交错读的竞态: - refreshSessionIdentity 的 CAS 不再用 endsWith(BOTMUX_IDENTITY_TURN=…) 做后缀 匹配:renderIdentityEnv 的行序是 TURN→OPEN_ID,任何盖了 openId 戳的身份 (publishOne 的默认产物)refresh 恒为 false,导致批准落库后跟进消息已能取到 token 的当轮仍 409,`botmux auth wait` 一直轮询到 5min 超时。改为按行匹配 TURN,并在文件已盖戳时校验 openId 一致;未盖戳(首次授权的 denied 文件)不算 冲突,保持可通过。 - 两处 auth-status refresh 调用补传 openId,避免刷新成功也把戳抹掉,使同一人 下一轮又退化回严格拒绝。 - turn 与 caller 合并进同一个 turn 文件(第一行 turn、第二行 caller),由 publishActiveTurn 一次原子写产出;wrapper 改为一次 open、两次 read 取一致快照, 删掉 turn.caller 独立文件、sessionActiveTurnCallerPath 导出与占位。原先两次 独立写/读之间必然存在「新 turn + 旧 caller」或「旧 turn + 新 caller」的混合态, 两个方向各能错放一次跨人命令,这次一并消除。 - TS 侧新增 readActiveTurnLine(取首行),refreshSessionIdentity 用它将 turn 语义 收敛到单一处;同样消除两行文件下 .trim() 恒不相等的隐患。 - wrapper 开头把继承的 BOTMUX_IDENTITY_TURN / BOTMUX_IDENTITY_OPEN_ID 像 MODE/DENY_MSG 一样置空:它们是本 PR 新增的、唯一能把「异人拒绝」翻转成 「同人放行」的输入,做纵深防御。 - PID marker 持久化 callerOpenId;adoptInitialActiveTurn / adoptDisplacedActiveTurn 增加 trustedCaller?.requestUserOpenId 兜底;marker 里 queuedTurns 重放回 queuedTypeAheadTurns 时带上 caller。崩溃恢复 reconcile 缺失 caller 只会多拒, 不会错人。 - promoteQueuedActivationTail 的 caller 改取已冻结的 promote 记录 (exactInput.trustedCaller?.requestUserOpenId),不再在 promote 当刻查 replyTargets:排久被 prune 的 tail 会查空而丢 caller,使同人续轮被误拒。 - 归位 worker-pool.ts 一处悬空的文档注释。 测试:新增真实文件用例锁定盖上戳 env 的同轮 refresh 成功、同人换轮成功且保戳、 异人 refresh 失败、未盖戳文件可通过、两行文件首行语义,以及 wrapper 单次 open 一致快照与继承 env 清零;新增 promote tail 从冻结记录取 caller 的用例,并补 worker 侧 marker/adopt/replay 的 caller 持久化断言。既有 mock 断言同步到新的 openId 契约。 验证(在本 checkout 实测): - npx tsc --noEmit、bun run build 通过; - 9 个相关测试文件 585 用例全绿(cli-identity / ipc-auth-request / daemon-rename-route / initial-user-turn-opening / raw-input-followup-atomicity / transfer-passthrough-gate / worker-durable-expiry-order / worker-screenshot-upload-hardening / session-lifecycle-start); - 10 处变异(CAS 退回后缀匹配、turn 读整段而非首行、wrapper 退回两次独立 read、 去掉继承 env 清零、publishActiveTurn 丢 caller 行、marker 不存 caller、 adopt 丢 trustedCaller 兜底、promote 退回 live 查询、queuedTurns 重放丢 caller、 auth-status refresh 不传 openId)全部被测试杀死; - 真实 publishActiveTurn 并发写 + 真实渲染 wrapper 的 144420 次单次 open 读, 两态各 7 万余次、混合态 0 次,确认交错窗口已消除。 影响面:改动集中在 trigger-user-auth 的凭证/turn 绑定(lark-cli 与 bytedcli 共用 wrapper)、auth-status 续期路由与 worker 的 turn 归属发布。非 trigger-user-auth 会话、无授权会话、bytedcli 的 wrapper 行为均不变;turn 文件 由一行变两行,TS 侧唯一消费者 refreshSessionIdentity 已同步取首行;沙盒按目录 绑定 cli-identity/<sid>.bin,无需改 allowlist。 Co-Authored-By: 47Seek <[email protected]>
|
🚀 Released in v3.45.0 |
合并最新 master(含 deepcoldy#1606/deepcoldy#1911/deepcoldy#1941/deepcoldy#1946/deepcoldy#1961/deepcoldy#2042 等按人鉴权演进)。 语义冲突处理: - bytedcli 身份同时携带五区域 cloudJwts 与 codeJwt(后者派生 codebase 同伴工具), mintByteCloudUserJwts 一次返回,去掉外层重复 mint。 - larkdev 平台凭据源暂不支持:grant client 端拒绝、toIdentity 收窄,platform 模式 fail-closed、auto 模式回落本地个人 HOME 五区域 mint。 - lark-cli 个人 app 两步授权的拒绝文案按 stage 区分(app-setup vs user-login), ByteCloud 家族(bytedcli/larkdev)统一 provider 文案、空 HOME 与 502/409 守卫。 - 沙箱 lark-cli HOME 物化在 publishOne/publishDelegated 叠加 sessionSandbox 透传。 - session-tmp 采用 master 新短路径布局(8 字符 profile+sid hash),根目录强制 deny 与本 PR 快照 carve 不受布局变化影响(seal 的是整个 session-tmp 根)。 - dashboard scope 加购/auth-status 取 master(绑定会话走 bot 应用,个人 app 首次 授权走 turn 发布路径,不经此 IPC);删除被 deepcoldy#1946 改名的旧 scope 测试文件。
Problem
With
triggerUserAuthenabled, the per-turnlark-cli/bytedcliwrapper refuses a command whenever its stamped turn id no longer matches the worker's live turn (turn-mismatch, exit 77):The guard compares turn ids only, not principals. The most common trigger is therefore entirely benign: while a turn is still running, the same person sends a follow-up (or taps a device-code authorization link and types "继续" while
botmux auth waitis polling). The follow-up opens a new turn, the credential file rotates, and every command in the old turn's tail — including the document read the agent was authorized to do — fails. The device-code flow compounds it: when the turn rotated during approval, the granted token was discarded withauth_turn_changedand never republished, so the next turn hitmissing_scopeagain. Users saw a recurring "this command belongs to the previous turn" loop and could not finish a simple doc read.Fix
Relax the turn binding only when both sides name the same human; cross-principal protection is unchanged.
turn.caller(one line, next to the existingturnfile) carrying the live turn's open id; published identities stampBOTMUX_IDENTITY_OPEN_IDinto their env file. The wrapper clearsturn-mismatchonly when both open ids are present and equal. Missing either side still denies (fail closed); a different human still exits 77.turnCallerOpenIdis carried on daemon→workerinit/message/raw_input(resolved from the accepted turn's reply target / active interactive turn), through the type-ahead queue, adopt/replacement paths and follow-ups, intosetCaptureIdentityandpublishActiveTurn.auth-statusfreezes the approver in the request record, keeps polling while the session's live caller is that same human, and on approval republishes the token for the live turn (with the open-id stamp). A different caller, a dead worker, or a live-turn marker that has not flipped yet keeps the strictauth_turn_changed. Bound lark tools (new--as usertool-binding path) self-resolve identity and simply return ready.Verification
bun run buildandtscclean on top of currentmaster.setCaptureIdentityargument andturnCallerOpenIdfield.Co-Authored-By: Claude [email protected]