Repository navigation
fix(traex): 网络策略沙盒下继续找到 traex 叶子进程,回复不再因 pid 绑错丢失 - #2535
Merged
Merged
Conversation
开了网络策略的沙盒里,TRAE 的启动链是 scope sh → network-runner → unshare → runner(内) → sh → sh → bwrap → bwrap init → traex,traex 在第 7~8 层(真沙盒实测), 超过通用 wrapper 查找的 6 层上限;TRAE 专用重试也只跑 6 秒,比 network-runner 的就绪等待还短。找不到叶子时 backend.cliPid 停在剥层后的 runner 进程,提交拿不到 自己拥有的 cliSessionId,bridge 挂不上 transcript,租约到期后轮次被退役。 - TRAE 叶子查找放宽层数,每次只读一次进程表(snapshotChildPids) - 重试改为 500ms 间隔、最多 5 分钟,同一后端/同一 pane 时持续找 - 找到后 backend.cliPid / bridgeCliPid / 进程身份上报一起更新 - currentTraexObservedPid 在已记录 pid 不是 traex 时继续向下找 非沙盒、非 Forge 的 TRAE 不进入这段逻辑,行为不变。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 29, 2026 18:20
Owner
Author
|
范围外的 Codex launcher 同类问题(同样是 6 层 / 6 秒)已记成 #2555,写了复现条件,归沙盒任务⑦。 |
Owner
Author
|
已合并,跟进一个评审中确认的不阻断项: 异步解析器缺 同步的 scheduleWrapperRealCliPid(launcherPid, {
// ...
isDirectLeaf: lp => isTraexProcess(lp, probes.commOf),另外记录一条已接受的成本尾巴:launcher 始终不 fork traex 的坏启动下,每会话会有 5 分钟 × 2 次/秒的全表 范围外的 Codex launcher 同类问题已在 #2555 跟踪。 |
deepcoldy
pushed a commit
to uestcwangci/botmux
that referenced
this pull request
Oct 30, 2026
…ity-recovery-2473-final 四次同步 master(0345cc5f1..eb43116,14 提交,含 deepcoldy#2514/deepcoldy#2534/deepcoldy#2535/deepcoldy#2541/ deepcoldy#2467/deepcoldy#2550/deepcoldy#2553/deepcoldy#2554/deepcoldy#2557/deepcoldy#2561/deepcoldy#2562 等)。与本 PR 仅 worker-pool.ts / worker.ts 文件交集,git 自动合并干净、无冲突标记;PR 关键接线(codexApp TurnFailureCode 四处、!turn.error 守卫、pool 恢复落账、worker 签名 final 失败字段、Pi boot 20s 预算)逐处 grep 仍在原位。合并树 build 过、 codex 集成/容量/engine/deployment/schedule 共 276 项 vitest 绿、 容量+Pi argv 46 项 bun 绿。 Co-Authored-By: Claude Code <[email protected]>
|
🚀 Released in v3.56.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
改了什么
修复用户反馈的问题:沙盒里跑的 TRAE 把最终回复丢了(决策看板 #87 第 1 点,维护者选 A 做)。
根因(用真沙盒量过):开了
sandboxNetworkPolicy后,TRAE 的启动链是从 scope supervisor 往下数,traex 在第 7 层;前面再有 OSC relay 时是第 8 层。
findLaunchedCliPid默认只往下找 6 层,TRAE 专用重试也只有 30 × 200ms = 6 秒,比 network-runner 自己等 namespace 和 slirp 就绪的时间(各最多 10 秒)还短。找不到叶子时,backend.cliPid就停在剥掉 relay/scope 后的 runner 进程(用户日志里的resolved real CLI pid … under launcher …就是这一步)。之后:writeInput拿这个 pid 查打开的 rollout,永远查不到,提交被确认了但拿不到 cliSessionId(会话库里没有 cliSessionId)structured_turn_retired,转发凭证被撤销botmux send,会报managed host relay capability is stale or missing改动
src/core/traex-leaf-pid.ts:TRAE 叶子查找的层数上限放宽到 16;每次查找只读一次进程表(snapshotChildPids,以前每个节点各 fork 一次ps -A);resolveTraexOwnershipPid从 worker 挪到这里,候选 pid 本身就是 traex 时直接返回backend.cliPid、cliCwd、bridgeCliPid和进程身份上报一起更新;currentTraexObservedPid在已记录的 pid 不是 traex 时继续往下找(防的是 payload 绑定先落地的情况)getChildPids改为复用snapshotChildPids,行为相同影响面
cliId === 'traex'且是 launcher 形态(文件沙盒 / Linux credential-only bwrap / Forge x TraeX)才进入这段逻辑。没开沙盒的 TRAE、其它 CLI 都不受影响getChildPids是公共函数(adopt 扫描、wrapper 解析等在用),只换了实现,输入输出不变;test/session-discovery.test.ts、test/launch-layers*.test.ts、test/find-launched-cli-pid.test.ts全绿startCodexLauncherPidResolve/resolveCodexOwnershipPid)同样是 6 层、6 秒。在网络策略沙盒下,npm 装的 Codex 会再多一层,大概率有同样的问题。这属于其它 CLI 的沙盒可用性(任务⑦),没在这里一起改,见下方 follow-up测试
test/traex-leaf-pid.test.ts:用实测的链路构造假进程树,覆盖叶子查找、ownership 解析、慢启动(第 25 秒才出现叶子)下的重试、后端被替换后停止、currentTraexObservedPid(用 worker-function-harness 执行真实函数)、snapshotChildPids读真实进程表test/find-launched-cli-pid.test.ts:执行 worker 真实的 spawn 接线,场景是 scope payload 先绑定、traex 在下面 7 层,断言最终backend.cliPid、bridgeCliPid和身份上报都落在叶子上test/traex-leaf-pid-real-sandbox.test.ts:在私有 mount + PID namespace 里用真实的 unshare + slirp4netns + bwrap 起网络策略沙盒,里面跑一个假traex,断言解析到的就是它,同时断言通用的 6 层查找找不到(证明链路确实这么深)。需要 root 和这几个工具,否则跳过;本机放在 isolate-run 里跑,结束后没有残留挂载和进程变异复验(每次只改一处,跑完还原):
bridgeCliPid = realPidcurrentTraexObservedPid改回直接返回已记录 pidFollow-up
🤖 Generated with Claude Code