pref(runtime): 统一执行生命周期,并强化任务结束与工作区安全机制#394
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
@xgopilot 先用通俗易懂的语言解释当前runtime进展是如何计算的(可以尝试举例子,最好有和之前方案的对比) |
|
/code 修复未解决的review |
…kspace fallback Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
|
@xgopilot 深度分析当前PR的模块边界、方案设计等等方面,分析可能会存在什么风险点,要求尽可能往多了找,严厉的批评这个PR的所有问题 |
@xgopilot 给出修复方案,不需要考虑兼容旧代码或是其他一切尝试兜底行为 |
@xgopilot 我这里有新方案,请你评估与你的方案的优劣: 不是“只求现在修得快”的应急式修补 Completion 只看当前未闭合事实 Implementation Changes
WorkspaceWrite 没有它就无法表达跨工具一致的 runtime 控制语义
tool_call: 普通写入打开 tool_call: obligation 文件级 scope 类型名固定为 VerificationObligation review obligation waiting_permission 临时态优先级表
HasBusinessProgress 用明确规则判定 |
@xgopilot 那么请你执行这套新方案吧,第三点允许采纳你的建议。任务完成记得输出具体的执行结果,同时提交PR到fork仓库中 |
执行结果已按你要求完成这套“硬切最小闭环方案”,并采纳你允许的第 3 点建议(未知/外部工具默认保守按可写处理)。 已完成改动
测试与验证已执行并通过:
新增/补强测试包括:
提交与推送
|
…semantics - remove sticky verify flags from completion gate and rely on unverified-write fact - replace temporary lifecycle restore with counter-based effective state derivation - add typed tool execution facts and consume them for write/verify semantics - default unknown/mcp/bash actions to conservative workspace_write=true unless explicitly read-only - upgrade runtime payload version to v2 and fail-close session containment on permission errors - add lifecycle/facts/verification regression tests Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
refactor(runtime): hard-cut lifecycle/completion/facts semantics
|
@xgopilot 批判性review整个PR,分析所有潜在风险点,其中模块边界划分、方案设计思路等等也是你的分析范围,找出所有漏洞,不许输出正向表扬。 |
@xgopilot 评估以下方案如何,看看是否适合直接实施:# Runtime 控制面重构方案(不兼容旧代码版) Summary本方案直接重构 runtime 的 completion / progress / lifecycle / tool facts 语义,不兼容旧 stop reason、旧 metadata 协议、旧 verify 猜测逻辑,也不保留任何“先补一下”的过渡层。目标是一次性把控制面改成可信事实驱动模型:
这版方案默认会直接替换现有:
Key Changes1. Completion 改成“验证义务”模型
2. 写入/验证改成“可信 typed facts”
3. 写后验证闭环改成 obligation 状态机
4. Progress 与 Completion 共用同一事实源
5. Lifecycle 改成“主态 + 临时态覆盖层”
6. stop reason 协议直接升 v2
7. TUI 生命周期展示对齐
8. Session containment 改成 fail-closed
9. 防腐约束
Public Interfaces / Types
Test Plan
Assumptions
|
@xgopilot 直接执行方案,不要有试图兼容或兜底旧代码行为,完成后提交PR到fork仓库 |
执行结果已按“直接执行方案、不要兼容兜底旧行为”的要求完成硬切改造,并推送到当前 PR 分支。 关键改动
新增/更新测试
验证
提交与推送
未完成项:无。 |
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(runtime/tools): hard-cut trust boundary and lifecycle state handling
|
/code 解决冲突,选择合适的方案 |
处理结果已完成“解决冲突并选择方案”,并直接推送到当前 PR 头分支 采用方案:
关键改动
验证
当前 |
- restore low-risk external write approval path from origin/main - keep trusted facts enrichment on manager execution path - add regression test to ensure MCP metadata cannot drive trusted facts Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
…conflicts Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
|
/code 解决冲突,不要引入编译错误 |
处理结果已完成“解决冲突,不要引入编译错误”的处理与验证。
|
|
/code 解决workspace_test冲突,不要引入编译错误 |
处理结果已完成
验证结果
代码推送
|
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix: resolve workspace_test merge conflict
|
/review |
| current.HasUnverifiedWrites = true | ||
| } | ||
| if summary.HasSuccessfulVerification { | ||
| current.HasUnverifiedWrites = false |
There was a problem hiding this comment.
[high] applyToolExecutionCompletion collapses write/verify into two booleans and then clears HasUnverifiedWrites whenever any verification succeeds in the turn. This is order-insensitive, so a turn containing both verify + write can end with HasUnverifiedWrites=false even when the latest write was not verified (especially with concurrent tool execution). Consider tracking write/verify by execution order or epoch, and only clear unverified writes when verification is proven to cover the latest write set.
There was a problem hiding this comment.
有,如果采用“按工具名轮转重排队列”,确实可能破坏模型原始工具调用顺序(尤其是跨工具存在隐式前后依赖时)。
当前这版代码里,这个风险已经被规避:
- 派发按原顺序:
internal/runtime/toolexec.go:71到internal/runtime/toolexec.go:76 - 结果按原 index 回填:
internal/runtime/toolexec.go:59到internal/runtime/toolexec.go:63、internal/runtime/toolexec.go:84到internal/runtime/toolexec.go:89 - 同名工具仍串行:
internal/runtime/toolexec.go:110到internal/runtime/toolexec.go:111、internal/runtime/toolexec.go:170到internal/runtime/toolexec.go:179
所以现在的语义是:
- 不再做“轮转重排”;
- 保留 assistant 提供的调用顺序作为调度输入;
- 但跨工具并发执行下,完成先后依然天然不保证(这是并发本身语义,不是队列重排造成的)。
未做内容:本轮未修改代码,仅回答该顺序语义问题。
There was a problem hiding this comment.
已按你指向的 review comment 完成修复并提交。
修复内容
- 修复点:
internal/runtime/turn_control.go的applyToolExecutionCompletion - 原问题:同一轮里只用聚合布尔值(
HasSuccessfulWorkspaceWrite/HasSuccessfulVerification)做收敛,忽略顺序,导致verify + write同轮时可能错误清除HasUnverifiedWrites - 现行为:改为按
summary.Results顺序逐条应用事实- 遇到成功写入事实:置
HasUnverifiedWrites=true - 遇到成功验证事实:置
HasUnverifiedWrites=false - 因此
verify -> write结论为true(仍有未验证写入),write -> verify结论为false
- 遇到成功写入事实:置
回归测试
- 更新:
internal/runtime/turn_control_test.go - 新增覆盖:
TestApplyToolExecutionCompletionKeepsUnverifiedWhenVerifyBeforeWriteTestApplyToolExecutionCompletionClearsWhenVerifyAfterWrite
验证
go test ./internal/runtime/...通过go test ./...通过
提交与推送
- Commit:
e2c89db - 已推送分支:
fork-pr-394-1776826146 - fork PR: fix(runtime): preserve unverified writes when verify occurs before write phantom5099/neo-code#52
未完成项:无。
…ify/write turns Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
fix(runtime): preserve unverified writes when verify occurs before write
Summary
本次改动聚焦
runtime/controlplane、运行态生命周期、completion gate、workspace 安全校验以及对应测试补强,目标是让运行闭环的状态表达更统一、写后验证更严格、权限等待态更清晰,同时避免 workspace 边界在 Windows 权限异常场景下被误放宽。What Changed
1. 统一 runtime 生命周期状态
RunStateplan / execute / verify / compacting / waiting_permission / stopped生命周期状态2. 新增 completion gate 并收紧完成条件
CompletionState与 completion blocked reasonpending_todounverified_writeverify_not_runpost_execute_closure_requiredHasUnverifiedWrites3. 重构 progress 评估输入与循环检测
ProgressInput从Phase切换为RunState4. 明确权限等待与 compact 的临时运行态
waiting_permissioncompactingrun_lifecycle5. 加强 workspace 安全校验
EvalSymlinks权限错误时直接把未解析路径当作安全路径6. 补强测试并修正旧测试语义
completion、phase、turn_control、workspace相关测试Files of Interest
internal/runtime/controlplane/completion.gointernal/runtime/controlplane/phase.gointernal/runtime/controlplane/progress.gointernal/runtime/run.gointernal/runtime/run_lifecycle.gointernal/runtime/turn_control.gointernal/runtime/toolexec.gointernal/runtime/permission.gointernal/security/workspace.gointernal/tui/core/app/update.goTesting
已执行:
go test ./internal/security ./internal/runtime ./internal/runtime/controlplanego test ./internal/security ./internal/runtime ./internal/runtime/controlplane -covergo test ./...相关模块覆盖率:
internal/security:92.3%internal/runtime:93.5%internal/runtime/controlplane:79.5%