๐Ÿ“… Historical page. 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. โ†’ See current
โ† All posts

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:

CaseCorrect envelope
Every step succeededok:true, no degraded
Some steps succeeded, the rest namedok:true + degraded:true + missing:[โ€ฆ]
Every step failed, and the failure was upstreamok:false + cause:'platform'
Every step failed inside our own computeok:false with no cause โ€” this one really is our defect
The caller's input was wrongok: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 when r is a fetch response, r.ok is the HTTP-status flag, not the envelope. A handler can test r.ok on 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:

  1. The envelope's ok is a claim about the whole purchase, so compute it from every step โ€” or name what is missing and say so.
  2. 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.
  3. Find these with a census over the deployed source, keyed on variable binding, not a regex over property names.
  4. Probe after the census, not instead of it โ€” a probe that reproduces a billing bug is a probe that pays for it.
โ† All posts