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-bounties): serve a last-known-good copy instead of 502ing when pump.fun blocks the bounty list
nirholas6e67e3a3606c
diff --git a/api/pump-bounties.js b/api/pump-bounties.jsindex 044911915..af37cf30f 100644--- a/api/pump-bounties.js+++ b/api/pump-bounties.js@@ -4,6 +4,15 @@// short server cache so we hit pump.fun rarely and serve every visitor from// cache. Pagination is cursor-based (pass `cursor` = the previous page's// `nextCursor`); `status` filters; `limit` caps at 50.+//+// pump.fun sits behind Cloudflare, which sometimes answers livestream-api+// requests with its own anti-bot challenge page (a 403 "Just a moment...",+// surfaced to us as a PumpGoError) with no server-side way to pass it. Before+// 2026-10-24 that left this route 502ing for every visitor for hours at a time+// (every 24h sample failed) even though the board had not actually changed.+// A long-lived last-known-good copy, written on every real success and served+// (marked stale) when the live fetch fails, rides out the block the same way+// api/_lib/pump-feed-fetch.js already does for the other pump.fun feeds.import { cors, json, error, wrap, method, rateLimited } from './_lib/http.js';import { limits, clientIp } from './_lib/rate-limit.js';@@ -11,6 +20,8 @@ import { cacheGet, cacheSet } from './_lib/cache.js';import { listBounties, PumpGoError } from './_lib/pump-go.js';import { clampInt } from './_lib/http-params.js';+const LKG_TTL_S = 1800;+export default wrap(async (req, res) => {if (cors(req, res, { methods: 'GET,OPTIONS' })) return;if (!method(req, res, ['GET'])) return;@@ -28,6 +39,7 @@ export default wrap(async (req, res) => {const status = url.searchParams.get('status') || null;const cacheKey = `pumpgo:list:${limit}:${cursor || '_'}:${status || '_'}`;+ const lkgKey = `${cacheKey}:lkg`;const cached = await cacheGet(cacheKey).catch(() => null);if (cached) {res.setHeader('cache-control', 'public, s-maxage=30, stale-while-revalidate=120');@@ -38,11 +50,17 @@ export default wrap(async (req, res) => {try {data = await listBounties({ limit, cursor, status });} catch (e) {- if (e instanceof PumpGoError) return error(res, e.status, e.code, e.message);- throw e;+ if (!(e instanceof PumpGoError)) throw e;+ const stale = await cacheGet(lkgKey).catch(() => null);+ if (stale) {+ res.setHeader('cache-control', 'public, s-maxage=30, stale-while-revalidate=120');+ return json(res, 200, { ...stale, stale: true });+ }+ return error(res, e.status, e.code, e.message);}await cacheSet(cacheKey, data, 30).catch(() => {});+ await cacheSet(lkgKey, data, LKG_TTL_S).catch(() => {});res.setHeader('cache-control', 'public, s-maxage=30, stale-while-revalidate=120');return json(res, 200, data);});diff --git a/api/pump-bounties/stats.js b/api/pump-bounties/stats.jsindex 9fb969599..ee9c287ce 100644--- a/api/pump-bounties/stats.js+++ b/api/pump-bounties/stats.js@@ -4,6 +4,11 @@// board: how many live bounties, total reward USD on offer, and total// submissions. Bounded by a page cap and cached for a couple of minutes, so the// walk runs at most once per window no matter how many visitors load the page.+//+// pump.fun's Cloudflare anti-bot challenge can reject the underlying list call+// for hours at a time (see api/pump-bounties.js); a long-lived last-known-good+// copy, written on every real success, is served (marked stale) instead of a+// 502 when that happens.import { cors, json, error, wrap, method } from './../_lib/http.js';import { cacheGet, cacheSet } from './../_lib/cache.js';@@ -13,6 +18,8 @@ const PAGE = 50;const MAX_PAGES = 20; // hard ceiling: ≤1000 bounties scanned per refreshconst CACHE_TTL_S = 120;const CACHE_KEY = 'pumpgo:stats:v1';+const LKG_KEY = 'pumpgo:stats:v1:lkg';+const LKG_TTL_S = 1800;export default wrap(async (req, res) => {if (cors(req, res, { methods: 'GET,OPTIONS' })) return;@@ -49,8 +56,13 @@ export default wrap(async (req, res) => {}} while (cursor);} catch (e) {- if (e instanceof PumpGoError) return error(res, e.status, e.code, e.message);- throw e;+ if (!(e instanceof PumpGoError)) throw e;+ const stale = await cacheGet(LKG_KEY).catch(() => null);+ if (stale) {+ res.setHeader('cache-control', 'public, s-maxage=120, stale-while-revalidate=300');+ return json(res, 200, { ...stale, stale: true });+ }+ return error(res, e.status, e.code, e.message);}const payload = {@@ -62,6 +74,7 @@ export default wrap(async (req, res) => {updatedAt: new Date().toISOString(),};await cacheSet(CACHE_KEY, payload, CACHE_TTL_S).catch(() => {});+ await cacheSet(LKG_KEY, payload, LKG_TTL_S).catch(() => {});res.setHeader('cache-control', 'public, s-maxage=120, stale-while-revalidate=300');return json(res, 200, payload);});diff --git a/tests/pump-bounties-handlers.test.js b/tests/pump-bounties-handlers.test.jsnew file mode 100644index 000000000..92dee5af8--- /dev/null+++ b/tests/pump-bounties-handlers.test.js@@ -0,0 +1,115 @@+// Handler-shape tests for api/pump-bounties.js and api/pump-bounties/stats.js.+//+// Production 2026-10-24: pump.fun's Cloudflare anti-bot challenge rejected+// livestream-api.pump.fun/bounties/tasks (a "Just a moment..." 403, surfaced+// here as a PumpGoError) for hours at a time. Neither route had a last-known-+// good fallback, so every single sample in the 24h log window 502'd even+// though the bounty board itself had not changed. These pin the fix: a+// long-lived cache entry written on every real success, served (marked+// `stale: true`) instead of a 502 when the live fetch fails and the short+// cache has already expired.++import { describe, it, expect, vi, beforeEach } from 'vitest';++vi.mock('../api/_lib/rate-limit.js', () => ({+ limits: { publicIp: vi.fn(async () => ({ success: true, reset: Date.now() + 1000 })) },+ clientIp: () => '203.0.113.1',+}));++const store = new Map();+vi.mock('../api/_lib/cache.js', () => ({+ cacheGet: vi.fn(async (k) => (store.has(k) ? store.get(k) : null)),+ cacheSet: vi.fn(async (k, v) => { store.set(k, v); }),+}));++const listBounties = vi.fn();+vi.mock('../api/_lib/pump-go.js', async () => {+ const actual = await vi.importActual('../api/_lib/pump-go.js');+ return { ...actual, listBounties };+});++function makeReqRes(url) {+ const req = { method: 'GET', url, headers: {} };+ const res = {+ statusCode: 200,+ headers: {},+ body: '',+ setHeader(k, v) { this.headers[k.toLowerCase()] = v; },+ getHeader(k) { return this.headers[k.toLowerCase()]; },+ end(b) { this.body = b ?? ''; },+ };+ return { req, res };+}++beforeEach(() => {+ store.clear();+ listBounties.mockReset();+});++describe('GET /api/pump-bounties: last-known-good fallback', () => {+ it('propagates the upstream failure when no last-known-good copy exists', async () => {+ const { default: handler } = await import('../api/pump-bounties.js');+ const { PumpGoError } = await import('../api/_lib/pump-go.js');+ listBounties.mockRejectedValue(new PumpGoError('pump.fun GO upstream 403', 502, 'pump_go_upstream'));++ const { req, res } = makeReqRes('/api/pump-bounties?limit=30');+ await handler(req, res);+ expect(res.statusCode).toBe(502);+ });++ it('serves the last-known-good list, marked stale, instead of a 502', async () => {+ const { default: handler } = await import('../api/pump-bounties.js');+ const { PumpGoError } = await import('../api/_lib/pump-go.js');++ listBounties.mockResolvedValueOnce({ items: [{ taskId: 't1' }], nextCursor: null });+ const warm = makeReqRes('/api/pump-bounties?limit=30');+ await handler(warm.req, warm.res);+ expect(warm.res.statusCode).toBe(200);+ // Expire the short-TTL live cache (the real one lapses after 30s) while+ // leaving the long-TTL last-known-good copy in place.+ store.delete('pumpgo:list:30:_:_');++ listBounties.mockRejectedValueOnce(new PumpGoError('pump.fun GO upstream 403', 502, 'pump_go_upstream'));+ const { req, res } = makeReqRes('/api/pump-bounties?limit=30');+ await handler(req, res);+ expect(res.statusCode).toBe(200);+ const body = JSON.parse(res.body);+ expect(body.stale).toBe(true);+ expect(body.items).toEqual([{ taskId: 't1' }]);+ });+});++describe('GET /api/pump-bounties/stats: last-known-good fallback', () => {+ it('propagates the upstream failure when no last-known-good copy exists', async () => {+ const { default: handler } = await import('../api/pump-bounties/stats.js');+ const { PumpGoError } = await import('../api/_lib/pump-go.js');+ listBounties.mockRejectedValue(new PumpGoError('pump.fun GO upstream 403', 502, 'pump_go_upstream'));++ const { req, res } = makeReqRes('/api/pump-bounties/stats');+ await handler(req, res);+ expect(res.statusCode).toBe(502);+ });++ it('serves the last-known-good totals, marked stale, instead of a 502', async () => {+ const { default: handler } = await import('../api/pump-bounties/stats.js');+ const { PumpGoError } = await import('../api/_lib/pump-go.js');++ listBounties.mockResolvedValueOnce({+ items: [{ reward: { totalUsd: 10 }, counts: { submissions: 2 }, likeCount: 1 }],+ nextCursor: null,+ });+ const warm = makeReqRes('/api/pump-bounties/stats');+ await handler(warm.req, warm.res);+ expect(warm.res.statusCode).toBe(200);+ expect(JSON.parse(warm.res.body).count).toBe(1);+ store.delete('pumpgo:stats:v1');++ listBounties.mockRejectedValueOnce(new PumpGoError('pump.fun GO upstream 403', 502, 'pump_go_upstream'));+ const { req, res } = makeReqRes('/api/pump-bounties/stats');+ await handler(req, res);+ expect(res.statusCode).toBe(200);+ const body = JSON.parse(res.body);+ expect(body.stale).toBe(true);+ expect(body.count).toBe(1);+ });+});