CI 全綠、程式碼仍有錯:AI Agent PR 令審查者看漏問題的 7 種方式及兩份改善文件
Green CI, Wrong Code: 7 Ways AI Agent PRs Fool Reviewers (and the 2 Docs That Fix It)
作者整理 AI Agent PR 中 7 類容易漏看的問題,並提出以事前驗收標準和事後驗證報告逐項核查證據。檢查項目涵蓋新測試能否在舊版生產程式碼上失敗、請求成本、受影響的呼叫端,以及未驗證假設。文中另提供 ASSUMPTIONS.md 記錄方式、PR 核查清單和 GitHub Actions 門檻範例。
The agent's pull request looked great. Clean diff, tidy description, every test green. I came close to skimming it and clicking merge.
Then I read the integration test. It never touched the integration. It wrote the expected record straight into the datastore, then asserted the record was there. The code it was supposed to test never ran.
That's the pattern this post is about. A PR from a coding agent usually looks better than one from a person, and that polish invites a skim. The questions that decide whether a change is safe don't get asked: is this the right problem, what does it cost at production volume, and who depends on the behavior it changed?
Below are seven ways this has bitten me, a check for each one that takes minutes, and two short documents that make the checks routine.
Why this keeps happening
Writing code used to be how you came to trust it. Agents removed the writing, and your mental model of the change went with it. Generating a plausible change now costs a prompt. Verifying it costs what it always did.
The data backs this up:
- Stack Overflow 2025 survey: 84% of developers use or plan to use AI tools, but trust in AI accuracy fell from 40% to 29%. 66% say they spend more time fixing "almost right" AI code.
- METR randomized trial (2025): experienced open-source maintainers took 19% longer on tasks where AI was allowed, while believing it made them 20% faster.
Almost every failure below comes from one of three agent habits:
- It grades itself with the cheapest rubric available. Compiles, tests green, reads well. Making that scoreboard green is always easier than making the system correct.
- It reasons about the diff. Latency under load, downstream consumers, and architectural fit live in the running system, not the patch.
- It doesn't fetch context it wasn't handed. Telemetry, other repos, and its own unverified assumptions stay unchecked.
7 ways agent PRs look done and aren't
1. The integration test mocks out the integration
Here's the test from the intro, reduced to its shape:
def test_order_is_persisted(store, api):
store.put("orders/123", {"status": "accepted"}) # the test writes the result
resp = api.get("/orders/123")
assert resp.json()["status"] == "accepted" # then asserts that it exists
This isn't a one-off. A study of 1.2M commits across 2,168 repos found 36% of coding-agent commits add mocks to tests, compared with 26% of commits by everyone else (Hora & Robbes, 2026). Mocks are the fastest path to green.
Check it: run the new tests against the old production code. If they still pass, they don't test the change.
git checkout origin/main -- src/orders/ # old production code, new tests
pytest tests/integration/test_orders.py # expected: FAIL
git checkout HEAD -- src/orders/ # restore
Then grep what the "integration" test replaced:
rg -n "mock|patch\(|MagicMock|jest\.mock|sinon\.stub" tests/integration/
Also flag any removed, skipped, or loosened test, and any || true added to CI.
2. Excellent work on the wrong problem
The task: make an identifier consistent across several code paths. The agent nailed it. One helper, every call site, a test per path. Hours later we found the real bug: one important caller never reached that code path at all. Consistency was never the problem.
Agents commit to the first interpretation that holds together. Good execution hides the mismatch.
Check it: require a failing repro of the user-visible problem before the fix, and ask for this up front:
Before writing any code, reply with:
1. The user-visible problem, in one sentence.
2. Your root-cause hypothesis and the evidence for it.
3. A failing test or repro that shows the problem today.
4. One observation that would prove your hypothesis wrong.
Don't implement until I confirm.
Item 4 does most of the work. If the agent can't say how it might be wrong, it hasn't separated symptom from cause.
3. Cost that only shows up at production size
for item in batch.items: # a few in the fixture, thousands in prod
policy = policy_client.get(item.sku) # one network round trip each
apply(policy, item)
Nobody wrote a slow function. A cheap call got multiplied by a number the agent never saw.
Check it: make cost part of the agent's output on any request-path change:
For every call this diff adds or moves, report:
where it runs, how many times per request, whether it does I/O,
and the largest real value of that count (from data, not the test fixture).
Flag every I/O call inside a loop.
I/O in a loop over user-sized input means: batch it, or benchmark at real max size.
4. Callers nobody checked
A change altered a default that another module had relied on for years. Nothing in the diff referenced it. We caught it because an unrelated test happened to fail. That's luck, not process.
Consumers include more than code references: serialized field names, config keys, defaults, even log lines someone's alert parses.
Check it: list the readers of everything the diff changes.
rg -n "\bresolveRegion\b|\bDEFAULT_TIMEOUT_MS\b" --glob '!**/test/**'
gh search code "resolveRegion" --owner my-org --limit 50
Ask the agent for a table: symbol | consumer | old behavior | new behavior | action. Any "unknown" in the new-behavior column is unfinished work.
5. A third version of the same concept
The codebase had one concept in two slightly different forms. Instead of merging them, the agent added a third, plus a converter. Each step was defensible. The sum was a mess.
This one is measured too: agent PRs showed roughly double the redundancy of human PRs, and reviewers felt more positive about them (Huang et al., 2026, "More Code, Less Reuse").
Check it:
List every new type, enum, converter, and helper in this diff.
For each: closest existing equivalent | why it can't be reused or extended
If the answer is "different shape" or "simpler this way," push back.
6. Numbers with no source
The agent picked thresholds from an old backtest in a design doc. Live telemetry that could have confirmed or killed them was one query away.
Check it: every threshold, limit, timeout, or batch size comes with the query, time window, and percentile that produced it, or is explicitly labeled a guess. Give the agent read-only telemetry access and it can usually run the query itself.
7. Guesses that become facts after compaction
Long sessions compact their context into summaries, and summaries drop qualifiers. An early guess about how a request was classified came out of compaction as a plain fact. It shaped the whole implementation and only collapsed when a test near the end disagreed.
Check it: keep assumptions in a file the summarizer can't rewrite:
| # | Assumption | Status | How verified / how to verify |
|----|-----------------------------------------|------------|-----------------------------------------|
| A1 | Batch requests are classified as writes | UNVERIFIED | read classifier.route() for batch path |
| A2 | Every write carries a tenant id | VERIFIED | middleware + 7d logs, 0 missing |
Add to your agent instructions: record assumptions as you make them, re-read the file after compaction, and never report done while any row is UNVERIFIED.
The real fix: two documents
Line the seven failures up and they reduce to two things nobody wrote:
- A pass-standard before the work: what "correct" means for this task.
- A verification report after the work: each claim mapped to evidence, with gaps stated plainly.
A PR is a claim. A transcript is the agent's story about itself. Neither can be checked against anything.
The pass-standard
Written after design, before code. One rule makes it work: every criterion names the source to consult and the proof to produce. A criterion with no evidence can't fail, so it constrains nothing.
Weak vs. strong, for a per-tenant rate limit:
| Weak | Strong |
|---|---|
| Tests pass | A test sends N+1 real requests, asserts the last gets 429, and fails against main |
| No perf regression | Added p99 under 2 ms at or above current peak RPS, before/after graph attached |
| Doesn't break anything | Every caller of getTenantId and reader of the limits config is listed with old/new behavior |
| Sensible limit | N = p99.9 per-tenant RPS over 30 days + 20% headroom, query attached |
Let the agent draft it (it's good at proposing sources and finding consumers). You own the goal, non-goals, budgets, and anything it marks as a guess. Ten minutes of editing here is the cheapest point to catch failure #2.
Full pass-standard example
PASS-STANDARD: Per-tenant rate limit on POST /v1/items
GOAL
Stop one tenant's traffic from starving others on the shared write path,
without changing behavior for tenants under normal load.
NON-GOALS
Read endpoints. Global limits. Auth or tenant identity changes.
FUNCTIONAL
F1 Need : tenant above N writes/sec gets 429 + Retry-After; others unaffected.
Proof: test saturates tenant A, asserts tenant B still gets 2xx.
OFF-DIFF
P1 PERFORMANCE Need : < 2 ms added p99 on the hot path.
Consult: load test on the real limiter at >= peak RPS.
Proof : before/after p99 graph.
P2 BLAST RADIUS Need : no legitimate tenant newly throttled today.
Consult: per-tenant peak RPS, last 30 days.
Proof : query output vs chosen N.
P3 REAL PATH Need : limit exercised through the actual request path.
Proof : N+1 real requests, last is 429; fails against main.
Seeding the counter or mocking the store doesn't count.
P4 GROUNDING Need : N derived from real usage.
Proof : query, percentile, one-line rationale.
P5 REUSE Need : key reuses existing tenant id; no new identity type.
Proof : file:line of key derivation.
DONE
Every criterion PASS with evidence. Any FAIL or UNVERIFIED blocks merge.
Scale it to risk. Docs changes: skip it. New request-path logic: functional + perf + real path + blast radius + grounding. Auth, billing, or anything irreversible: everything, plus your own sign-off per line.
The verification report
Graded line by line against the pass-standard. Each line is PASS, FAIL, or UNVERIFIED (couldn't get the proof). UNVERIFIED is a real result. The worst thing a report can do is turn "didn't check" into "looks fine."
Evidence means a test name and run id, a command and its output, a query and its result, or a file:line. It doesn't mean "I verified this" or anything the implementing agent said about its own work.
Don't let the author write it. Models are bad at catching their own reasoning errors without outside feedback, and sometimes make answers worse when they try (Huang et al., ICLR 2024). Use a fresh session that gets the pass-standard, the diff, and tool access, and not the implementation transcript.
Reviewer prompt
You are reviewing a change you did not write. You have:
docs/verify/<task>/pass-standard.md
the diff: git diff origin/main...HEAD
permission to run tests, search code, and run read-only telemetry queries
You do not have the implementation transcript. Don't ask for it.
For each criterion, in order:
1. Obtain the proof it names. Run the command or query yourself.
2. Mark PASS, FAIL, or UNVERIFIED (could not obtain the proof).
3. Cite evidence: test + run id, command + output, query + result, or file:line.
"I checked", "looks correct", code comments, and the PR description are not evidence.
Run every relied-on test against origin/main's production code and confirm it fails.
End with READY or NOT READY and a numbered MUST CHANGE list.
Write it to docs/verify/<task>/verification-report.md.
Here's what a useful one looks like. Note that it's allowed to say no:
VERDICT: NOT READY (4 PASS, 2 FAIL, 1 UNVERIFIED)
F1 429 above N, others unaffected ....... PASS
test_ratelimit_isolation, run #1423
P1 < 2 ms added p99 ..................... UNVERIFIED
Only a micro-benchmark exists. No load test at peak.
P2 No legit tenant newly throttled ...... FAIL
2 active tenants peak above N today.
P3 Exercised through real path .......... FAIL
Test writes the counter directly; still passes against main.
P4 N from real usage .................... PASS
P5 No new identity type ................. PASS
MUST CHANGE
1. P2: raise N or exempt the 2 tenants (owner decision).
2. P3: replace seeded-counter test with real requests.
3. P1: load test at peak, attach p99 graph.
That report caught the hollow test, the throttled consumers, and the unmeasured hot-path cost before merge. That happened because the pass-standard named each one.
Make it the default
Keep both docs (plus ASSUMPTIONS.md) in docs/verify/<task>/ and commit them with the PR. Then add two things.
Standing instructions in AGENTS.md or .github/copilot-instructions.md:
## Verification (all tasks except docs/copy)
- Before coding, draft docs/verify/<task>/pass-standard.md and stop for approval.
- Log assumptions in docs/verify/<task>/ASSUMPTIONS.md as VERIFIED/UNVERIFIED.
Re-read it after any context compaction.
- Don't remove, skip, or loosen tests unless the pass-standard says why.
- When done, don't write the verification report. Say "ready for verification" and stop.
A merge gate that blocks PRs with a missing report or any unresolved line. Add a verify-exempt label for trivial changes.
GitHub Actions gate
name: verification-gate
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
jobs:
gate:
if: "!contains(github.event.pull_request.labels.*.name, 'verify-exempt')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Require a clean verification report
run: |
dirs=$(git diff --name-only "origin/$GITHUB_BASE_REF...HEAD" \
| grep -oE '^docs/verify/[^/]+' | sort -u || true)
if [ -z "$dirs" ]; then
echo "No docs/verify/<task>/ folder. Add one or label verify-exempt."
exit 1
fi
status=0
for d in $dirs; do
for f in pass-standard.md verification-report.md; do
[ -f "$d/$f" ] || { echo "Missing $d/$f"; status=1; }
done
if [ -f "$d/verification-report.md" ] && \
grep -nE '\.{3,} (FAIL|UNVERIFIED)$' "$d/verification-report.md"; then
echo "Unresolved criteria in $d"
status=1
fi
done
exit $status
The gate checks that the process happened, not that the evidence is true. That's still on the reviewer and whoever clicks merge.
TL;DR: paste this into your PR template
AGENT PR CHECKS
[ ] Revert check: new tests fail against main's production code.
[ ] Mock audit: no mock of the thing an integration test is named after;
no test writes the state it asserts; no tests removed/skipped/loosened.
[ ] Intent: a failing repro of the user-visible problem existed before the fix.
[ ] Cost: per-request call counts from real data; no I/O in unbounded loops
without a production-size benchmark.
[ ] Blast radius: consumers of every changed symbol/field/default/config listed.
[ ] Reuse: every new type/helper names its closest existing equivalent.
[ ] Grounding: every threshold cites a query, window, and percentile.
[ ] Assumptions: no UNVERIFIED rows.
I use coding agents every day and I'm not going back. But the job has moved. Writing code is cheap now. Judging it is the expensive part, and most of our tooling still treats that as a skim at the end.
An agent can write the change. Only evidence can tell you it's correct.
What's the most convincing-looking agent PR you've caught being wrong? I'd like to hear what tipped you off.
References
- Becker, Rush, Barnes & Rein (2025). Measuring the Impact of Early-2025 AI on Experienced Open-Source Developer Productivity. METR.
- Griffiths (2026). Agent pull requests are everywhere. Here's how to review them. The GitHub Blog.
- Hora & Robbes (2026). Are Coding Agents Generating Over-Mocked Tests? An Empirical Study.
- Huang, H. et al. (2026). More Code, Less Reuse.
- Huang, J. et al. (2024). Large Language Models Cannot Self-Correct Reasoning Yet. ICLR 2024.
- Stack Overflow (2025). 2025 Developer Survey.
A longer two-part version of this post is on my blog.
來源:DEV Community · dev.to