The Agent Reintroduces a Bug You Already Fixed in an Earlier Session
说明与用途
AI 代理可能会重新引入已修复的错误,如果没有通过测试来强制执行修复。添加以不变式命名的回归测试并将其设为合并要求,可确保错误保持修复状态。
问题
An AI coding agent can reintroduce a bug that was previously fixed because it has no memory of past fixes, leading to regressions that are hard to detect until a regression test fails.
结果
By encoding invariants as executable tests and keeping them close to the code, teams prevent AI agents from reintroducing previously fixed bugs, even across refactors.
工作流
- 1. Identify the bug and fix it in the current session.
- 2. Add a regression test that reproduces the original failure (red) and passes after the fix.
- 3. Name the test after the invariant, not the implementation.
- 4. Add a short comment only for non‑obvious constraints.
- 5. If the bug depends on a boundary, add an end‑to‑end test that drives the real path.
- 6. Commit the corrected code, the regression test, and the comment together.
- 7. Run the test against the previous commit to confirm it would have caught the original failure.
- 8. Make the test a merge requirement so every future session must pass it.
证据
An agent has no memory of a fix it made in a previous session, so nothing structurally stops it from reintroducing the exact bug you already paid to remove.
Write the regression test before considering the bug closed.
If the bug lived across a layer transition, a unit test is insufficient — drive the real path and assert the observable outcome.
- 记录日期: 2026-11-01T06:28:47.994Z