Two missing assignment lines: our service pages said "0 calls" while the list said 9,886
A buyer considering an x402 endpoint does two reads. First the catalog — one row among many, cheap to fetch. Then the detail read — "who is this seller, is anyone actually using it, what does it cost?" That second read is where trust is built or lost.
Ours was lying. On 2026-12-01, GET /api/services said x402-gas had trialCount=9886, callCount=9. GET /api/services/x402-gas said trialCount=0, callCount=0. Same server, same row, same instant. The server-rendered detail page agreed with the wrong one: "0 paid calls · 0 trials".
Not one service. Every service. If a single endpoint returns 0 while the list returns a five-digit number, the bug is never in the number — it's in the path that reads it.
The shape of the bug
The gateway is Go, with a small store layer. ListServices and GetService both run a query against services, and both scan trial_count and call_count into local variables:
var trialCount, callCount int // ... rows.Scan(..., &trialCount, &callCount, ...) Then ListServices does what you'd expect:
s.TrialCount = trialCount s.CallCount = callCount GetService — a separate function, same table, same columns — doesn't. The two Scan targets are locals; once the function returns, they're garbage. The struct field stays at its zero value, and zero is a perfectly plausible answer. Nothing errors. Nothing logs. JSON encodes 0 and the status code is 200.
That's the whole bug: two lines that exist in one row-mapper and not the other.
Four call sites, one silent zero
GetService isn't only behind /api/services/:id. It feeds:
- the JSON detail endpoint,
- the SSR detail page (
/service.html?id=…), roughly 2,000 pages, - the semantic-search fallback, and
- the sandbox endpoint.
So the same two lines were missing from four production surfaces. The list endpoint, which has its own mapper, kept telling the truth the entire time. That asymmetry is the most useful clue in the whole incident: when one read of a row disagrees with another read of the same row, stop looking at the data.
Why none of our existing checks caught it
This is the part worth stealing if you run a paid API.
We have guards that fetch every served static page and judge its claims. We have a schema guard that checks /api/services and /api/services/:id return the advertised field shapes. We have a census of exact numeric claims on standing pages.
All three missed it, for the same reason:
- The detail numbers are rendered at request time. They are not in the static corpus, so the page-claim guards never see them.
- The schema guards check shape, not agreement.
trialCount: 0is a valid integer. The field exists. The contract is satisfied. -
0is not an error value. If the bug had returnednull, half our guards would have fired. Zero is what a fresh, unused service legitimately looks like — so a dead market and a young one are indistinguishable by the value alone.
The correct test isn't "does this endpoint answer?" It's:
for a sample of ids, does the aggregate read and the per-item read agree, field by field, right now?
That is a different axis, and it needs its own measurement. Ours is a small guard that pulls the top N services by trialCount from the list, then reads each one through both the JSON door and the SSR door and compares. Counts only grow, so a detail count below the list count is a defect with no false positives from timing. If the list says 1,568 trials, the detail read cannot say 0.
Proving the patch instead of assuming it
A two-line fix looks obvious, which is exactly when you should be suspicious of your own reading. We copied the deployed source tree twice on the build host: one control (unchanged), one with the patch applied. Then ran the same test against both.
- Unpatched:
TrialCount=0 CallCount=0, want 1568/59→ FAIL. - Patched:
TrialCount=1568 CallCount=59→ PASS.
Both trees compile. The difference is behavioural, not textual. That control group is the difference between "the patch should work" and "we watched it change the answer."
The patch is staged for our next gateway build. Until it ships, the parity guard stays red — which is the point. A guard that goes green on a fix that isn't deployed is worse than no guard.
Three lessons that generalise past this one bug
1. Cross-endpoint consistency is its own test axis. Most teams test that each endpoint returns 200 with the right shape. Very few test that two endpoints that describe the same entity agree with each other. List/detail pairs, summary/export pairs, search-result/detail pairs — every one of those is a place where a shared row mapper can be copied and half-edited. Pick the field that only grows, like a counter, and assert monotonic agreement; you get a check with no flakiness.
2. Zero is the most dangerous default. Every zero-value bug in Go, every missing assignment, every empty slice marshals to something that looks like a legitimate answer. If a field's zero value is plausible domain data, no schema validation will save you. Only an independent second source — another endpoint, another query path — can.
3. Duplicated mappers drift, so make them comparable. The real defect was a copy-paste of a scan loop, with the write-back lines dropped. The durable defence isn't discipline; it's a test that fails when the copies disagree. We now have that for the field pair we got wrong.
If you operate a paid endpoint, this costs about thirty lines and one cron entry. The failure it catches doesn't look like an outage — it looks like nobody uses your product. Ours did, for every page, while the counter on the list page climbed.

