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): give the [name] dispatcher its declared 300s budget instead of wrapCron's 120s default

nirholas2e7c0f555135
diff --git a/api/cron/[name].js b/api/cron/[name].js
index 65319db56..36b4c28b1 100644
--- a/api/cron/[name].js
+++ b/api/cron/[name].js
@@ -182,12 +182,21 @@ async function handleIrlDropsRefund(req, res) {
return json(res, 200, report);
}
-export default wrapCron(async (req, res) => {
- const name = req.query?.name;
- const handler = typeof name === 'string' ? HANDLERS[name] : null;
- if (!handler) return error(res, 404, 'not_found', 'unknown cron');
- return handler(req, res);
-});
+// vercel.json grants this route 300s (`functions["api/cron/[name].js"].maxDuration`);
+// without passing maxDurationMs here, wrapCron falls back to its 120s default and
+// races every job behind this shared dispatcher against that instead, truncating
+// anything that legitimately needs more than 120s (e.g. run-buyback, solana-agents-crawl).
+export const maxDuration = 300;
+
+export default wrapCron(
+ async (req, res) => {
+ const name = req.query?.name;
+ const handler = typeof name === 'string' ? HANDLERS[name] : null;
+ if (!handler) return error(res, 404, 'not_found', 'unknown cron');
+ return handler(req, res);
+ },
+ { maxDurationMs: maxDuration * 1000 },
+);
// ═══════════════════════════════════════════════════════════════════════════
// solana-agents-crawl — index external Solana agents (Metaplex + AgenC)
diff --git a/tests/cron-dispatcher-routing.test.js b/tests/cron-dispatcher-routing.test.js
index 18d358c1a..ed2b889e7 100644
--- a/tests/cron-dispatcher-routing.test.js
+++ b/tests/cron-dispatcher-routing.test.js
@@ -1,8 +1,10 @@
import { describe, it, expect } from 'vitest';
import { readFileSync, readdirSync } from 'node:fs';
-import { fileURLToPath } from 'node:url';
+import { fileURLToPath, pathToFileURL } from 'node:url';
import { dirname, join } from 'node:path';
+import { DEFAULT_CRON_MAX_DURATION_MS } from '../api/_lib/http.js';
+
// 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
@@ -57,3 +59,27 @@ describe('cron dispatcher routing (vercel.json ↔ [name].js)', () => {
expect(shadowed, `route alternation shadows dedicated cron files: ${shadowed.join(', ')}`).toEqual([]);
});
});
+
+// 2026-10-24 production incident: run-buyback (23 occurrences) and
+// solana-agents-crawl (12) both 503'd at ~120.0s latency over 24h, the exact
+// `[cron] <name> exceeded its 120000ms budget` wrapCron timeout signature.
+// Root cause: this dispatcher serves every HANDLERS job through ONE
+// `wrapCron(async (req, res) => {...})` call with no maxDurationMs option, so
+// wrapCron falls back to its DEFAULT_CRON_MAX_DURATION_MS (120s) for every job
+// behind it, even though vercel.json declares 300s for this exact route
+// (`"api/cron/[name].js": { "maxDuration": 300 }`). Any job that legitimately
+// needs more than 120s (a Solana registry crawl, an on-chain buyback sweep)
+// gets cut off by the external race before it can finish, regardless of how
+// much time Cloud Run actually gives it.
+describe('cron dispatcher timeout wiring', () => {
+ it('declares a maxDuration matching vercel.json, so wrapCron does not truncate every dispatched job at the 120s default', async () => {
+ const vercel = JSON.parse(readFileSync(join(ROOT, 'vercel.json'), 'utf8'));
+ const declaredMs = vercel.functions['api/cron/[name].js'].maxDuration * 1000;
+
+ const { maxDuration } = await import(pathToFileURL(join(ROOT, 'api/cron/[name].js')).href);
+
+ expect(maxDuration).toBeGreaterThan(0);
+ expect(maxDuration * 1000).toBe(declaredMs);
+ expect(maxDuration * 1000).toBeGreaterThan(DEFAULT_CRON_MAX_DURATION_MS);
+ });
+});