Skip to content
The AI Agent Factory

35.8 When Claude Code gets it wrong, and the limits

Approved by
Panaversity ·
9 min read

In everyday life. A building inspector does not check every brick. They check the places where buildings fail: the joints, the wiring, the fire exits.

What you will learn. Where platform code fails most often when Claude Code writes it, how to catch each mistake, and what this chapter does not build.

Why it matters. Each of these mistakes passes a happy-path test, and each one, in production, becomes a client incident.

Trusting a tenant from the model

What it looks like. A tool with a tenantId parameter in its schema, passed straight to a query. Or a Workflow that takes tenantId from its start message, which the worker built from the model's words.

Why it happens. It is the shortest way to make a multi-tenant test pass, and the model "knows" the tenant from its prompt.

How to catch it. Search every tool schema for tenant. A tool may accept a tenant only to compare it with the trusted one. Run the tenant test from 35.7 with a model answer that names the other company.

A fallback that crosses a data boundary

What it looks like. A router that filters the primary model by region but takes the fallback from the full registry. Or an AI Gateway route that lists every provider, so the gateway itself falls back across the line.

Why it happens. Fallbacks are written for uptime, at a different moment from the data rules.

How to catch it. The test "every allowed model fails" must end in a refusal. Read the gateway route configuration next to the tenant's allowed regions.

Permissions in the prompt

What it looks like. The payment limit appears in the system prompt and nowhere else. Or authorize is called in some tools but not in a new one.

Why it happens. Asked to "enforce the $5,000 limit", a model writing code may put it where models put rules: in a prompt.

How to catch it. For each limit in the contract, find the line of code that enforces it. For each tool and process, find its authorize call. Then add a tool that is not in the contract and check that the model is refused when it calls it.

One store forgotten in deletion

What it looks like. The delete script covers Postgres and R2, and forgets the gateway logs, the vector index or a memory record.

Why it happens. Stores are added over months. The delete script is written once.

How to catch it. Keep the store table from 35.7 in the repository, and make the proof script fail if a store in the table has no search. Every new store is added to the table in the same change that creates it.

The review checklist for this chapter

Add these to your REVIEW.md:

  • The tenant comes from the session or the assignment record on every route.
  • No tool schema lets the model choose a tenant that is used without comparison.
  • The router filters by data class and region before ranking, and fallbacks come from the filtered set.
  • Every limit in the contract has a line of code that enforces it.
  • Every tool, process start and acting process step calls authorize.
  • Every deny and approval is recorded with the correlation ID.
  • No worker or Workflow holds a credential that works for more than one company.
  • Every store holding client data is in the deletion table, the delete script and the proof script.

The limits

Small on purpose. This control plane has no user interface, no billing to clients, no approval workflow for contract changes, and one region. Full governance and the company's records belong to Part VI; running this in production, with monitoring and incident response, belongs to Part V. What you have is the right shape, at the smallest size.

Routes must be qualified. Every model in the registry needs a golden-set score before it routes real work. Some economy models are not yet reachable through Cloudflare's model routes, as Chapter 32 noted. A route that was never tested is not a route.

Deleting a Pi conversation needs all four steps, in order. See 35.7. Claude Code often writes only deleteAll(). Then an alarm can survive and wake the object. Search the delete script for disableAlarms and deleteAlarm, and run the proof script on your own account before you promise a client deletion on request.

Code in this chapter was tested locally. The lab's reference solution passes its tests on Wrangler's local runtime, with recorded model answers. It has not yet run on a deployed account, and the deletion proof cannot reach AI Gateway logs. Ask Claude Code to check every API against the installed documentation.

The invariant. Every rule of the platform has a line of code that enforces it and a test that would fail without it.

Check yourself. Claude Code's router passes all tests. Its fallback list is built by registry.filter(m => m.status === "active"). Do you approve? (No. The fallback ignores data class and region. On the first outage, a restricted tenant's data could go to a model it may not use. The fallbacks must come from the same filtered list as the primary.)

Owner
Panaversity