修了一个从没复现过的崩溃
A fix for a crash it never reproduced
智能体为一个自己从没触发过的故障加了守卫或分支,说是“防止”它发生;没人知道这个修复是否对准了真正原因,审查者也没注意到描述里的这句坦白。
适用于: Claude Code · Cursor · Codex · Copilot agent
症状
PR 描述里写着类似“无法复现,但这样应该能防止”的话。改动前没有失败的测试或捕获到的输入,改动后也没有证明。新加的分支从未执行过。
为什么会这样
@roulerdelaroute 讲了一个 Claude 提的 PR:它加了一个新分支来防止坏数据包导致崩溃,但“一直没能复现那个坏数据包”。8 个以上的审查智能体都没注意到描述里的这句话,反而在从未运行过的代码上挑小毛病。写一个看似合理的守卫很容易,证明原因却需要复现;没有复现,修复就是一个读起来像答案的猜测。
示例
示意,基于 @roulerdelaroute 的描述。
diffPR: "Prevent crash on malformed packet. Note: could not reproduce the bad packet."
function parsePacket(buf) {
+ if (buf.length < HEADER_LEN + 2) return null; // guess at the cause, never executed
const len = buf.readUInt16BE(HEADER_LEN);
...
复制即用的修复
按你用的智能体挑选文件。规则片段用英文写,放进任何仓库都能用。
规则
Claude Code:加入 CLAUDE.md
CLAUDE.md## Reproduce before you fix
- Before fixing a bug, reproduce it: a failing test, a captured input, or a command that shows
the failure. Paste the failing output.
- If you cannot reproduce it, say so in the first line of your reply and do not present a change
as the fix. Offer it as a hypothesis, with what evidence would confirm it.
- After the fix, run the same reproduction and paste the passing output.
- Reviewers: check the description for "could not reproduce" or "should prevent" before reading the code.
规则
Codex、Copilot 编码智能体等:加入 AGENTS.md
AGENTS.md## Reproduce before you fix
- Before fixing a bug, reproduce it: a failing test, a captured input, or a command that shows
the failure. Paste the failing output.
- If you cannot reproduce it, say so in the first line of your reply and do not present a change
as the fix. Offer it as a hypothesis, with what evidence would confirm it.
- After the fix, run the same reproduction and paste the passing output.
- Reviewers: check the description for "could not reproduce" or "should prevent" before reading the code.
Cursor 规则
Cursor:项目规则
.cursor/rules/fix-without-repro.mdc---
description: "AgentFails: A fix for a crash it never reproduced"
alwaysApply: true
---
## Reproduce before you fix
- Before fixing a bug, reproduce it: a failing test, a captured input, or a command that shows
the failure. Paste the failing output.
- If you cannot reproduce it, say so in the first line of your reply and do not present a change
as the fix. Offer it as a hypothesis, with what evidence would confirm it.
- After the fix, run the same reproduction and paste the passing output.
- Reviewers: check the description for "could not reproduce" or "should prevent" before reading the code.
技能
团队共享的 /verify 技能(Claude Code)
把它提交进仓库,让整个团队(以及每个智能体会话)跑同一套检查。把命令换成你项目里真实的命令。
.claude/skills/verify/SKILL.md---
name: verify
description: Verify the current change before calling it done. Use before every commit, PR, or "done" message.
---
# Verify
Run every step and paste the real output. Never summarize a step you did not run.
1. **Scope**: run `git diff --stat` and `git status --short`. For every changed file, say which part
of the request needs it. Any file you cannot justify gets reverted, or listed under
"Unrequested changes" for the user to decide.
2. **Build and types**: `npm run build` (or the project's build command).
3. **Tests**: `npm test`. Report pass/fail counts. If a test was edited, skipped or deleted,
say so explicitly with the reason.
4. **Behavior**: exercise the changed behavior once for real (a curl, a CLI run, a screenshot)
and show what happened.
5. **Report** in this format:
- Requested: <one line>
- Changed files: <list, each with its reason>
- Checks run: <command -> result>
- Not done / unsure: <list, or "none">