让编码智能体先查清测试为何偶发超时
作者为同一排查任务分别编写智能体指令和人工审查说明,用夜间构建中的偶发超时做示例。智能体需结合失败报告、测试代码和构建日志给出可复核的原因,确认原因且修复方案获批后才改代码。
AI 深度解读
把「修一下这个偶发失败的测试」交给 AI Agent,它很可能先调大超时。夜间构建绿了,团队却还是不知道:是测试本身不稳、构建环境变慢,还是产品行为变了?
作者的做法是给同一个任务写两份简报。给 Agent 的一份规定查什么、何时停、交回什么,给人的一份规定怎么核对证据、谁来拍板。下次派发这类任务时,你可以直接借用这个结构,让一次没产出补丁的排查也能推进问题。
把「修好测试」改成「查清为什么超时」
偶发失败的测试(flaky test)最难处理的地方,是同一项检查有时过、有时不过。一次重跑成功,只能说明这次过了。原文给出的场景是夜间构建里某个测试偶尔超时,测试、环境、产品这三个方向都还没排除。
给 Agent 的简报把任务终点定成一份可复核的发现,同时给出证据来源、允许改动的范围和停止条件。
OUTCOME
Determine why the named test times out in the nightly build. Return a
finding a reviewer can check. Make a code change only if the cause and
an approved remedy are established.
SOURCES
Start with the failure report, the test's current code, the relevant
build logs, and the team's approved test conventions. Record the build
and commit IDs you used. If a source is missing or inaccessible, name it
in the report.
SCOPE
Inspect the named test and the product path it exercises. Compare passing
and failing runs where evidence exists. Keep changes to that path and its
test coverage. Do NOT weaken an assertion, increase a timeout, or disable
the test just to make the build pass.
DECISION POINTS
- Evidence points to a product regression: report it before changing
product behavior.
- Intended behavior is unclear: ask the test or feature owner to decide.
- Evidence can't separate test, environment, and product: deliver the
competing explanations and the next check that would separate them.
CHECKS
For an approved fix: run the relevant test and existing build checks.
Record what ran, the environment, and the result.
For an investigation without a fix: identify the logs and comparisons
that support the finding.
DELIVERY
Return the cause or remaining uncertainty, links to evidence, any
approved change, check results, and known limits. Do not merge or deploy
unless the task separately authorizes it.
看 DECISION POINTS 的第三条。现有材料分不出是哪一类问题时,Agent 要交回仍然成立的解释,以及下一项能帮助区分它们的检查。比如日志只记了整条用例耗时,下一步就可以比较通过和失败的运行里,同一个关键步骤各花了多久。调大超时则需要当作一个有证据支持、待批准的修法来讨论。
人的简报负责接住 Agent 停下来的那一步
给执行者的简报只写三件事:提供访问权限、核对结论、把要拍板的问题交给负责人。
Open the named build and repository, and make sure the agent can reach
the failure report and logs. Check that its finding matches the recorded
runs. Bring any proposed behavior change or unresolved test expectation
to the named owner before authorizing a fix, then review the result.
看最后两行。Agent 发现产品行为可能变了,或者说不清测试到底应该期待什么时,执行者要先找测试或功能负责人确认,再授权修复。两份简报得在这个节点对齐。只要 Agent 需要停下来等人决定,执行者就得知道该找谁,以及要拿哪次运行的证据去问。若修复还要过特定构建或设备验证,作者建议另列 QA 清单。
我的判断
我认同把「找到原因」和「提交修复」写成两个交付条件。相比只在提示词里加一句「别调超时」,这套写法给了 Agent 一条可走的路:证据不足时,交回日志、候选原因和下一项检查。作者也披露自己为做 AI 任务交接工具的 Wagglet 写作。原文给的是一组示例简报,没有报告真实排查结果、成功率或与单份简报的对照,效果仍是经验判断。
两份简报能不能跑起来,取决于 CI 是否保留了可比的日志、测试预期是否有人说得清。只有一条超时报错时,写得再细也不够归因。小团队里,派任务、审日志和维护测试的可能是同一个人,用一张工单写清「Agent 的交付」和「负责人拍板的条件」也能落实同样的分工。跨团队排查时,单独给执行者一份短简报更方便交接。
能拿来做什么
- 派发前端端到端测试或 Node 集成测试的排查任务时,附上失败报告、通过与失败的构建记录和对应的 commit ID,方便 Agent 比较同一条测试的运行结果。
- 在工单里写清调大超时、放宽断言或跳过用例的批准条件,并标明谁能确认预期行为。
- 审查 Agent 提交的结论时,对照它引用的运行记录。若仍有多个可能原因,就把那项能区分它们的检查接成下一步,有获准的补丁再跑相关测试和现有构建检查。