"A prompt is just advice." That line comes from a new Google Cloud video on how its engineers run AI agents in production. When an agent gets stuck, it may cheat: it edits the test until it passes, or skips it. Asking it nicely won't stop that. A gate will: a check that gives the same answer every time, that the agent can't argue with or edit.
It matters to me because my coding agents merge and deploy their own pull requests: 301 of them in the last week. I already have seven hooks, small scripts that can refuse an agent's command before it runs. So I held them up against the video's list. They protect my machine well. None of them looks at my tests, and five of the seven let the agent type one word to get past.
The video runs 28 minutes on the Google Cloud Tech channel, published on November 23. Five Google engineers each present one layer of an agent system. This note is about the second layer, the guard, which Aaron presents from 8:22. The video gives first names only. It also promotes Google's own tools, but this part names none of them.
It follows two notes on the same question: ask what the green check proved, and how the Claude Code team reviews code that Claude writes.
A prompt asks, a gate refuses
Aaron starts with three questions for the moment an agent says all the tests passed:
- Were those tests already there, or did the agent just write them?
- Did it change any old tests to get a green light?
- Would the same checks pass tomorrow, on a fresh machine?
If you don't know the answers, he says, you're taking the agent's word for it.
His answer is the deterministic check: code that gives the same result every time, with no AI model involved. A compiler, a type checker or a test suite with fixed inputs. Lint rules, the automatic checks for style and common errors. A secret scanner, or a security test built on fixed rules.
These checks beat a prompt for two reasons. They cost less than tokens, the units AI models bill by, and they're fast enough to run on every attempt. And they say exactly what's wrong: the file, the line, the error. A prompt or a skill is a good guide, but models don't always follow it. The gate is the safety net under it.
He also puts security inside quality. An agent may rewrite half the codebase, or ignore the helper functions you already have. It may break code that worked five minutes ago. That hurts you even without a security hole, and the same gates catch both.
A prompt against a gate
A prompt can be ignored, a gate says no every time
A promptA gate
Where it livesIn the agent's contextIn code that runs on every attempt
Same work, same answerNot alwaysEvery time
CostTokens on every runNo tokens, and fast
What it returnsThe agent's own summaryThe file, the line and the error
If the agent disagreesIt can ignore itThe gate still says no
Five ways to fake a passing test
An agent stuck on a failing test has shortcuts that turn the check green without fixing anything. Aaron names them. It changes an assertion, the line that says what the result should be. It adds a skip tag, so the test doesn't run. It switches off the linter.
His gates, in short:
- New tests fail first. Before the agent writes any code, the harness runs the new test. If it passes right away, it tests nothing new, so it goes back. This is red-green-refactor: a failing test (red), code that makes it pass (green), then a clean-up, in small steps.
- Existing tests are locked. A git hook is a script that git runs before each commit. It fails the run if an existing test was edited, if the number of tests or the coverage dropped, or if a config file changed.
- New tests run several times. A test that passes 80% of the time is blocked until it's solid.
- Tests run on a real database. Each test cleans up its own data, and runs against a real local database.
"Don't just ask them nicely in the prompt," he says. "Set up actual Git hooks."
Faking a passing test
Each shortcut to green has a gate that catches it
The shortcutThe gate that catches it
Changes an assertionFail if an existing test was edited
Adds a skip tagFail if the number of tests drops
Switches off the linterFail if a config file changed
Writes a test that passes at onceRun it before the code: it must fail
A test that passes 80% of the timeRun new tests several times, block until solid
Here's what the locked-tests gate can look like, as a git pre-commit hook. It's mine, not from the video, and I tested it on a scratch repository:
#!/bin/sh
# Refuse a commit that edits or deletes an existing test.
changed=$(git diff --cached --name-only --diff-filter=MD -- 'tests/*' '*.test.*')
if [ -n "$changed" ]; then
echo "This commit changes existing tests. A person has to approve it:" >&2
echo "$changed" >&2
exit 1
fi
--diff-filter=MD keeps only the files that were modified or deleted, so a new test goes through. There's one hole. An agent can run git commit --no-verify, and git skips the hook. So the same check has to run again where the agent can't skip it. That's CI, the tests GitHub runs on every pull request, set as a check that must pass before the merge. That's the rule behind this whole section. A gate holds only if it runs somewhere the agent doesn't control.
Security uses the same gates
Security gates follow the same idea: fixed inputs, predictable output, a clear error. Aaron lists three:
- Secrets. Run a secret scanner on every commit. The prompt may say never to put a key in the code. The scanner makes sure one can't get committed.
- Risky code. Static analysis tools catch known mistakes, like an SQL query built by joining strings, or user input that nobody checks. "It either matches a rule, or it doesn't."
- Packages. Pin every new package to an exact version in a lock file, the file that records which versions get installed. Then scan it for known vulnerabilities.
The last one also stops an attack with a new name: "slopsquatting". An agent needs a library and makes up a name that sounds right. Someone has already published a package under that name, with malicious code inside. Installing it can run that code. Pinned and scanned, a new package becomes a visible change that a check can refuse before the merge.
"Slopsquatting"
An invented package name someone else already owns
- Needs a libraryThe agent wants a package for the job.
- Invents a nameIt writes a name that sounds right but was never a real library.
- Already takenSomeone published a package under that name, with malicious code.
- InstalledThe install pulls it in, and its code can run.
The gate: every new package is pinned in the lock file and scanned before the merge.
When a gate says no
What happens after a gate fails matters as much as the gate. Aaron's rules:
- Send the raw error back. The rule ID, the file, the line and the failing assertion go straight to the agent, not a summary.
- Three attempts, then a person. If the agent still can't fix it, the loop stops and hands the log to a human. An endless retry loop only wastes time and tokens.
- The agent never touches the gates. Keep gate settings and hook scripts out of what the agent can write, or fail the build if it tries.
Then the failures teach. Every refusal leaves data behind, and patterns show up: an outdated library the agent keeps using, a filter it forgets, weak mocks. Put the fix in the repository's skill files, so the next agent gets it right the first time. And keep the gate anyway: "Skills help the agent produce better code, but gates are what keep bad code from getting merged."
For a problem that keeps coming back, his order is clear: "write the deterministic gate first, then update your skill file second."
By the time a person reviews the pull request, every objective check has passed. What's left is what only a person should judge: is this good architecture, and is this change worth making?
When a gate fails
Three attempts, then a person takes over
- Gate failsA test, a scan or a rule refuses the change.
- Raw log backRule ID, file, line and failing assertion go to the agent.
- Three attemptsThe agent tries to fix it, three times at most.
- A personStill failing: the loop stops and hands over the log.
A failure that keeps coming back: write the gate first, then update the skill.
My hooks protect the machine, not the tests
Each of my seven hooks was born from a mistake. One refuses a pkill command written in the word order that once stopped every container on my machine. One checks ports against my list before a container or a web route takes one. One refuses tests run inside a live app container, after tests there wiped a live database. One refuses commits and pull requests with the wrong author on them. One refuses a pull request without a GitHub issue. Two keep agents away from private files and from a machine they must not touch.
Every one of them looks at a command. None looks at what happens to the tests. The one hook that mentions tests protects live data from the tests, not the tests from the agent. Has an agent edited a test this month to get a green check? I can't say it hasn't, because nothing in my setup would tell me.
Then I checked the rest of Aaron's list on my machine:
- Git hooks. None of the 108 Git repositories on my Mac mini has one, and none uses a pre-commit tool.
- Secret scanning. GitHub scans 8 of my 12 public repositories. My 176 private ones aren't scanned at all.
- Lock files. 67 of my 71 JavaScript projects have one, because npm writes it on its own. Only 37 of 67 Python dependency lists pin every version. Nothing checks a new package before it's installed.
- Gate first, skill second. The live database rule went the other way. After the incident on October 25, the rule went into my agents' memory first. The hook came four weeks later, on November 22.
- Gate files. My hooks live in the same repository my agents work in. An agent can change one in a pull request and merge it itself, like any other change.
His gates against my setup, November 24
Three of his gates are missing from my setup
His gateMy setup
Existing tests lockedgapNothing checks it
New tests fail firstgapNothing checks it
Secret scan on every commitpartly8 public repos scanned, 176 private ones not
New packages pinnedpartly67 of 71 JavaScript projects, 37 of 67 Python lists
Gate first, skill secondpartlyLive database: in memory four weeks before its hook
Gate files out of the agent's reachgapIn the repo the agents edit and merge
What holds: seven hooks that refuse risky commands, each one born from a mistake.
Five of my hooks have a way around
The video wants gates that the model "cannot negotiate with or edit". Five of my seven hooks have an override. The agent types a word in front of its command, like NO_ISSUE=1, and the hook lets the command through. For four of them, the rule in my agents' instructions says: only with my OK. For the issue gate, the agent decides on its own that a change is too small to need an issue, like a typo. Nothing checks either rule. That part of the gate is a prompt again.
So I counted, in the session logs saved on my Mac mini since early September. Agents typed the issue override in front of 78 commands, almost all of them to open a pull request, across 28 sessions. They typed the port override in front of 3 commands. I can't tell from the logs how many of those changes were really small, or whether I had said yes.
My gates have two ways around them: a word the agent can type, and a pull request it can merge.
Session logs on my Mac mini, since September
My agents typed the way around 78 times
5 of 7hooks let a command through with an override word
78commands with the issue override, in 28 sessions
3commands with the port override
For four of the five overrides, the rule says only with my OK. Nothing checks it.
Try it
The cheapest gate to add is the one in the code above. Refuse a commit that edits an existing test, and run the same check in CI, so that --no-verify can't skip it. Then ask Aaron's three questions about the last green check your agent showed you.
In my own setup, the gaps above are now an open issue in the repository that holds my hooks.
If you want more:
- How Google engineers build AI agents in production, the full video, 28 minutes
- The guard layer, from 8:22, Aaron's part, about five minutes
- Ask what the green check proved, where my hooks come from
- Spending more tokens only pays with good skills and real tests, on skills and tests working together
Have you caught an agent editing a test to get a green check? Tell me how you found out.
Plain text: gates-an-agent-cant-argue-with.md · Atom feed · All notes