feat(runtime): Runtime 层重构与工具并发执行优化#289
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
/simplify |
CompletedImplemented fixes for the unresolved review items that were worth addressing, then ran a code-simplifier sub-agent pass and kept the resulting simplification. What I changed
Tests added/updated
Validation
Commit and push
Not done
|
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(runtime): harden terminal event and tool parallelism
|
/review -codex |
|
/simplify |
完成情况已按你的要求完成:先读取历史评论并处理值得修复的未解决 review 项,再执行了一轮 code-simplifier 简化并整合。 已修复项
新增/调整测试
简化(code-simplifier pass)
验证
提交与推送
未执行
|
…OL blocking - reset no-progress streak when evidence is present - scope permission ask serialization per run instead of global lock - remove test data race in stubToolManager under parallel tool execution - sync runtime event docs with emitted phase/progress events Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
|
/review -codex |
fix(runtime): resolve simplify follow-up issues
|
/review -codex |
|
/simplify |
|
/code -codex 继续修编译不过问题 |
处理结果已继续修复当前分支“编译不过”问题,根因是 本次修改
验证
提交与推送
未执行
|
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(runtime): preserve ErrMaxLoopReached sentinel on loop-limit exit
@xgopilot 直接把runtime的并发执行逻辑下沉到工具层有问题吗?是否干扰tool职责?或是当前runtime的并发是否影响runtime职责 |
结论不建议把 你这次 PR 里的 runtime 并发实现本身不越权,属于 runtime 该负责的“回合编排”。 为什么不建议下沉
当前实现是否影响 runtime 职责不影响,且是合理增强:
这些都属于 runtime 的“执行策略层”,不是工具层的“能力实现层”。 建议的分层准则(最小可行)
本次未执行仅做架构分析与结论回复,未修改代码。 |
@xgopilot 执行方案,不允许直接在这个PR中提交 |
执行结果已按你给的最小闭环方案在本地完成实现与验证,且未在当前 PR 分支提交/推送。 本地已实现改动
验证结果
未执行
|
@xgopilot 如果直接改成runtime不限制,tool层一次最多只能用固定个数的工具呢 |
结论不建议改成“ 原因
建议方案(最小改造)
直接回答你的问题“runtime 不限制,tool 层固定并发”可以跑,但会弱化分层、放大运行时开销和治理盲区,不建议作为主方案。建议采用“runtime 主调度 + tools 防护阀”的双层模型。 本次执行
|
@xgopilot 我还是不够明白,假设tool工具层固定只能并发执行3个工具,那么在runtime固定并发执行4个同名工具有什么意义?直接把runtime并发执行删了不就行了 |
直接回答你这个例子里( 为什么是这样
那 runtime 并发还能不能删不建议直接删。原因不是“这个同名场景加速”,而是职责和治理:
可落地结论
本次执行
|
/code -codex |
# Conflicts: # internal/runtime/run.go # internal/runtime/runtime_test.go
# Conflicts: # internal/runtime/run.go # internal/runtime/runtime_test.go
|
/code 给我解决冲突 |
处理结果已完成冲突消解,并把与 本次修改
核心处理点:
验证
提交与推送
未执行
|
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(runtime): resolve merge conflicts with main
|
/code 重修,接收没有最大循环数(8) |
# Conflicts: # docs/context-compact.md # internal/runtime/run.go # internal/runtime/runtime.go # internal/runtime/runtime_internal_helpers_test.go
|
/code 修复报错,并提高测试覆盖率直到100% |
完成情况已按你的指令完成“修复报错 + 提升覆盖率”。 本次修改
验证结果
提交与推送
未完成
|
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
test: fix runtime compile regression and improve patch coverage

变更说明
本次 PR 主要针对
internal/runtime层进行了深度的架构重构与能力升级。核心改动包括:将原有的工具串行执行机制升级为并发执行以大幅提升运行效率,引入独立的控制面(Control Plane)用以清晰管理执行阶段与停止决策,并新增了基于“进展追踪”的死循环(防卡死)拦截机制。#279
改动内容
并发工具调用支持 (Parallel Tool Execution)
internal/runtime/toolexec.go,将executeAssistantToolCalls的实现方式由串行遍历迭代,改为基于goroutine+sync.WaitGroup的高并发执行模式。sync.Mutex保护执行过程中的最早异常抛出点,保证并发状态下的稳定退出。架构解耦与控制面 (Control Plane) 剥离
internal/runtime/controlplane模块,明确定义了执行阶段Phase(如PhasePlan、PhaseExecute、PhaseVerify)。decider.go)与专门的停机原因枚举(StopReason),将整个运行的最终中止原因严格划分为互斥的四类:success(正常结束)、max_loops(轮数超限)、error(运行时异常)、canceled(上下文取消),避免了以往原因模糊的问题。runtime.go按照职责拆分出run_lifecycle.go(运行生命周期) 和session_scheduler.go(包含全新的细粒度会话锁管理与目录解析),并移除了冗余的errors.go。执行监控与死循环拦截 (Progress Monitoring)
progress.go),通过追踪每次循环后工具结果所贡献的“进展证据”(Evidence)进行分数评价。streak >= 3),将触发ErrNoProgressStreakLimit强制终止任务。事件派发流改造 (Event Emitter) 与标准事件结构
event_emitter.go。RuntimeEvent结构(Envelope),现在的事件包默认附带了Timestamp(时间戳)、Turn(当前轮次)、Phase(所处阶段)以及PayloadVersion等更丰富的强类型元数据。EventPhaseChanged、EventProgressEvaluated以及EventStopReasonDecided,且优化了部分现有事件命名(如EventCompactDone改为EventCompactApplied)。全方位测试覆盖保证
runtime_progress_test.go和run_termination_test.go测试模块;重构扩充runtime_test.go。实现了并发错误回调、阶段流转状态机、死锁终止机制等所有新特性与边界的充分覆盖。改动原因
预期收益