fix(agent): 防止异步准备阶段并发启动多个运行 - #153
Merged
Merged
Conversation
helsome
approved these changes
Sep 22, 2026
helsome
left a comment
Owner
There was a problem hiding this comment.
审查 head 331e27fd2e7aac60b259e608cef9b06b0233cfd5:这个修复把单 runtime 的互斥预留前移到首次 await 之前,并在启动失败时通过 finally 释放;成功路径进入 prepareRun 后会先建立 activeRun 再返回,因此不会在 reservation 释放时留下新的并发窗口。回归测试覆盖同 session、跨 session 并发启动,以及 lookup 失败后的 busy 状态释放与重试。作者报告 Bun 1.4.2 / Windows 11,focused 修复前 22 pass / 3 fail、修复后 25 / 0,shared 1074 / 0,全 workspace typecheck exit 0。当前 GitHub Actions 是首次 fork 的 action_required,没有实际 CI jobs,我不把它写成 CI 通过;按小型、内部正确性修复和现有可复现证据,APPROVE。合并后仍需以 merge SHA 的 main workflow 为准。
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.
改动说明
RunManager.startRun()原先在异步读取会话、写入 run 和用户消息之后才设置activeRun。两个同时到达的请求可以一起通过空闲检查,覆盖单运行状态并并发进入 runtime。现在在首次异步操作之前预留启动会话,在
finally中释放启动标记;isRunning()和hasActiveRun()也涵盖准备阶段。并发请求沿用RUN_IN_PROGRESS拒绝,启动失败后仍可重试。新增三个回归用例,覆盖同会话/跨会话并发启动,以及会话读取失败后的状态释放和重试。使用真实文件存储与可控 runtime,不需要模型或行情凭证。
关联 Issue
本次是独立发现的并发启动缺陷,不关闭其他 roadmap issue。PR #53 会修改同一文件,但其当前补丁未覆盖这段异步启动的互斥窗口;合并时需留意重叠。
测试报告
环境:Bun 1.4.2 (744846f84),Windows 11 (build 26200),上游基线
f0f4643410b70a02c199f28bd6ffb7dfe95041ad。实际使用独立安装的 Bun 可执行文件运行;类型检查时将其目录加入当前进程 PATH。等价命令及结果:
首次沙箱运行 shared 测试为 1073 pass / 1 fail:既有 PiRuntimeAdapter 测试写入
D:\tmp\pi被沙箱拒绝(EPERM)。同一份代码在获准的沙箱外重跑后全部通过。未改动该测试。改动生产文件按仓库 CI 的高信号 secret 模式扫描,无命中。
UI 截图
Scope / 后续
仅修改运行管理器与对应测试。不引入任务排队、不改动会话分支功能。本地未运行真实 Pi/LLM 或 Electron E2E;本次验证针对启动互斥与持久化路径。