Skip to main content
coreydaley.dev

The MessagePit scope I threw away after an hour

At 8:17 tonight I committed a Mailtrap provider stub to MessagePit. At 8:34 I committed an agent whose whole job was to keep that stub, and the SendGrid and Twilio stubs next to it, honest against the real provider APIs. At 9:22 I deleted all of it.

The deletion commit removed the internal/mailtrap package, about 640 lines once you count its 24 tests, plus a /provider-compat skill, a spec-analyst subagent, and the Python script that held them together. Most of the lines I wrote in that hour didn’t survive it, and I think the hour was well spent anyway.

Where the evening started

If you read the first MessagePit post, the pitch is simple: a Mailpit fork that catches Twilio SMS on localhost the way Mailpit catches email. Since then it has grown a SendGrid v3 stub, and tonight’s first commit added Mailtrap’s Email Sending API: one endpoint, POST /api/send, with Bearer auth, a body-size cap, address validation, and a handler that builds a MIME message and drops it in the same inbox as everything else.

That commit did something good along the way. With two email providers on the table, the duplicated security code was obvious, so it moved into a shared mailadapter package: a 10 MiB body limit, a constant-time Bearer check, header sanitizing, and a shared JSON error helper. It also gave every provider its own port by type: email stubs in 8100–8199, SMS in 8200–8299 (Twilio moved there from 1775), capture tools in 8300–8399. The rule I wrote down was “the next provider in a range gets the next sequential number — no gaps.”

The compat agent

With three provider stubs, the question I kept circling was drift. MessagePit’s whole value is that your real SDK points at it and can’t tell the difference. The project CLAUDE.md I wrote in that 8:34 commit says it plainly: the stubs “aim for full behavioral fidelity with the real API, not just ‘good enough.’” Every time Twilio or SendGrid changes something, the stub is wrong until someone notices.

So I built the someone. It started as a slash command and four minutes later became a project-local skill, which is the shape I use for anything multi-step in my agent-config setup. The workflow:

  1. Infer the claimed scope. A Python script regexes the provider’s Go source and the route registrations in server/server.go for routes, auth scheme, JSON request fields, and every status code the handler can return.
  2. Fetch the real spec. The skill hands the spec URL and the claimed scope to a spec-analyst subagent. Its instructions say “You do not write code.” It fetches the provider’s OpenAPI document, finds the matching operations, and returns a compact Spec Snapshot: path, auth, required and optional fields, response codes, anything claimed that isn’t in the spec, and anything in the spec the stub doesn’t claim yet. The subagent was there to keep a provider’s entire OpenAPI document out of the main context.
  3. Generate compat_test.go. One TestCompat_* per endpoint, each building the exact request the spec requires, asserting the status code and body shape, and covering one error case. The file header reads // Code generated by /provider-compat. DO NOT EDIT., and it is fully regenerated on every run.
  4. Run the tests and print a fidelity score. It ends with either Twin is in sync. or Action required: see failures above.

On paper, it’s sound agent engineering. The context isolation is right, and the split between human-owned behavior tests and machine-owned spec tests is explicit. I still like the idea. (For the record, no generated compat_test.go ever made it into a commit. The removal message lists one, but whatever got generated died in the working tree.)

The case against it

The commit message doesn’t argue the case. Looking at the code, this is the case I’d make.

The test froze a moving target. The spec registry pointed at the main branch of Twilio’s and SendGrid’s OpenAPI repositories. For Mailtrap it pointed at a documentation page, because I didn’t have a machine-readable spec to point at. So the generated test’s contents depended on whatever someone else’s default branch said on the day I ran the skill, interpreted by a model each time. A DO NOT EDIT file that changes when a third party pushes, or when the model reads a docs page differently, isn’t a regression test. It’s a snapshot with a confident header. When it went red, I’d have to work out whether the stub drifted, the spec moved, or the generator changed its mind.

The scope inference was confidently wrong. The skill’s own example output listed SendGrid’s status codes as 202, 400, 401, 413, and 500. Run the script against the SendGrid package as it stands just before the deletion and it reports [202, 400]. The 401 comes from the shared mailadapter.BearerAuth, so it never appears in the provider’s own source. The 413 is http.StatusRequestEntityTooLarge, which isn’t in the script’s lookup table. Twilio’s auth comes back as none, because the regex only knows about Authorization and X-Auth-Token headers. The “claimed scope” that drove everything downstream was a regex’s guess, and the regex couldn’t see the helpers I’d extracted twenty minutes earlier.

The guard was bigger than the thing it guarded. A 66-line agent, a 154-line skill, a 203-line script, a registry, and two new sections in CLAUDE.md, all to watch three handlers with one endpoint each. That’s a lot of moving parts to keep in sync with the code it’s supposed to keep in sync.

And why Mailtrap went with it

Mailtrap is the part I think about more. Nothing was wrong with the code. It was tested, it used the shared helpers, and it built correct MIME. But every provider in MessagePit has a cost written right into the project CLAUDE.md: a config default and validation block, a CLI flag and env var, a listener in server.go, a Dockerfile EXPOSE, Makefile targets, and a README section with ports, config, and a docker-compose example.

Mailtrap’s stub was one more JSON-in, MIME-out email endpoint alongside SendGrid’s. Looking back, I think it was scope I’d added because the pattern made it easy, not because MessagePit needed it. The history doesn’t record that; it’s my read. Paying that per-provider cost forever for a second email API I didn’t need was the wrong trade.

What survived

The useful part of the evening stayed in the tree.

mailadapter survived. The port scheme survived, and the no-gaps rule did its small job: with Mailtrap gone, SendGrid moved from 8101 to 8100.

The removal commit also quietly fixed SendGrid itself. Error responses changed from {"error": "..."} to SendGrid’s {"errors": [{"message": "..."}]} shape, every personalizations[] entry now requires a to, and every content[] entry rejects an empty type or value with a message that says (minLength=1). That’s OpenAPI vocabulary, and the updated test says outright that it follows the SendGrid spec. I read those as the product of an hour spent with the real spec open.

That’s the distinction I came away with. Reading the real spec carefully was worth doing, and in my judgement it’s where those fixes came from. Building a machine to re-read it forever, generate tests from it, and score me against it was a commitment I hadn’t earned yet. One email stub and one SMS stub don’t have a drift problem. They have a “check the spec when you touch the handler” problem, and that fits in a code review.

If MessagePit grows to a dozen providers, or one of these APIs starts moving under me, the compat idea is still in the git history. Better to reach for it then than to maintain it now.

The pattern

In my experience, agents make it cheap to add scope and make that scope look finished: tests, docs, a skill with a tidy report format. What they don’t hand you is evidence that you need it. The useful question tonight wasn’t “is this well built?” Everything I deleted was reasonably well built. It was “would I accept this as a pull request from someone else, knowing I’d own it?” For a second email provider I didn’t need and an agent guarding three one-endpoint handlers, the answer was no. It took about an hour to see that, which is a good price.

When did you last merge something of your own that you’d have sent back if a teammate had opened it?

Related posts