Skip to content

fix(agent-core-v2): scope verification to the change and stop repeating passed checks - #4451

Merged
RealKai42 merged 2 commits into
mainfrom
fix/verification-scope
Oct 27, 2026
Merged

RealKai42 merged 2 commits into
mainfrom
fix/verification-scope

Conversation

@RealKai42

@RealKai42 RealKai42 commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Requirement or Bug

交付验证对所有任务一刀切、通过后没有停止条件、压缩后又要求全部复验,导致没有新信息的重复验证;遇到与改动无关的失败也没有处理规则。

Bug Reproduction Steps

  1. 渲染默认系统提示,看 Delivering work 段:每个回合宣布完成前(包括只回答问题、做诊断,以及 explore / plan 子 agent),都要求"项目标准的 build 和 test 在交付物上通过",并且没有任何"什么时候停止验证"的说明。
  2. 在有测试的项目里跑一个会触发压缩的长任务:压缩后注入的摘要前缀要求"把摘要当笔记而不是证据,凡是说已完成、测试已通过、修复已生效的,都先自己验证";而系统提示 Context management 段写的是"把摘要当作准确记录,不要重做它报告已完成的工作"。两处指令直接矛盾。
  3. 同一段里,"测试是红的就不能宣布完成"对任何失败测试都生效,提示词也没有说明遇到与改动无关的 bug 或失败测试该怎么办。仓库里本来就有失败测试时,按字面要求 agent 只能去修任务之外的代码,或者不宣布完成。

Root Cause

Code Changes

只改提示词文本和对应测试,不改代码逻辑。

 system.md · Delivering work
-  宣布 work 完成前:项目标准 build + test 必须在交付物上通过;原始场景端到端、真实调用
+  宣布 change 完成前:覆盖这次改动的项目标准 build + test 必须在交付物上通过;原始场景端到端、真实调用
+  这些检查通过后:只有新的改动、失败或未解决的疑虑,才重复或扩大检查
-  测试是红的,不能宣布完成
+  覆盖这次改动的测试是红的,不能宣布完成
+  不要试图修无关的 bug 或失败测试,改为在最终回复里说明
 compaction-summary-prefix.md(压缩后注入给模型)
-  把摘要当笔记而不是证据:凡"已完成 / 测试已通过 / 修复已生效"都先自己验证
+  摘要报告已完成的工作不重做、报告已通过的检查不重跑;只复查摘要标为未验证的内容
 compaction-instruction.md(写摘要时的指令)
   声称完成但从未验证的,标为未验证
+  检查通过后、它覆盖的代码又被修改的,也把该结果标为未验证
  • refactor(agent-core-v2): simplify the default system prompt #3390 加回这句时要防的问题保持不变:用项目标准命令、在最终交付形态上验证,并且要真实调用,而不是只 import 或编译。
  • "测试是红的"的收窄和"不修无关失败"必须一起改:只加后者的话,遇到无关失败时 agent 既不能宣布完成,又不能修。
  • 压缩指令新增的一句是压缩前缀修改的配套保护。压缩指令要求只保留代码的最终版本,"测试通过后又改了代码"的先后顺序可能在摘要里丢失。既然恢复后的模型会信任摘要里的"已通过",就由写摘要的模型把过期的通过结果标出来——它此时仍能看到完整上下文。

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
验证句的适用对象(the work → a change) 每个回合宣布完成前都要按交付形态跑标准 build / test 并端到端验证,包括只回答问题、做诊断、出计划,以及 explore / plan 子 agent 只对做了改动的工作提这个要求;没有改动时仍受"没验证的要直说、不能把未验证说成完成"约束 希望 agent 回答问题时也自动跑 build / test 来佐证结论的用户 在请求里明确要求运行,或写进 AGENTS.md
标准 build / test 的范围(加 that cover the change) 项目标准 build 和 test 必须在交付物上通过 覆盖本次改动的标准 build 和 test 必须通过;"用项目标准命令""在交付物本身上验证""真实调用而非只 import / 编译"不变 大仓库、monorepo 中依赖 agent 默认跑全仓构建和测试的用户 明确要求全量运行,或在 AGENTS.md 里规定必跑命令
新增停止规则 没有停止条件,通过后可以继续重复或叠加验证 检查通过后,只有新的改动、失败或未解决的疑虑才重复或扩大检查 希望 agent 通过后再换其他方式交叉验证的用户 明确要求额外验证;或配置 Stop hook
失败测试的处理("测试是红的"限定到覆盖改动的测试;新增"不修无关 bug / 失败测试") 任何测试是红的都不能宣布完成;遇到与改动无关的 bug 或失败测试没有规则 只有覆盖改动的测试是红的才不能宣布完成;无关的 bug 和失败测试不修,改为在最终回复里说明 希望 agent 遇到原有失败或无关 bug 时顺手修掉的用户 在请求里明确要求修复,或写进 AGENTS.md
压缩摘要前缀第二句 压缩后把摘要中所有"已完成 / 已通过 / 已修复"都先复验一遍 已完成的不重做、已通过的不重跑,只复查摘要标为未验证的内容 长任务压缩后依赖 agent 自动复验全部结论的用户 摘要标为未验证的仍会复查;也可以明确要求重跑
压缩指令新增一句 只把"声称完成但从未验证"的结果标为未验证 还会把"通过后覆盖的代码又被修改"的结果标为未验证 无(新增约束) 不需要

受影响人群:

  • 验证段(system.md 的四行变化):所有使用内置系统提示的会话,包括 TUI、print 模式(kimi -p)、desktop 与 web(kap-server)、VS Code、ACP;默认 agent,以及 coder / explore / plan 子 agent 和 Tower worker。自定义 SYSTEM.md 或自定义 agent 只有在模板里包含 ${base_prompt} 时才受影响。
  • 压缩相关的两处:所有发生完整压缩(自动或 /compact)的会话。旧版本写的会话里已有的摘要保持原文,下次压缩起使用新文本;识别摘要消息靠 origin.kind,不依赖文本,读取旧会话不受影响。

测试覆盖:

  • profile-shared.test.ts:计划模式说明位置的断言改用新首句作锚点。
  • fullCompaction.test.ts:4 处前缀、3 处压缩指令的内联快照更新;手动压缩用例的 input_tokens 从 1192 改为 1215,即新增那句的估算增量(94 个字符,约 23 个 token)。
  • 单测只能锁定文本。行为层面做了两轮本地真实模型对照,都使用 Kimi 托管模型(高推理强度)、无交互模式。
  • 第一轮(验证范围与压缩):4 个场景(只问问题;修 bug;加功能后手动压缩再写提交说明;加功能、改动后按要求不跑测试,再压缩写提交说明),新旧各 2 次,共 16 个会话。
    • 所有改动类任务的最终代码事后跑 npm test 全部通过;只问问题的任务两组都没有改文件,也没跑 build / test。
    • 压缩后两组都没有重跑已通过的检查,也没有出现"未在最终代码上运行却声称测试通过";在"改动后未重跑测试"的场景里,两组的摘要都标出了验证已过期。
    • 旧组在这些场景里同样没有出现过度验证,所以这一轮只能说明没有回归,不能证明修复有效。总输入 token 新组少约 7%,主要来自旧组一次额外的命令行与临时脚本验证,样本太小,不能据此说明节省幅度。
  • 第二轮(失败测试的处理),每组 3 次:
    • 仓库里本来就有一个与改动无关的失败测试,任务是修一个定价 bug:main 的文本、本 PR 第一个提交的文本、最终文本三组共 9 次,全部修好了 bug、没有改无关模块,并在最终回复里写明该失败与本次改动无关;没有一次声称测试全部通过。三组行为没有差别。
    • 改动本身会让另一个模块的测试失败,同一模块里还有一个原本就失败的测试,任务是调整默认税率:本 PR 第一个提交的文本和最终文本两组共 6 次,全部更新了因改动而失败的测试,没有动原本就失败的那个,并在回复里把它标为与本次改动无关。加上"不修无关失败"之后,模型没有把自己造成的失败当成无关。
    • 这两个场景里,不加这句提示 agent 也能正确处理,所以这一轮说明的是新提示没有带来回归,不说明它在这些场景里改变了行为。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

…ng passed checks

The delivery verification rule in the default system prompt applied to every
turn, required the project's standard build and test commands regardless of
what changed, and had no point at which checking stops. After compaction, the
summary prefix also told the agent to re-verify everything the summary
reported as done or passed, contradicting the system prompt's instruction not
to redo work the summary reports as done.

- Apply the build-and-test requirement to changes, and only to the standard
  build and test commands that cover the change; keep verifying the
  deliverable itself with real calls.
- Once those checks pass, repeat or broaden them only for a new change, a
  failure, or an unresolved concern.
- After compaction, rely on what the summary reports as done or passed and
  re-check only what it marks as unverified.
- Have the compaction summary mark a passed check as unverified when the code
  it covers changed afterwards.
Copilot AI balanced review requested due to automatic review settings October 26, 2026 15:54
@changeset-bot

changeset-bot Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d9f06bd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T15:56:46.760764Z 63e596c PR opened
🔒 Security Review ✅ Completed 2026-10-26T15:58:14.391102Z 63e596c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@d9f06bd
npx https://pkg.pr.new/@moonshot-ai/kimi-code@d9f06bd

commit: d9f06bd

The red-tests rule in the delivery paragraph applied to any failing test,
and nothing said what to do with bugs or broken tests the change did not
cause. Read literally, a pre-existing failure left the agent two options:
fix code outside the task or never call the work complete.

- Only tests that cover the change keep the work from being marked
  complete.
- Do not attempt to fix unrelated bugs or broken tests; mention them in
  the final message instead.
- Drop the changeset; this PR ships without one.
@RealKai42
RealKai42 merged commit 3154ec4 into main Oct 27, 2026
17 checks passed
@RealKai42
RealKai42 deleted the fix/verification-scope branch October 27, 2026 06:21
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
MoonshotAI#4410 MoonshotAI#4413 MoonshotAI#4431 MoonshotAI#4450 MoonshotAI#4451 MoonshotAI#4485 MoonshotAI#4524 were each implemented earlier —
the compaction prefix suite, the media-recovery case, the OAuth callback
socket drain, the split delivering-work section, the compaction wording,
the reasoning-key order and the 10-step todo reminder are all in the tree
and pinned by their own tests. Each row now carries that probe.

Only MoonshotAI#4410 needed care: upstream patched paths that this fork renamed
(`human/llm/builtin/protocol` versus `human/llm/requester/bases`), so the
matching was done on the behaviour — stripDynamicToolContext is gone and
extractEventUsage already reads usage only on terminal response events.

Ledger: closed 22 -> 28, remaining 71.
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.

3 participants