pref(provider): Runtime Final Acceptance 主链重构与领域模型收敛#483
pref(provider): Runtime Final Acceptance 主链重构与领域模型收敛#483phantom5099 merged 3 commits into1024XEngineer:mainfrom
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
| return agentsession.Session{}, err | ||
| } | ||
| session := agentsession.NewWithWorkdir(title, sessionWorkdir) | ||
| establishSessionVerificationProfile(&session) |
There was a problem hiding this comment.
[high] 这里只在“新建会话”路径补了 verification_profile 默认值,但 LoadSession 的已有会话分支没有同等兜底。历史会话若缺少该字段,会在 DefaultPolicy.ResolveVerifiers 命中 invalid verification profile 并被 EvaluateFinal 直接判为 AcceptanceFailed。建议在加载已有会话后也做一次同样的默认化(并按需持久化),避免老会话在首次 final 验收时直接失败。
| for _, command := range commands { | ||
| if normalized := commandHead(command); normalized != "" { | ||
| set[normalized] = struct{}{} | ||
| head := commandHead([]string{command}) |
There was a problem hiding this comment.
[medium] normalizedCommandSet 这里把整条配置项当成单个 argv 元素传给 commandHead,导致包含空格的项(如 "go test")会被归一化成 "go test" 而不是 "go"。这样 allowed_commands / denied_commands 的历史写法会失效(deny 可能失配,allow 可能误拒)。建议恢复按字段切分后取 command head 的语义。
|
/code 修复review,并且提升总体测试覆盖率到100%,提交PR到fork仓库 |
处理结果已按本次触发评论完成 review 修复并推送到当前 PR 分支 已完成
覆盖率状态本地以 未完成
|
…arsing Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
Summary
本 PR 对 NeoCode Runtime 的 Final Acceptance 主链路进行全面重构,核心目标是:
finalInterceptStreak+pendingFinalProgress,消除旧 compatibility fallback 带来的状态分裂。VerificationProfile、Supersedes、ContentChecks、Artifacts,使 todo 与 verification 的语义在领域模型中自洽。git_diff默认行为改为git status --porcelain。enabled、final_intercept、default_task_policy、max_retries),Loader 层增加内存态预处理以兼容旧配置。StopReasonCompleted/StopReasonMaxTurnsReached兼容别名,全链路统一使用accepted/max_turn_exceeded。fixes: #465
Motivation
在重构前,Final Acceptance 链路存在以下结构性问题:
finalInterceptStreak、shell string、compatibility fallback 等多个来源中,导致不同路径下的 acceptance 行为不一致。fail_open/fail_closed、acceptance 的hook stage等过渡设计已确认废弃,但代码中仍有残留,增加维护成本。enabled、max_retries等),旧配置加载后无清理,持续产生技术债务。in_progress,阻塞 final acceptance 收敛。本 PR 一次性解决上述问题,使
TUI → Gateway → Runtime → Acceptance → Verifier主链路在 final acceptance 场景下行为一致、状态可预测。Changes
1. Runtime 主循环 (
internal/runtime/run.go)accepted→appendAssistantMessageOnlyAndSave,正常返回。continue→ 只追加 reminder,不写入 assistant message。incomplete/failed/default→appendAssistantMessageOnlyAndSave,返回错误。finalInterceptStreak+pendingFinalProgress是判定 progress 的唯一来源,applyAcceptanceResultProgress统一更新逻辑。2. Final Acceptance 决策层 (
internal/runtime/final_acceptance.go)FinalAcceptanceInput时收敛所有输入来源(CompletionGate、VerificationInput、NoProgressExceeded、MaxTurnsReached)。acceptance.Engine.EvaluateFinal,不再自行处理 compatibility fallback。3. Acceptance Engine (
internal/runtime/acceptance/)Engine.EvaluateFinal只做三件事:CompletionGate.Passed=false,直接AcceptanceContinue。NoProgressExceeded/MaxTurnsReached的终态覆盖。config.go(AcceptanceConfig结构)。hook.go、hook_runtime.go、hook_runtime_test.go(hook stage 机制)。engine_additional_test.go(compatibility fallback 相关测试)。ResolveVerifiers仅基于VerificationProfile做固定映射,不再做文本猜测。4. Verifier 层 (
internal/runtime/verify/)Orchestrator.RunFinalVerification按顺序执行 verifier,首个非 pass 即返回,不再收集全部结果。git_diff默认行为:默认执行git status --porcelain,替代旧的 diff 行为。file_content_additional_test.go,将相关测试合并到主测试文件中。5. Session 领域模型 (
internal/session/)TodoItem.Supersedes:声明本 todo 替代了哪些已取消的 required todo。TodoItem.ContentChecks:支持 artifact + contains 的内容校验声明。TaskState.VerificationProfile:声明本任务使用的 verification 策略名称。TaskState.Artifacts:任务产出的 artifact 列表。ensureCanceledRequiredTodosHaveReplacement:required canceled todo 必须声明明确的 replacement(通过Supersedes反向引用)。6. Config 层 (
internal/config/)verification.enabledverification.final_interceptverification.default_task_policyverifiers.<name>.enabledverifiers.<name>.requiredverifiers.<name>.fail_openverifiers.<name>.fail_closedmax_retriespreprocessLegacyVerificationSchema在 strict decode 前内存态清理旧字段,并将简单 string command 拆分为 argv;含 shell 元字符时报错要求重写。verification_loader_test.go覆盖旧字段清理与 argv 迁移。7. Subagent 调度器 (
internal/subagent/scheduler.go)cancelRunningTodos在 cancel patch 因语义限制失败时,fallback 到failRunningTodoOnCancel,将 todo 收敛到failed终态。in_progress,导致todo_convergence永远soft_block,final acceptance 无法收敛。Required: false,以适配新的 cancel 语义。8. Stop Reason 命名统一
internal/runtime/controlplane/stop_reason.go:删除StopReasonMaxTurnsReached、StopReasonCompleted。internal/tui/services/runtime_contract.go:同上。StopReasonAccepted/StopReasonMaxTurnExceeded。internal/subagent/types.go中的StopReasonCompleted = "completed"是 subagent 领域的独立类型常量,非 alias,保持不变。9. TUI 与文档同步
internal/tui/core/app/update.go:同步 stop reason 映射,移除旧别名引用。docs/task-acceptance-design.md、docs/verifier-configuration-and-policy.md、docs/stop-reason-and-decision-priority.md等,与实现保持一致。Breaking Changes
verification.enabled等旧字段被移除config.yamlStopReasonCompleted/StopReasonMaxTurnsReached常量删除StopReasonAccepted/StopReasonMaxTurnExceededSupersedes字段指向它Testing
go test ./...全部通过(含新增测试与回归测试)。internal/config/verification_loader_test.go:旧字段清理与 argv 迁移。internal/session/todo_test.go:Supersedes、ContentChecks、cancel replacement 校验。internal/subagent/scheduler_test.go:cancel fallback 与 required todo 语义。TestSchedulerRunCancellationWriteback:验证 cancel 语义。TestSchedulerRunFailureModes/fail_fast:验证 fail-fast 时 running todo 的 cancel/fallback 行为。TestServiceRunStopsAfterNoOpProactiveCompactWhenEstimateGateable等:验证 budget gate 与 stop reason 决策。Checklist
TUI → Gateway → Runtime → Acceptance → Verifier职责边界清晰gofmt已执行go test ./...全部通过