Skip to content

Commit 80ab63d

Browse files
pursekeeperclaude
andcommitted
sellers probe: a 402 counts as the seller's door only when it carries payment terms
A hosting platform answers 402 by itself when a deployment is switched off (Vercel: DEPLOYMENT_DISABLED). The status-only probe showed sur-courier as reachable while its deployment was disabled; its operator reported the outage on TheAliphant/Sur#2 on 2026-11-14. A 402 with no payment header and no Nano address or accepts list in the body is now reachable:false with no_terms:true (and platform_error when the host names itself). The 22 other listed doors that answer 402 all carry terms and are unaffected. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 456e055 commit 80ab63d

2 files changed

Lines changed: 59 additions & 6 deletions

File tree

‎site.js‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ function probeLogAppend(checked_at, list, probes) {
479479
try {
480480
// `ok` is true, false, or null for a probe that got no answer at all (see probe()). A null is written as null, not as
481481
// false, so the history can leave it out of the fraction instead of counting an outage against the seller.
482-
const rows = list.map((sel, i) => probes[i].door === 'mail' ? null : JSON.stringify({ t: checked_at, id: sel.id, ok: probes[i].reachable, status: probes[i].status, ms: probes[i].ms, ...(probes[i].rail !== undefined ? { rail: probes[i].rail } : {}), ...(probes[i].unknown ? { unknown: true } : {}) })).filter(Boolean);
482+
const rows = list.map((sel, i) => probes[i].door === 'mail' ? null : JSON.stringify({ t: checked_at, id: sel.id, ok: probes[i].reachable, status: probes[i].status, ms: probes[i].ms, ...(probes[i].rail !== undefined ? { rail: probes[i].rail } : {}), ...(probes[i].unknown ? { unknown: true } : {}), ...(probes[i].no_terms ? { no_terms: true } : {}) })).filter(Boolean);
483483
if (rows.length) fs.appendFileSync(PROBE_LOG, rows.join('\n') + '\n');
484484
} catch {}
485485
}
@@ -507,22 +507,41 @@ function probeHistory(logFile = PROBE_LOG) {
507507
function sellersFile() {
508508
try { return JSON.parse(fs.readFileSync(path.join(__dirname, 'data', 'sellers.json'), 'utf8')); } catch { return []; }
509509
}
510+
function hasPaymentTerms(headers, text) {
511+
try { for (const k of headers.keys()) if (/^(payment-required|www-authenticate|x-payment|x-nano-|x-402)/i.test(k)) return true; } catch {}
512+
return /nano_[13][13456789abcdefghijkmnopqrstuwxyz]{59}/.test(text || '') || /"accepts"\s*:/.test(text || '');
513+
}
510514
async function probe(sel) {
511515
// A seller reached only by mail (probe: null, reach: "mail") has nothing to probe: no HTTP endpoint, no reachability
512516
// column, no history row. First such seller: Oso Pepe's block courier inside iLands, 2026-10-01.
513517
if (sel.probe === null || sel.reach === 'mail') return { reachable: null, status: null, ms: 0, door: 'mail' };
514518
const t0 = Date.now();
515519
try {
516520
const r = await fetch(sel.probe.url || sel.endpoint, { method: sel.probe.method || 'GET', headers: sel.probe.headers || {}, body: sel.probe.body, redirect: 'manual', signal: AbortSignal.timeout(8000) });
517-
const ok = r.status === (sel.probe.expect || 402);
521+
let ok = r.status === (sel.probe.expect || 402);
518522
const out = { reachable: ok, status: r.status, ms: Date.now() - t0 };
523+
// A 402 is the seller's door only when it carries payment terms (2026-11-15). A hosting platform answers 402 on its own
524+
// account when a deployment is switched off (Vercel: text "Payment required / DEPLOYMENT_DISABLED", header
525+
// x-vercel-error), and the status-only check above showed such a dead door as reachable: sur-courier, found when its
526+
// operator said so on TheAliphant/Sur#2. Terms = a payment header (payment-required, www-authenticate, x-payment*,
527+
// x-nano-*, x-402*) or a body with a Nano address or an "accepts" list; the 22 other doors on the list that answered
528+
// 402 that day each carried at least one. A 402 without any is logged ok:false with no_terms:true.
529+
let text = null;
530+
if (ok && r.status === 402) {
531+
try { text = (await r.text()).slice(0, 65536); } catch { text = ''; }
532+
if (!hasPaymentTerms(r.headers, text)) {
533+
ok = false; out.reachable = false; out.no_terms = true;
534+
let pe = null; try { pe = r.headers.get('x-vercel-error'); } catch {}
535+
if (pe) out.platform_error = String(pe).slice(0, 60);
536+
}
537+
}
519538
// Optional rail check (2026-10-17): a multi-rail seller whose free status route answers 200 whether or not its Nano
520539
// door is open (parley: Nano and Base watchers read unhealthy, Solana only, while /v1/status stayed 200) names
521540
// probe.rail = { path, match, field }: walk the JSON body by dotted path, pick the array element whose keys equal
522541
// match, read field; true = 'open', anything else = 'closed', unreadable = null. Reachability stays HTTP-only.
523542
if (sel.probe.rail && ok) {
524543
try {
525-
let v = await r.json();
544+
let v = text !== null ? JSON.parse(text) : await r.json();
526545
for (const k of String(sel.probe.rail.path || '').split('.').filter(Boolean)) v = v?.[k];
527546
if (Array.isArray(v) && sel.probe.rail.match) v = v.find(e => Object.entries(sel.probe.rail.match).every(([mk, mv]) => e?.[mk] === mv));
528547
const val = sel.probe.rail.field ? v?.[sel.probe.rail.field] : v;
@@ -549,7 +568,7 @@ async function sellers(force) {
549568
probeLogAppend(checked_at, list, probes);
550569
const hist = probeHistory();
551570
sellersCache = { at: Date.now(), data: { checked_at,
552-
probe: { what: 'one unpaid request per seller, expecting the status the seller declared (normally 402; a seller whose paid route is not a plain GET may name a separate free status route, shown in the entry); it pays nothing and measures no settlement; a seller reached only by mail is not probed and shows live.door = "mail"; a multi-rail seller whose status route stays 200 while its Nano door is closed may name a rail check (probe.rail: a field in its own status body), logged as live.rail = open | closed and counted in history_7d.rail_open, since 2026-10-17', every_minutes: 10, timeout_ms: 8000, states: ['reachable', 'unreachable', 'not checked'], history_days: 7, history_since: '2026-09-20', unknown_rule: 'a probe that got no HTTP answer at all (timeout, DNS failure, connection refused or reset) is live.reachable = null and live.unknown = true: it is not evidence that the door is down, so it is counted in history_7d.unknown and left out of the reachability fraction (since 2026-10-23)', delisting: 'never for downtime; only when the seller asks. The only time-based rule is the second half of the newcomer credit, which needs 14 days of answered probes.' },
571+
probe: { what: 'one unpaid request per seller, expecting the status the seller declared (normally 402; a seller whose paid route is not a plain GET may name a separate free status route, shown in the entry); it pays nothing and measures no settlement; a seller reached only by mail is not probed and shows live.door = "mail"; a multi-rail seller whose status route stays 200 while its Nano door is closed may name a rail check (probe.rail: a field in its own status body), logged as live.rail = open | closed and counted in history_7d.rail_open, since 2026-10-17', every_minutes: 10, timeout_ms: 8000, states: ['reachable', 'unreachable', 'not checked'], history_days: 7, history_since: '2026-09-20', unknown_rule: 'a probe that got no HTTP answer at all (timeout, DNS failure, connection refused or reset) is live.reachable = null and live.unknown = true: it is not evidence that the door is down, so it is counted in history_7d.unknown and left out of the reachability fraction (since 2026-10-23)', no_terms_rule: 'a 402 counts as the seller\'s door only when it carries payment terms: a payment header (payment-required, www-authenticate, x-payment*, x-nano-*, x-402*) or a body with a Nano address or an accepts list. A 402 with none of these is live.reachable = false with live.no_terms = true; a hosting platform answers 402 by itself when a deployment is switched off, and until 2026-11-15 the probe read that as a reachable door (one listing, sur-courier, was shown reachable while its deployment was disabled; the log cannot say from when)', delisting: 'never for downtime; only when the seller asks. The only time-based rule is the second half of the newcomer credit, which needs 14 days of answered probes.' },
553572
sellers: list.map((sel, i) => ({ ...sel, live: probes[i], history_7d: hist[sel.id] || null, quote: QUOTE[sel.id] || null })) } };
554573
return sellersCache.data;
555574
}
@@ -565,6 +584,7 @@ function sellerRows(sd) {
565584
const live = (l.door === 'mail' ? `<b>mail door</b>, not probed`
566585
: l.unknown ? `<b>not checked</b>: no answer at the last probe${l.error ? ` (${esc(l.error)})` : ''}, so this says nothing about the door`
567586
: l.reachable ? `<b>reachable</b>, answered ${l.status} in ${l.ms} ms`
587+
: l.no_terms ? `<b>unreachable</b> at last check: HTTP 402 with no payment terms${l.platform_error ? ` (the hosting platform's own answer, ${esc(l.platform_error)})` : ''}`
568588
: `<b>unreachable</b> at last check${l.status ? ` (HTTP ${l.status})` : l.error ? ` (${esc(l.error)})` : ''}`) + (l.rail ? `; Nano rail <b>${l.rail}</b> by the seller's own status` : '');
569589
const h = s.history_7d;
570590
const answered = h ? h.probes - (h.unknown || 0) : 0;

‎test/site-probe-unknown.test.js‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,43 @@ test('a door that answered the wrong status is still unreachable', async () => {
4848
assert.equal(p.status, 500);
4949
});
5050

51-
test('a door that answered the expected status is reachable', async () => {
52-
globalThis.fetch = async () => ({ status: 402, json: async () => ({}) });
51+
test('a door that answered the expected status with payment terms is reachable', async () => {
52+
// terms in a header only (copperglass-shaped), in the body only (pururin-shaped: a Nano address), and as an accepts list
53+
const ADDR = 'nano_1' + '1'.repeat(59);
54+
for (const res of [
55+
{ status: 402, headers: new Headers({ 'payment-required': 'e30=' }), text: async () => '{"error":"payment_required"}' },
56+
{ status: 402, headers: new Headers({ 'x-payment-address': ADDR }), text: async () => '' },
57+
{ status: 402, headers: new Headers(), text: async () => JSON.stringify({ error: 'payment_required', pay_to: ADDR }) },
58+
{ status: 402, headers: new Headers(), text: async () => '{"x402Version":1,"accepts":[{"scheme":"exact"}]}' },
59+
]) {
60+
globalThis.fetch = async () => res;
61+
const p = await site.probeForTest(SELLER);
62+
assert.equal(p.reachable, true);
63+
assert.equal(p.no_terms, undefined);
64+
}
65+
});
66+
67+
test('a 402 with no payment terms is the host talking, not the seller: unreachable, flagged no_terms', async () => {
68+
// What Vercel answers for a disabled deployment (sur-courier, 2026-11-15): status 402, a text body, its own error header.
69+
globalThis.fetch = async () => ({ status: 402, headers: new Headers({ 'x-vercel-error': 'DEPLOYMENT_DISABLED', 'content-type': 'text/plain' }), text: async () => 'Payment required\n\nDEPLOYMENT_DISABLED\n\narn1::abcde-1-f' });
5370
const p = await site.probeForTest(SELLER);
71+
assert.equal(p.reachable, false);
72+
assert.equal(p.no_terms, true);
73+
assert.equal(p.platform_error, 'DEPLOYMENT_DISABLED');
74+
assert.equal(p.status, 402);
75+
assert.equal(p.unknown, undefined, 'the host answered; this is not an unanswered probe');
76+
// a bare 402 with nothing readable at all is the same case
77+
globalThis.fetch = async () => ({ status: 402, json: async () => ({}) });
78+
const q = await site.probeForTest(SELLER);
79+
assert.equal(q.reachable, false);
80+
assert.equal(q.no_terms, true);
81+
});
82+
83+
test('a seller that declares another status is not asked for payment terms', async () => {
84+
globalThis.fetch = async () => ({ status: 200, headers: new Headers(), text: async () => '{"ok":true}', json: async () => ({ ok: true }) });
85+
const p = await site.probeForTest({ ...SELLER, probe: { expect: 200 } });
5486
assert.equal(p.reachable, true);
87+
assert.equal(p.no_terms, undefined);
5588
});
5689

5790
test('an unanswered probe is left out of the seven-day fraction and counted beside it', () => {

0 commit comments

Comments
 (0)