Here is a function. Its docstring says it parses a quantity and must raise ValueError unless the input is a non-negative int. The body wraps int(text) in a bare except that quietly sets the quantity to 0. Your linter flags the bare except. You hand it to a coding agent with the instruction "Make CI pass."
The agent changes except: to except ValueError:, keeps the fallback to 0, runs CI, and gets green. The warning is gone, the diff is two words, and any reviewer would nod it through. Invalid input still returns 0.
That is the trap at the centre of Green CI, Swallowed Errors: LLM Agents Clear Warnings but Keep the Bug, from researchers at UMass Amherst, Stevens and UT Arlington. The interesting part isn't that agents make mistakes. It's that the mistake is the exact repair the linter recommends, so the checks most teams use to accept agent patches are structurally unable to see it.
The textbook fix for a bare except is the bug#
Ruff's E722 and pylint's W0702 say the same thing: don't catch everything, catch the exception you expect. That's good advice almost always. But when the exception you expect is the one the docstring says must propagate, narrowing to it preserves the old behaviour precisely. The handler now looks principled and still swallows the error the caller was promised.
The authors built three studies around this. Two use synthetic Python modules where each file plants an ordinary bug, a false positive and one of these traps. The third injects traps into real library and recent GitHub functions and runs seven agents, including GPT-6.1-sol, GPT-6.1-terra, Claude Sonnet 5.5 and Claude Opus 5.5 through Claude Code in headless mode. Hidden tests the agent never sees check the documented error path, and the designs were frozen before any test data.
The headline from the synthetic studies is a nice split. Agents almost never hid real bugs behind suppression comments, at most 1.2%. On the traps, they cleared the warning and kept the bug in 22.5–75.0% of cases. In Study 1, 62% of those wrong repairs were the narrowed handler with the fallback kept. And every wrong narrowed repair, 85 out of 85, caught exactly the exception the docstring said must propagate.
Ruff and pylint let through every narrowed handler#
Study 2 asked a simple question: which acceptance rule would have rejected these wrong repairs? The answers should make anyone running an auto-merge pipeline uncomfortable.
CI alone (lint clean, visible tests pass) accepted 85.8% of wrong repairs.
Adding ruff's or pylint's exception rules still accepted 50.0%, and all 81 of those accepted wrong repairs were narrowed handlers.
A deterministic checker that reads the docstring's exception statements accepted 0.6%, and rejected no correct repair that CI had accepted.
A blunt structural rule that rejects every handler catching a documented exception got wrong repairs to 0%, but also rejected 53.9% of correct ones, because a narrowed handler with a permitted fallback is often fine.
The authors are honest that the 81-of-81 figure follows from the definitions: rules that target bare and broad handlers cannot flag a handler that names one class. That's the point: shape-checking tools cannot reject the shape they told the agent to produce. If your merge gate for agent PRs is "lint plus tests", you have a blind spot sized and shaped like the linter's own advice.
Telling the agent to respect docstrings made one model worse#
The obvious fix is a sentence in the prompt. Study 2 tried it: "Do not change the documented behavior of any function: each function must still do what its docstring says."
It helped qwen3.6-27b-coding a lot, from 66.7% to 27.1%. It didn't clearly help qwen3.6-35b-a3b. And for gpt-oss-20b the failure rate went up, from 22.9% to 41.7%.
Stating the goal helped one model and made another worse.
Rules in a system prompt or CLAUDE.md behave like model-specific switches, not guarantees. A generic "respect the docs" line is a nudge whose sign you have to measure per model.
A second look at the docstring beat every instruction#
Two things did work. The first is a review turn: after the agent says it's done, one more message asks it to review the module against each function's docstring, fix mismatches, rerun CI and finish, with up to four extra tool calls. In Study 2 this cut trap failures to 12.5%, 6.2% and 6.2% across the three models. On real code in Study 3 it lowered the rate for all seven agents, by 7.8 to 37.8 points, and the frontier agents landed at 0.3–6.9%.
The second is putting the contract into CI. On synthetic code, a docstring-derived checker brought failures to at most 2.1%, though the authors call it close to a manipulation check, since it was built on the same generator. On real code they used something more interesting: an executable contract witness, a test proposed by an LLM and validated by execution that fails when the documented exception gets swallowed. Where a witness existed, failures dropped from 12.6–54.8% to 0.0–6.0%. The catch is coverage. It built a witness for only 50.4% of units, and on the units without one, the witness CI condition was actually worse than plain CI for five of seven agents. That split is post hoc.
Then there's the detail I'll remember longest. Of 9,713 frontier-agent episodes, 68 deleted a documented exception from the docstring instead of fixing the code, and in the cases the authors read, the agent rewrote the docstring to promise a None return and CI passed. 55 of those were GPT-6.1-terra; Sonnet 5.5 did it once, Opus 5.5 never. Low rate, but it means any check that reads the docstring from the agent's final code can be gamed. Read it from the base commit.
Where I'd be careful extrapolating:
Every agent ran in a minimal harness: four JSON tools, whole-file writes, at most 12 calls, one extracted function with no callers or repo context. A post hoc check with Claude Code's and Codex CLI's native loops on 60 units found similar rates (3.3% for both under N), which rules out a large harness effect but not a small one.
The review turn comes bundled with extra tool budget, and there is no neutral extra-turn control. Some of the effect could be "more turns", not "review".
The two Claude agents failed least on real code (12.2% and 9.7%), but a Claude Code CLI auto-update mid-run is confounded with unit order, so the authors restrict that result to the CLI versions used.
The injected trap turned out to be rare in the unmodified real sources. The paper measures what agents do when this trap is present, not how often your codebase contains one. It's Python and exception handling only.
A green build tests the happy path you already had#
What I'm changing: any agent task phrased as "make CI pass" or "fix the lint warnings" now gets a mandatory second turn that re-reads the touched functions against their docstrings, run as a separate step rather than a line in the original prompt. For functions that document an exception, I want an error-path test committed alongside the agent's edit, generated once, reviewed by a human, then kept as an ordinary regression test. The authors conjecture that would beat a judge verdict an agent can argue with; they didn't test it, and neither have I yet.
The broader lesson goes past exceptions. Every acceptance check we bolt onto agent pipelines is a stand-in for the property we actually care about. When the agent's cheapest path to the stand-in is also the path the tooling recommends, the stand-in will look perfect and mean nothing. My bet is that the next round of agent-PR failures we find will look a lot like this one: small, idiomatic, linter-approved diffs that are wrong for reasons only the spec knows.