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(pump-trending): read the rich coin board through the shared pump.fun reader so a rate limit stops answering 502
nirholasa7c6ea6bba56
diff --git a/api/pump/trending.js b/api/pump/trending.jsindex 39752fce2..29b5ac2d4 100644--- a/api/pump/trending.js+++ b/api/pump/trending.js@@ -14,8 +14,7 @@ import { cors, json, method, wrap, error, rateLimited } from '../_lib/http.js';import { limits, clientIp } from '../_lib/rate-limit.js';import { normalizeGatewayURL } from '../../src/ipfs.js';import { getTrendingSlim } from '../_lib/pump-trending.js';--const PUMP_FRONTEND_BASE = 'https://frontend-api-v3.pump.fun';+import { fetchPumpBoard } from '../_lib/pump-feed-fetch.js';// Separate cache slot for the rich (full-coin) payload — it carries far more per// token than the thin projection api/_lib/pump-trending.js caches, so it must@@ -30,10 +29,12 @@ const STALE_MAX_MS = 10 * 60_000;const UPSTREAM_TIMEOUT_MS = 5000;// Serve a cached feed past its TTL when live upstreams are down. Returns the-// sliced value if the slot holds enough items and is within the stale window,-// else null. Keyed by the same `limit >=` rule as the fresh-cache check.+// sliced value while it is within the stale window, else null. A slot holding+// fewer rows than asked still serves: the visualizer's 48-row request used to+// 502 while this instance held a perfectly good 24-row board, and a shorter+// list of real coins beats an outage envelope.function serveStale(slot, limit, now) {- if (!slot.value || slot.limit < limit) return null;+ if (!slot.value) return null;if (now - slot.storedAt > STALE_MAX_MS) return null;return slot.value.slice(0, limit);}@@ -54,27 +55,22 @@ function repairCoinImages(coins) {return coins;}+// Read through the shared pump.fun board reader (api/_lib/pump-feed-fetch.js)+// rather than a bare fetch. pump.fun sits behind Cloudflare, which answers a+// burst from the shared Cloud Run egress with a fast 429; the bare fetch here+// had no retry, no identified user-agent and only this instance's memory to+// fall back on, so a cold instance turned every rate-limit blip into a 502+// within ~100ms. The shared reader retries once honouring Retry-After and+// keeps a cross-instance last-known-good board for 30 minutes.+//+// Returns { data, stale } or null when the board failed with nothing to serve.async function fetchPumpFunRich(limit) {- const url = new URL('/coins', PUMP_FRONTEND_BASE);- url.searchParams.set('offset', '0');- url.searchParams.set('limit', String(limit));- url.searchParams.set('sort', 'market_cap');- url.searchParams.set('order', 'DESC');- url.searchParams.set('includeNsfw', 'false');- let upstream;- try {- upstream = await fetch(url, { headers: { accept: 'application/json' }, signal: AbortSignal.timeout(UPSTREAM_TIMEOUT_MS) });- } catch {- return null;- }- if (!upstream.ok) return null;- const body = await upstream.json().catch(() => null);- const coins = Array.isArray(body) ? body : Array.isArray(body?.coins) ? body.coins : null;- if (!Array.isArray(coins)) return null;- const data = repairCoinImages(- coins.filter((c) => c && typeof c.mint === 'string' && c.mint.length >= 32),- );- return data.length ? data : null;+ const board = await fetchPumpBoard({ limit, timeoutMs: UPSTREAM_TIMEOUT_MS });+ if (!board?.rows?.length) return null;+ // The board rows are shared with other readers through the cache, so repair+ // images on copies rather than mutating rows another caller may hold.+ const data = repairCoinImages(board.rows.map((c) => ({ ...c })));+ return { data, stale: board.stale };}export default wrap(async (req, res) => {@@ -100,8 +96,15 @@ export default wrap(async (req, res) => {'cache-control': 'public, max-age=15, s-maxage=30',});}- const richData = await fetchPumpFunRich(limit);- if (!richData) {+ const board = await fetchPumpFunRich(limit);+ if (board?.stale) {+ // Live board failed but the shared last-known-good copy answered. Say+ // so, and keep the edge cache short so the live source is retried soon.+ return json(res, 200, { data: board.data.slice(0, limit), stale: true }, {+ 'cache-control': 'public, max-age=10, s-maxage=20',+ });+ }+ if (!board) {// Upstream down — serve the last good payload as stale rather than blanking// the visualizer. Shorter edge cache so we retry the live source soon.const stale = serveStale(_richCache, limit, now);@@ -110,10 +113,11 @@ export default wrap(async (req, res) => {'cache-control': 'public, max-age=10, s-maxage=20',});}+ console.warn('[pump/trending] rich board unavailable (pump.fun live + last-known-good) and no stale cache');return error(res, 502, 'upstream_error', 'Trending market data is temporarily unavailable');}- _richCache = { value: richData, storedAt: now, expiresAt: now + TTL_MS, limit };- return json(res, 200, { data: richData }, { 'cache-control': 'public, max-age=15, s-maxage=30' });+ _richCache = { value: board.data, storedAt: now, expiresAt: now + TTL_MS, limit };+ return json(res, 200, { data: board.data.slice(0, limit) }, { 'cache-control': 'public, max-age=15, s-maxage=30' });}// Thin projection: fetch+cache+fallback lives in api/_lib/pump-trending.js,diff --git a/data/changelog.json b/data/changelog.jsonindex baebe92af..ef1810baa 100644--- a/data/changelog.json+++ b/data/changelog.json@@ -1,6 +1,15 @@{"$comment": "Curated changelog entries for three.ws, the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security, desktop (desktop entries become the desktop app's release notes). `link` is optional and must be a live three.ws path.","entries": [+ {+ "date": "2026-10-08",+ "title": "The coin visualizer and communities keep loading when pump.fun throttles us",+ "summary": "The full coin board behind the pump.fun visualizer, the communities page and the home page's live coin now retries a rate-limited read once and falls back to the last board any server saw in the past 30 minutes, marked as slightly stale, instead of showing an error.",+ "tags": [+ "fix"+ ],+ "link": "/communities"+ },{"date": "2026-10-08","title": "Community sentiment readings are back on coin pages and the Oracle",diff --git a/tests/api/pump-trending-resilience.test.js b/tests/api/pump-trending-resilience.test.jsindex 1922c6007..46c44ff5d 100644--- a/tests/api/pump-trending-resilience.test.js+++ b/tests/api/pump-trending-resilience.test.js@@ -155,3 +155,94 @@ describe('pump/trending resilience', () => {expect(res.body.error).toBe('upstream_error');});});++// The ?rich=1 lane (the 3D visualizer and the coin wall) reads the full pump.fun+// coin board through the shared reader in api/_lib/pump-feed-fetch.js. Before+// that it used a bare fetch with no retry and an instance-local stale cache, so+// a Cloudflare 429 on a cold instance answered 502 in under 100ms.+function richBoard(count, tag = 'R') {+ return JSON.stringify(+ Array.from({ length: count }, (_, i) => ({+ mint: `${tag}${String(i).padStart(3, '0')}`.padEnd(44, 'x'),+ symbol: `${tag}${i}`,+ name: `Rich ${i}`,+ usd_market_cap: 1_000_000 - i,+ image_uri: '',+ })),+ );+}++describe('pump/trending rich board resilience', () => {+ it('retries a pump.fun rate limit once and serves the live board', async () => {+ const handler = await freshHandler();+ let calls = 0;+ global.fetch = vi.fn(async (url) => {+ expect(String(url)).toContain('frontend-api-v3.pump.fun/coins');+ calls += 1;+ if (calls === 1) return new Response('error code: 1015', { status: 429, headers: { 'retry-after': '0' } });+ return new Response(richBoard(48), { status: 200 });+ });+ const res = makeRes();+ await handler(makeReq('/api/pump/trending?limit=48&rich=1'), res);++ expect(res.statusCode).toBe(200);+ expect(res.body.stale).toBeUndefined();+ expect(res.body.data).toHaveLength(48);+ expect(res.body.data[0].usd_market_cap).toBe(1_000_000);+ expect(calls).toBe(2);+ const init = global.fetch.mock.calls[0][1];+ expect(init.headers['user-agent']).toMatch(/three\.ws/);+ });++ it('serves the last-known-good board as stale once the live board fails', async () => {+ // Fake only the clock: the shared reader's retry backoff is a real timer.+ vi.useFakeTimers({ toFake: ['Date'] });+ vi.setSystemTime(new Date('2026-10-08T00:00:00Z'));+ const handler = await freshHandler();+ global.fetch = vi.fn(async () => new Response(richBoard(48), { status: 200 }));+ const primed = makeRes();+ await handler(makeReq('/api/pump/trending?limit=48&rich=1'), primed);+ expect(primed.statusCode).toBe(200);++ // Past both the handler TTL and the shared board TTL, inside the 30 min+ // last-known-good window, with pump.fun hard down.+ vi.setSystemTime(new Date('2026-10-08T00:12:00Z'));+ global.fetch = vi.fn(async () => new Response('x', { status: 503, headers: { 'retry-after': '0' } }));+ const res = makeRes();+ await handler(makeReq('/api/pump/trending?limit=48&rich=1'), res);++ expect(res.statusCode).toBe(200);+ expect(res.body.stale).toBe(true);+ expect(res.body.data).toHaveLength(48);+ });++ it('serves a shorter cached board instead of a 502 when a larger limit misses', async () => {+ // Fake only the clock: the shared reader's retry backoff is a real timer.+ vi.useFakeTimers({ toFake: ['Date'] });+ vi.setSystemTime(new Date('2026-10-08T00:00:00Z'));+ const handler = await freshHandler();+ global.fetch = vi.fn(async () => new Response(richBoard(24), { status: 200 }));+ await handler(makeReq('/api/pump/trending?limit=24&rich=1'), makeRes());++ vi.setSystemTime(new Date('2026-10-08T00:01:00Z'));+ global.fetch = vi.fn(async () => new Response('x', { status: 429, headers: { 'retry-after': '0' } }));+ const res = makeRes();+ await handler(makeReq('/api/pump/trending?limit=48&rich=1'), res);++ expect(res.statusCode).toBe(200);+ expect(res.body.stale).toBe(true);+ expect(res.body.data).toHaveLength(24);+ });++ it('502s only when the board is down and nothing was ever cached', async () => {+ const handler = await freshHandler();+ global.fetch = vi.fn(async () => new Response('x', { status: 500, headers: { 'retry-after': '0' } }));+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});+ const res = makeRes();+ await handler(makeReq('/api/pump/trending?limit=48&rich=1'), res);+ warn.mockRestore();++ expect(res.statusCode).toBe(502);+ expect(res.body.error).toBe('upstream_error');+ });+});