Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(x402): keep liveness observations and repeated skips out of the loop failure stats

nirholas99846f41c734
diff --git a/api/_lib/x402/pipelines/service-uptime-monitor.js b/api/_lib/x402/pipelines/service-uptime-monitor.js
index 3d851e1c8..19081f478 100644
--- a/api/_lib/x402/pipelines/service-uptime-monitor.js
+++ b/api/_lib/x402/pipelines/service-uptime-monitor.js
@@ -113,6 +113,14 @@ export function classifyProbe(status, errMsg) {
return { alive: false, classification: 'unreachable', error_msg: errMsg || 'unreachable' };
}
+// The error_msg an x402_autonomous_log row gets for a probe verdict. Only a
+// FAILING verdict carries one: see recordCall for why an alive-but-4xx third
+// party must not stamp a payment-shaped error code onto a success row.
+export function logErrorMsgFor(verdict) {
+ if (!verdict) return null;
+ return verdict.alive ? null : (verdict.error_msg || null);
+}
+
function hostOf(u) {
try { return new URL(u).host.toLowerCase(); } catch { return null; }
}
@@ -287,6 +295,17 @@ async function upsertUptime(sql, runId, target, v) {
// One x402_autonomous_log row per probe (endpoint_type 'self' — this pipeline is
// a self-pipeline; value_extracted carries the verdict). The loop also records a
// single aggregate summary row for the run() entry.
+//
+// error_msg is written ONLY when the probe verdict is a failure. A
+// `reachable_unexpected` verdict (any non-5xx 4xx) means the service is UP and
+// the row is recorded success=true, so stamping `http_400`/`http_405` there put
+// thousands of third-party observations into the column the loop's own failure
+// stats read: on 2026-08-06 every single http_400 and http_405 in the last 48h
+// came from this monitor observing templated or verb-picky third-party routes
+// (readx.sh /api/:name/followers, earth.x402.press /earth/ask), none of them a
+// payment failure. The full detail (last_status, error_msg, classification)
+// still lands in x402_service_uptime and in this row's value_extracted, which is
+// where the reliability surface reads it.
async function recordCall(sql, runId, target, v) {
const host = hostOf(target.resource) || target.resource;
try {
@@ -306,7 +325,7 @@ async function recordCall(sql, runId, target, v) {
method: v.method,
latency_ms: v.latency_ms ?? null,
})},
- ${v.latency_ms ?? 0}, ${v.alive}, ${v.error_msg}, ${'reliability'})
+ ${v.latency_ms ?? 0}, ${v.alive}, ${logErrorMsgFor(v)}, ${'reliability'})
`;
} catch (err) {
log.warn('uptime_log_insert_failed', { resource: target.resource, message: err?.message });
diff --git a/api/cron/x402-ring-tick.js b/api/cron/x402-ring-tick.js
index 0ce88ad5c..5b2f75155 100644
--- a/api/cron/x402-ring-tick.js
+++ b/api/cron/x402-ring-tick.js
@@ -125,10 +125,42 @@ async function ringDailySpent() {
return Number(rows[0]?.spent || 0);
}
-// One structured, queryable row for a skipped/failed tick. Every non-paying tick
-// outcome leaves a trail (task 04 constraint). Wrapped — a DB fault never crashes
-// the cron.
-async function recordSkip(runId, origin, reason, extra = {}) {
+// How long an UNCHANGED skip reason stays coalesced into one log row (seconds).
+// A per-minute cron whose payer is underfunded writes 1,440 identical rows a day;
+// by 2026-08-06 'Ring Tick' held 22,865 rows, every one of them success=false
+// with amount 0, which is what made the service read as "10,000 calls, zero
+// successes" in the loop's own stats when it had in fact never placed a call.
+// The trail still exists (task 04 constraint) and every suppressed tick is
+// counted into the next row's value_extracted, so nothing is lost: what changes
+// is that a steady-state skip stops impersonating thousands of failed payments.
+const SKIP_LOG_COALESCE_SECONDS = Number(process.env.X402_RING_TICK_SKIP_LOG_COALESCE_S || 900);
+
+// One structured, queryable row for a skipped/failed tick. A reason that differs
+// from the last one ALWAYS writes immediately, so a state change is never
+// delayed; a repeat of the same reason inside the coalesce window increments a
+// counter instead. Wrapped: a DB fault never crashes the cron, and a Redis fault
+// falls through to the unconditional write (losing rows is worse than noise).
+async function recordSkip(runId, origin, reason, extra = {}, redis = null) {
+ let suppressed = 0;
+ if (redis && SKIP_LOG_COALESCE_SECONDS > 0) {
+ let quiet = false;
+ try {
+ const windowKey = `x402:ring-tick:skip-log:${reason}`;
+ const suppressedKey = `x402:ring-tick:skip-suppressed:${reason}`;
+ const n = Number(await redis.incr(windowKey));
+ if (n === 1) {
+ await redis.expire(windowKey, SKIP_LOG_COALESCE_SECONDS);
+ // Ticks the previous window swallowed are reported on the row that
+ // reopens it, so the count of skipped ticks stays exact.
+ suppressed = Number(await redis.getset(suppressedKey, 0)) || 0;
+ } else {
+ // Same reason, still inside the window: count it and stay quiet.
+ await redis.incr(suppressedKey);
+ quiet = true;
+ }
+ } catch { /* Redis down: fall through and write the row */ }
+ if (quiet) return;
+ }
try {
await sql`
INSERT INTO x402_autonomous_log
@@ -137,7 +169,7 @@ async function recordSkip(runId, origin, reason, extra = {}) {
VALUES
(${runId}, ${'self'}, ${'Ring Tick'}, ${`${origin}/api/cron/x402-ring-tick`},
${'solana:mainnet'}, ${0}, ${ASSET}, ${false}, ${reason}, ${'ring-tick'},
- ${JSON.stringify({ skipped: true, reason, ...extra })})
+ ${JSON.stringify({ skipped: true, reason, ...extra, ...(suppressed ? { suppressed_ticks: suppressed } : {}) })})
`;
} catch (err) {
log.warn('ring_tick_skip_log_failed', { reason, message: err?.message });
@@ -227,7 +259,7 @@ export default wrapCron(async (req, res) => {
getMint(conn, new PublicKey(USDC_MINT)),
]);
} catch (err) {
- await recordSkip(runId, origin, 'rpc_preflight_failed', { message: err?.message });
+ await recordSkip(runId, origin, 'rpc_preflight_failed', { message: err?.message }, redis);
await sendOpsAlert('x402 ring tick paused: RPC preflight failed', String(err?.message || err), { signature: 'ring-tick:rpc' });
return json(res, 200, { ok: false, skipped: true, reason: `rpc_preflight_failed: ${err?.message}`, run_id: runId });
}
@@ -262,7 +294,7 @@ export default wrapCron(async (req, res) => {
await recordSkip(runId, origin, bp.reason, {
detail: bp.detail, sol_lamports: Number.isFinite(solLamports) ? solLamports : null,
usdc_atomic: Number.isFinite(usdcAtomic) ? usdcAtomic : null, min_usdc_atomic: pbp.minUsdcAtomic,
- });
+ }, redis);
await sendOpsAlert(
`x402 ring tick paused: ${bp.reason}`,
`sol=${solLamports} usdc=${usdcAtomic} floor=${cfg.solFloorLamports} min_usdc=${pbp.minUsdcAtomic}`,
@@ -302,7 +334,7 @@ export default wrapCron(async (req, res) => {
sol_lamports: Number.isFinite(solLamports) ? solLamports : null,
floor_lamports: cfg.solFloorLamports,
calls_per_day_budget: gov.callsPerDayBudget,
- });
+ }, redis);
await sendOpsAlert(
'x402 ring tick paused: runway_exhausted',
`payer spendable SOL cannot sustain 1 call/min for ${cfg.runwayDays}d (sol=${solLamports}, floor=${cfg.solFloorLamports}); fund the payer to resume`,
@@ -345,7 +377,7 @@ export default wrapCron(async (req, res) => {
sponsor: sponsorAddress,
sponsor_lamports: sponsorLamports,
floor_lamports: cfg.solFloorLamports,
- });
+ }, redis);
await sendOpsAlert(
'x402 ring tick paused: sponsor_fee_wallet_floor',
`sponsor fee wallet ${sponsorAddress} holds ${sponsorLamports} lamports, below the ${cfg.solFloorLamports} settle floor; every sponsored settle would be refused. treasury-topup reclaim should refill it; if this persists past one cycle, fund the economy master.`,
@@ -396,7 +428,7 @@ export default wrapCron(async (req, res) => {
if (remaining <= 0) {
await recordSkip(runId, origin, 'ring_daily_cap_reached', {
daily_spent_atomic: dailySpent, daily_cap_atomic: cfg.dailyCapAtomic,
- });
+ }, redis);
log.info('ring_tick_daily_cap_reached', { spent: dailySpent, cap: cfg.dailyCapAtomic });
return json(res, 200, {
ok: true, skipped: true, reason: 'ring_daily_cap_reached',
diff --git a/data/changelog.json b/data/changelog.json
index 0229aae56..997801611 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,27 @@
{
"$comment": "Curated changelog entries for three.ws, the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.",
"entries": [
+ {
+ "date": "2026-08-06",
+ "title": "The autonomous buyer stopped paying for calls it could never complete",
+ "summary": "Three.ws runs a fleet of agents that pay each other's endpoints around the clock, and a slice of those calls had been failing the same way every time for weeks. The model inspector could not read compressed 3D files, so paying to inspect one of the platform's own rigged avatars returned an error even though the file was perfectly valid: five of the eight reference avatars failed that way on every attempt, and the paid Model Check service failed with them. Two internal monitors were also calling the club tipping endpoint the wrong way round, sending their payment with a request shape the endpoint does not accept, so the payment health checks they exist to run had never once completed. Both are fixed, and the buyer now handles a moved price properly: if an endpoint re-quotes between the moment we read its price and the moment we pay, the buyer re-reads the new terms and settles once against those instead of giving up, with the spend limit and the recipient check re-applied to the new quote. Finally, two sources of phantom failures are gone from the activity log: a free liveness probe of an outside service no longer files a reachable service as an error, and a per-minute driver that is waiting on funding no longer writes a fresh failure row every sixty seconds.",
+ "tags": [
+ "fix",
+ "improvement",
+ "infra"
+ ],
+ "link": "/x402"
+ },
+ {
+ "date": "2026-08-06",
+ "title": "Agora Guilds can actually fill now, and an expired bounty gives its money back",
+ "summary": "The Commons hosts two kinds of shared work: an Arena, where several citizens race the same bounty and the first accepted proof takes the whole prize, and a Guild, where several citizens each contribute a part and split the reward. A live run on the test network showed the Guild could almost never fill. The moment its first contributor signed up, the job left the \"open\" state, and the part of the engine that looks for work only ever considered open jobs, so every remaining seat sat empty until the deadline passed. Guilds now stay joinable while they still have seats, which is what the rest of the system already assumed. Three more faults surfaced in the same run. A signup that succeeded on-chain but whose confirmation got lost in transit was being filed as a failure, which parked a seat with nobody working it; that is now recognised and recovered. A rate-limited connection could convince the engine that its own registered citizens did not exist, and enough of those at once shut the whole population down; registration now reads the chain back instead of giving up, and a failed balance check no longer drops a citizen. The last contributor's share was also reported too high, because the payment that empties a job's escrow also returns the deposit that kept that account open, and the deposit was being counted as reward; shares are now measured net of it and match what the chain actually paid. Separately, a bounty that expires without filling used to leave its reward locked up forever, since a passing deadline does not return anything on its own. The creator now reclaims it automatically, and a race whose result the chain has already settled no longer shows a runner still running.",
+ "tags": [
+ "fix",
+ "improvement"
+ ],
+ "link": "/agora"
+ },
{
"date": "2026-08-06",
"title": "Every critical security advisory in the platform's open-source dependencies is cleared",
@@ -18301,6 +18322,16 @@
"tags": [
"fix"
]
+ },
+ {
+ "date": "2026-08-06",
+ "title": "Chat can read replies out loud again, in the voice you pick",
+ "summary": "Voice output in chat was unreachable: a leftover experimental avatar module had no on-screen switch, silently swallowed spoken replies for anyone whose browser still remembered it turned on, and the speech step never ran when an answer finished normally. Settings now has a real Speak replies aloud switch under Avatar, with a picker for any voice your browser has installed and a Preview button to hear it before you commit. Finished replies are read once and only once, even on providers that end a stream twice, and a loaded 3D agent mouths along with the words.",
+ "tags": [
+ "fix",
+ "feature"
+ ],
+ "link": "/chat"
}
]
}
diff --git a/docs/x402-ring-economy.md b/docs/x402-ring-economy.md
index 99ea0573b..6574592c3 100644
--- a/docs/x402-ring-economy.md
+++ b/docs/x402-ring-economy.md
@@ -731,6 +731,16 @@ even cover tip headroom hard-skips (`insufficient_payer_usdc`). Decision logic:
`planBackpressure()` in
[api/_lib/x402/ring-tick-plan.js](../api/_lib/x402/ring-tick-plan.js).
+A **repeated, unchanged** skip reason is coalesced into one log row per
+`X402_RING_TICK_SKIP_LOG_COALESCE_S` window (default 900s) instead of one per
+minute. A reason that DIFFERS from the last one always writes immediately, and
+the row that reopens a window carries `suppressed_ticks`, so the trail stays
+complete and exact. Before this, an underfunded payer wrote 1,440 identical
+`success=false, amount=0` rows a day: by 2026-08-06 the `Ring Tick` service held
+22,865 of them, which read in the loop's own stats as "22,865 calls, zero
+successes" when the tick had in fact never placed a call. Set the window to `0`
+to restore a row per skipped tick.
+
**Never raise the settle price ahead of funding.** The defaults ($1.00 settle,
$1.10 tick cap, $50/day) are sized to the ring's real balances. Scaling to higher
daily volume is an env change (`X402_PRICE_RING_SETTLE`,
diff --git a/tests/x402-service-uptime-log-shape.test.js b/tests/x402-service-uptime-log-shape.test.js
new file mode 100644
index 000000000..de1c9107f
--- /dev/null
+++ b/tests/x402-service-uptime-log-shape.test.js
@@ -0,0 +1,37 @@
+import { describe, it, expect } from 'vitest';
+import { classifyProbe, logErrorMsgFor } from '../api/_lib/x402/pipelines/service-uptime-monitor.js';
+
+// The uptime monitor probes third-party x402 services for free (no X-PAYMENT,
+// amount 0). Some of those routes are templated (readx.sh /api/:name/followers)
+// or verb-picky (earth.x402.press /earth/ask), so a HEAD probe legitimately
+// answers 400 or 405 while the service is UP. Recording that status as the log
+// row's error_msg made the monitor the single largest source of http_400 and
+// http_405 in x402_autonomous_log, which reads as "the loop is sending malformed
+// paid requests" when no payment was involved at all.
+//
+// The verdict itself must not change: alive/classification/last_status still
+// carry the observation into x402_service_uptime and value_extracted.
+
+describe('service uptime probe verdicts', () => {
+ it('still classifies every probe status exactly as before', () => {
+ expect(classifyProbe(402, null)).toMatchObject({ alive: true, classification: 'live_paywall' });
+ expect(classifyProbe(200, null)).toMatchObject({ alive: true, classification: 'live_free' });
+ expect(classifyProbe(301, null)).toMatchObject({ alive: true, classification: 'live_free' });
+ expect(classifyProbe(400, null)).toMatchObject({ alive: true, classification: 'reachable_unexpected', error_msg: 'http_400' });
+ expect(classifyProbe(405, null)).toMatchObject({ alive: true, classification: 'reachable_unexpected', error_msg: 'http_405' });
+ expect(classifyProbe(503, null)).toMatchObject({ alive: false, classification: 'server_error', error_msg: 'http_503' });
+ expect(classifyProbe(null, 'timeout')).toMatchObject({ alive: false, classification: 'unreachable', error_msg: 'timeout' });
+ });
+
+ it('logs an error only for verdicts that mean the service is down', () => {
+ // Up: no payment-shaped error code on a success row.
+ expect(logErrorMsgFor(classifyProbe(400, null))).toBeNull();
+ expect(logErrorMsgFor(classifyProbe(405, null))).toBeNull();
+ expect(logErrorMsgFor(classifyProbe(402, null))).toBeNull();
+ expect(logErrorMsgFor(classifyProbe(200, null))).toBeNull();
+ // Down: the outage still reaches the loop's failure stats.
+ expect(logErrorMsgFor(classifyProbe(503, null))).toBe('http_503');
+ expect(logErrorMsgFor(classifyProbe(500, null))).toBe('http_500');
+ expect(logErrorMsgFor(classifyProbe(null, 'network_error'))).toBe('network_error');
+ });
+});