The bug was in the lines that looked the same
An agent enabled the wrong provider in OpenPike's catalog because a hundred entries ended in identical lines. It passed the agent, CI and review. The mechanics of why, and the checks that replaced hoping review would catch it.
OpenPike is a gateway for LLM traffic. Customers store their own provider keys with us, point their agents at our endpoint, and we forward each request to the right provider with the right key. Getting “the right provider” wrong is the worst bug this system can have, because the thing we forward is someone else’s credential.
On November 22, 2026, we shipped exactly that bug. An agent asked to switch on one provider, AI21, also pointed a different provider, AkashML, at AI21’s API address. Anyone who had stored an AkashML key would have had it sent to AI21.
No key moved. I’ll show why below. But the change went through the agent, CI and my own review without anyone noticing, and every one of those layers failed for a reason that generalizes. This is the write-up I wish I’d had before it happened.
The data
Every provider OpenPike knows about lives in one JSON file, catalog.json. About 120 entries. A provider is switched off until its API address has been confirmed from the provider’s own docs, so most entries look like this:
{
"slug": "akashml",
"name": "AkashML",
"tier": "openai-compatible",
"adapter": "openai-compatible",
"formats": ["chat"],
"auth": "bearer",
"baseUrl": null,
"verify": true,
"enabled": false
},
Seven of those lines are identical across roughly a hundred entries. What distinguishes one record from another is slug and name, at the top of the block. The mutable part, the part every change touches, is at the bottom.
That layout is not unusual. Most config and fixture files in real systems look like this: a key near the top, a long tail of fields that default to the same values.
How the edit landed on the wrong record
Coding agents edit files with exact string replacement. The tool takes an old_string and a new_string, and in most harnesses it refuses unless old_string matches exactly once in the file. That uniqueness requirement is a good safety rail for code. For this file it’s a trap.
The three lines the agent needed to change (baseUrl, verify, enabled) appear about a hundred times. To make the match unique, the agent has to widen it until it includes something that only appears once. The commit’s diff shows what it most likely anchored on: the context lines below the change are the opening of the next entry, "slug": "alibaba".
@@ -245,9 +245,10 @@
"auth": "bearer",
- "baseUrl": null,
- "verify": true,
- "enabled": false
+ "baseUrl": "https://api.ai21.com/studio/v1",
+ "verify": false,
+ "enabled": true,
+ "notes": "Base URL from the provider's API docs: https://docs.ai21.com/... (read 2026-11-22)."
},
{
"slug": "alibaba",
That is a reasonable-looking anchor if you assume AI21 sits directly before Alibaba in an alphabetized list. It doesn’t. AkashML sits between them. The agent’s edit was unique, it matched, it was syntactically valid JSON, and it changed the wrong record. I can’t see the agent’s tool calls from that session anymore, so the anchoring is inferred from the diff, but nothing else in the file would have produced a unique match ending at that point.
The general failure: a uniqueness check on text is not an identity check on data. The tool guaranteed the edit touched exactly one place. Nothing guaranteed it was the right one.
Why CI passed
CI validated the catalog against its JSON Schema and a handful of rules: slugs unique, enabled providers have every field an adapter needs, prices reference real models. AkashML, switched on with a valid HTTPS address, a verify: false flag and a notes string, satisfied every one of them. The schema described the shape of a correct entry. It said nothing about relationships between entries, which is where this bug lived.
Why review passed
A unified diff shows three lines of context around each hunk. The slug was four lines above the first changed line. Look at the hunk above again: there is no "slug": "akashml" in it. What a reviewer sees is “a disabled provider got AI21’s address and AI21’s docs link,” next to a commit message that says “enable AI21.” The diff is internally consistent with the message. It’s just consistent with the wrong record.
Then a later pull request switched on the real AI21 entry, correctly. Both commits were titled “enable AI21.” In review, the second looked like the finished version of the first. Two honest commit messages, one misplaced edit, and no reason to look twice.
Blast radius
Before fixing anything I wanted to know whether a key had actually gone to the wrong company. Two facts settled it.
First, the request path. When a request names akashml/some-model, the gateway resolves the provider by slug, then loads that workspace’s stored key for that slug. If there isn’t one, it returns 424 missing_provider_key before any upstream call is made. The address is only used after a key has been found.
Second, the data. One read-only query against production:
SELECT COUNT(*) FROM provider_keys WHERE provider = 'akashml';
-- 0
No AkashML keys existed, so no request could ever have reached the wrong address. The window was about a day, and we were pre-launch. Had either fact been different, the next steps would have been finding the affected workspaces in the usage log and telling those customers to rotate their keys. Writing that sentence down before you need it is worth doing for any credential-routing system.
How it was actually found
Not by review. Another agent, doing an unrelated task, was updating a public tracking issue that lists which providers are switched on. Before editing the list, it cross-checked each provider against the catalog on main, noticed two entries with the same address, stopped, and wrote up what it had found before touching anything.
That’s the second time an agent has caught a bug for me by doing something humans are bad at: comparing two artifacts that are supposed to agree, carefully, every time, without getting bored. A human scanning a list of URLs sees a list of URLs.
Turning the invariant into a check
The fix itself was a one-line revert. The useful work was making this class of mistake fail the build. Two rules went into the catalog validator.
No two providers share an address. If two entries point at one host path, one provider’s customer keys go to the other. This is the invariant that was actually violated, and it’s cheap to check.
An entry’s documentation must be its own. A copied entry might get a slightly different address, so the first rule alone isn’t enough. But a copy almost always drags along the original’s notes and docs link. So: for every enabled provider, find the sites its notes link to, and fail if any of those sites hosts a different provider.
/** "docs.ai21.com" -> "ai21.com". Naive on purpose; see below. */
function siteOf(url) {
try {
return new URL(url).hostname.split(".").slice(-2).join(".");
} catch {
return null;
}
}
// site -> slugs whose addresses live there
const owners = new Map();
for (const p of catalog.providers) {
for (const field of ["baseUrl", "messagesBaseUrl"]) {
const site = p[field] ? siteOf(p[field]) : null;
if (site) (owners.get(site) ?? owners.set(site, new Set()).get(site)).add(p.slug);
}
}
const addresses = new Map();
for (const p of catalog.providers) {
for (const field of ["baseUrl", "messagesBaseUrl"]) {
const url = p[field];
if (!url) continue;
if (addresses.has(url)) errors.push(`${p.slug}: ${field} ${url} is already used by ${addresses.get(url)}`);
else addresses.set(url, p.slug);
}
if (!p.enabled || typeof p.notes !== "string") continue;
for (const url of p.notes.match(/https?:\/\/[^\s)"',]+/g) ?? []) {
const others = [...(owners.get(siteOf(url)) ?? [])].filter((s) => s !== p.slug);
if (others.length) errors.push(`${p.slug}: notes cite ${url}, which is ${others.join(", ")}'s site`);
}
}
The first version of the second rule had a hole: it only fired if the cited site belonged to another provider and not this one. A copied entry usually carries the copied address too, so the copy “owns” the site and slips through. The rule now fails whenever any other provider lives on that site. We ran the old catalog through both rules to confirm they fail on it, and the fixed one through to confirm they pass.
Two honest limitations a principal engineer will spot. siteOf takes the last two labels of a hostname, which is wrong for co.uk-style suffixes and for providers that share a hosting platform’s domain. The correct tool is the public suffix list. We don’t need it yet, every current provider is on its own registrable domain, and a false positive here fails loudly in CI where a human decides. I’d rather have a check that’s occasionally too strict on this file than one that’s quietly too lenient.
Structured files get structured edits
The checks catch the outcome. The rule that prevents the cause went into AGENTS.md, which every coding agent in the repo reads first:
Change
catalog.jsonandprices.jsonwith a script that parses the JSON and selects the entry by itsslug(inprices.json, by its model key), using Node orjqon the parsed JSON, never with text find-and-replace. Check the result by slug before committing.
In practice that’s one line:
jq '(.providers[] | select(.slug == "ai21")) |= . + {
baseUrl: "https://api.ai21.com/studio/v1", verify: false, enabled: true
}' catalog.json > catalog.tmp && mv catalog.tmp catalog.json
The selector is the identity. There is no way for that edit to land on AkashML, because it never looks at text.
This is the actual lesson, and it’s not specific to agents. Agents are extremely good at editing text, and the edit tools they use are designed around text. A catalog isn’t text; it’s data that happens to be serialized as text. When records share long identical runs, any edit keyed on surrounding text is keyed on the wrong thing. Humans make the same mistake with multi-cursor find and replace. Agents just make it with more confidence and less hesitation.
What I’d add next
Three things I haven’t built yet, in the order I’d build them:
- Semantic diffs for data files in PRs. A CI step that parses the before and after versions and comments something like
akashml: enabled false -> true, baseUrl null -> https://api.ai21.com/.... That puts the identity back into the review surface. A text diff can’t, because the identity isn’t near the change. - Ownership on the dangerous fields. Any change that touches an address in the catalog requires an explicit review from me, separate from routine price updates. Most changes to this file are boring. The ones that move keys shouldn’t look like them.
- Moving the identity next to the change, or out of the format entirely. Keying the file by slug (
"akashml": { ... }) instead of a list of objects would make every hunk carry its record’s name for free. It’s a migration, so it waits until it’s cheap.
The general version
Look at the data files in your own repos: YAML, JSON, Terraform variables, fixtures, feature flag configs. Most are full of repeated blocks that differ only by a key near the top. Agents will edit them by matching text. Diffs will hide the key. Reviewers will approve what they’re shown, especially when the commit message agrees with it.
So I’ve stopped asking review to protect those files. If a property has to hold, like every address unique or every record’s docs pointing at itself, it belongs in a check that runs on every change. If an edit has to land on a specific record, it goes through a tool that selects records, not text. Review is for judgment. Invariants belong in code.