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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(ops): reconcile the settle-health sensor against the facilitator book so governed refusals stop reading as rail faults
nirholas9665dbbac108
diff --git a/api/_lib/ops/x402-settle-health.js b/api/_lib/ops/x402-settle-health.jsindex 90ce99e63..9f0254741 100644--- a/api/_lib/ops/x402-settle-health.js+++ b/api/_lib/ops/x402-settle-health.js@@ -107,7 +107,9 @@ const FEE_GOVERNOR = /^fee_runway_exhausted/i;// The sponsor-floor refusal, as the ring records it. x402-spec.js answers 503// `settlement_unavailable` for a fee wallet under its floor, so the reason token// arrives either as the 503 prose or as the raw floor signature.-const SPONSOR_FLOOR = /^(settlement temporarily unavailable|fee_wallet_below_floor|sponsor_sol_floor|sol_floor)/i;+// `insufficient_lamports_for_fee` is the same starvation reported from inside+// the settle path (see runway-lab's bucketer, which files it under floor too).+const SPONSOR_FLOOR = /^(settlement temporarily unavailable|fee_wallet_below_floor|sponsor_sol_floor|sol_floor|insufficient_lamports_for_fee)/i;/*** Why did the settle rate fall? Two failure shapes are indistinguishable in the@@ -185,7 +187,10 @@ export function diagnoseSettleDrop({ noSolanaAccept, floorSignals, governorSkips'`npm run logs -- -s three-ws-api --grep "settle_failed" --since 3h`. ' +'A 502 cluster with empty simulation logs is a duplicate-signature or ' +'RPC-preflight fault; a 402 cluster is verify/facilitator rejection. A 503 ' +- 'cluster is not a rail fault at all, it is the sponsor floor (checked above). ' ++ 'cluster is a deliberate refusal (fee-governor budget or sponsor floor); ' ++ 'both are reconciled against the facilitator book above, so a 503 surplus ' ++ 'surviving into this hint means the facilitator log and the ring log ' ++ 'disagree — read x402_self_facilitator_log.reject_reason directly. ' +'See docs/ops/production-log-triage.md.',};}@@ -194,13 +199,25 @@ export function diagnoseSettleDrop({ noSolanaAccept, floorSignals, governorSkips* Classify pre-aggregated settle buckets into a subsystem verdict. Pure — no DB,* no clock — so the thresholds and the rail-fault split are unit-testable* against the exact bucket shape the DB returns.+ *+ * `facilitatorRejects` is the same window's deliberate-refusal counts from the+ * facilitator's own book (`x402_self_facilitator_log.reject_reason`). It exists+ * because the ring log is REASON-BLIND for refusals that arrive over HTTP: a+ * settle the wallet fee governor refused reaches `x402_autonomous_log` as a bare+ * `http_503` (pre-2026-08-06: `http_502`), matches RAIL_STATUS, and reads as a+ * rail fault — which is how 2026-08-05 production showed `cause: "rail"` for+ * ~1,200 refusals that were the budget governor pacing on purpose. The+ * reconciliation below re-attributes status-only 5xx faults to the governor /+ * floor, clamped by min() so a window skew between the two logs can never+ * invent faults or attribute more than actually happened.* @param {Array<{ success: boolean, paid: boolean, reason: string, n: number }>} buckets- * @param {{ minAttempts?: number }} [opts]+ * @param {{ minAttempts?: number,+ * facilitatorRejects?: { governor?: number, floor?: number } }} [opts]* @returns {{ status: 'ok'|'degraded'|'down'|'unknown', settled: number,* faults: number, attempts: number, rate: number|null,* faultClasses: Array<{ reason: string, n: number }>, detail: string, hint?: string }}*/-export function classifySettleBuckets(buckets, { minAttempts = MIN_ATTEMPTS } = {}) {+export function classifySettleBuckets(buckets, { minAttempts = MIN_ATTEMPTS, facilitatorRejects } = {}) {let settled = 0;let faults = 0;// Counted but deliberately kept OUT of the rate: these two explain a collapse@@ -228,6 +245,29 @@ export function classifySettleBuckets(buckets, { minAttempts = MIN_ATTEMPTS } =faultBy[b.reason] = (faultBy[b.reason] || 0) + n;}}++ // Re-attribute status-only 5xx faults to the deliberate refusals the+ // facilitator book proves happened in the window. 503 drains first (the+ // current status both refusals wear), then 502 (the pre-2026-08-06 mapping,+ // and any path still routed through the generic settle_failed throw).+ const drainStatusFaults = (count) => {+ let remaining = Math.max(0, Math.floor(Number(count) || 0));+ let drained = 0;+ for (const key of ['http_503', 'http_502']) {+ if (remaining <= 0) break;+ const take = Math.min(faultBy[key] || 0, remaining);+ if (take <= 0) continue;+ faultBy[key] -= take;+ if (faultBy[key] === 0) delete faultBy[key];+ faults -= take;+ remaining -= take;+ drained += take;+ }+ return drained;+ };+ governorSkips += drainStatusFaults(facilitatorRejects?.governor);+ floorSignals += drainStatusFaults(facilitatorRejects?.floor);+const attempts = settled + faults;const faultClasses = Object.entries(faultBy).map(([reason, n]) => ({ reason, n }))@@ -274,7 +314,8 @@ export function classifySettleBuckets(buckets, { minAttempts = MIN_ATTEMPTS } =// settles that ran, ran. Carry the skip count so a wallet quietly sliding// toward its budget shows up before the rate does.return {- status: 'ok', settled, faults, attempts, rate, faultClasses, governorSkips,+ status: 'ok', settled, faults, attempts, rate, faultClasses,+ noSolanaAccept, floorSignals, governorSkips,detail: governorSkips > 0 ? `${base}; ${governorSkips} paced by the fee governor` : base,};}@@ -324,7 +365,25 @@ export async function gatherX402SettleHealth() {GROUP BY success, paid, reason`);- const v = classifySettleBuckets(buckets);+ // The facilitator's own book for the same window: the ring log only carries+ // `http_5xx` for a refusal that came back over HTTP, so this is the sole+ // record of WHY those settles were refused. Fail-soft to zero: a missing+ // table (pre-migration) must not take the whole sensor down with it.+ const rejects = await sql`+ SELECT split_part(COALESCE(reject_reason, ''), ':', 1) AS reason,+ count(*)::int AS n+ FROM x402_self_facilitator_log+ WHERE ts >= now() - ${WINDOW_INTERVAL}::interval+ AND action = 'settle' AND ok = false+ GROUP BY 1+ `.catch(() => []);+ const facilitatorRejects = { governor: 0, floor: 0 };+ for (const r of rejects) {+ const n = Number(r?.n) || 0;+ if (FEE_GOVERNOR.test(String(r?.reason || ''))) facilitatorRejects.governor += n;+ else if (SPONSOR_FLOOR.test(String(r?.reason || ''))) facilitatorRejects.floor += n;+ }+ const v = classifySettleBuckets(buckets, { facilitatorRejects });return {...base,status: v.status,diff --git a/docs/ops/production-log-triage.md b/docs/ops/production-log-triage.mdindex 149eba998..204b88172 100644--- a/docs/ops/production-log-triage.md+++ b/docs/ops/production-log-triage.md@@ -240,6 +240,18 @@ HTTP 502/503 GET|POST /api/x402/*, /api/mcp ua: threews-x402-autonomous/1.0 or`fee_runway_exhausted` skips in `x402_autonomous_log` rather than as failedpaid calls.+ **The sensor reads through the status codes now.** `x402_autonomous_log` is+ reason-blind for refusals that arrive over HTTP (the row says `http_503` or,+ pre-2026-08-06, `http_502`; the reason lives only in+ `x402_self_facilitator_log.reject_reason`). Since 2026-08-07 the healthz+ `x402_settle` sensor reconciles those status-only 5xx rows against the+ facilitator book for the same window, re-attributing them to `fee_governor` /+ `sponsor_floor` before it computes the rate. So `metrics.cause` is trustworthy+ even for governed refusals recorded as bare 5xx, the settle rate judges the+ rail alone, and a `cause: "rail"` verdict now genuinely means the rail. (The+ 2026-08-05 storm read `down`/`rail` at settle 26.1% under exactly this+ blindness; the same data now reads as governor pacing with a healthy rail.)+---## 🟡 HTTP 502 on `/api/coin/*` — `coingecko-quota-exhausted-502`diff --git a/scripts/gcp-triage.mjs b/scripts/gcp-triage.mjsindex 66dec2f81..38f99a37c 100644--- a/scripts/gcp-triage.mjs+++ b/scripts/gcp-triage.mjs@@ -198,7 +198,7 @@ const KNOWN_HTTP_SIGNATURES = [test: (g) => g.status >= 500 && (g.path.startsWith('/api/x402') || g.path === '/api/mcp')&& /^threews-/.test(g.userAgent),class: 'owner',- action: `5xx on paid x402 routes from the platform's own agent traffic has THREE distinct causes that look identical here; diagnose from app logs before concluding anything (2026-07-28 incident: all three fired at once). (1) npm run logs -- -s three-ws-api --app --grep "fee_wallet_below_floor" --since 1h; hits mean the sponsor fee wallet is under X402_SPONSOR_SOL_FLOOR_LAMPORTS. Config/self-heal territory: run POST /api/cron/treasury-topup (its reclaimIdleAgentSol leg refunds the fee wallet from idle agent SOL), no owner money needed unless every reclaim source reports at_or_below_floor. (2) grep "data_unavailable" instead; those are paid endpoints refunding honestly (no charge) because no market data source could answer. Fixed for pump.fun mints 2026-07-28 (crypto-intel prices bonding-curve coins via the pump.fun feed); a recurrence means a data-source outage, not wallets. (3) grep "broadcast_failed"; the reason now carries the simulation-log tail. "insufficient funds" on the token transfer = the ring payer's USDC float dipped below per-tick volume; run POST /api/cron/economy-rebalance (Bearer CRON_SECRET) and expect results[].status "swapped". ONLY when rebalance skips with insufficient_sol_surplus AND treasury-topup's reclaim finds nothing is it genuinely dry; then the owner sends SOL (or USDC) to the economy master WwwuGbqHrwF5RG89KhUbmRWEvjnRH9k5kVM5p7T3WwW and treasury-topup distributes within minutes. Verify recovery: healthz x402_settle returns to ok and the 5xx storm stops. Alternative to funding: throttle the ring to funded runway (X402_RING_TICK_CONCURRENCY and cadence knobs). ${RUNBOOK} §x402-wallets-dry.`,+ action: `5xx on paid x402 routes from the platform's own agent traffic has THREE distinct causes that look identical here; diagnose from app logs before concluding anything (2026-07-28 incident: all three fired at once). (0) FIRST read healthz x402_settle metrics.cause: it reconciles these 5xx against the facilitator's reject_reason book, so fee_governor there means the wallet fee governor spent the daily SOL budget (fund the fee wallet or accept the pacing; not a rail fault), and sponsor_floor means the floor case in (1). Only cause "rail" needs the log archaeology below. (1) npm run logs -- -s three-ws-api --app --grep "fee_wallet_below_floor" --since 1h; hits mean the sponsor fee wallet is under X402_SPONSOR_SOL_FLOOR_LAMPORTS. Config/self-heal territory: run POST /api/cron/treasury-topup (its reclaimIdleAgentSol leg refunds the fee wallet from idle agent SOL), no owner money needed unless every reclaim source reports at_or_below_floor. (2) grep "data_unavailable" instead; those are paid endpoints refunding honestly (no charge) because no market data source could answer. Fixed for pump.fun mints 2026-07-28 (crypto-intel prices bonding-curve coins via the pump.fun feed); a recurrence means a data-source outage, not wallets. (3) grep "broadcast_failed"; the reason now carries the simulation-log tail. "insufficient funds" on the token transfer = the ring payer's USDC float dipped below per-tick volume; run POST /api/cron/economy-rebalance (Bearer CRON_SECRET) and expect results[].status "swapped". ONLY when rebalance skips with insufficient_sol_surplus AND treasury-topup's reclaim finds nothing is it genuinely dry; then the owner sends SOL (or USDC) to the economy master WwwuGbqHrwF5RG89KhUbmRWEvjnRH9k5kVM5p7T3WwW and treasury-topup distributes within minutes. Verify recovery: healthz x402_settle returns to ok and the 5xx storm stops. Alternative to funding: throttle the ring to funded runway (X402_RING_TICK_CONCURRENCY and cadence knobs). ${RUNBOOK} §x402-wallets-dry.`,},{id: 'coingecko-quota-exhausted-502',diff --git a/tests/api/x402-settle-health.test.js b/tests/api/x402-settle-health.test.jsindex 7a315d9b0..e9f3030f9 100644--- a/tests/api/x402-settle-health.test.js+++ b/tests/api/x402-settle-health.test.js@@ -301,3 +301,74 @@ describe('classifySettleBuckets: a governed throttle is not a rail fault', () =>expect(isRailFault('fee_runway_exhausted:10022298+10000>10000000')).toBe(false);});});++// The ring log is reason-blind for refusals that arrive over HTTP: a settle the+// governor refused reaches x402_autonomous_log as a bare http_503 (pre+// 2026-08-06: http_502) and used to read as a rail fault. On 2026-08-05+// production this showed `cause: "rail"` at settle 26.1% while the facilitator+// book held 75k+ fee_runway_exhausted rejects — the operator was sent to debug+// a healthy rail. `facilitatorRejects` carries that book into the classifier.+describe('classifySettleBuckets: facilitator-book reconciliation of status-only faults', () => {+ // The live 2026-08-05 shape, scaled: settles landing, a 502/503 wall, and the+ // facilitator book attributing nearly all of it to the governor.+ const reasonBlindOutage = [+ { success: true, paid: true, reason: 'none', n: 443 },+ { success: false, paid: true, reason: 'http_502', n: 1172 },+ { success: false, paid: true, reason: 'http_503', n: 24 },+ { success: false, paid: true, reason: 'settle_failed', n: 29 },+ ];++ it('re-attributes governor-refused 5xx rows so the rate judges the rail alone', () => {+ const v = classifySettleBuckets(reasonBlindOutage, {+ facilitatorRejects: { governor: 1180 },+ });+ // 503 drains first, then 502: 24 + 1156 attributed, 16 http_502 + 29+ // settle_failed remain genuine rail faults.+ expect(v.governorSkips).toBe(1180);+ expect(v.faults).toBe(45);+ // The rate now judges the rail alone (443/488, not 443/1668), and per the+ // established pacing semantics a healthy residual rail reads OK with the+ // governed volume named in the detail, instead of yesterday's down/rail.+ expect(v.rate).toBeGreaterThan(0.9);+ expect(v.status).toBe('ok');+ expect(v.detail).toMatch(/1180 paced by the fee governor/);+ });++ it('clamps attribution at the observed status faults, never inventing negatives', () => {+ // Window skew between the two logs can put more rejects in the book than+ // 5xx rows in the ring log. min() caps the drain; faults never go below the+ // non-status rail signatures.+ const v = classifySettleBuckets(reasonBlindOutage, {+ facilitatorRejects: { governor: 50_000, floor: 10_000 },+ });+ expect(v.faults).toBe(29);+ expect(v.governorSkips).toBe(1196);+ expect(v.floorSignals).toBe(0);+ expect(v.faultClasses).toEqual([{ reason: 'settle_failed', n: 29 }]);+ });++ it('floor rejects drain what the governor left and outrank it in the verdict', () => {+ const v = classifySettleBuckets(reasonBlindOutage, {+ facilitatorRejects: { governor: 1000, floor: 150 },+ });+ // governor drains 24 http_503 + 976 http_502; floor drains 150 more 502s.+ expect(v.governorSkips).toBe(1000);+ expect(v.floorSignals).toBe(150);+ expect(v.faults).toBe(75);+ expect(v.cause).toBe('sponsor_floor');+ });++ it('a genuine rail outage with an empty facilitator book still blames the rail', () => {+ const v = classifySettleBuckets(reasonBlindOutage, { facilitatorRejects: { governor: 0, floor: 0 } });+ expect(v.cause).toBe('rail');+ expect(v.faults).toBe(1225);+ expect(v.status).toBe('down');+ });++ it('omitting facilitatorRejects behaves exactly as before', () => {+ const withOpt = classifySettleBuckets(reasonBlindOutage, {});+ const without = classifySettleBuckets(reasonBlindOutage);+ expect(withOpt).toEqual(without);+ expect(without.cause).toBe('rail');+ });+});