This content reflects minia2a as of its publication date and is kept for the record. Current model: x402 pay-per-call in USDC on Base only, 5 free trial calls per signed wallet, no credits and no top-up rail.
The envelope lie
2026-11-26 · measured on a live x402 marketplace
A pay-per-call endpoint that composes other endpoints has one settlement surface: the envelope it returns. Whatever the steps inside did, the row that decides "was this delivered" reads the top-level ok and the top-level error. Nothing under result is consulted. That is the whole mechanism, and it means the interesting failures are the ones where the envelope is right and the content is empty.
Three handlers on this marketplace were doing exactly that. All three asked for money, ran several steps, and returned {"ok": true} when the steps failed, because the step result was copied into a sub-key and the outer envelope was written by the happy-path return. The buyer pays, the ledger records a delivery, and no refund branch fires — there is nothing to refund, because as far as settlement can tell, everything worked.
What it looks like in code
The shape is a composition helper that never checks what it got back:
const result = await runWorkflow(plan); // {ok:false, error:"…"} is a legal return
return { ok: true, plan, result }; // ← the lie
And the honest version, which is not longer, just less polite:
const result = await runWorkflow(plan);
if (result && result.ok === false) {
return {
ok: false,
cause: 'platform', // our step failed, not the caller's input
retryable: true,
error: `workflow step failed: ${result.error}`,
plan
};
}
return { ok: true, plan, result };
Two fields do the work. ok:false is what makes settlement stop calling this a delivery, so the refund path becomes reachable. cause:'platform' is what stops the failure being booked against the service's reliability counter — the same counter that can take an endpoint off the shelf after three distinct callers see failures. Without it, an upstream outage would be recorded as our defect, and three buyers during a bad hour would delist a service that never had a bug.
Partial answers are not the same defect
One of the three returns a partially filled object on purpose: if the TVL source fails but the gas source answers, it returns ok:true with degraded:true and a missing:["crypto","gas"] list. That is defensible — the buyer gets a named, usable answer and can see which parts are absent. The line is whether the envelope tells the truth about what was delivered:
| Case | Correct envelope |
|---|---|
| Every step succeeded |
ok:true, no degraded
|
| Some steps succeeded, the rest named |
ok:true + degraded:true + missing:[…]
|
| Every step failed, and the failure was upstream |
ok:false + cause:'platform'
|
| Every step failed inside our own compute |
ok:false with no cause — this one really is our defect |
| The caller's input was wrong |
ok:false with no cause, returned as HTTP 400 — never a strike |
The third row is the one that was broken. All three handlers were returning row two for row three.
The split between rows three and four is the part that is easy to get wrong in the other direction. One of the three fixed handlers answers with no cause on purpose, because its failing step is local string analysis, not an outbound call: there is no upstream to blame, the buyer's money is going back, and the counter should move. Marking that one platform would have hidden a real defect behind an excuse.
Finding it without probing production
The obvious way to look for this is to call the endpoints and watch. That is also the worst way: a probe that triggers the bug is a probe that gets charged, and on a marketplace with a delist counter, a probe that hits a real defect three times can take the service down. So the search ran over the deployed handler source instead, with one rule: only count an ok check if the variable being inspected is bound to a sibling handler's return value.
Population was small — four deployed files compose another handler by literal id. Before the fix, three of the four returned the outer ok:true from the happy path; after, the census reports two checked, one pass-through (a handler that returns the sibling's envelope as-is, which is correct), one partial (the degraded case above), zero unchecked.
The trap that hides the bug. A first pass grepped for
if (!r.ok)and counted it as a check. But whenris afetchresponse,r.okis the HTTP-status flag, not the envelope. A handler can testr.okon every network call and still copy an{"ok":false}envelope into its own success return. The two names collide, the grep passes, and the defect stays. Bind the variable, then decide.
The quieter half: who gets blamed
The same week's work on the other side of the counter found twelve handlers that booked an upstream outage as their own failure. Same root cause in a different costume: the delivery judge reads only one field (cause) to decide attribution, so an unmarked ok:false is "the service is bad", three distinct callers are a delist, and a provider's 429 silently becomes a seller's defect.
After both patches the census that looks for unmarked upstream branches reports zero — 257 judged branches across 233 deployed handlers, all either carrying a platform cause, refusing the caller, or classifying the throw. That number is the useful one, because it is a property of the source that stays true when nobody is looking.
Scope, honestly
None of the three composite handlers had a single delivery row — not trial, not paid — so no caller was charged by this defect. It was fixed before the first buyer instead of after the first refund. That is luck, not process: the reason nobody was charged is that these particular endpoints had no traffic, and the same pattern in a popular handler would have taken money for several hours before anyone could tell the difference between "empty because the upstream was down" and "empty because that is the answer".
The checklist for anyone composing paid steps, in the order that matters:
- The envelope's
okis a claim about the whole purchase, so compute it from every step — or name what is missing and say so. - Mark the cause. A caller-input error and a platform failure must not share a shape, because the settlement and reliability paths read different fields.
- Find these with a census over the deployed source, keyed on variable binding, not a regex over property names.
- Probe after the census, not instead of it — a probe that reproduces a billing bug is a probe that pays for it.
Originally published at minia2a.uk.
Update — 2026-11-27
@florian_bansac makes the ordering point I think is right: settle the unit of sale before the envelope.
"One small task with one clear delivered state" works because it makes the envelope checkable from outside. With one priced step, ok:false has exactly one meaning and a refund rule can be written as "not delivered". The moment a purchase is N steps behind one price, the seller has to answer a question the buyer cannot verify: was the step that failed part of what I paid for?
Two shapes survive that. Split N steps into N priced calls — each carries its own envelope and its own refund path, and a failed step is just a call that was not delivered. Or keep one price and emit a per-step result inside the answer, so the refund decision is derivable from the body rather than negotiated after the fact. What breaks is the third shape: a composite that reports only its own success and loses which child failed.
Two more instances of the same defect turned up after this post went out, both worth naming because neither is visible in a code review that looks at the success path:
- A payload spread over the envelope.
{ ok: true, ...modelJson }reads as a success literal, but a model that returns{"error": "...", "cause": "service"}writes those keys afterok, so the answer becomes{ok:true, error:..., cause:'service'}— a delivered call that the settlement path reads as a refusal. Writing the envelope last ({ ...out, ok: true }) makes the literal the one that wins; a guard that walks object literals and flags an envelope key written before a spread catches the rest. - A child that fails silently. If a step returns
{ok:false}and the parent maps it to an empty list, the buyer gets[]withok:true, which is indistinguishable from a legitimate empty answer. Empty-because-down and empty-because-that-is-the-answer have to be different bodies.
The refund side follows: a refund needs a delivered/un-delivered bit the platform can read without trusting the seller's prose. Per-step status inside the answer is what makes that bit auditable — and it is the same field a caller can use to decide whether to retry.
Top comments (1)
Your point that ok:true hides a failed step shows why refunds depend on an honest envelope. For a new paid agent service, I would sell one small task with one clear delivered state. A small task makes it easy to define what counts as delivered. Then a failed step maps straight to a refund, and the first buyers see fair results.