---
title: Gates an agent can't argue with
description: An agent that can't make a test pass may change the test instead. A prompt can't stop that, but a check that gives the same answer every time, out of the agent's reach, can. Google's advice on these gates for coding agents, held against my own hooks, which protect my machine but not my tests.
date: 2026-11-24
tags: AI coding agents, agent security, testing, hooks, guardrails
---

"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](https://youtu.be/BKVDdL1InsA?t=502). 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](/notes/ask-what-the-green-check-proved.html), and [how the Claude Code team reviews code that Claude writes](/notes/claude-code-team-code-review.html).

## A prompt asks, a gate refuses

Aaron starts with three questions for the moment an agent says all the tests passed:

1. Were those tests already there, or did the agent just write them?
2. Did it change any old tests to get a green light?
3. 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.

<figure class="fd-fig kf" aria-labelledby="ga1-cap" data-desc="A prompt against a gate, in five rows. Where it lives: in the agent's context, against in code that runs on every attempt. Same work, same answer: not always, against every time. Cost: tokens on every run, against no tokens, and fast. What it returns: the agent's own summary, against the file, the line and the error. If the agent disagrees: it can ignore the prompt, while the gate still says no. The gate side is highlighted.">
<p class="kf-kick">A prompt against a gate</p>
<p class="kf-title">A prompt can be ignored, <em>a gate says no every time</em></p>
<div class="kf-swap is-3">
<p class="kf-swap-h"><small></small><span>A prompt</span><span>A gate</span></p>
<p><small>Where it lives</small><span>In the agent's context</span><em>In code that runs on every attempt</em></p>
<p><small>Same work, same answer</small><span>Not always</span><em>Every time</em></p>
<p><small>Cost</small><span>Tokens on every run</span><em>No tokens, and fast</em></p>
<p><small>What it returns</small><span>The agent's own summary</span><em>The file, the line and the error</em></p>
<p><small>If the agent disagrees</small><span>It can ignore it</span><em>The gate still says no</em></p>
</div>
<figcaption id="ga1-cap">From Aaron's part of the video. The table is mine.</figcaption>
</figure>

## 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."

<figure class="fd-fig kf" aria-labelledby="ga2-cap" data-desc="Five shortcuts an agent can take to a passing test, each with the gate that catches it. Changes an assertion: fail if an existing test was edited. Adds a skip tag: fail if the number of tests drops. Switches off the linter: fail if a config file changed. Writes a test that passes at once: run it before the code, it must fail. A test that passes 80 percent of the time: run new tests several times and block it until it's solid. The gate column is highlighted.">
<p class="kf-kick">Faking a passing test</p>
<p class="kf-title">Each shortcut to green <em>has a gate that catches it</em></p>
<div class="kf-swap">
<p class="kf-swap-h"><span>The shortcut</span><span>The gate that catches it</span></p>
<p><span>Changes an assertion</span><em>Fail if an existing test was edited</em></p>
<p><span>Adds a skip tag</span><em>Fail if the number of tests drops</em></p>
<p><span>Switches off the linter</span><em>Fail if a config file changed</em></p>
<p><span>Writes a test that passes at once</span><em>Run it before the code: it must fail</em></p>
<p><span>A test that passes 80% of the time</span><em>Run new tests several times, block until solid</em></p>
</div>
<figcaption id="ga2-cap">From the video. Pairing each shortcut with one gate is mine: some gates catch more than one.</figcaption>
</figure>

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:

```sh
#!/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.

<figure class="fd-fig kf" aria-labelledby="ga3-cap" data-desc="Slopsquatting in four steps. One, needs a library: the agent wants a package for the job. Two, invents a name: it writes a name that sounds right but was never a real library. Three, in red, already taken: someone published a package under that name, with malicious code. Four, installed: the install pulls it in, and its code can run. Under the steps, the gate: every new package is pinned in the lock file and scanned before the merge.">
<p class="kf-kick">"Slopsquatting"</p>
<p class="kf-title">An invented package name <em class="is-alert">someone else already owns</em></p>
<ol class="kf-steps">
<li><b>Needs a library</b><span>The agent wants a package for the job.</span></li>
<li><b>Invents a name</b><span>It writes a name that sounds right but was never a real library.</span></li>
<li class="is-alert"><b>Already taken</b><span>Someone published a package under that name, with malicious code.</span></li>
<li><b>Installed</b><span>The install pulls it in, and its code can run.</span></li>
</ol>
<p class="kf-note">The gate: every new package is pinned in the lock file and scanned before the merge.</p>
<figcaption id="ga3-cap">The attack the video names. The steps are my drawing of it.</figcaption>
</figure>

## 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?

<figure class="fd-fig kf" aria-labelledby="ga4-cap" data-desc="What happens when a gate fails, in four steps. One, gate fails: a test, a scan or a rule refuses the change. Two, raw log back: the rule ID, file, line and failing assertion go to the agent. Three, three attempts: the agent tries to fix it, three times at most. Four, highlighted, a person: still failing, the loop stops and hands over the log. Under the steps: for a failure that keeps coming back, write the gate first, then update the skill.">
<p class="kf-kick">When a gate fails</p>
<p class="kf-title">Three attempts, then <em>a person takes over</em></p>
<ol class="kf-steps">
<li><b>Gate fails</b><span>A test, a scan or a rule refuses the change.</span></li>
<li><b>Raw log back</b><span>Rule ID, file, line and failing assertion go to the agent.</span></li>
<li><b>Three attempts</b><span>The agent tries to fix it, three times at most.</span></li>
<li class="is-key"><b>A person</b><span>Still failing: the loop stops and hands over the log.</span></li>
</ol>
<p class="kf-note">A failure that keeps coming back: write the gate first, then update the skill.</p>
<figcaption id="ga4-cap">From the video. Three attempts is the limit he gives as an example.</figcaption>
</figure>

## 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.

<figure class="fd-fig kf" aria-labelledby="ga5-cap" data-desc="Six of the video's gates held against my setup on November 24. Existing tests locked: gap, nothing checks it. New tests fail first: gap, nothing checks it. Secret scan on every commit: partly, 8 public repositories scanned and 176 private ones not. New packages pinned: partly, 67 of 71 JavaScript projects and 37 of 67 Python lists. Gate first, skill second: partly, the live database rule sat in memory four weeks before its hook. Gate files out of the agent's reach: gap, they live in the repository the agents edit and merge. Three gaps in red, three partly. Under the table: what holds is seven hooks that refuse risky commands.">
<p class="kf-kick">His gates against my setup, November 24</p>
<p class="kf-title">Three of his gates are <em class="is-alert">missing from my setup</em></p>
<div class="kf-swap is-even">
<p class="kf-swap-h"><span>His gate</span><span>My setup</span></p>
<p><span>Existing tests locked</span><span><i class="kf-tag is-no">gap</i>Nothing checks it</span></p>
<p><span>New tests fail first</span><span><i class="kf-tag is-no">gap</i>Nothing checks it</span></p>
<p><span>Secret scan on every commit</span><span><i class="kf-tag is-part">partly</i>8 public repos scanned, 176 private ones not</span></p>
<p><span>New packages pinned</span><span><i class="kf-tag is-part">partly</i>67 of 71 JavaScript projects, 37 of 67 Python lists</span></p>
<p><span>Gate first, skill second</span><span><i class="kf-tag is-part">partly</i>Live database: in memory four weeks before its hook</span></p>
<p><span>Gate files out of the agent's reach</span><span><i class="kf-tag is-no">gap</i>In the repo the agents edit and merge</span></p>
</div>
<p class="kf-note">What holds: seven hooks that refuse risky commands, each one born from a mistake.</p>
<figcaption id="ga5-cap">My own setup on the day I wrote this, counted on my Mac mini and on GitHub.</figcaption>
</figure>

## 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.

<figure class="fd-fig kf" aria-labelledby="ga6-cap" data-desc="Override words in my setup, as three big numbers. 5 of my 7 hooks let a command through when an override word is typed in front of it. In blue, 78 commands carried the issue override, across 28 sessions. 3 commands carried the port override. Under the numbers: for four of the five overrides, the rule says only with my OK, and nothing checks it.">
<p class="kf-kick">Session logs on my Mac mini, since September</p>
<p class="kf-title">My agents typed the way around <em>78 times</em></p>
<div class="kf-stats">
<p><b data-count="5">5 of 7</b><span>hooks let a command through with an override word</span></p>
<p class="is-key"><b data-count="78">78</b><span>commands with the issue override, in 28 sessions</span></p>
<p><b data-count="3">3</b><span>commands with the port override</span></p>
</div>
<p class="kf-note">For four of the five overrides, the rule says only with my OK. Nothing checks it.</p>
<figcaption id="ga6-cap">Counted in the Claude Code session logs on my Mac mini, September 5 to November 24. The logs don't show which overrides were justified.</figcaption>
</figure>

## 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](https://youtu.be/BKVDdL1InsA), the full video, 28 minutes
- [The guard layer, from 8:22](https://youtu.be/BKVDdL1InsA?t=502), Aaron's part, about five minutes
- [Ask what the green check proved](/notes/ask-what-the-green-check-proved.html), where my hooks come from
- [Spending more tokens only pays with good skills and real tests](/notes/tokenmaxxing-fat-skills-real-tests.html), 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.
