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(okx): stop an unreadable relayer balance being reported as an empty one
nirholas20a1a249d92e
diff --git a/api/okx/3d/[service].js b/api/okx/3d/[service].jsindex cb00049d1..fcd4e8950 100644--- a/api/okx/3d/[service].js+++ b/api/okx/3d/[service].js@@ -196,25 +196,32 @@ async function healthReport() {// and fail the subsystem when no route can actually settle: a rail that// quotes a price it cannot collect is exactly the never-402-then-502// case the challenge gate exists to prevent.+ // Three states, deliberately kept apart. A relayer whose balance+ // READ failed carries an `error` and no `funded` key, and folding+ // that into "false" would answer a public endpoint with a confident+ // out-of-gas diagnosis for what is really an unreadable account.const facilitator = rail.facilitator?.configured ?? false;- const relayerFunded = rail.relayer?.configured ? rail.relayer.funded === true : null;- const settleable = rail.settleable && (facilitator || relayerFunded !== false);- if (!settleable) {- const err = new Error(- relayerFunded === false- ? 'X Layer settlement relayer is out of gas (OKB balance 0)'- : 'X Layer settlement route is not configured',- );- err.detail = { settleable: false, block: rail.rpc?.block, token: rail.token?.symbol, facilitator_configured: facilitator, relayer_funded: relayerFunded };- throw err;- }- return {+ const relayer = rail.relayer || { configured: false };+ const relayerFunded = relayer.configured && typeof relayer.funded === 'boolean' ? relayer.funded : null;+ const relayerError = relayer.configured ? relayer.error || null : null;+ const settleable = Boolean(rail.settleable) && (facilitator || relayerFunded === true);+ const detail = {settleable,block: rail.rpc?.block,token: rail.token?.symbol,facilitator_configured: facilitator,relayer_funded: relayerFunded,+ ...(relayerError ? { relayer_error: relayerError } : {}),};+ if (!settleable) {+ let reason = 'X Layer settlement route is not configured';+ if (relayerFunded === false) reason = 'X Layer settlement relayer is out of gas (OKB balance 0)';+ else if (relayerError) reason = `X Layer settlement relayer balance could not be read: ${relayerError}`;+ const err = new Error(reason);+ err.detail = detail;+ throw err;+ }+ return detail;}),]);return { ok: subsystems.every((s) => s.ok), subsystems, checkedAt: new Date().toISOString() };diff --git a/docs/okx-marketplace.md b/docs/okx-marketplace.mdindex 6f719d484..4d9dfa18e 100644--- a/docs/okx-marketplace.md+++ b/docs/okx-marketplace.md@@ -78,6 +78,23 @@ curl https://three.ws/api/okx/3d/catalogcurl https://three.ws/api/okx/3d/health```+`health` answers `200` when every subsystem is up and `503` when one is not, so a buyer can+gate on the status code alone. The `payment-rail` subsystem is the one worth reading before+paying. It carries:++| Field | What it tells a buyer |+| --- | --- |+| `settleable` | Whether a payment made right now could actually be collected, not merely that a rail is configured |+| `block` | The X Layer block height the probe read, so the reading has an age |+| `token` | The fee token's `symbol()`, read from the contract rather than from our config |+| `facilitator_configured` | Whether settlement routes through the OKX facilitator |+| `relayer_funded` | When settlement routes through our own relayer instead, whether that relayer holds the gas to broadcast the redemption. `null` means the relayer is not the route in use |+| `relayer_error` | Present only when the relayer's balance could not be read at all, which is a different fact from a balance of zero |++The row goes `ok: false` (and the endpoint `503`) when nothing can settle, because a rail that+quotes a price it cannot collect would take a payment and fail afterwards. That is the one+health reading that should stop you paying.+---## three.ws Forgediff --git a/prompts/finish/_context/okx-ai-RUNBOOK.md b/prompts/finish/_context/okx-ai-RUNBOOK.mdindex a88e7f7dd..99cd65679 100644--- a/prompts/finish/_context/okx-ai-RUNBOOK.md+++ b/prompts/finish/_context/okx-ai-RUNBOOK.md@@ -348,7 +348,10 @@ Re-verify the relayer's OKB balance is still enough for ≥3 settlement tx beforstill 0, so it has never broadcast one. `/api/okx/3d/health` reports that reading itself as`relayer_funded` on the `payment-rail` row and fails the subsystem when the only settlementroute is a relayer with no gas, so a dry relayer shows up on the free health lane instead of-as a 502 after a buyer has already paid (committed 2026-09-09, live on the next deploy).+as a 502 after a buyer has already paid (commit `4e9ad0419`, refined by `a085871d7`). To tell+whether the running revision has it, read the field rather than a deploy date:+`curl -s https://three.ws/api/okx/3d/health | jq '.subsystems[] | select(.name=="payment-rail")'`+carries `relayer_funded` once it is live and only `settleable` before.Once funded, run [`okx-ai-04-e2e-real-payment-test.md`](../913-okx-ai-04-e2e-real-payment-test.md). It needs ≥3real settlements with transaction hashes.diff --git a/tests/api/okx-identity-studio.test.js b/tests/api/okx-identity-studio.test.jsindex e726f3524..ad3e022bb 100644--- a/tests/api/okx-identity-studio.test.js+++ b/tests/api/okx-identity-studio.test.js@@ -335,6 +335,28 @@ describe('free lanes over HTTP', () => {expect(rail.error).toMatch(/out of gas/);});+ // A balance READ that fails carries an error and no reading at all, which is+ // a different fact from a reading of zero. Collapsing the two answers a+ // public endpoint with a confident "out of gas" for an unreadable account.+ it('GET /health separates an unreadable relayer balance from a measured zero', async () => {+ mountHealthyProbes();+ fetchRoutes.rpc = (url, init) => {+ const rpc = jsonRpcBody(init);+ if (rpc?.method === 'eth_getBalance') {+ return jsonResponse(200, { jsonrpc: '2.0', id: rpc.id, error: { code: -32000, message: 'relayer account unavailable' } });+ }+ return healthyXlayerRpc(url, init);+ };+ const res = makeRes();+ await handler(makeReq({ method: 'GET', service: 'health' }), res);+ const rail = JSON.parse(res.body).subsystems.find((s) => s.name === 'payment-rail');+ expect(rail.ok).toBe(false);+ expect(rail.relayer_funded).toBe(null);+ expect(rail.error).toMatch(/could not be read/);+ expect(rail.error).not.toMatch(/out of gas/);+ expect(rail.relayer_error).toBeTruthy();+ });+it('GET /health goes 503 when a subsystem is down — never a hardcoded ok', async () => {fetchRoutes.render = () => new Response(null, { status: 500 });fetchRoutes.forgeSubmit = () => jsonResponse(200, FORGE_CATALOG);