DEV Community

minia2a
minia2a

Posted on Originally published at minia2a.uk

A count that counts the slice is not a count

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.

A count that counts the slice is not a count

2026-11-27 · nine defects found in a live pay-per-call catalogue

A paid endpoint answers with an array of 50 NFTs and a field nftCount: 50. The wallet it was asked about has more. Nothing else in the response says so — no flag, no cursor, no "showing 50 of N". The buyer, usually an agent, budgeted one call, got a number that looks like an answer, and moved on with a conclusion built on part of the data.

That is not a wrong answer. A wrong answer gets caught: the value fails a schema check, contradicts another field, or crashes the caller. This one passes every check the caller can run, because it is exactly the shape of a correct answer. It is only smaller.

On 2026-11-27 we swept our own catalogue for it — 96 output-side slice(0, N) sites and 94 count: something.length sites across the deployed handlers — and found nine live endpoints doing it. This is what the family looks like, why per-endpoint smoke tests never catch it, and the disclosure shape that makes it impossible.

The shape

const items   = (data.items || []).slice(0, 50);   // cap the payload
return { ok: true, nftCount: items.length, nfts: items };
//                                ^^^^^^^^^^^^ counts the slice
Enter fullscreen mode Exit fullscreen mode

nftCount is a promise about the wallet; items.length is a fact about the array. After the slice those are different numbers, and the field is named for the one it is not. The buyer reads how many NFTs this wallet has and is told how many we decided to send.

Two smaller variants of the same lie turned up in the same sweep. One returns a count from upstream but truncates the body with no marker at all: the page text stops at 50,000 characters and the response has no field that distinguishes "this page is 50,000 characters" from "this page is longer and you are reading a prefix". The other cuts a banner to 500 characters and calls it the banner.

Why the buyer cannot notice

Compare it with a nearer-miss failure we fixed earlier the same day: an endpoint returned contentLength: 120000 next to an html string that had been trimmed. That is at least self-comparable — a careful caller can check html.length against contentLength and see the gap.

nftCount: 50 gives the caller nothing to compare against. There is no second number. The only way to learn that another page exists is to call a different API (the upstream explorer) and read its pagination token — which is not something a caller paying for your abstraction should have to do.

Smoke tests do not catch it either. A test wallet with 50 NFTs returns 50 of 50: correct. The defect only exists for wallets past the cap, and the bigger the wallet, the more wrong the answer — which is exactly backwards from how damage should scale.

The general rule. Any cap on an output array or string needs a field that says the cap was hit. Silence is a claim that the cap was not hit, and the server is the only party that knows.

The disclosure shape

What we now emit, on all nine:

{
  "ok": true,
  "nftCount": 312,          // from the upstream answer, not from the array
  "returnedNfts": 50,       // what is actually in `nfts`
  "nftsTruncated": true,    // the cap was hit
  "hasMore": true,          // the upstream says another page exists
  "nfts": [ /* 50 items */ ]
}
Enter fullscreen mode Exit fullscreen mode

Four fields, and each answers a question the buyer would otherwise have to guess at:

  • nftCount — how many exist (taken from upstream, never from the sliced array);
  • returnedNfts — how many you got;
  • nftsTruncated — whether the two differ because of our cap;
  • hasMore — whether the upstream itself has another page (only when the upstream exposes pagination; a bare "there's more" without a way to get it is a taunt, not a disclosure).

For string bodies the pair is returnedHtmlChars and htmlTruncated, plus a switch (raw: false) for callers who wanted the structure and not the body in the first place. Live check after the change: a wallet whose upstream answer carried a non-empty next_page_params now reports hasMore: true; a JSON object with 120 keys reports keysTruncated: true with keys capped at 50.

The second shape: an error page served as content

The same sweep turned up a sibling that is worse in one way. One endpoint fetched /robots.txt and, when the host answered 404 with an HTML error page, returned that HTML as the robots body. A caller parsing it as robots directives sees markup it cannot parse — or, worse, extracts the wrong rule from a page that happens to contain the word Disallow.

The fix is the same discipline applied to the status code: only a 2xx body is content. A 404 is an answer — "this host has no robots.txt" — and it is expressible:

{ "ok": true, "present": false, "robots": null, "status": 404 }
Enter fullscreen mode Exit fullscreen mode

present: false is a fact about the host. robots: "<html>…" was a fact about the error page dressed up as the first.

What to do if you publish endpoints

  • Grep your handlers for .length on anything that was assigned from a slice in the same function. That pair is the bug.
  • Take counts from the upstream payload, never from the array you built.
  • Every cap gets a boolean. If the boolean is always false in your tests, the test data is too small, not the code too good.
  • Distinguish "no such resource" from "resource fetch failed" — a 404 body is not the resource.
  • If you cannot afford the extra fields, shrink the default page and say the page size in the schema. A documented cap is a contract; an undocumented one is a bug with good manners.

None of this is exotic. It is the difference between an API whose answers a program can reason about and one whose answers merely look plausible — and for an agent buying calls it has no way to audit, plausible is the dangerous kind.

The marketplace is at minia2a.uk — 1,958 pay-per-call endpoints in USDC on Base, 5 free trial calls per signed wallet on the endpoints that offer trials, no registration. The nine endpoints in this post now carry the disclosure fields above; if you call one and the caps bite, the response will tell you so.


Originally published at minia2a.uk.

Top comments (2)

Collapse
 
userxnom profile image
Abdullah Naseer •

The framing that hooked me is that this bug passes every check the caller can run. A wrong value fails a schema check or contradicts another field, but nftCount: 50 next to 50 items is exactly the shape of a correct answer — only smaller — and a test wallet with exactly 50 NFTs would never catch it. The distinction you draw is the lasting part: nftCount is a promise about the wallet, items.length is a fact about the array, and naming the field for the number it is not is what turns a cap into a lie. The four-field disclosure shape is a good fix because each field answers a question the buyer would otherwise have to guess at, and the sibling bug is even worse in its own way — a 404 error page served as robots.txt hands the caller markup dressed up as directives. Which of the nine endpoints was the hardest to fix — was there one where the upstream itself never exposed a real total, so nftCount had to stay honest about not knowing?

Collapse
 
irck_ysia_d79705b3a189af9 profile image
Irck Ysia •

Great breakdown on "A count that counts the slice is not a count"! Really appreciate clear, practical #webdev posts like this—I've been building a zero-dependency vanilla JS static web hub over Black Friday weekend myself and simplicity wins every time. Dropping a heart!