Repository navigation
perf(agent-runtime): order parallel tool batches by resource conflicts - #1982
Conversation
Any Write or Edit in an assistant message made pi run the whole batch sequentially, so unrelated reads and writes paid one Host round trip each. Write and Edit now join pi's parallel batches, and a batch-local planner orders calls only where their declared resource claims conflict; same-file work keeps source order, everything else overlaps. The execution policy becomes one spec table with per-call claims. An Edit with MV, REM or a named register claims the whole workspace, because host-core keeps named registers per session and a CUT @x must stay ahead of a PUT @x on another file. A registered call is always released: waiting and releasing wrap the catalog executor outside the mode guard and argument checks, with a turn-end backstop for parent and delegate batches, so a call that throws, is rejected or aborts never leaves its successors waiting. Host-core, PathMutex and Bash/Task semantics are unchanged; Task mixed with Write/Edit stays sequential. Refs vastsa#1908
The amendment line named the change by its commit title because the pull request number did not exist yet. Point it at the pull request so the ADR history resolves to the review. Status stays Proposed.
The English tools spec gained a claim table, and the locale check requires each Chinese mirror to keep the same table structure, so the Docs checks job failed. Translate the Parallel file batches section into the zh-CN tools spec and update the zh-CN concurrency paragraph, which still described read-only batches.
vastsa
left a comment
There was a problem hiding this comment.
当前 head 9eead29d0e9a99207d1422dd41f9d5ab49d27a29 暂不能合入:新增的读写并发存在文件别名遗漏,会破坏同一文件的源顺序保证。
具体复现:临时工作区创建 actual.txt,再创建 alias.txt -> actual.txt,用 realpath 确认是同一文件;同一模型回复发出 [Read alias.txt, Write actual.txt]。在现有 runtime.test.ts 的 startBatch/gatedHost 上增加回归,保持 Read 的 Host 响应未完成:候选已进入 [first, second],Write 没有等待 Read;替换为当前 main 的 runtime.ts 和 tool-execution-policy.ts 后同一测试通过(只进入 first,释放后才进入 second)。生产 Runtime/pi 执行链是真实的,Host RPC 为可控闸门;这不是实际磁盘读写撕裂 E2E,但直接证明新增调度丢失顺序。
原因在 batch-planner.ts 的 sameFile:完整 lexical key 或 basename 相同才判定冲突。不同 basename 的文件符号链接(以及硬链接等别名)均不满足;PathMutex 也使用 lexical key,不能兜底。Host 的 resolve_tool_path_with_external 会解析符号链接,而 tool_write 对 resolved 路径执行 std::fs::write,Host 的单写准入不能排除并发 Read。原来的整批串行保护在这个 PR 中被移除了。
建议沿用当前 planner 补齐资源身份:对 Host 实际访问的文件使用可信的别名/文件身份信息,无法证明独立的路径保守串行(远程工作区不能依赖 sidecar 本机 realpath);或者在能够保证别名安全前保留相关写批次的串行边界。仅增加 basename 特判无法覆盖这类输入。请加入不同文件名的符号链接读写回归,并检查硬链接、远程路径和不存在目标的保守策略。至少覆盖上述顺序及反向顺序,验证父代理与子代理共用的入口。
已完成:确认 main 的 Write/Edit sequential 策略确实让混合批次串行,性能问题存在;候选原有 batch-planner/runtime/subagent 三文件 489/489 测试通过,共享包构建通过,git diff --check 通过,六项远端 CI 全绿。新增别名回归在 main 通过、候选失败。因已有可复现的正确性阻碍,本轮没有继续运行完整本地 Host/Electron E2E,也没有修改或推送贡献者代码。
Replace lexical file independence with Host-owned identities and source-order admission. Keep execution leases alive through blocking file work, review snapshots and rollback, while preserving permission checks and legacy fallback. Integrate upstream main at 97cc04d and retain existing write limits. Add alias, reversed-arrival, cancellation and queue-fairness regressions with synchronized protocol and runtime specifications.
|
感谢指出这个问题。原来的词法路径和 basename 判断确实漏掉了不同名称指向同一文件的情况, 修改内容
也补了一项排队回归:尚未满足源序依赖的后继,不能作为公平性屏障挡住另一个批次,否则可能间接卡住自己的前驱。 验证结果候选提交: 在 Windows 上执行:
Host 全量 release 测试未通过,出现后台进程、数据迁移和远程权限用例失败。另用未修改的
其余失败尚未逐项确认;全量检查在这之后中止,因此这里不将 Host 全量测试记为通过。 文件符号链接创建受本机 范围这次增加的 Host 协议用于解决当前读写并发的正确性问题,规格、ADR 和 E2E 计划已同步。每会话写额度仍为 1; 请重点复核文件别名、源序与公平性的关系,以及取消和回滚时的租约释放边界。 |
Publish active turn state before awaiting Host capabilities and honor cancellation before provider dispatch. Update the history restore fixture and add a pending-negotiation regression test. Avoid blocking identity classification on Unix FIFOs, retain post-open identity checks, and cover special-file fallback with a regression test.
|
已在
另外做了一轮独立审查,发现 Unix FIFO 的身份分类可能阻塞。现在先筛选普通文件,Unix 打开时使用 本地验证:agent-runtime 1,632 项通过、1 项跳过;历史恢复测试通过;Electron trusted extensions 57/57 通过;真实 Host 的并发文件与 Task/read E2E 通过。Native 定向测试、Clippy、格式及 JS 构建和 lint 通过;文件符号链接 E2E 仍受本机权限限制而跳过。 本次提交的远端 CI 已全部通过(6/6):JS 综合检查、Linux Rust 全量测试、Windows Rust / transcript cache E2E、Electron trusted extensions E2E、文档检查和最新基线检查。Linux CI 也覆盖了新增的 FIFO 用例。CI 结果 |
vastsa
left a comment
There was a problem hiding this comment.
Re-reviewed Host identity/source-order admission against the previously independently reproduced whole-batch serialization bottleneck and differently named symlink ordering regression. Host-owned identities, conservative unknown-resource fencing, execution-owned leases and legacy/remote fallback address the root cause. No remaining material blocker found.
Original bdc35fa fails to compile on macOS: f_flags is u32 while MNT_LOCAL is i32 (E0308/E0277). Added minimal fix f571c78 on this PR branch: cast the flag constant only.
Validated f571c78 locally:
- shared, agent-runtime, agent-host and host-runtime builds pass. Runtime: 117 files / 1632 tests pass. Host-runtime: 22 files / 161 tests pass.
- macOS Host full suite: 1106 pass, 1 ignored, 0 fail. File-focused 47 and ToolBudget 26 tests pass (overlap full suite). cargo fmt and diff checks pass.
- Production Runtime/pi with candidate-built real Host E2E passes parent/delegate differently named symlink AND hardlink Read/Write both orders, independent-file concurrent dispatch, real-tag Edit, two separate Write rollbacks, concurrent ask-mode approvals with independent allow/deny. macOS symlink cases executed without skips. History restore test passes.
- Initially reused dependencies were incompatible/stale; installed locked dependencies in isolated worktree and reran successfully. Primary environment unchanged. Initial E2E binary path typo prevented launch; corrected path completed successfully.
- Latest main 97cc04d is ancestor. PR integration 481663f and validated head have identical tree 99dfc960a3b02ec9d9d9d681efceef4c5adbbcde.
Concurrent-dispatch evidence is not a real-load wall-clock speedup claim. No local Electron UI or native Windows run; waiting for all new-head remote CI gates before merging.
Refs #1908
让已证明独立的文件读写在同一模型批次中重叠,并由 Host 保证别名文件的冲突调用保持源顺序。根据 review,本次用可信 Host 文件身份替换最初的词法路径/basename 冲突判断。
行为与实现
验证
候选:
20abd41b51bd35606d3f9ec1db416ef251d631de;基线:97cc04debf261a423987a9d3ced4036d80073c5b,为候选祖先。Host 全量 release 测试未通过并已中止。在未修改的上述 upstream 基线上独立复现了远程权限通知与旧数据迁移路径格式两项失败;其余失败尚未逐项确认,不能据此将全量测试记为通过。
文件符号链接创建受本机 EPERM 限制,该项跳过;Linux/macOS 原生执行、Electron UI、远端 CI 和 PR integration candidate 尚未验证。未测量真实负载墙钟性能,不沿用旧版性能数字。
规格、协议、ADR 与 E2E 计划已同步。请重点复核文件别名、源序与公平性的关系,以及取消/回滚时的租约释放边界。此保证限于单个 Host 中参与协调的文件工具及回滚,不覆盖任意外部进程、Bash 或另一个 Host 实例。