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(cron): route the dispatcher jobs in production + tolerant x402 payer key parsing

fudjiaad6cd466a7aa
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9637877bf..1278d4f7a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr
- **Markets — Live Crypto Prices** (`/coins`) — Live global cryptocurrency market data: total market cap, dominance, Fear & Greed, and the top coins with prices, 24h/7d moves, and 7d sparklines. Every coin links to a rich /coin/:id detail page with an interactive chart, market stats, related news, and official links.
- **Tutorial · 3D Store Guide for Shopify** (`/tutorials/shopify-store-guide`) — A guide avatar walks your Shopify storefront, spotlights the hero, bestsellers, and reviews, and narrates each one — two script tags in theme.liquid, free roam included.
+- **30+ background jobs were unreachable in production — payouts, subscriptions, and buybacks are back** — A routing gap meant every background job served by the shared cron dispatcher — payment distribution, subscription billing, royalty settlement, club and coin payouts, $THREE buybacks, and the pump.fun monitors — returned 404 in production while working fine in development. The route is fixed and a test now fails the suite if a new job is ever added without it. The x402 payment engine also no longer stalls when its wallet key is pasted into configuration with quotes, spaces, or line breaks — all common paste formats now load cleanly. `[fix, infra]`
- **36 npm packages refreshed — every published SDK and MCP server now matches the platform** — A full audit of the @three-ws npm catalog found 36 packages whose published builds had fallen behind the platform — SDK improvements, MCP tool updates, and registry manifests that existed here but not on npm. All 36 are republished and current, including the core SDK, the page narrator, the React components, the Solana agent kit, and the full MCP server family. Two broken package builds were repaired along the way, and the Shopify store-guide tutorial now points at the fresh releases. (`/tutorials/shopify-store-guide`) `[sdk, improvement]`
- **3D avatars load about 4x faster - and reliably everywhere** — Seven of the heaviest built-in avatars were compressed from a combined 42 MB down to under 10 MB (76% smaller), so avatar pickers, NPC scenes, and the walk companion appear much sooner - especially on slower connections. Along the way we fixed a loading bug: a few pages, including the live agent-to-agent trade demo, could silently show placeholder capsule figures instead of the real 3D avatars. Every 3D surface on the site now decodes compressed avatars correctly. `[improvement, fix]`
- **A little Fourth of July on the homepage** — For Independence Day (July 1–5) the homepage wears a touch of red, white, and blue: a soft ribbon glow along the top of the page and real launch-and-burst fireworks that rise and shower over the hero. It's sparse and tasteful, respects your reduced-motion setting, pauses when the tab is in the background, and retires itself automatically once the holiday passes. (`/`) `[improvement]`
diff --git a/api/_lib/x402/pay.js b/api/_lib/x402/pay.js
index 3306041aa..963622b24 100644
--- a/api/_lib/x402/pay.js
+++ b/api/_lib/x402/pay.js
@@ -105,13 +105,48 @@ export function expectedFeeLamports({ selfPay, priorityMicrolamports = 0, cuLimi
// Load the autonomous payer keypair. Seed wallet preferred; agent wallet is the
// documented fallback. In non-prod a local test wallet file is honored so the
// loop and manual tests can run without env wiring.
+// Decode a 64-byte Solana secret key from any of the encodings that end up in
+// env vars in practice: base58 (the canonical form), a JSON array of 64 ints
+// (Solana CLI keypair file pasted verbatim), or base64. Tolerates the paste
+// artifacts that broke production — surrounding quotes, whitespace, and
+// newlines — instead of letting bs58 throw "Non-base58 character" and silently
+// pausing every x402 engine on the ring. Returns null when nothing decodes.
+export function decodeSeedSecret(secret) {
+ const raw = String(secret ?? '').trim().replace(/^["']|["']$/g, '').trim();
+ if (!raw) return null;
+ if (raw.startsWith('[')) {
+ try {
+ const arr = JSON.parse(raw);
+ if (Array.isArray(arr) && arr.length === 64) return Uint8Array.from(arr);
+ } catch { /* fall through */ }
+ return null;
+ }
+ // Strip embedded whitespace/newlines (multi-line paste) before decoding.
+ const compact = raw.replace(/\s+/g, '');
+ try {
+ const bytes = bs58.decode(compact);
+ if (bytes.length === 64) return bytes;
+ } catch { /* try base64 next */ }
+ try {
+ const buf = Buffer.from(compact, 'base64');
+ // Buffer.from is lenient — require a clean round-trip so a mistyped
+ // base58 string can't half-decode into 64 garbage bytes.
+ if (buf.length === 64 && buf.toString('base64').replace(/=+$/, '') === compact.replace(/=+$/, '')) {
+ return Uint8Array.from(buf);
+ }
+ } catch { /* undecodable */ }
+ return null;
+}
+
export function loadSeedKeypair() {
- const b58 = process.env.X402_SEED_SOLANA_SECRET_BASE58
+ const secret = process.env.X402_SEED_SOLANA_SECRET_BASE58
|| process.env.X402_AGENT_SOLANA_SECRET_BASE58;
- if (b58) {
- const raw = bs58.decode(b58);
- if (raw.length !== 64) throw new Error(`seed keypair: expected 64 bytes, got ${raw.length}`);
- return Keypair.fromSecretKey(raw);
+ if (secret) {
+ const bytes = decodeSeedSecret(secret);
+ if (!bytes) {
+ throw new Error('x402 pay: seed keypair undecodable — X402_SEED_SOLANA_SECRET_BASE58 must be 64 bytes as base58, base64, or a JSON array of 64 ints');
+ }
+ return Keypair.fromSecretKey(bytes);
}
if (process.env.NODE_ENV !== 'production') {
try {
diff --git a/api/cron/[name].js b/api/cron/[name].js
index 07437e23f..efa94b9b5 100644
--- a/api/cron/[name].js
+++ b/api/cron/[name].js
@@ -6,6 +6,15 @@
* verbatim move of the original per-file handler body — no logic changes,
* especially around auth / CRON_SECRET checks.
*
+ * ROUTING — READ THIS BEFORE ADDING A HANDLER. This project uses a legacy
+ * `routes` array in vercel.json, which does NOT auto-route dynamic [name]
+ * segments: every job name in HANDLERS must ALSO appear in the explicit
+ * `/api/cron/(name-a|name-b|…)` → `/api/cron/[name]?name=$1` route there, or
+ * the job 404s in production while working fine in local dev. That exact gap
+ * silently killed all 30+ dispatcher jobs (payouts, subscriptions, buybacks,
+ * pumpfun monitors) until July 2026. tests/cron-dispatcher-routing.test.js
+ * fails the suite if the map and the route drift — keep both in sync.
+ *
* Cron paths handled (kebab-case → handler):
* audit-log-cleanup → handleAuditLogCleanup
* erc8004-crawl → handleErc8004Crawl
diff --git a/data/changelog.json b/data/changelog.json
index 13a5b03f2..3b920882f 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. `link` is optional and must be a live three.ws path.",
"entries": [
+ {
+ "date": "2026-07-04",
+ "title": "30+ background jobs were unreachable in production — payouts, subscriptions, and buybacks are back",
+ "summary": "A routing gap meant every background job served by the shared cron dispatcher — payment distribution, subscription billing, royalty settlement, club and coin payouts, $THREE buybacks, and the pump.fun monitors — returned 404 in production while working fine in development. The route is fixed and a test now fails the suite if a new job is ever added without it. The x402 payment engine also no longer stalls when its wallet key is pasted into configuration with quotes, spaces, or line breaks — all common paste formats now load cleanly.",
+ "tags": [
+ "fix",
+ "infra"
+ ]
+ },
{
"date": "2026-07-04",
"title": "36 npm packages refreshed — every published SDK and MCP server now matches the platform",
diff --git a/public/changelog.json b/public/changelog.json
index c1567ac8b..89ec447ec 100644
--- a/public/changelog.json
+++ b/public/changelog.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-07-04T22:35:52.837Z",
+ "generated_at": "2026-07-04T22:43:53.800Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
@@ -26,6 +26,17 @@
"launch"
]
},
+ {
+ "date": "2026-07-04",
+ "type": "update",
+ "title": "30+ background jobs were unreachable in production — payouts, subscriptions, and buybacks are back",
+ "summary": "A routing gap meant every background job served by the shared cron dispatcher — payment distribution, subscription billing, royalty settlement, club and coin payouts, $THREE buybacks, and the pump.fun monitors — returned 404 in production while working fine in development. The route is fixed and a test now fails the suite if a new job is ever added without it. The x402 payment engine also no longer stalls when its wallet key is pasted into configuration with quotes, spaces, or line breaks — all common paste formats now load cleanly.",
+ "link": null,
+ "tags": [
+ "fix",
+ "infra"
+ ]
+ },
{
"date": "2026-07-04",
"type": "update",
diff --git a/public/changelog.xml b/public/changelog.xml
index b4b83f117..f8de71f98 100644
--- a/public/changelog.xml
+++ b/public/changelog.xml
@@ -22,6 +22,14 @@
<category>launch</category>
<description>A guide avatar walks your Shopify storefront, spotlights the hero, bestsellers, and reviews, and narrates each one — two script tags in theme.liquid, free roam included.</description>
</item>
+ <item>
+ <title>30+ background jobs were unreachable in production — payouts, subscriptions, and buybacks are back</title>
+ <link>https://three.ws/changelog</link>
+ <guid isPermaLink="false">2026-07-04:30+ background jobs were unreachable in production — payouts, subscriptions, and buybacks are back</guid>
+ <pubDate>Sat, 04 Jul 2026 12:00:00 GMT</pubDate>
+ <category>fix</category>
+ <description>A routing gap meant every background job served by the shared cron dispatcher — payment distribution, subscription billing, royalty settlement, club and coin payouts, $THREE buybacks, and the pump.fun monitors — returned 404 in production while working fine in development. The route is fixed and a test now fails the suite if a new job is ever added without it. The x402 payment engine also no longer stalls when its wallet key is pasted into configuration with quotes, spaces, or line breaks — all common paste formats now load cleanly.</description>
+ </item>
<item>
<title>36 npm packages refreshed — every published SDK and MCP server now matches the platform</title>
<link>https://three.ws/tutorials/shopify-store-guide</link>
diff --git a/public/features.json b/public/features.json
index c4fc30658..4853866f1 100644
--- a/public/features.json
+++ b/public/features.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-07-04T22:35:52.825Z",
+ "generated_at": "2026-07-04T22:43:53.788Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json",
"site": {
"name": "three.ws",
diff --git a/tests/cron-dispatcher-routing.test.js b/tests/cron-dispatcher-routing.test.js
new file mode 100644
index 000000000..18d358c1a
--- /dev/null
+++ b/tests/cron-dispatcher-routing.test.js
@@ -0,0 +1,59 @@
+import { describe, it, expect } from 'vitest';
+import { readFileSync, readdirSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import { dirname, join } from 'node:path';
+
+// The cron dispatcher (api/cron/[name].js) is reachable in production ONLY
+// through the explicit `/api/cron/(…)` entry in vercel.json's legacy `routes`
+// array — Vercel does not auto-route dynamic [name] segments when `routes` is
+// present. A handler added to the map without a matching route name 404s in
+// production while working fine locally; that gap silently killed every
+// dispatcher job (payouts, subscriptions, buybacks, pumpfun monitors) until
+// July 2026. These tests pin the two lists together.
+
+const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
+
+function handlerNames() {
+ const src = readFileSync(join(ROOT, 'api/cron/[name].js'), 'utf8');
+ const block = src.match(/const HANDLERS = \{([\s\S]*?)\n\};/);
+ expect(block, 'HANDLERS map not found in api/cron/[name].js').toBeTruthy();
+ return [...new Set([...block[1].matchAll(/'([a-z0-9-]+)':/g)].map((m) => m[1]))];
+}
+
+function cronRoute() {
+ const vercel = JSON.parse(readFileSync(join(ROOT, 'vercel.json'), 'utf8'));
+ return (vercel.routes || []).find(
+ (r) => typeof r.src === 'string' && r.src.startsWith('/api/cron/(') && r.dest === '/api/cron/[name]?name=$1',
+ );
+}
+
+describe('cron dispatcher routing (vercel.json ↔ [name].js)', () => {
+ it('the /api/cron/(…) → [name] route exists', () => {
+ expect(cronRoute(), 'missing /api/cron/(…) → /api/cron/[name]?name=$1 entry in vercel.json routes').toBeTruthy();
+ });
+
+ it('every HANDLERS job name is routable (no silent production 404s)', () => {
+ const route = cronRoute();
+ const rx = new RegExp(`^${route.src}$`);
+ const unrouted = handlerNames().filter((n) => !rx.test(`/api/cron/${n}`));
+ expect(unrouted, `add these to the /api/cron/(…) route alternation in vercel.json: ${unrouted.join(', ')}`).toEqual([]);
+ });
+
+ it('every routed name has a handler (no dead route entries)', () => {
+ const route = cronRoute();
+ const names = route.src.match(/\(([^)]*)\)/)[1].split('|');
+ const handlers = new Set(handlerNames());
+ const dead = names.filter((n) => !handlers.has(n));
+ expect(dead, `these routed names have no HANDLERS entry: ${dead.join(', ')}`).toEqual([]);
+ });
+
+ it('the route never shadows a dedicated api/cron/*.js file', () => {
+ const route = cronRoute();
+ const rx = new RegExp(`^${route.src}$`);
+ const dedicated = readdirSync(join(ROOT, 'api/cron'))
+ .filter((f) => f.endsWith('.js') && f !== '[name].js')
+ .map((f) => f.slice(0, -3));
+ const shadowed = dedicated.filter((n) => rx.test(`/api/cron/${n}`));
+ expect(shadowed, `route alternation shadows dedicated cron files: ${shadowed.join(', ')}`).toEqual([]);
+ });
+});
diff --git a/tests/x402-seed-secret.test.js b/tests/x402-seed-secret.test.js
new file mode 100644
index 000000000..15ac20d87
--- /dev/null
+++ b/tests/x402-seed-secret.test.js
@@ -0,0 +1,45 @@
+import { describe, it, expect } from 'vitest';
+import bs58 from 'bs58';
+import { Keypair } from '@solana/web3.js';
+
+import { decodeSeedSecret } from '../api/_lib/x402/pay.js';
+
+// The x402 payer key is the single credential behind every ring settle, seed
+// call, and autonomous spend. In July 2026 a paste artifact in the env var
+// (strict bs58.decode saw a non-base58 character) silently paused all three
+// engines every tick. decodeSeedSecret must accept every encoding an operator
+// realistically pastes — and reject garbage cleanly instead of half-decoding.
+
+const kp = Keypair.generate();
+const bytes = kp.secretKey; // 64 bytes
+const b58 = bs58.encode(bytes);
+const b64 = Buffer.from(bytes).toString('base64');
+const jsonArr = JSON.stringify(Array.from(bytes));
+
+describe('decodeSeedSecret', () => {
+ it('decodes canonical base58', () => {
+ expect(decodeSeedSecret(b58)).toEqual(bytes);
+ });
+
+ it('decodes base64 and JSON-array forms', () => {
+ expect(decodeSeedSecret(b64)).toEqual(bytes);
+ expect(decodeSeedSecret(jsonArr)).toEqual(bytes);
+ });
+
+ it('tolerates paste artifacts: quotes, whitespace, newlines', () => {
+ expect(decodeSeedSecret(`"${b58}"`)).toEqual(bytes);
+ expect(decodeSeedSecret(` ${b58}\n`)).toEqual(bytes);
+ expect(decodeSeedSecret(`'${b64}'`)).toEqual(bytes);
+ // A 64-char-wrapped multi-line paste of the base58 form.
+ const wrapped = b58.replace(/(.{32})/g, '$1\n');
+ expect(decodeSeedSecret(wrapped)).toEqual(bytes);
+ });
+
+ it('rejects garbage and wrong lengths instead of half-decoding', () => {
+ expect(decodeSeedSecret('')).toBeNull();
+ expect(decodeSeedSecret(null)).toBeNull();
+ expect(decodeSeedSecret('not-a-key-0OIl')).toBeNull();
+ expect(decodeSeedSecret(bs58.encode(bytes.slice(0, 32)))).toBeNull(); // 32-byte seed, not 64
+ expect(decodeSeedSecret(JSON.stringify(Array.from(bytes.slice(0, 32))))).toBeNull();
+ });
+});
diff --git a/vercel.json b/vercel.json
index 042d236bb..1f961841a 100644
--- a/vercel.json
+++ b/vercel.json
@@ -2108,6 +2108,10 @@
"src": "/api/x402-facilitator/([^/]+)",
"dest": "/api/x402-facilitator/[action]?action=$1"
},
+ {
+ "src": "/api/cron/(audit-log-cleanup|cleanup-csrf-tokens|club-payouts|cosmetic-splits-sweep|erc8004-crawl|expire-pending-purchases|fetch-x-metrics|index-delegations|irl-drops-refund|monetization-payouts|process-subscriptions|process-withdrawals|pump-agent-stats|pumpfun-graduations-sync|pumpfun-monitor|pumpfun-signals|run-buyback|run-coin-cycle|run-coin-payouts|run-dca|run-distribute-payments|run-subscriptions|run-three-buyback|run-x-scheduled-posts|run-x-triggers|settle-royalties|siwx-gc|solana-agents-crawl|solana-attest-event-cleanup|solana-attestations-crawl|treasury-autopilot|unstoppable-tick)",
+ "dest": "/api/cron/[name]?name=$1"
+ },
{
"src": "/api/agents/([^/]+)/wallet/([^/]+)",
"dest": "/api/agents/[id]"