Dev.to WebDev 🛠 Dev 👁 0 📖 4 min read

Your agent doesn't need a browser — it needs an inbox with a TTL

Most "agent needs a browser" problems are not browser problems. They are inbox problems wearing a browser costume. An agent that has to sign up somewhere does not need to render a page, move a mouse, or solve a layout t

Most "agent needs a browser" problems are not browser problems. They are inbox problems wearing a browser costume.

An agent that has to sign up somewhere does not need to render a page, move a mouse, or solve a layout that changed at 3am. It needs one primitive: a mailbox it can open and read as an API call. Everything else — the form, the click, the confirmation screen — is a human ceremony wrapped around "we sent you a code."

Once you model email as the interface, the signup flow collapses into three calls. And once you do that a few hundred times, you stop debugging selectors and start debugging something far more interesting: queue semantics.

The mental model that actually holds

An inbox is a message queue with a hostile SLA. Messages arrive late, out of order, sometimes twice, sometimes never. Your consumer is a regex, which is a very optimistic parser. And the producer is a third party you do not control and cannot ask to be more careful.

Treat it like a queue and the design questions become obvious:

  • What is the message key? The address itself. One address per logical signup, not one shared address for the whole fleet.
  • What is the TTL? Verification codes die in minutes. An address that lives forever is an address that accumulates junk and eventually receives a code meant for a different run.
  • What is the ack? Reading the message and extracting the code. If you cannot extract it, you have an unacked message, and you should fail loudly rather than poll forever.

Failure modes you will hit in the first week

1. Concurrent runs sharing one inbox. Two workers sign up for the same service at the same time. Two codes land. Worker A reads worker B's code, gets a 400, retries, and now you have two half-created accounts and an audit trail nobody can explain. Fix: address per run, full stop. Not per project, not per service — per run.

2. Retries that create duplicates. The signup POST times out. The account was in fact created. Your retry creates a second one. The inbox now has two codes from two accounts and no way to tell them apart except arrival order, which is exactly the thing you cannot trust.

3. The parse that works until it doesn't. Verification emails are not a format, they are a genre. Real examples from one afternoon:

  • Your code is 481920
  • 481920 is your verification code
  • Use code: K7F-2M9 (alphanumeric, hyphenated)
  • a code only in the subject line, body says "see above"
  • a code in an image (give up, use a different provider)
  • a magic link instead of a code, where the token is a query parameter on a URL that also appears three times in the HTML for tracking pixels

A single \d{6} regex covers maybe 70% of them and fails silently on the rest, which is the worst possible outcome. Write a small ordered list of patterns, return the first match with the pattern that matched, and log which one fired. When something breaks in six weeks, that log line is the whole investigation.

4. Preview truncation. Many providers store a short preview and a full body separately. The code is in the part you did not fetch. If your client returns only one field, you will spend an evening convinced the code never arrived.

5. Late arrivals. The mail server took 40 seconds. Your timeout was 30. The code arrives after you gave up, sits in the inbox, and gets picked up by the next run on the same address. This is how you get a mysterious "code expired" on a run that never received anything.

The shape of the code

The consumer is boring on purpose:

// one address per run, short TTL, poll with a real predicate
const inbox = await mail.createInbox({ ttlMinutes: 15 });

await signup({ email: inbox.address });   // whatever the flow needs

const msg = await inbox.waitFor({
  timeoutMs: 45_000,
  match: (m) => m.subject + m.bodyText,
});

const { code, pattern } = extractCode(msg.subject, msg.bodyText);
if (!code) throw new Error(`no code matched; subject=${msg.subject}`);

Three properties matter more than the code itself:

  • waitFor takes a predicate, not a subject prefix. Prefixes lie; providers localise.
  • The timeout is longer than the p95 delivery time you measured, not longer than you feel is reasonable. Measure it once, write it down.
  • The inbox is closed when the run ends, whether it succeeded or not. Leaked inboxes are how failure mode 5 keeps happening.

Where this leaves you

The interesting consequence is not that signup gets faster. It is that signup becomes idempotent-ish and observable: every run has an address, every address has a lifetime, every code has a pattern that matched it, and every failure has a message you can read instead of a screenshot you can stare at.

Browser automation optimises for looking like a human. A mailbox API optimises for being a queue. Only one of those survives a redesign of the signup page.

I ended up building the mailbox side as an API for exactly this reason — create an address, wait for a message, read the code, discard the address. That is the whole product, and it is at kakan.email if the shape of it is useful to you.

Address as identity. Inbox as queue. TTL as the thing that keeps it honest.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.