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: handle fetch errors gracefully in forge smoke tests and update avatar URL handling

fudjiac7269269d80d
diff --git a/api/cron/forge-smoke.js b/api/cron/forge-smoke.js
index 147d5f60c..695d5b48d 100644
--- a/api/cron/forge-smoke.js
+++ b/api/cron/forge-smoke.js
@@ -57,12 +57,20 @@ function requireCron(req, res) {
return true;
}
+// Never throws: a timeout or network failure comes back as status 0 so every
+// caller's non-200 branch reports it as a failed check instead of the
+// rejection escaping Promise.all and 500ing the whole cron run.
async function fetchJson(url, options = {}, timeoutMs = 15_000) {
- const res = await fetch(url, {
- ...options,
- headers: { 'user-agent': 'threews-forge-smoke/1.0', ...options.headers },
- signal: AbortSignal.timeout(timeoutMs),
- });
+ let res;
+ try {
+ res = await fetch(url, {
+ ...options,
+ headers: { 'user-agent': 'threews-forge-smoke/1.0', ...options.headers },
+ signal: AbortSignal.timeout(timeoutMs),
+ });
+ } catch (err) {
+ return { status: 0, body: { error: String(err?.message || err) } };
+ }
let body = null;
try {
body = await res.json();
@@ -75,12 +83,18 @@ async function fetchJson(url, options = {}, timeoutMs = 15_000) {
// A generation only counts when the GLB exists AND starts with the binary
// glTF magic — a 200 with an HTML error page must not pass.
async function verifyGlb(glbUrl) {
- const res = await fetch(glbUrl, {
- headers: { range: 'bytes=0-3', 'user-agent': 'threews-forge-smoke/1.0' },
- signal: AbortSignal.timeout(20_000),
- });
- if (!res.ok) return { ok: false, reason: `GLB fetch returned HTTP ${res.status}` };
- const bytes = new Uint8Array(await res.arrayBuffer());
+ let res;
+ let bytes;
+ try {
+ res = await fetch(glbUrl, {
+ headers: { range: 'bytes=0-3', 'user-agent': 'threews-forge-smoke/1.0' },
+ signal: AbortSignal.timeout(20_000),
+ });
+ if (!res.ok) return { ok: false, reason: `GLB fetch returned HTTP ${res.status}` };
+ bytes = new Uint8Array(await res.arrayBuffer());
+ } catch (err) {
+ return { ok: false, reason: `GLB fetch failed: ${err?.message || err}` };
+ }
const magic = String.fromCharCode(...bytes.slice(0, 4));
if (magic !== 'glTF') return { ok: false, reason: `GLB magic bytes were "${magic}", not "glTF"` };
return { ok: true };
diff --git a/src/play/arena-world.js b/src/play/arena-world.js
index 4202ef563..858d6df35 100644
--- a/src/play/arena-world.js
+++ b/src/play/arena-world.js
@@ -275,12 +275,13 @@ export class ArenaWorld {
// or stalls — so a crowd never ends up with a missing body.
async _makeAvatar(glbUrl, { fallback = '/avatars/mannequin.glb', timeout = 20000 } = {}) {
let gltf;
+ let loadedUrl = glbUrl;
try { gltf = await this._loadTemplateTimed(glbUrl, timeout); }
- catch { gltf = await this._loadTemplate(fallback); }
+ catch { gltf = await this._loadTemplate(fallback); loadedUrl = fallback; }
// Clone so multiple agents can share one downloaded GLB.
const model = cloneSkeleton(gltf.scene);
model.traverse((o) => { if (o.isMesh) { o.castShadow = true; o.frustumCulled = false; } });
- return new ArenaAvatar(model, this._lib, this._loopByName, CLIPS);
+ return new ArenaAvatar(model, this._lib, this._loopByName, CLIPS, loadedUrl);
}
// ── Spawning ──────────────────────────────────────────────────────────────
@@ -876,7 +877,7 @@ export class ArenaWorld {
// ── One avatar (agent or spectator) ──────────────────────────────────────────
class ArenaAvatar {
- constructor(model, lib, loopByName, clipMap) {
+ constructor(model, lib, loopByName, clipMap, avatarUrl = '') {
this.object = model;
this._clipMap = clipMap;
this._loopByName = loopByName;
@@ -885,7 +886,7 @@ class ArenaAvatar {
// Inject the shared canonical clips so attach() builds retargeted actions
// without re-fetching or re-parsing them.
for (const [name, clip] of lib.clips) this.anim.clips.set(name, clip);
- this.anim.attach(model);
+ this.anim.attach(model, { avatarUrl });
this._configureLoops();
this._emoteTimer = 0;
this._moving = false;