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(ops): stop the world sensor calling a cold CDN edge a missing asset

nirholas77884bb1fffd
diff --git a/.gitignore b/.gitignore
index a3f82a3e3..87ebaf617 100644
--- a/.gitignore
+++ b/.gitignore
@@ -411,3 +411,7 @@ SECURITY-AUDIT.md
# Scratch harnesses for local 3D/pose debugging — never committed.
scripts/.scratch/
/workers/avatar-reconstruction/eval/adversarial/
+
+# Scratch copies of the built changelog feed (regenerate with npm run build:pages)
+old_changelog.json
+new_changelog.json
diff --git a/api/cron/world-health.js b/api/cron/world-health.js
index 8a252b294..fba949332 100644
--- a/api/cron/world-health.js
+++ b/api/cron/world-health.js
@@ -52,25 +52,44 @@ function requireCron(req, res) {
return false;
}
+// A 404/410 is the world's own answer: the asset is genuinely gone. Every other
+// failure (timeout, socket error, 5xx, 429) describes the network or the CDN at
+// this instant, not the scene, so it must not be reported as a missing asset.
+function isAuthoritativeMiss(status) {
+ return status === 404 || status === 410;
+}
+
+async function headOnce(url) {
+ try {
+ const res = await fetch(url, {
+ method: 'HEAD',
+ redirect: 'follow',
+ headers: { 'user-agent': 'threews-world-health/1.0' },
+ signal: AbortSignal.timeout(ASSET_TIMEOUT_MS),
+ });
+ return { ok: res.ok, status: res.status };
+ } catch (e) {
+ return { ok: false, status: 0, error: e?.name === 'TimeoutError' ? 'timeout' : 'unreachable' };
+ }
+}
+
// HEAD every asset URL with a bounded number in flight so the whole sweep
-// finishes well inside the 10s cron budget even with a large scene.
+// finishes well inside the 10s cron budget even with a large scene. A transient
+// failure is retried once before it counts: an 8s timeout on a cold CDN edge
+// used to alert "World asset MISSING" and park a degraded verdict for the full
+// cache hour, indistinguishable from a real 404.
async function headAll(urls, concurrency) {
const results = new Array(urls.length);
let cursor = 0;
async function worker() {
while (cursor < urls.length) {
const i = cursor++;
- try {
- const res = await fetch(urls[i], {
- method: 'HEAD',
- redirect: 'follow',
- headers: { 'user-agent': 'threews-world-health/1.0' },
- signal: AbortSignal.timeout(ASSET_TIMEOUT_MS),
- });
- results[i] = { ok: res.ok, status: res.status };
- } catch (e) {
- results[i] = { ok: false, status: 0, error: e?.name === 'TimeoutError' ? 'timeout' : 'unreachable' };
+ let out = await headOnce(urls[i]);
+ if (!out.ok && !isAuthoritativeMiss(out.status)) {
+ out = await headOnce(urls[i]);
+ if (!out.ok) out.transient = !isAuthoritativeMiss(out.status);
}
+ results[i] = out;
}
}
await Promise.all(Array.from({ length: Math.min(concurrency, urls.length) }, worker));
@@ -107,9 +126,17 @@ export default wrapCron(async (req, res) => {
// `blueprints` is the patched-/status asset list ({id, assetUrl}); tolerate an
// older revision that predates the patch by treating an absent list as empty.
const blueprints = Array.isArray(status?.blueprints) ? status.blueprints : [];
- const assetUrls = blueprints
- .map((b) => b?.assetUrl)
- .filter((u) => typeof u === 'string' && /^https?:\/\//.test(u));
+ // One asset is shared by many blueprints (a scene of 136 entries resolves to
+ // 17 distinct files), so sweep the distinct set: 8x fewer requests inside the
+ // same 10s budget, and one broken file counts once instead of once per user.
+ const blueprintIdsByAsset = new Map();
+ for (const b of blueprints) {
+ const u = b?.assetUrl;
+ if (typeof u !== 'string' || !/^https?:\/\//.test(u)) continue;
+ if (!blueprintIdsByAsset.has(u)) blueprintIdsByAsset.set(u, []);
+ if (b?.id) blueprintIdsByAsset.get(u).push(b.id);
+ }
+ const assetUrls = [...blueprintIdsByAsset.keys()];
const problems = [];
@@ -127,12 +154,29 @@ export default wrapCron(async (req, res) => {
// 3. HEAD every referenced asset; a 404 will crash the scene on join.
const checks = await headAll(assetUrls, ASSET_CONCURRENCY);
const missing = [];
+ const unreachable = [];
checks.forEach((c, i) => {
- if (!c.ok) {
- const bp = blueprints.find((b) => b.assetUrl === assetUrls[i]);
- missing.push({ assetUrl: assetUrls[i], blueprintId: bp?.id, status: c.status, error: c.error });
- }
+ if (c.ok) return;
+ const ids = blueprintIdsByAsset.get(assetUrls[i]) || [];
+ const entry = {
+ assetUrl: assetUrls[i],
+ blueprintId: ids[0],
+ blueprintIds: ids,
+ status: c.status,
+ error: c.error,
+ };
+ (c.transient ? unreachable : missing).push(entry);
});
+ // Reported but never escalated: the scene still loads for everyone whose edge
+ // serves the file, so this is a CDN observation, not a broken world.
+ if (unreachable.length) {
+ problems.push(`${unreachable.length} blueprint asset(s) unreachable this tick`);
+ console.warn(
+ `[world-health] transient asset failures: ${unreachable
+ .map((m) => `${m.assetUrl} (${m.error || `HTTP ${m.status}`})`)
+ .join(', ')}`,
+ );
+ }
if (missing.length) {
problems.push(`${missing.length} blueprint asset(s) missing`);
const detail = missing
@@ -164,6 +208,8 @@ export default wrapCron(async (req, res) => {
status: outcome,
protected: isProtected,
blueprintCount: blueprints.length,
+ assetCount: assetUrls.length,
...(missing.length ? { missingAssets: missing } : {}),
+ ...(unreachable.length ? { unreachableAssets: unreachable } : {}),
});
});
diff --git a/public/.well-known/agent.json b/public/.well-known/agent.json
index ee8984152..c50a3cce6 100644
--- a/public/.well-known/agent.json
+++ b/public/.well-known/agent.json
@@ -111,7 +111,7 @@
"glb"
],
"examples": [
- "Validate https://example.com/model.glb",
+ "Validate https://three.ws/avatars/cesium-man.glb",
"Is this GLB spec-compliant?",
"Check my model for errors"
]
@@ -129,7 +129,7 @@
],
"examples": [
"How many triangles are in this model?",
- "Inspect https://example.com/scene.glb",
+ "Inspect https://three.ws/avatars/studio.glb",
"Show texture stats for this GLB"
]
},
@@ -146,7 +146,7 @@
"examples": [
"How can I make this model smaller?",
"Optimize this GLB for web delivery",
- "Suggest compression for https://example.com/avatar.glb"
+ "Suggest compression for https://three.ws/avatars/brainstem.glb"
]
},
{
@@ -163,7 +163,7 @@
"paid"
],
"examples": [
- "Inspect https://example.com/model.glb (A2A x402)",
+ "Inspect https://three.ws/avatars/cesium-man.glb (A2A x402)",
"Vet this GLB before I mint it"
],
"inputModes": [
diff --git a/public/spatial-mcp/demo.js b/public/spatial-mcp/demo.js
index a457b5143..cabf20db9 100644
--- a/public/spatial-mcp/demo.js
+++ b/public/spatial-mcp/demo.js
@@ -126,7 +126,7 @@ document.getElementById('artifact-json').textContent = JSON.stringify(transforme
const BROKEN_EXAMPLE = {
spatialMcpVersion: '0.2',
kind: 'hologram',
- scene: { glbUrl: 'http://example.com/model.glb', format: 'usdz' },
+ scene: { glbUrl: 'http://three.ws/avatars/xbot.glb', format: 'usdz' },
camera: { autoRotate: 'yes' },
ar: { supported: true },
meta: { title: 'ok to keep', session_id: 'sess_01HZY3', price_usd: '0.25' },
diff --git a/tests/world-health-asset-sweep.test.js b/tests/world-health-asset-sweep.test.js
new file mode 100644
index 000000000..0eb092149
--- /dev/null
+++ b/tests/world-health-asset-sweep.test.js
@@ -0,0 +1,170 @@
+/**
+ * world-health asset sweep: what counts as a missing blueprint asset.
+ *
+ * The sensor HEADs every asset the scene references and marks the world degraded
+ * when one is gone, because a 404 crashes Hyperfy on join. Two defects made it
+ * report a healthy world as broken:
+ * 1. It swept `blueprints` verbatim. A live scene of 136 entries resolves to 17
+ * distinct files, so it fired 8x the requests inside a 10s budget and counted
+ * one broken file once per blueprint that referenced it.
+ * 2. Any failure counted as "missing". An 8s timeout against a cold CDN edge
+ * raised a "World asset MISSING" ops alert and parked a degraded verdict for
+ * the full cache hour, identical to a genuine 404. Observed 2026-07-30: the
+ * sensor reported "1 blueprint asset(s) missing" while all 17 assets served
+ * 200 to an independent sweep.
+ *
+ * Contracts under test:
+ * 1. Distinct assets are swept once each, not once per referencing blueprint.
+ * 2. A transient failure is retried, and a retry that succeeds is not a miss.
+ * 3. A sustained transient failure degrades nothing and raises no alert.
+ * 4. A 404 is authoritative: no retry, degraded, alert raised.
+ */
+
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+
+vi.mock('../api/_lib/alerts.js', () => ({ sendOpsAlert: vi.fn() }));
+vi.mock('../api/_lib/cache.js', () => ({ cacheSet: vi.fn(async () => {}) }));
+
+import handler from '../api/cron/world-health.js';
+import { sendOpsAlert } from '../api/_lib/alerts.js';
+
+const SECRET = 'test-cron-secret';
+
+// Two blueprints share one asset, a third has its own: 3 entries, 2 distinct URLs.
+const SHARED = 'https://world.three.ws/assets/shared.glb';
+const SOLO = 'https://world.three.ws/assets/solo.glb';
+const STATUS_BODY = {
+ protected: true,
+ blueprints: [
+ { id: 'bp-a', assetUrl: SHARED },
+ { id: 'bp-b', assetUrl: SHARED },
+ { id: 'bp-c', assetUrl: SOLO },
+ ],
+};
+
+function fakeRes() {
+ const headers = {};
+ return {
+ statusCode: 0,
+ body: undefined,
+ headersSent: false,
+ writableEnded: false,
+ setHeader(k, v) { headers[String(k).toLowerCase()] = v; },
+ getHeader(k) { return headers[String(k).toLowerCase()]; },
+ end(b) { this.body = b; this.writableEnded = true; },
+ };
+}
+
+const req = () => ({
+ method: 'GET',
+ url: '/api/cron/world-health',
+ headers: { authorization: `Bearer ${SECRET}` },
+});
+
+/**
+ * Stub fetch: /status returns the scene, every other URL is resolved by `assets`,
+ * a map of URL to an array of per-attempt outcomes (so a retry can differ from the
+ * first try). Records each HEAD so we can assert the request count.
+ */
+function stubFetch(assets) {
+ const heads = [];
+ const attempts = new Map();
+ vi.stubGlobal('fetch', vi.fn(async (url, opts) => {
+ const u = String(url);
+ if (u.endsWith('/status')) {
+ return { ok: true, status: 200, json: async () => STATUS_BODY };
+ }
+ expect(opts?.method).toBe('HEAD');
+ heads.push(u);
+ const n = attempts.get(u) || 0;
+ attempts.set(u, n + 1);
+ const plan = assets[u] || [200];
+ const outcome = plan[Math.min(n, plan.length - 1)];
+ if (outcome === 'timeout') throw Object.assign(new Error('timed out'), { name: 'TimeoutError' });
+ return { ok: outcome >= 200 && outcome < 300, status: outcome };
+ }));
+ return heads;
+}
+
+let warnSpy;
+let logSpy;
+beforeEach(() => {
+ process.env.CRON_SECRET = SECRET;
+ warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
+ sendOpsAlert.mockReset();
+});
+afterEach(() => {
+ vi.unstubAllGlobals();
+ warnSpy.mockRestore();
+ logSpy.mockRestore();
+});
+
+async function run() {
+ const res = fakeRes();
+ await handler(req(), res);
+ return JSON.parse(res.body);
+}
+
+describe('world-health asset sweep', () => {
+ it('sweeps each distinct asset once, not once per referencing blueprint', async () => {
+ const heads = stubFetch({ [SHARED]: [200], [SOLO]: [200] });
+ const body = await run();
+
+ expect(body.status).toBe('ok');
+ expect(body.blueprintCount).toBe(3);
+ expect(body.assetCount).toBe(2);
+ // 3 blueprints, 2 distinct assets, so exactly 2 HEADs.
+ expect(heads).toHaveLength(2);
+ expect(new Set(heads)).toEqual(new Set([SHARED, SOLO]));
+ });
+
+ it('retries a transient failure and clears it when the retry succeeds', async () => {
+ const heads = stubFetch({ [SHARED]: ['timeout', 200], [SOLO]: [200] });
+ const body = await run();
+
+ expect(body.status).toBe('ok');
+ expect(body.missingAssets).toBeUndefined();
+ expect(body.unreachableAssets).toBeUndefined();
+ // SHARED was tried twice, SOLO once.
+ expect(heads.filter((u) => u === SHARED)).toHaveLength(2);
+ expect(sendOpsAlert).not.toHaveBeenCalled();
+ });
+
+ it('never degrades the world or alerts on a sustained transient failure', async () => {
+ stubFetch({ [SHARED]: ['timeout'], [SOLO]: [200] });
+ const body = await run();
+
+ expect(body.status).toBe('ok');
+ expect(body.missingAssets).toBeUndefined();
+ expect(body.unreachableAssets).toHaveLength(1);
+ expect(body.unreachableAssets[0].assetUrl).toBe(SHARED);
+ // The regression: this used to raise "World asset MISSING" on a cold edge.
+ expect(sendOpsAlert).not.toHaveBeenCalled();
+ });
+
+ it('treats a 404 as authoritative: no retry, degraded, alert raised', async () => {
+ const heads = stubFetch({ [SHARED]: [404], [SOLO]: [200] });
+ const body = await run();
+
+ expect(body.status).toBe('degraded');
+ expect(body.unreachableAssets).toBeUndefined();
+ expect(body.missingAssets).toHaveLength(1);
+ // Counted once, but both blueprints that reference it are named.
+ expect(body.missingAssets[0].blueprintIds).toEqual(['bp-a', 'bp-b']);
+ // A 404 is the world's own answer, so it is never re-probed.
+ expect(heads.filter((u) => u === SHARED)).toHaveLength(1);
+ expect(sendOpsAlert).toHaveBeenCalledTimes(1);
+ expect(sendOpsAlert.mock.calls[0][0]).toBe('World asset MISSING');
+ });
+
+ it('retries a 5xx before believing it, since the file may still be there', async () => {
+ const heads = stubFetch({ [SHARED]: [503, 503], [SOLO]: [200] });
+ const body = await run();
+
+ expect(heads.filter((u) => u === SHARED)).toHaveLength(2);
+ expect(body.status).toBe('ok');
+ expect(body.unreachableAssets).toHaveLength(1);
+ expect(body.unreachableAssets[0].status).toBe(503);
+ });
+});