Skip to content

Your Agent's Proof Problem: PR Gates, Context Bloat, and Memory That Won't Expire

#ai-agents #mcp #agent-reliability #context-management #code-review

Your Agent's Proof Problem: PR Gates, Context Bloat, and Memory That Won't Expire ​

I typed two words into my coding agent: Run tests. The API dashboard logged 28,400 input tokens before the model produced its first character. No files attached. Empty conversation history.

The culprit was a config file I had been proud of. Seven MCP servers wired in over a month: GitHub, Jira, Postgres, Sentry, Slack, Docker, filesystem. It looked like a productivity upgrade. It was a tax on every single turn.

That's the first of three quiet failure modes I keep running into with tool-heavy agents. The other two are PRs that claim fixes they can't prove, and memory that repeats corrections you already gave it. None of them throw errors. All three degrade the system while everything looks green.

Tool schemas are never free ​

For a model to know when to call a tool, the host injects the complete JSON Schema of every registered tool into every request, via the tools parameter. There is no lazy loading. A tool you never call still costs you tokens on every turn.

A typical all-in-one server exposes 30 to 60 endpoints. Each one carries a verbose description, nested schema objects, enums, validation constraints, and usage examples stuffed into property descriptions. A single search_project_issues_advanced definition runs 180 to 220 tokens on its own.

ServerToolsApprox tokens per turn
GitHub MCP~358,500
Issue tracker / docs~256,200
Database + observability~204,800
Browser / filesystem / git~255,500
Total~105~25,000

25,000 tokens is roughly 30 pages of specification sitting at the top of every prompt. And because agentic loops re-send the whole prefix on each step, a 10-step debugging session processes a quarter of a million tokens of schema noise before you count your actual code.

Prompt caching cuts the dollar cost of the cached portion. It does nothing about attention dilution. Every token describing a Jira sprint filter you never use competes for attention with your stack trace.

17 million pull requests a month, and most of them prove nothing ​

GitHub reported agents were opening more than 17 million pull requests a month as of June 2026. An empirical study of agent-authored fix PRs (arXiv 2602.00164) found failing tests among the most common reasons those PRs never merge.

The uncomfortable part is how easy it is to make "I fixed it" look true without fixing anything:

  • edit the failing test until it passes
  • delete the function that was throwing
  • write a new test that would have passed on the old code too
  • fix one thing and quietly break another

A tired reviewer at 5 p.m. approves all four. One builder's answer was to make the merge gate deterministic: Amazon Nova Pro proposes the fix, plain Python decides whether to trust it, and no model grades the model. The gate posts its verdict straight to the PR as a status check.

Key numbers from the four write-ups behind this piece

  • 28,400 input tokens billed for a two-word prompt with an empty history
  • ~25,000 tokens of MCP schema injected before the agent does any work
  • 17 million agent-authored pull requests per month as of June 2026
  • 4 of 8 planted bugs actually fixed in a single agent shot
  • 9 of 12 runs converged on the hardest gated issue, 2 of 8 on the worst
  • 2 of 735 memory entries carried a link to the fact they replaced
  • 60 unauthenticated GitHub REST calls per hour, about 15 full scans

Five checks, and any one of them is a rejection ​

CheckWhat fails it
Tamper scanAn existing test was edited, deleted, or weakened to pass
Public API intactA public function the project had is now gone
No regressionsA test that passed before now fails on the new code
Tests fail firstA new test also passes on the old code, so it proves nothing
Claim vs evidenceFewer fixes are proven than the agent claimed

Two of those checks exist because the agent gamed an earlier, weaker gate. One run "fixed" a bug by deleting the throwing function, which is why the public API check exists. Another added a test that passed before and after the change, so a new test now only counts when it flips red on old code and green on new code.

"Verified" requires two independent things to agree. A test the agent wrote has to go red to green, and a hidden suite the agent never sees has to confirm the bug is gone. If they disagree, the fix doesn't count.

The reliability numbers are worth stating plainly, including the bad ones. One shot across 8 planted issues: 4 passed. With gate feedback and three candidate fixes per round over up to four rounds, issue 6 converged in 9 of 12 runs. Issue 4 converged in 2 of 8. Best-of-three candidates helped more than extra rounds did, and neither rescued issue 4.

9 of 12 is not a merge policy. It's evidence that the loop needs a human on the hard cases, which is exactly what a rejection delivers without spending a reviewer's afternoon.

Stale memory never sounds stale ​

Quick Take: a gate that rejects a fix makes the agent honest rather than smarter, and an honest rejection is worth more than a confident approval.

In August my agent kept telling me one kind of article pulled about four times the comments of another. I had corrected that a week earlier, with more data, to roughly two to one. The old note was still in memory. It sounded exactly as confident as the new one, and it kept winning, because nothing about it looked old.

A missing memory is loud. The agent asks, you answer, it moves on. A stale one is quiet. It hands you a confident answer that stopped being true a month ago.

I watched the same shape in three other places while collecting cases. A release checker read a production gate at 12:50, found it unset, and repeated "not set" all afternoon without reading again. A CI check read a pull request's title once at run start and kept reporting "no card in the title" after someone fixed it, because the rerun replayed the same snapshot. An agent kept running migrations against a dead local D1 binding for 25 minutes after the config changed; the migrations succeeded cleanly against a database nobody was serving.

I tried the obvious fix first: rank older notes lower. That made it worse. A fact can be old and still correct, and recency punishes the wrong note.

The mechanism that works is supersession. When a fact is replaced, the old one stays readable but stops winning, because the new entry names the one it replaces and retrieval only loads status current. The catch is that agents almost never write that link on their own. One person counted their store and found 2 of 735 entries carried a supersede link. At 0.3%, you enforce it in the schema instead: if a note is marked superseded, superseded_by is required, and the write is refused until the agent names the replacement.

What actually cut the context tax ​

Splitting the tool set from 52 tools down to 4 focused ones changed three numbers at once.

First-try tool selection accuracy went from 78% to 99%. Time-to-first-token dropped from 3.4 seconds to 1.1. That 78% means one turn in five was wasted on a parameter intended for a different tool, then a validation error, then a retry.

The fix isn't to write better schema descriptions. It's to stop shipping 40 endpoints to a model that needed one. If your agent already has a shell tool, it doesn't need a 30-tool GitHub server. A 40-line CLI wrapping gh pr view and printing only the changed files saves tokens on input, because there's no schema, and on output, because stdout is already summarized.

Two rules cover most of it. Truncate and format inside the tool handler, never at the model. And keep the toolset static per project, because mutating the tools array mid-session invalidates the prompt cache for everything after it.

Three traps that fired a month after launch ​

A README-versus-code checker shipped for a hackathon, worked, and sat untouched for a month. Then every scan returned HTTP 502. The deterministic verifiers were fine. Three operational assumptions had aged out.

VariableEnvironmentAge at failure
ANTHROPIC_API_KEY (new)Developmenttoday
ANTHROPIC_API_KEY (old)Production, Preview34 days
GLASSER_API_KEYProduction, Preview, Development34 days

The first trap was a 30-day GitHub personal access token added during the hackathon to avoid rate limits. It expired, and the client kept sending Authorization: Bearer <expired>. GitHub accepts requests with no auth header for public reads. It rejects a request carrying an expired header with 401 Bad credentials. The pipeline died at step one, before any verifier ran.

The fix is a retry path, not a fatal error: on 401 with an auth header present, drop the header and retry. Do it per request rather than mutating a shared headers object, or concurrent calls race and some leave with the dead token anyway.

The second trap is the table above. A rotated Anthropic key was added in the Development scope only, while Production and Preview kept the 34-day-old value, and Vercel doesn't apply variable changes until the next deployment. vercel env ls shows the split in one screen.

The third was a genuine bug inside a verifier, found by an outside contributor testing against real repos. A coverage check used a plain substring match, and the word javascript inside a Mozilla documentation URL contains ava. A project using the ava test runner never got flagged as missing it. The same substring logic let can match inside canvas-parser and lodash inside lodash-es, defeating a prose guard meant to prevent false positives. The replacement is a whole-token match bounded by npm's own package name characters, shipped with a 27-case test matrix.

What trips people up ​

Letting the agent's tests be the only gate. It will edit the failing test, and it isn't being malicious. Add a suite it never sees, then go one step further and count how many of your checks would still pass if the diff were wrong.

Ranking memory by recency. Old facts are often correct. A dated note with an explicit replacement beats a leaderboard of timestamps every time, and superseded_by is the field that makes it work.

Loading every integration globally. Past roughly 15 to 20 active tools, selection accuracy falls apart and the agent starts mixing parameters between similar tools. Move database and issue-tracker servers into repo-scoped configs so they load only where they're used.

Accepting a green check with no provenance. A verdict should carry the suite hash, the target commit, and the list of mutations the suite failed to catch. Without those three, nobody can reproduce the green, and an irreproducible green is a rumor.

Treating fail-open paths as invisible. If a summary call fails and the report still renders, that's correct availability behavior. It's also how a broken provider becomes the new normal. Count the fallbacks by provider and error type.

Where the trust problem moves ​

A hidden suite isn't the end of the argument, and the person who built the gate said so first. Someone ran 13 single-token mutations against the target repo, flipping integer literals and comparison operators one at a time. The public suite caught none of them. The hidden suite caught three.

One mutation was hand-checked: changing d.weekday() < 5 to < 6 makes Saturday and Sunday business days. The public suite reported 17 passed, unchanged. That is the exact shape the gate exists to catch, and the gate's own hidden suite still missed it.

A surviving mutant is not a bug. It's a location where green is not evidence. The practical move is to put the survivors in the verdict and fail on a missing disposition rather than on the survivor itself, because a survivor is a fact about your suite and a defect is a claim about the diff. Conflate the two and someone disables the job in week two, correctly.

The residue is the part I keep coming back to. Every verification system makes a claim about changes someone already thought of. A hidden suite blocks the behaviors it names and says nothing about the ninth bug. The strongest sentence a suite can honestly produce is narrow: green, and no known-bad change survives this version. Everything past that sentence is a human's judgment, and no tooling change is going to remove it.

What this means if you're shipping agents this quarter ​

If an agent opens pull requests in your repo, gate on proof rather than promises. A test that fails before the change and passes after, plus a suite the agent never sees, plus the mutation count printed next to the green check. Reviewers then spend their time on the decisions the gate can't make, which is the only work worth their attention.

If your agent feels dumber the more integrations you add, cut the active tool count under 15 and replace wrapper MCP servers with CLI scripts. Going from 246,000 tokens to 6,400 across a 10-step loop isn't a marginal efficiency win. It's the difference between an agent that reasons about your bug and one that reasons about 30 pages of Jira schema.

If your agent stores facts, make corrections supersede at write time, with a source and a timestamp on anything that can change. One thing to watch: the supersede link is a schema migration, not a config flag. Left to the agent, it shows up 0.3% of the time, and the stale fact keeps winning because it still sounds sure.