case studies

How Tokening Stops Parallel AI Agents From Spending One Grant Twice

A call can be perfectly in scope and still arrive at the wrong moment. Picture two workers that picked up the same task. Both hold the same one-use grant. Both send the same valid edit within a few milliseconds of each other. If the gateway checks the counter, forwards both calls and only then writes the counter down, both edits go through. The grant said one. WordPress got two.

This isn’t exotic. Job queues hand out the same work twice, schedulers fire late and early, and agents retry when a reply takes too long. Any limit that’s read and updated in separate steps will lose to timing sooner or later.

Tokening does the check and the spend in a single SQLite statement. It only succeeds while a use is left, and the database lets one writer through at a time. The spend is committed before the call leaves the gateway.

Two parallel calls on a one-use grant: one is allowed, one is refused

What the numbers say

The release tests race two callers against a fresh one-use grant, through separate database connections, a thousand times. In the v0.1.1 release that ran on all five platforms: Linux and macOS on Intel and ARM, and Windows. Every platform recorded 1,000 allowed calls, 1,000 refusals and zero uses left over. The release results have the counts.

The WordPress demo does the same with a real upstream. Two calls hit a new grant at the same moment. One wins and WordPress records one write. The other is refused with “allowed 1 use and has none left,” and never reaches WordPress.

Spend first, then send

The order matters in the other direction too. Tokening spends the use before it forwards the call. If WordPress then times out, the use is still gone.

That can feel harsh, but the alternative is worse. A timeout doesn’t tell you whether the write happened. Giving the use back would let a retry write a second time when the first one may have landed. So Tokening leaves the decision with you: look at the post, and if it really didn’t change, issue a fresh grant.

What this doesn’t promise

Tokening controls its own counter. It can’t make the database and WordPress agree in one transaction, and it doesn’t try. What it guarantees is narrower and easy to check: one use, at most one call out the door.