fix(runtime): 修复 resume_verify_closure 首轮 verify 启动失败并完善状态机闭环#666
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! |
|
/code 提高测试覆盖率到90,完成后推送到我的分支 |
Result已补充并提交测试覆盖改进,提交为 What Changed
Verification
Fork PR已创建 fork 内回灌 PR:Cai-Tang-www#65 |
Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: Cai-Tang-www <106404101+Cai-Tang-www@users.noreply.github.com>
test(runtime): raise resume verify coverage
|
/review |
| return | ||
| } | ||
|
|
||
| resume, err := s.checkpointStore.GetLatestResumeCheckpoint(ctx, sessionID) |
There was a problem hiding this comment.
Medium: applyResumeCheckpoint auto-applies the latest row for session_id, but it never validates the stored workspace_key or transcript_revision before forcing resumeNextBaseLifecycle/pendingSystemReminder. Because SetResumeCheckpoint persists both fields, a stale checkpoint from before a restore or workdir change can still steer an unrelated next run into plan/verify. This should be gated on the checkpoint still matching the current session/workspace state before applying it.
| } | ||
|
|
||
| report := s.evaluateAcceptGate(ctx, &state, turnOutput.assistant) | ||
| s.emitVerificationLifecycleEvents(ctx, &state, completionState, report) |
There was a problem hiding this comment.
Medium: this PR starts emitting verification_started, verification_stage_finished, and verification_finished, but the downstream TUI contract is not wired for them yet. internal/tui/services/gateway_stream_client.go still falls through to the default branch for these event types, and internal/tui/core/app/update.go has no handlers registered, so the payloads arrive as raw maps and are effectively ignored. As written, the new observability path is incomplete for existing clients.
变更背景
当前 Runtime 的 run-state 机制已接近完整,但在 resume 场景中存在一个关键启动缺口:
resume_verify_closure时,会在新 Run 首轮将 base lifecycle 覆盖为verify;setBaseRunState会触发"" -> "verify"转移;该问题已经被 review 明确指出,属于功能正确性问题(非风格问题)。
本 PR 做了什么
1) 修复
resume_verify_closure启动失败在
internal/runtime/run.go中,将首轮 base state 设置改为通过新引导入口执行:setBaseRunState改为applyTurnBaseRunState。在
internal/runtime/run_lifecycle.go新增:applyTurnBaseRunState(ctx, state, next):state.lifecycle == ""且next == verify时,先安全引导到plan,再进入verify;该方案不放宽全局状态转移规则,避免把“特殊恢复场景”扩散为“通用状态机语义放宽”。
2) 增加回归测试
在
internal/runtime/run_lifecycle_test.go新增:TestApplyTurnBaseRunStateBootstrapsVerifyFromEmptyverify时会经历"" -> "plan" -> "verify",并最终稳定在verify。3) 同次提交内包含的状态机完整化改动
本分支还包含前一提交中对 runtime 状态机的完整化增强(已在分支历史中):
waiting_user_question生命周期状态并接入优先级计算。ask_user执行链路中引入显式挂起/恢复与兜底清理,防止 pending 状态泄漏。resume_applied事件及恢复策略投影(replay_plan/resume_verify_closure)。改动价值
resume_verify_closure现在可以在新 Run 首轮正常启动,不再在 provider 调用前失败。ValidateRunStateTransition的通用规则,最小化副作用。风险与兼容性评估
"" -> "plan" -> "verify"),属于可解释、可消费的状态机演进。验证
已在本地完成:
go test ./internal/runtime/...go test ./...均通过。
关键文件
internal/runtime/run.gointernal/runtime/run_lifecycle.gointernal/runtime/run_lifecycle_test.gointernal/runtime/permission.gointernal/runtime/checkpoint_resume.gointernal/runtime/verification_events.gointernal/config/feishu_test.go