Skip to content

refactor(runtime):验收机制重建#592

Merged
phantom5099 merged 25 commits into1024XEngineer:mainfrom
phantom5099:rebuild-verify
May 10, 2026
Merged

refactor(runtime):验收机制重建#592
phantom5099 merged 25 commits into1024XEngineer:mainfrom
phantom5099:rebuild-verify

Conversation

@phantom5099
Copy link
Copy Markdown
Collaborator

@phantom5099 phantom5099 commented May 9, 2026

1. 原有问题

重建前的 Runtime 验收链路存在几个结构性问题。

验收标准来源不稳定:旧逻辑依赖 InferTaskKind 从用户原始输入做关键词推断,例如“创建文件”推断为写入任务,“看看”推断为只读任务。Plan 阶段模型已经声明了验证要求,但验收链路没有把这份声明作为一等输入。

Decider 决策树覆盖不足decider/decide.go 通过硬编码 RequiredNextActions 续跑,能表达的动作很有限。真实任务需要跑测试、检查文件内容、验证命令结果或处理 todo 收敛时,Decider 往往只能给出模糊建议。

FinalIntercept 旁路过多finalInterceptStreakpendingFinalProgressshouldPromotePendingFinalProgress 等状态让“是否继续”变成多处隐式判断,读文件、搜索、工具调用都可能影响完成判定,最终容易出现既过早停止又难以解释的状态。

Progress 误承担完成判定:旧的 NoProgress / BusinessProgress 试图判断“有没有业务进展”,但这个判断和 Accept Gate、todo、facts、completion protocol 职责重叠,容易把正常探索、连续验证或连续编辑误判为停滞。

2. 当前方案

核心原则:验收标准来自结构化 Plan,Runtime 只做确定性事实检查;Progress 不再判断业务进展,只负责重复循环检测。

2.1 Plan.Verify 结构化

PlanSpec.VerifySummaryView.Verify 从自然语言列表升级为 AcceptChecks

type AcceptCheck struct {
    ID       string
    Kind     string
    Target   string
    Match    string
    Required *bool
    Params   map[string]string
}

兼容旧 []string 格式,反序列化时自动迁移为结构化检查。AcceptChecks.Normalize() 的去重 key 包含 kindtargetmatchparamsrequired,避免不同 content_contains 条件或 required 属性被合并。

2.2 Accept Gate 二元终态

Accept Gate 只读取执行期事实,不重新执行命令。

Check kind 判定来源
output_only assistant 有可见输出
workspace_change 执行期确认存在工作区写入
command_success 执行期存在匹配命令的成功记录
file_exists 目标文件存在或执行期有读写事实
content_contains 文件内容或执行期事实满足 contains
tool_fact 工具 facts 中存在明确验证事实

最终只有两类结果:全部 required checks 通过则 accepted;任一 required check 失败则 accept_check_failed。拒绝工具调用本身不会直接导致失败,但如果被拒绝的是 required check 所需证据且后续没有补跑,最终会失败。

2.3 Completion Protocol

模型停止调用工具但没有输出结构化 task_completion 时,Runtime 注入完成协议提醒继续一轮,而不是立即终止。

  • 连续缺失达到上限后终止为 missing_completion_signal
  • 中间出现工具调用会重置缺失计数
  • ThinkingMetadata 响应不计入缺失计数

2.4 Todo 边界

Plan 模式下,todo ownership 由结构化 Plan 决定。

  • 应用 plan artifact 时把 PlanSpec.Todos 补入 session todos
  • Accept Gate 只验收 plan-owned todos 和 plan 执行后新增的 required 非终态 todos
  • CurrentPlan=nil 或 completed plan 不继承旧 todo
  • direct build 无 active plan 时,通过 bootstrap 提醒模型先创建本轮 todo,而不是复用旧 todo
  • todo_not_found 返回恢复建议和当前活跃 todo ID,帮助模型纠正 ID

2.5 Repeat Cycle Detector

NoProgressBusinessProgress 已全量移除。Progress 现在只检测重复循环:

  • 当前工具签名相同
  • 当前结果指纹相同
  • 当前子目标指纹相同

三者同时相同才累加 RepeatCycleStreak。达到阈值后先注入 REMINDER_REPEAT_CYCLE;如果下一轮仍然重复,才 hard stop 为 repeat_cycle

读文件、grep、git status、测试命令、验证通过、写入成功、todo 状态变化都不再参与 Progress 计数。它们分别由 facts、accept gate、todo convergence 和 completion protocol 负责。

2.6 工具超时与搜索稳定性

工具超时不再只依赖全局 tool_timeout_sec

  • 普通工具仍以配置默认值为基础
  • workspace 扫描类工具首轮至少 60s:filesystem_grepfilesystem_globcodebase_search_textcodebase_search_symbol
  • timeout 后同一签名指数退避,最高 160s
  • workspace 扫描类工具按 tool + scope/dir 聚合退避 key,换关键词不丢失退避状态
  • repository walker 和 filesystem grep/glob 统一跳过高噪声目录:.cache.tmptmpbuilddistouttargetcoverage.next.nuxt.turbo.parcel-cache.vitevendorbinobj

2.7 配置迁移

配置升级流程会清理已废弃字段,避免旧配置在严格 YAML 解析时启动失败。

  • 删除 runtime.max_no_progress_streak
  • 保留 runtime.max_repeat_cycle_streak
  • 删除 verification 下旧的废弃字段
  • 继续保留 context budget 迁移与 verifier command argv 迁移

3. 删除内容

删除项 说明
internal/runtime/decider/ 删除 TaskKind 推断和硬编码 RequiredNextActions
internal/runtime/acceptance/ 删除旧 Acceptance engine / policy / decider
internal/runtime/final_acceptance.go 删除旧最终验收编排
internal/runtime/acceptance_service.go 删除旧 AcceptanceService
internal/runtime/acceptance_events.go 删除旧验收事件定义
internal/runtime/before_completion_orchestrator.go 删除旧完成前编排器
internal/runtime/task_kind.go 删除任务类型推断
internal/runtime/verify/git_diff.go 由 workspace facts / workspace_change 检查替代
NoProgress / BusinessProgress 体系 删除 evidence、exploration window、no-progress reminder、no-progress stop reason

4. 新增与核心修改

模块 变更
internal/runtime/acceptgate/ 新增二元 Accept Gate 和 check 判定逻辑
internal/runtime/acceptgate_runtime.go 接入 Runtime facts、plan-owned todo 过滤、acceptance 事件
internal/session/plan.go 新增 AcceptCheck / AcceptChecks,兼容旧 verify 格式
internal/runtime/run.go 接入 completion protocol、accept gate、repeat-cycle hard stop
internal/runtime/controlplane/progress.go 简化为 repeat-cycle detector
internal/runtime/controlplane/stop_reason.go 保留 missing_completion_signalaccept_check_failedrepeat_cycle 等真实终止原因
internal/runtime/permission.go 增加扫描类工具基础超时和自适应 timeout backoff
internal/repository/path.go 扩大 repository walker 噪声目录过滤
internal/tools/filesystem/helpers.go filesystem grep/glob 对齐噪声目录过滤
internal/runtime/todo_bootstrap.go direct build 无 active plan 时提醒创建本轮 todo
internal/config/context_budget_migration.go 清理旧 runtime.max_no_progress_streak 配置
internal/tui/core/app/update.go 展示新的 stop reason、验收结果和 todo 冲突行为

5. 多端适配

Gateway

Gateway 主链路无需额外业务逻辑。gateway_runtime_bridge.go 已适配精简后的 DecisionSnapshotStatusStopReasonSummaryDetails

TUI

TUI 已适配:

  • 新 stop reason 的状态展示与活动日志
  • AcceptanceDecidedPayload.Summary / Results 的结构化展示
  • todo_not_found 冲突时清空过期 todo 面板

Web

Web 端协议类型中仍保留向后兼容字段,但当前 PR 的核心改动主要在 Runtime/TUI。若 Web 直接消费 ProgressScore 的旧字段,需要跟进移除 has_business_progressno_progress_streak、evidence 等显示逻辑,并只展示 repeat-cycle 相关字段。

6. 验证记录

已针对当前改动运行过以下目标测试:

go test ./internal/config
go test ./internal/runtime
go test ./internal/runtime/controlplane
go test ./internal/promptasset ./internal/tui/services ./internal/tui/core/app

全仓 go test ./... 仍存在两个与本 PR 无关的本地/环境失败:

  • internal/runner TestCapSignerHelpers:Windows 路径断言差异
  • internal/tools/codebase TestCodebaseCommonHelpersEvalSymlinks(root) Access is denied

7. 预期收益

验收可解释:所有失败都能对应到具体 required check 或 todo 收敛状态,不再依赖 TaskKind 推断。

完成判定收敛:Completion Protocol 处理“模型停了但没声明完成”,Accept Gate 处理“声明完成后是否满足验收”,职责分开。

循环防护更窄更稳:Progress 不再尝试理解业务进展,只抓真正重复的工具签名、结果和子目标,降低误停概率。

旧配置可升级:删除 max_no_progress_streak 后,已有用户配置可以通过 migration 自动清理,不会因为严格 YAML 解析启动失败。

Copy link
Copy Markdown

@fennoai fennoai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found 3 correctness regressions in the new accept-gate / todo-boundary flow. Performance, security, and docs passes did not add separate locations beyond these code-level issues.

Comment thread internal/session/plan.go Outdated
Comment thread internal/runtime/acceptgate_runtime.go
Comment thread internal/runtime/acceptgate/checks.go Outdated
@phantom5099
Copy link
Copy Markdown
Collaborator Author

@xgopilot 修复编译错误,把缺失字段补上

@fennoai
Copy link
Copy Markdown

fennoai Bot commented May 10, 2026

结果

已修复当前分支的编译错误,并推送到 phantom5099:rebuild-verify

本次改动:

  • internal/runtime/state.go 将缺失的 toolTimeoutBackoff map[string]int 补回 runState
  • 保持 internal/runtime/permission.go 的自适应工具超时退避逻辑可正常读写运行态状态

验证:

  • go test ./internal/runtime/...
  • go test ./internal/tui/...
  • go test ./internal/cli/...
  • go build ./...

提交:241241ea fix(runtime): restore tool timeout backoff state

View job run

@phantom5099 phantom5099 merged commit 06d6471 into 1024XEngineer:main May 10, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants