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): refuse a paid forge job before settlement when delivery storage is down
nirholasb481c2cc8814
diff --git a/api/_okx3d/forge.js b/api/_okx3d/forge.jsindex 53a6cb4ef..57b6145fa 100644--- a/api/_okx3d/forge.js+++ b/api/_okx3d/forge.js@@ -42,6 +42,7 @@ import { catalogEntry, FORGE_TOOL, FORGE_STATUS_TOOL } from '../_lib/okx-catalogimport { startForge, pollOnce, originFromReq } from '../_mcp-studio/gpt-forge-client.js';import { shapeSubmit, shapePoll, tierOf } from '../_mcp-studio/studio-shape.js';import { checkPromptSafety } from '../_mcp-studio/safety.js';+import { objectStorageUsable } from '../_lib/r2.js';import { renderTurntable, describeGeometry } from '../_lib/3d-vision.js';export { PROTOCOL_VERSION, FORGE_TOOL, FORGE_STATUS_TOOL };@@ -187,6 +188,24 @@ function buildForgeTool(entry) {return toolError('invalid_input', 'prompt is required: describe one subject in 3 to 1000 characters.');}+ // Delivery, not just generation, has to be up before we take money.+ // This row settles when the lane ACCEPTS the job, and the finished mesh+ // reaches the buyer only once materializeCreation has copied it into the+ // delivery bucket. On 2026-09-09 that copy was failing on a rejected R2+ // credential for every job since 2026-09-07, so the lane still accepted+ // (and charged) work that could never reach a `done` state: a buyer paid+ // and polled forever. The probe is the cached, single-flighted one the+ // browser-upload path already relies on, so this costs a paid call one+ // signed list per minute, and it fails OPEN on a transient fault: only a+ // deterministically rejected or unconfigured credential refuses here.+ const storage = await objectStorageUsable();+ if (!storage.ok) {+ return toolError('delivery_unavailable', 'model delivery storage is unavailable right now, so this call was not charged; try again shortly', {+ retry_after: 120,+ charged: false,+ });+ }+// The high tier is hold-gated on the generator; the buyer has already// paid this row's price, so the job runs operator-funded (internal seed),// the same way the custom GPT runs it. strictTier keeps the promise: ifdiff --git a/docs/okx-marketplace.md b/docs/okx-marketplace.mdindex 65016181a..45a18adfc 100644--- a/docs/okx-marketplace.md+++ b/docs/okx-marketplace.md@@ -218,6 +218,13 @@ unit tests in [`tests/api/okx-forge.test.js`](../tests/api/okx-forge.test.js).- **HD means HD.** If the high-detail lane will not take a job, `forge-hd` answers`tier_unavailable` (with `charged: false` and a `retry_after`) instead of quietly servinga standard mesh at the HD price. That refusal is also before settlement.+- **Delivery has to be up before you are charged.** A finished mesh reaches you only once+ it has been copied into the delivery bucket, so a paid row checks that the bucket is+ writable before it hands the job to the generator. If it is not, the call answers+ `delivery_unavailable` (with `charged: false` and a `retry_after`) rather than accepting,+ settling, and leaving you polling a job that can never reach `done`. The check is cached+ and fails open on a transient fault, so only a credential that is deterministically+ rejected or missing stops the row selling.- **A real MCP client gets a 402.** The shared three.ws MCP servers answer OAuth-capableclients (`Accept: text/event-stream`, `mcp-protocol-version`) with a 401 so they candiscover OAuth. The OKX.AI endpoints never do: every unpaid paid-tool call is a 402 withdiff --git a/tests/api/okx-forge.test.js b/tests/api/okx-forge.test.jsindex 359e90fcb..802983cd0 100644--- a/tests/api/okx-forge.test.js+++ b/tests/api/okx-forge.test.js@@ -43,6 +43,14 @@ vi.mock('../../api/_lib/rate-limit.js', () => ({clientIp: vi.fn(() => '203.0.113.9'),}));+// The paid rows refuse before settlement when the delivery bucket is+// unwritable, so every case here needs a verdict for that probe. Keep the real+// module and override only the probe: a test must never reach for real R2.+vi.mock('../../api/_lib/r2.js', async (importOriginal) => ({+ ...(await importOriginal()),+ objectStorageUsable: vi.fn(async () => ({ ok: true, reason: null, message: null })),+}));+vi.mock('../../api/_lib/usage.js', () => ({recordEvent: vi.fn(),logger: () => ({ info: () => {}, warn: () => {}, error: () => {} }),@@ -615,6 +623,37 @@ describe('each row drives its own lane', () => {expect(out.structuredContent.error).toBe('tier_unavailable');});+ // Generation being up is not enough: this row settles when the lane ACCEPTS+ // the job, but the buyer only ever receives a mesh that reached the delivery+ // bucket. A rejected R2 credential broke that copy for every job from+ // 2026-09-07, while the lane kept accepting and charging work that could+ // never finish.+ it('refuses BEFORE settlement when the delivery bucket is unwritable, and never submits', async () => {+ const { objectStorageUsable } = await import('../../api/_lib/r2.js');+ vi.mocked(objectStorageUsable).mockResolvedValueOnce({+ ok: false,+ reason: 'rejected',+ message: 'The request signature we calculated does not match the signature you provided.',+ });+ const out = await callTool('forge-draft', FORGE_TOOL, { prompt: 'a fox' });+ expect(out.isError).toBe(true);+ expect(out.structuredContent.error).toBe('delivery_unavailable');+ expect(out.structuredContent.charged).toBe(false);+ expect(out.structuredContent.retry_after).toBe(120);+ // Nothing reached the generator, so nothing can settle.+ expect(submitted).toHaveLength(0);+ });++ // The probe fails OPEN on a transient fault, so a flaky list never takes the+ // paid rows down: only a deterministic rejection refuses.+ it('still sells when the storage probe reports a transient fault', async () => {+ const { objectStorageUsable } = await import('../../api/_lib/r2.js');+ vi.mocked(objectStorageUsable).mockResolvedValueOnce({ ok: true, reason: null, message: null });+ const out = await callTool('forge-draft', FORGE_TOOL, { prompt: 'a fox' });+ expect(out.isError).toBeFalsy();+ expect(submitted).toHaveLength(1);+ });+it('rejects an unsafe prompt BEFORE any generation runs, so it can never settle', async () => {const out = await callTool('forge-draft', FORGE_TOOL, { prompt: 'a nude child' });expect(out.isError).toBe(true);