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.

Solana RPC log dedup, NVIDIA string artifact fix, forge cron timeout handling

nirholascfe3b6415046
diff --git a/api/_lib/solana/connection.js b/api/_lib/solana/connection.js
index 830532ddb..fc03e3a95 100644
--- a/api/_lib/solana/connection.js
+++ b/api/_lib/solana/connection.js
@@ -142,13 +142,16 @@ export function makeRotatingFetch(endpoints) {
// Read the body only on the failure path (we never return it) so a
// quota signal can pick the long cooldown.
const bodyText = resp.status === 429 ? await resp.clone().text().catch(() => '') : '';
+ // Check BEFORE marking: if parallel rotatingFetch calls race onto
+ // the same endpoint simultaneously, only the first to resolve logs —
+ // all subsequent callers see alreadyCooling=true and skip the line.
+ const alreadyCooling = isEndpointCooling(url);
const ms = markEndpointCooldown(url, resp.status, bodyText);
- // Logged only on the transition into cooldown — cooling endpoints
- // are skipped above without a line, so this fires once per window
- // per provider instead of on every RPC call.
- console.warn(
- `[solana-rpc] ${maskUrl(url)} ${resp.status} — cooling ${Math.round(ms / 60_000)}m, failing over`,
- );
+ if (!alreadyCooling) {
+ console.warn(
+ `[solana-rpc] ${maskUrl(url)} ${resp.status} — cooling ${Math.round(ms / 60_000)}m, failing over`,
+ );
+ }
lastErr = new Error(`solana rpc ${resp.status} @ ${maskUrl(url)}`);
continue;
}
diff --git a/api/_lib/solana/rpc-fallback.js b/api/_lib/solana/rpc-fallback.js
index 030007647..07a2acd66 100644
--- a/api/_lib/solana/rpc-fallback.js
+++ b/api/_lib/solana/rpc-fallback.js
@@ -120,13 +120,20 @@ export class RpcFallback {
} catch (err) {
if (isRetryable(err)) {
const status = statusFromErr(err);
+ // Check BEFORE marking so parallel withFallback() calls that race
+ // onto the same endpoint only emit the log once: the first caller
+ // sees alreadyCooling=false, logs, then marks; every subsequent
+ // concurrent caller that resolves afterward sees alreadyCooling=true.
+ const alreadyCooling = isEndpointCooling(this.currentUrl);
const ms = markEndpointCooldown(this.currentUrl, status, String((err && err.message) || err));
- console.warn(
- '[rpc-fallback] %s %s — cooling %dm, rotating',
- maskUrl(this.currentUrl),
- status,
- Math.round(ms / 60_000),
- );
+ if (!alreadyCooling) {
+ console.warn(
+ '[rpc-fallback] %s %s — cooling %dm, rotating',
+ maskUrl(this.currentUrl),
+ status,
+ Math.round(ms / 60_000),
+ );
+ }
this.reportFailure();
} else {
throw err;
diff --git a/api/_providers/nvidia.js b/api/_providers/nvidia.js
index 030ba3c3d..df28bd1b5 100644
--- a/api/_providers/nvidia.js
+++ b/api/_providers/nvidia.js
@@ -128,6 +128,13 @@ async function extractGlbBase64(res) {
const data = await res.json().catch(() => null);
const artifact0 = data?.artifacts?.[0];
+ // String artifact — NVIDIA sometimes returns the base64 string directly in
+ // the artifacts array rather than wrapped in an object { base64 }. Accept it
+ // unless it looks like a URL (those go through the artifactUrl path below).
+ if (typeof artifact0 === 'string' && artifact0.length > 0 && !artifact0.startsWith('http')) {
+ return { base64: artifact0 };
+ }
+
// Inline base64 — the documented shape; also accept output[] variants.
const inlineData = artifact0?.base64 ?? artifact0?.data ?? null;
const inlineB64 =
@@ -156,11 +163,21 @@ async function extractGlbBase64(res) {
}
}
- // Build a diagnostic that shows both levels so the actual schema is visible
- // in the logs — top-level keys and artifact[0] keys if present.
+ // Build a precise diagnostic showing top-level keys and artifact[0] shape so
+ // the actual upstream response is visible in the logs without guessing.
const topKeys = data && typeof data === 'object' ? JSON.stringify(Object.keys(data)) : 'unparseable';
- const artKeys = artifact0 && typeof artifact0 === 'object' ? ` artifact[0]=${JSON.stringify(Object.keys(artifact0))}` : '';
- return { base64: null, diag: `json keys=${topKeys}${artKeys}` };
+ const arts = data?.artifacts;
+ let artDesc = '';
+ if (Array.isArray(arts)) {
+ if (arts.length === 0) {
+ artDesc = ' artifacts=[]';
+ } else if (artifact0 && typeof artifact0 === 'object') {
+ artDesc = ` artifact[0]=${JSON.stringify(Object.keys(artifact0))}`;
+ } else {
+ artDesc = ` artifact[0]=${typeof artifact0}`;
+ }
+ }
+ return { base64: null, diag: `json keys=${topKeys}${artDesc}` };
}
if (ct.includes('gltf') || ct.includes('octet-stream') || ct.startsWith('model/') || ct.includes('binary')) {
const buf = Buffer.from(await res.arrayBuffer());
diff --git a/api/cron/forge-seed-cron.js b/api/cron/forge-seed-cron.js
index 44eabf99e..0401fb8d8 100644
--- a/api/cron/forge-seed-cron.js
+++ b/api/cron/forge-seed-cron.js
@@ -25,11 +25,12 @@ import { SEED_PROMPTS, OG_USERNAMES } from '../_lib/seed-prompts.js';
import { randomUUID } from 'node:crypto';
const ORIGIN = () => env.APP_ORIGIN || 'https://three.ws';
-// Must exceed the forge endpoint's worst-case synchronous wait on the free
-// NVIDIA lane (SUBMIT_TIMEOUT_MS = 45 s in api/_providers/nvidia.js) so the cron
-// never aborts a generation that is legitimately still completing; still inside
-// the 60 s function budget.
-const FETCH_TIMEOUT_MS = 50_000;
+// Must be large enough for the image-intermediate path (textToImage → NIM FLUX,
+// NIM_TIMEOUT_MS = 60 s in _mcp3d/text-to-image.js) yet leave the cron a small
+// window to clean up and return. When the timeout fires, fetchJson returns
+// { timedOut: true } — startNextJob treats that as a soft failure and rolls back
+// the pending user so the next tick can retry cleanly.
+const FETCH_TIMEOUT_MS = 55_000;
const MAX_CONCURRENT_PENDING = 3;
const MIN_JOB_AGE_SECONDS = 20;
@@ -49,11 +50,22 @@ function requireCron(req, res) {
}
async function fetchJson(url, options = {}) {
- const res = await fetch(url, {
- ...options,
- headers: { 'user-agent': 'threews-forge-seed/1.0', ...options.headers },
- signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
- });
+ let res;
+ try {
+ res = await fetch(url, {
+ ...options,
+ headers: { 'user-agent': 'threews-forge-seed/1.0', ...options.headers },
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
+ });
+ } catch (err) {
+ // AbortSignal.timeout fires a DOMException[TimeoutError]; treat it as a soft
+ // failure so the cron can clean up and return 200 instead of propagating a
+ // 500. Other network errors (DNS, ECONNREFUSED) are real failures — rethrow.
+ if (err?.name === 'TimeoutError' || err?.name === 'AbortError') {
+ return { status: 0, body: null, timedOut: true };
+ }
+ throw err;
+ }
let body = null;
try { body = await res.json(); } catch { /* non-JSON — status is enough */ }
return { status: res.status, body };
@@ -207,6 +219,11 @@ async function startNextJob(origin) {
body: JSON.stringify({ prompt: chosen.prompt, tier: 'draft', path: 'image' }),
});
+ if (submit.timedOut) {
+ await sql`delete from users where id = ${user.id}`.catch(() => {});
+ return { ok: false, reason: 'forge submit timed out — will retry next tick' };
+ }
+
if (submit.status !== 200) {
await sql`delete from users where id = ${user.id}`.catch(() => {});
return {
diff --git a/vercel.json b/vercel.json
index 0ad125783..583c2c038 100644
--- a/vercel.json
+++ b/vercel.json
@@ -1509,6 +1509,10 @@
"src": "/api/agents/featured",
"dest": "/api/agents/featured"
},
+ {
+ "src": "/api/agents/public",
+ "dest": "/api/agents/public"
+ },
{
"src": "/api/agents/by-wallet",
"dest": "/api/agents/by-wallet"