Skip to content

[code-review] trial_fork: verify-passed but uncommitted winner worktree force-deleted, work silently lost #2795

Description

@topcheer

文件: internal/tool/trial_fork.go
行号: 232-247(keep 判定 + cleanupWorktrees)、190-230(verify 执行条件)、378-397(scoreTrial)

问题描述

胜者 worktree 保留条件为 winner >= 0 && results[winner].Commits > 0,但打分中 VerifyPass 占 100 分(远超 Commits 的 20 分),且 verify 只要求 status == "completed"、在 dirty 未提交树上执行。一个未 commit 的 trial 可以仅凭 verify 通过胜出,随后 git worktree remove --force 删除其 worktree——验证通过的全部未提交工作被静默销毁,trial/* 分支上也无任何内容。

触发场景

  1. 两 trial 并行;trial 1 编辑文件、测试通过但未 commit(sub-agent 未服从 "commit all changes" 软性提示词),status=completed
  2. trial 2 正常 commit 但 verify 失败
  3. 打分:trial 1 = 100+5 = 105 > trial 2 ≤ 35 → trial 1 胜出
  4. winner.Commits == 0 → keep=-1 → worktree remove --force 销毁 trial 1 worktree
  5. 报告输出 WINNER: trial 1 + adopt 提示 git diff base..trial/... | git apply(diff 为空),anyUsable=true、IsError=false

预期行为 vs 实际行为

  • 预期:verify 通过的胜者成果应保留(worktree 或分支上至少一处)
  • 实际:未提交成果被 force 删除且不可恢复;报告误宣告可用;调用方 agent 以为有产出继续后续步骤

注意 keep 判定与 anyUsable 判定对同一 trial 的 "usable" 语义不一致(VerifyPass 在 anyUsable 算 usable、在 keep 不算)——明确的逻辑矛盾。注释 "no committed work is lost" 恰恰掩盖了未提交胜者工作丢失。

修复建议

  • keep 条件放宽为 Commits > 0 || VerifyPass;或
  • inspect 后对胜出且 Dirty 的 trial 自动快照提交(如 trial: uncommitted winner snapshot)
  • 报告在 winner 无 commit 时明确警告 adopt diff 为空

严重程度

high(仅限 trial_fork 试验产物,不影响主 checkout;独立复核 subagent 已确认触发路径)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions