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(pages): bound every per-page fetch so a dead edge cannot freeze a spinner

nirholasd8f11baf8398
diff --git a/src/agent-detail.js b/src/agent-detail.js
index 4ee99eae0..7b0d562bb 100644
--- a/src/agent-detail.js
+++ b/src/agent-detail.js
@@ -2962,8 +2962,12 @@ document.addEventListener('click', (e) => {
if (value && value !== '—') navigator.clipboard?.writeText(value)?.catch(() => {});
});
-async function fetchJson(url) {
- const res = await fetch(url, { credentials: 'include' });
+// Every agent-page fetch is time-bounded. A black-holed edge or a stalled
+// serverless cold start used to leave the profile parked on its skeleton with
+// no way out; on timeout the abort rejects, fetchAgentRecord retries once, and
+// a second failure lands on the designed "Couldn't load this agent" state.
+async function fetchJson(url, { timeout = 8000, ...opts } = {}) {
+ const res = await fetch(url, { credentials: 'include', ...opts, signal: AbortSignal.timeout(timeout) });
if (!res.ok) {
const err = new Error(`${url} → HTTP ${res.status}`);
err.status = res.status;
diff --git a/src/agent-skills-nfts.js b/src/agent-skills-nfts.js
index 23e0ae3fd..5acb44713 100644
--- a/src/agent-skills-nfts.js
+++ b/src/agent-skills-nfts.js
@@ -13,8 +13,10 @@
* Docs: https://docs.helius.dev/compression-and-das-api/digital-asset-standard-api
*/
-async function fetchJson(url) {
- const r = await fetch(url, { credentials: 'include' });
+// Bounded so a stalled DAS query cannot hang the agent's turn: the skill
+// awaits this inline, and without a deadline the chat sits mid-reply forever.
+async function fetchJson(url, { timeout = 8000 } = {}) {
+ const r = await fetch(url, { credentials: 'include', signal: AbortSignal.timeout(timeout) });
if (!r.ok) throw new Error(`request failed: ${r.status}`);
return r.json();
}
diff --git a/src/agent-skills-pumpfun-watch.js b/src/agent-skills-pumpfun-watch.js
index 56c839232..adeef6777 100644
--- a/src/agent-skills-pumpfun-watch.js
+++ b/src/agent-skills-pumpfun-watch.js
@@ -35,8 +35,10 @@ const _state = {
/** Active whale-trade watchers keyed by mint. Value is the AbortController. */
const _whaleWatchers = new Map();
-async function fetchJson(url) {
- const r = await fetch(url, { credentials: 'include' });
+// Bounded so a stalled feed cannot hang the agent's turn: the watch skills
+// await this inline, and without a deadline the chat sits mid-reply forever.
+async function fetchJson(url, { timeout = 8000 } = {}) {
+ const r = await fetch(url, { credentials: 'include', signal: AbortSignal.timeout(timeout) });
if (!r.ok) throw new Error(`request failed: ${r.status}`);
return r.json();
}
diff --git a/src/game/npc/npc-aixbt.js b/src/game/npc/npc-aixbt.js
index 88c82f938..ccdf3ae3f 100644
--- a/src/game/npc/npc-aixbt.js
+++ b/src/game/npc/npc-aixbt.js
@@ -234,8 +234,12 @@ function closePanel() {
if (opener && typeof opener.focus === 'function') opener.focus();
}
-async function fetchJson(path) {
- const res = await fetch(path, { headers: { accept: 'application/json' } });
+// Bounded: the NPC panel shows a "Loading…" line before every one of these,
+// and a stalled upstream used to freeze the panel with no way to recover. The
+// abort surfaces through the same catch as any other failure, so the panel
+// gets its designed error state instead.
+async function fetchJson(path, { timeout = 8000 } = {}) {
+ const res = await fetch(path, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(timeout) });
const body = await res.json().catch(() => null);
if (!res.ok || !body || body.error) {
const err = new Error(body?.error_description || `request failed (${res.status})`);
diff --git a/src/gestures-page.js b/src/gestures-page.js
index 16445604f..4e6222a47 100644
--- a/src/gestures-page.js
+++ b/src/gestures-page.js
@@ -76,8 +76,20 @@ const sigFor = (clip) => state.signatures?.clips?.[clip] || null;
/* ── data ──────────────────────────────────────────────────────────────── */
-async function fetchJson(url) {
- const res = await fetch(url, { headers: { accept: 'application/json' } });
+// The gesture grid sets aria-busy before each of these loads. Without a
+// deadline a stalled CDN left the grid busy with no error and no content, so
+// every manifest/signature/hint fetch carries one and the catch below paints
+// the designed error box instead.
+async function fetchJson(url, { timeout = 8000 } = {}) {
+ let res;
+ try {
+ res = await fetch(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(timeout) });
+ } catch (err) {
+ // These messages are printed verbatim into the page's error boxes, so a
+ // deadline reads as a sentence rather than the platform's "signal timed out".
+ if (err?.name === 'TimeoutError') throw new Error(`${url} did not answer within ${timeout / 1000}s`, { cause: err });
+ throw err;
+ }
if (!res.ok) throw new Error(`${url} responded ${res.status}`);
return res.json();
}
diff --git a/src/launch-detail.js b/src/launch-detail.js
index 07a7a95f8..a738bcfa8 100644
--- a/src/launch-detail.js
+++ b/src/launch-detail.js
@@ -274,8 +274,14 @@ function resolveMint() {
// ── data ─────────────────────────────────────────────────────────────────────
-async function fetchJson(url, { signal } = {}) {
- const r = await fetch(url, { signal });
+// Time-bounded on every call: the coin page paints skeletons for the chart,
+// safety and trades panels before these resolve, and an edge that never
+// answers used to leave all three spinning forever. The per-call deadline
+// composes with the caller's own signal (a stale request being abandoned)
+// instead of replacing it, so both cancellation reasons still work.
+async function fetchJson(url, { signal, timeout = 8000 } = {}) {
+ const deadline = AbortSignal.timeout(timeout);
+ const r = await fetch(url, { signal: signal ? AbortSignal.any([signal, deadline]) : deadline });
if (!r.ok) {
// Carry the status and the API's machine-readable code so callers can tell
// an honest empty state ("this coin has no market yet") apart from an
diff --git a/src/markets-page.js b/src/markets-page.js
index 4d4d0f1f2..7a8818949 100644
--- a/src/markets-page.js
+++ b/src/markets-page.js
@@ -11,8 +11,11 @@ import { onPageReady } from './shell/page-lifecycle.js';
const $ = (id) => document.getElementById(id);
-async function getJson(url) {
- const res = await fetch(url, { headers: { accept: 'application/json' } });
+// Every markets panel paints a skeleton before its request resolves, so each
+// one is time-bounded: a stalled edge now rejects and the panel shows its
+// designed error state with a retry instead of shimmering indefinitely.
+async function getJson(url, { timeout = 8000 } = {}) {
+ const res = await fetch(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(timeout) });
if (!res.ok) {
const err = new Error(`fetch ${url} → ${res.status}`);
err.status = res.status;
diff --git a/src/mission-control/enrich.js b/src/mission-control/enrich.js
index c3a6a2ca3..02ba2e8b6 100644
--- a/src/mission-control/enrich.js
+++ b/src/mission-control/enrich.js
@@ -54,8 +54,11 @@ export function createEnricher({ store }) {
});
}
- async function fetchJson(url) {
- const r = await fetch(url, { headers: { accept: 'application/json' } });
+ // Bounded per request. Enrichment runs behind a small concurrency queue, so
+ // a single stalled upstream would otherwise hold a queue slot forever and
+ // starve every later row of its enrichment.
+ async function fetchJson(url, { timeout = 8000 } = {}) {
+ const r = await fetch(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(timeout) });
if (!r.ok) throw new Error(`HTTP ${r.status}`);
return r.json();
}
diff --git a/src/seeker.js b/src/seeker.js
index c566ec0f6..bbe260e26 100644
--- a/src/seeker.js
+++ b/src/seeker.js
@@ -56,8 +56,20 @@ function escapeHtml(s) {
// apiFetch carries the session cookie and, on mutations, the x-csrf-token the
// server requires; a plain fetch would be refused by /api/seeker/verify.
-async function fetchJson(url, init = {}) {
- const res = await apiFetch(url, { credentials: 'include', ...init });
+//
+// apiFetch bounds each ATTEMPT but retries a safe method up to three times, so
+// a persistently black-holed edge could still hold the page for a minute. The
+// signal here is the whole-call ceiling on top of that: the verify button and
+// the agent list both paint a busy state before the call, and once the ceiling
+// fires the request rejects and the caller paints its designed error row.
+// Mutations get a longer ceiling because /api/seeker/verify reads the chain.
+const CALL_TIMEOUT_MS = 20_000;
+const MUTATION_TIMEOUT_MS = 45_000;
+
+async function fetchJson(url, { timeout, ...init } = {}) {
+ const isMutation = (init.method || 'GET').toUpperCase() !== 'GET';
+ const ceiling = timeout ?? (isMutation ? MUTATION_TIMEOUT_MS : CALL_TIMEOUT_MS);
+ const res = await apiFetch(url, { credentials: 'include', ...init, signal: AbortSignal.timeout(ceiling) });
const body = await res.json().catch(() => null);
return { ok: res.ok, status: res.status, body };
}
@@ -68,7 +80,16 @@ let user = null;
let signingIn = false;
async function loadSession() {
- const { ok, body } = await fetchJson('/api/auth/me');
+ // A timed-out or failed session probe means "we cannot prove you are signed
+ // in", which is the same paint as signed-out. Swallowing it here keeps the
+ // hero from being blocked behind an unhandled rejection.
+ let ok = false;
+ let body = null;
+ try {
+ ({ ok, body } = await fetchJson('/api/auth/me'));
+ } catch (err) {
+ console.warn('[seeker] session probe failed', err);
+ }
user = ok ? body?.user || null : null;
paintSession();
return user;
@@ -160,7 +181,15 @@ async function loadAgents() {
ui.agentsError.hidden = true;
ui.agents.hidden = false;
ui.agents.setAttribute('aria-busy', 'true');
- const { ok, body } = await fetchJson('/api/agents');
+ let ok = false;
+ let body = null;
+ try {
+ ({ ok, body } = await fetchJson('/api/agents'));
+ } catch (err) {
+ // A ceiling abort throws rather than returning ok:false. Without this the
+ // list would stay aria-busy forever with no retry offered.
+ console.warn('[seeker] agents load failed', err);
+ }
ui.agents.setAttribute('aria-busy', 'false');
if (!ok) {
ui.agents.hidden = true;
@@ -207,8 +236,13 @@ function paintVerification(status) {
async function loadVerification() {
if (!user) { paintVerification(null); return; }
- const { ok, body } = await fetchJson('/api/seeker/status');
- paintVerification(ok ? body : null);
+ try {
+ const { ok, body } = await fetchJson('/api/seeker/status');
+ paintVerification(ok ? body : null);
+ } catch (err) {
+ console.warn('[seeker] verification status failed', err);
+ paintVerification(null);
+ }
}
async function runVerification() {
@@ -242,7 +276,9 @@ async function runVerification() {
} catch (err) {
console.error('[seeker] verify failed', err);
ui.verifyMsg.dataset.kind = 'error';
- ui.verifyMsg.textContent = 'Network error. Check your connection and try again.';
+ ui.verifyMsg.textContent = err?.name === 'TimeoutError'
+ ? 'Verification took too long to answer. Try again in a moment.'
+ : 'Network error. Check your connection and try again.';
} finally {
ui.verifyBtn.disabled = false;
}
diff --git a/src/shared/wallet-card.js b/src/shared/wallet-card.js
index bfd290749..1b9448c05 100644
--- a/src/shared/wallet-card.js
+++ b/src/shared/wallet-card.js
@@ -60,8 +60,11 @@ function esc(s) {
);
}
-async function fetchJson(url) {
- const r = await fetch(url, { credentials: 'include' });
+// Bounded: the card renders a loading row for net worth and reputation before
+// these resolve, and an edge that never answers used to leave both rows
+// shimmering. On timeout the caller's catch paints the designed fallback.
+async function fetchJson(url, { timeout = 8000 } = {}) {
+ const r = await fetch(url, { credentials: 'include', signal: AbortSignal.timeout(timeout) });
if (!r.ok) {
const e = new Error(`http_${r.status}`);
e.status = r.status;
diff --git a/tests/browser-page-fetch-deadlines.test.js b/tests/browser-page-fetch-deadlines.test.js
new file mode 100644
index 000000000..85040a150
--- /dev/null
+++ b/tests/browser-page-fetch-deadlines.test.js
@@ -0,0 +1,65 @@
+// Every per-page `fetchJson` helper in the browser bundle is its own copy of
+// the same three lines, and nine of them shipped with no deadline: the page
+// painted a skeleton, called fetch(), and had no way back if the edge never
+// answered. A user on a captive-portal Wi-Fi or behind a black-holing proxy sat
+// on a spinner forever, with no error and no retry.
+//
+// The fix is per-file, so nothing stops the next copy-paste from dropping the
+// signal again. This test pins the invariant on the source: each named helper
+// must bound its own request, and the module-level ones must accept a
+// caller-supplied override so a genuinely slow endpoint can ask for more.
+import { describe, it, expect } from 'vitest';
+import { readFileSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { dirname, join } from 'node:path';
+
+const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
+
+// file -> the helper every network read on that surface goes through.
+const HELPERS = [
+ ['src/agent-detail.js', 'fetchJson'],
+ ['src/launch-detail.js', 'fetchJson'],
+ ['src/seeker.js', 'fetchJson'],
+ ['src/gestures-page.js', 'fetchJson'],
+ ['src/agent-skills-nfts.js', 'fetchJson'],
+ ['src/agent-skills-pumpfun-watch.js', 'fetchJson'],
+ ['src/shared/wallet-card.js', 'fetchJson'],
+ ['src/game/npc/npc-aixbt.js', 'fetchJson'],
+ ['src/mission-control/enrich.js', 'fetchJson'],
+ ['src/markets-page.js', 'getJson'],
+ // The reference implementation these were modelled on.
+ ['src/theater.js', 'fetchJson'],
+];
+
+/** The source of `name`'s declaration, up to the first blank line after it. */
+function helperSource(file, name) {
+ const src = readFileSync(join(ROOT, file), 'utf8');
+ const at = src.indexOf(`async function ${name}(`);
+ expect(at, `${file}: no "async function ${name}(" found`).toBeGreaterThan(-1);
+ const end = src.indexOf('\n\n', at);
+ return src.slice(at, end === -1 ? src.length : end);
+}
+
+describe('per-page fetch helpers are time-bounded', () => {
+ for (const [file, name] of HELPERS) {
+ it(`${file}: ${name}() bounds its request`, () => {
+ const body = helperSource(file, name);
+ const bounded = /AbortSignal\.timeout\(/.test(body) || /new AbortController\(/.test(body);
+ expect(bounded, `${file}: ${name}() must pass an abort signal`).toBe(true);
+ expect(/signal/.test(body), `${file}: ${name}() must hand the signal to fetch`).toBe(true);
+ });
+
+ it(`${file}: ${name}() lets the caller change the deadline`, () => {
+ // A hardcoded constant is fine until one endpoint is legitimately slow
+ // (an on-chain verify, a cold worker) and the only escape is editing
+ // the helper. Every copy takes an override in its options object.
+ const body = helperSource(file, name);
+ expect(/\btimeout\b/.test(body), `${file}: ${name}() must accept a timeout option`).toBe(true);
+ });
+ }
+
+ it('covers every helper the audit found, so a deletion here is visible', () => {
+ expect(HELPERS).toHaveLength(11);
+ expect(new Set(HELPERS.map(([f]) => f)).size).toBe(HELPERS.length);
+ });
+});