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): wire maxDurationMs into wrapCron for ten more 300s-budget crons

nirholas15e77e4c4150
diff --git a/api/cron/avaturn-seed-cron.js b/api/cron/avaturn-seed-cron.js
index b337a2ea3..0f9e62079 100644
--- a/api/cron/avaturn-seed-cron.js
+++ b/api/cron/avaturn-seed-cron.js
@@ -49,6 +49,10 @@ const SLOT_TTL_MS = 280_000;
// Username claims that may be retried within a tick before it gives up.
const CLAIM_ATTEMPTS = 3;
+// vercel.json declares 300s for this route; without wiring it into wrapCron
+// below, wrapCron falls back to its own DEFAULT_CRON_MAX_DURATION_MS (120s).
+export const maxDuration = 300;
+
// Origin the rigged base bodies are served from (/avatars/*.glb).
const ORIGIN = () => env.APP_ORIGIN || 'https://three.ws';
@@ -259,4 +263,4 @@ export default wrapCron(async (req, res) => {
} finally {
await slot.release();
}
-});
+}, { maxDurationMs: maxDuration * 1000 });
diff --git a/api/cron/economy-reconcile.js b/api/cron/economy-reconcile.js
index 7032a8c9f..f2ba903b7 100644
--- a/api/cron/economy-reconcile.js
+++ b/api/cron/economy-reconcile.js
@@ -54,6 +54,12 @@ const LAMPORTS_PER_SOL = 1_000_000_000;
const LEASE_KEY = 'cron:economy-reconcile:lease';
const LEASE_SECONDS = 25 * 60;
+// vercel.json declares 300s for this route; wiring that into wrapCron (below)
+// is what makes the external race match it instead of wrapCron's own
+// DEFAULT_CRON_MAX_DURATION_MS (120s) fallback, same fix x402-ring-leak-scan.js
+// needed for the identical bug.
+export const maxDuration = 300;
+
async function upsertVerdict({ source, sourceRef, txSig, network, amountAtomic, dbStatus, chainStatus, reconciled, discrepancy, detail, runId }) {
try {
await withDbRetry(() => sql`
@@ -345,4 +351,4 @@ export default wrapCron(async (req, res) => {
tampers,
results,
});
-});
+}, { maxDurationMs: maxDuration * 1000 });
diff --git a/api/cron/fact-check-benchmark.js b/api/cron/fact-check-benchmark.js
index 8391e3503..b7a3899f7 100644
--- a/api/cron/fact-check-benchmark.js
+++ b/api/cron/fact-check-benchmark.js
@@ -44,6 +44,10 @@ const RUN_DEADLINE_MS = Number(process.env.FACT_CHECK_BENCHMARK_DEADLINE_MS) ||
// and trips the refusal for no gain.
const CONCURRENCY = Number(process.env.FACT_CHECK_BENCHMARK_CONCURRENCY) || 6;
+// vercel.json declares 300s for this route; without wiring it into wrapCron
+// below, wrapCron falls back to its own DEFAULT_CRON_MAX_DURATION_MS (120s).
+export const maxDuration = 300;
+
export default wrapCron(async (req, res) => {
if (!method(req, res, ['GET'])) return;
if (!requireCron(req, res)) return;
@@ -129,4 +133,4 @@ export default wrapCron(async (req, res) => {
} finally {
await releaseLock().catch(() => {});
}
-});
+}, { maxDurationMs: maxDuration * 1000 });
diff --git a/api/cron/forge-smoke.js b/api/cron/forge-smoke.js
index 69cc50d65..403c3eed2 100644
--- a/api/cron/forge-smoke.js
+++ b/api/cron/forge-smoke.js
@@ -51,6 +51,9 @@ const SMOKE_PROMPT = 'a small wooden toy boat with a striped sail';
// a slow-but-working lane could blow the deadline instead of reporting. 240 s
// leaves the alerting and the response inside that deadline.
export const GENERATION_BUDGET_MS = 240_000;
+// vercel.json declares 300s for this route; without wiring it into wrapCron
+// below, wrapCron falls back to its own DEFAULT_CRON_MAX_DURATION_MS (120s).
+export const maxDuration = 300;
const POLL_INTERVAL_MS = 5_000;
const POLL_TIMEOUT_MS = 15_000;
const LAST_STATUS_KEY = 'forge-smoke:last';
@@ -338,4 +341,4 @@ export default wrapCron(async (req, res) => {
llm: llm.ok ? { status: 'ok', provider: llm.provider } : { status: 'error', reason: llm.reason },
redis: redisBurn,
});
-});
+}, { maxDurationMs: maxDuration * 1000 });
diff --git a/api/cron/gmgn-seed.js b/api/cron/gmgn-seed.js
index da0b747c9..0a3153ea0 100644
--- a/api/cron/gmgn-seed.js
+++ b/api/cron/gmgn-seed.js
@@ -32,6 +32,10 @@ const FETCH_TIMEOUT_MS = 8000;
// Be respectful: 300ms between gmgn requests so we don't hammer them.
const INTER_REQUEST_DELAY_MS = 300;
+// vercel.json declares 300s for this route; without wiring it into wrapCron
+// below, wrapCron falls back to its own DEFAULT_CRON_MAX_DURATION_MS (120s).
+export const maxDuration = 300;
+
// gmgn tab → our label. smart_degen/pump_smart = proven smart money buyers.
// launchpad_smart = launch specialists. renowned = KOL (community influence;
// labelled 'kol', which Oracle's pedigree treats as proven and its cold-start
@@ -228,4 +232,4 @@ export default wrapCron(async (req, res) => {
fallback_used: fallbackUsed,
ms: Date.now() - started,
});
-});
+}, { maxDurationMs: maxDuration * 1000 });
diff --git a/api/cron/recompute-reputation.js b/api/cron/recompute-reputation.js
index 73bceb249..fc7b92cd7 100644
--- a/api/cron/recompute-reputation.js
+++ b/api/cron/recompute-reputation.js
@@ -24,6 +24,10 @@ import { requireCron } from '../_lib/cron-auth.js';
// cron budget and, at a 10-minute cadence, rolls a few thousand agents per hour.
const BATCH = 40;
+// vercel.json declares 300s for this route; without wiring it into wrapCron
+// below, wrapCron falls back to its own DEFAULT_CRON_MAX_DURATION_MS (120s).
+export const maxDuration = 300;
+
export default wrapCron(async (req, res) => {
if (!method(req, res, ['GET', 'POST'])) return;
if (!requireCron(req, res)) return;
@@ -51,4 +55,4 @@ export default wrapCron(async (req, res) => {
console.error('[recompute-reputation] failed:', err?.message || err);
return json(res, 200, { ok: false, error: err?.message || String(err) });
}
-}, { requireWriteCapacity: true });
+}, { requireWriteCapacity: true, maxDurationMs: maxDuration * 1000 });
diff --git a/api/cron/sketchfab-showcase.js b/api/cron/sketchfab-showcase.js
index 03ef5a802..cb7ad0617 100644
--- a/api/cron/sketchfab-showcase.js
+++ b/api/cron/sketchfab-showcase.js
@@ -53,6 +53,10 @@ import { requireCron } from '../_lib/cron-auth.js';
const MAX_ATTEMPTS = 3;
+// vercel.json declares 300s for this route; without wiring it into wrapCron
+// below, wrapCron falls back to its own DEFAULT_CRON_MAX_DURATION_MS (120s).
+export const maxDuration = 300;
+
function uploadsPerRun() {
const n = Number(env.SKETCHFAB_UPLOADS_PER_RUN || 2);
if (!Number.isFinite(n)) return 2;
@@ -294,4 +298,4 @@ export default wrapCron(async (req, res) => {
refreshed,
results,
});
-});
+}, { maxDurationMs: maxDuration * 1000 });
diff --git a/api/cron/smart-money-graph.js b/api/cron/smart-money-graph.js
index f5afad3e0..cbcf347c0 100644
--- a/api/cron/smart-money-graph.js
+++ b/api/cron/smart-money-graph.js
@@ -17,6 +17,10 @@ import { requireCron } from '../_lib/cron-auth.js';
const NETWORK = 'mainnet';
+// vercel.json declares 300s for this route; without wiring it into wrapCron
+// below, wrapCron falls back to its own DEFAULT_CRON_MAX_DURATION_MS (120s).
+export const maxDuration = 300;
+
export default wrapCron(async (req, res) => {
if (!method(req, res, ['GET', 'POST'])) return;
if (!requireCron(req, res)) return;
@@ -32,4 +36,4 @@ export default wrapCron(async (req, res) => {
reason: result.reason || null,
ms: Date.now() - started,
});
-});
+}, { maxDurationMs: maxDuration * 1000 });
diff --git a/api/cron/strategy-fanout.js b/api/cron/strategy-fanout.js
index 0550eec0e..13d0d2e40 100644
--- a/api/cron/strategy-fanout.js
+++ b/api/cron/strategy-fanout.js
@@ -17,6 +17,10 @@ import { requireCron } from '../_lib/cron-auth.js';
const NETWORKS = ['mainnet', 'devnet'];
+// vercel.json declares 300s for this route; without wiring it into wrapCron
+// below, wrapCron falls back to its own DEFAULT_CRON_MAX_DURATION_MS (120s).
+export const maxDuration = 300;
+
export default wrapCron(async (req, res) => {
if (!method(req, res, ['GET', 'POST'])) return;
if (!requireCron(req, res)) return;
@@ -30,4 +34,4 @@ export default wrapCron(async (req, res) => {
}
}
return json(res, 200, { ok: true, ...out });
-});
+}, { maxDurationMs: maxDuration * 1000 });
diff --git a/api/cron/x402-prepaid-settle.js b/api/cron/x402-prepaid-settle.js
index 93e889363..81286e9d4 100644
--- a/api/cron/x402-prepaid-settle.js
+++ b/api/cron/x402-prepaid-settle.js
@@ -14,6 +14,10 @@ import { loadSettler, sendBatchTransfers } from '../_lib/x402/prepaid-chain.js';
const usd = (atomics) => (Number(atomics) / 1e6).toFixed(6);
+// vercel.json declares 300s for this route; without wiring it into wrapCron
+// below, wrapCron falls back to its own DEFAULT_CRON_MAX_DURATION_MS (120s).
+export const maxDuration = 300;
+
export default wrapCron(async (req, res) => {
if (!method(req, res, ['GET', 'POST'])) return;
if (!requireCron(req, res)) return;
@@ -63,4 +67,4 @@ export default wrapCron(async (req, res) => {
unconfirmed: out.unconfirmed.length,
failed: out.failed.length,
});
-});
+}, { maxDurationMs: maxDuration * 1000 });
diff --git a/package.json b/package.json
index 5503e4749..b1f5a8d98 100644
--- a/package.json
+++ b/package.json
@@ -277,7 +277,7 @@
"audit:route-shadowing": "node scripts/audit-route-shadowing.mjs",
"audit:handlers": "node scripts/audit-empty-handlers.mjs",
"audit:x402-catalog": "node scripts/audit-x402-catalog.mjs",
- "gate": "npm run check:conflicts && npm run check:claude && npm run check:cli-scripts && npm run check:vendored && npm run check:model-viewer && npm run check:gcloudignore && npm run check:fetch-timeouts && npm run check:tdz-bootstrap && npm run check:event && npm run check:cron-syntax && npm run check:home-matrix && npm run check:studio-openapi && npm run test:gate && npm run test:gate-3d && npm run audit:mcp && npm run audit:mcp-golden && npm run audit:mcp-safety && npm run audit:mcp-catalog && npm run check:mcp-counts && npm run test:mcp-surface && npm run check:mcp-catalog && npm run audit:mcp-listing && npm run audit:mcp-surfaces && npm run check:pay-skills && npm run audit:routes && npm run audit:handlers && npm run audit:pages && npm run audit:links && npm run check:awesome && npm run check:prompt-library && npm run audit:docs && npm run check:docs-freshness && npm run audit:upstreams && npm run check:tutorials && npm run audit:hidden-guard && npm run audit:inline-handlers && npm run audit:x402-catalog && npm run audit:tokens && npm run audit:states && npm run audit:motion-tokens && npm run audit:guards && npm run audit:tour-atlas && npm run check:ios-icons && npm run check:macos-icon && npm run check:apple-widget && npm run check:ios-app && npm run check:windows-widget && npm run check:announce && npm run i18n:home && npm run check:skills-seed && npm run check:openai-skills && npm run check:skills-pack && npm run check:skill-repos && npm run check:skills-spec && npm run check:well-known-skills && npm run check:postman-collection && npm run check:openai-fields && npm run audit:motion && npm run audit:tour-global && npm run check:doc-media && npm run check:images && npm run audit:route-shadowing && npm run check:site-builder-embeds",
+ "gate": "npm run check:conflicts && npm run check:claude && npm run check:cli-scripts && npm run check:vendored && npm run check:model-viewer && npm run check:gcloudignore && npm run check:fetch-timeouts && npm run check:tdz-bootstrap && npm run check:event && npm run check:cron-syntax && npm run check:cron-budget-wiring && npm run check:home-matrix && npm run check:studio-openapi && npm run test:gate && npm run test:gate-3d && npm run audit:mcp && npm run audit:mcp-golden && npm run audit:mcp-safety && npm run audit:mcp-catalog && npm run check:mcp-counts && npm run test:mcp-surface && npm run check:mcp-catalog && npm run audit:mcp-listing && npm run audit:mcp-surfaces && npm run check:pay-skills && npm run audit:routes && npm run audit:handlers && npm run audit:pages && npm run audit:links && npm run check:awesome && npm run check:prompt-library && npm run audit:docs && npm run check:docs-freshness && npm run audit:upstreams && npm run check:tutorials && npm run audit:hidden-guard && npm run audit:inline-handlers && npm run audit:x402-catalog && npm run audit:tokens && npm run audit:states && npm run audit:motion-tokens && npm run audit:guards && npm run audit:tour-atlas && npm run check:ios-icons && npm run check:macos-icon && npm run check:apple-widget && npm run check:ios-app && npm run check:windows-widget && npm run check:announce && npm run i18n:home && npm run check:skills-seed && npm run check:openai-skills && npm run check:skills-pack && npm run check:skill-repos && npm run check:skills-spec && npm run check:well-known-skills && npm run check:postman-collection && npm run check:openai-fields && npm run audit:motion && npm run audit:tour-global && npm run check:doc-media && npm run check:images && npm run audit:route-shadowing && npm run check:site-builder-embeds",
"test:stake-program": "node scripts/test-event-markets-stake.mjs",
"test:gate-3d": "vitest run tests/glb-canonicalize.test.js tests/animation-retarget.test.js tests/animation-retarget-rest-pollution.test.js tests/viewer-framing.test.js",
"audit:mcp-golden": "node scripts/audit-mcp-golden.mjs",
@@ -313,6 +313,7 @@
"audit:llm-metering": "node scripts/audit-llm-metering.mjs",
"check:cron-drift": "node scripts/check-cron-drift.mjs",
"check:cron-syntax": "node scripts/check-cron-drift.mjs --offline",
+ "check:cron-budget-wiring": "node scripts/check-cron-budget-wiring.mjs",
"check:xai-models": "node scripts/check-xai-models.mjs",
"check:earnings-board": "node scripts/check-earnings-board.mjs",
"audit:custodial-keys": "node scripts/audit-custodial-key-health.mjs",
diff --git a/scripts/check-cron-budget-wiring.mjs b/scripts/check-cron-budget-wiring.mjs
new file mode 100644
index 000000000..68b573cf7
--- /dev/null
+++ b/scripts/check-cron-budget-wiring.mjs
@@ -0,0 +1,147 @@
+#!/usr/bin/env node
+// Verify every cron handler that vercel.json grants more than the
+// DEFAULT_CRON_MAX_DURATION_MS (120s) default actually tells wrapCron about its
+// larger budget.
+//
+// 2026-10-24 incident, found twice by hand from a log signature before this
+// check existed: api/cron/x402-ring-leak-scan.js and api/cron/[name].js both
+// declared `maxDuration: 300` in vercel.json but never passed `maxDurationMs`
+// into wrapCron() (api/_lib/http.js), so wrapCron fell back to its 120s
+// default and answered 503 cron_timeout on every run once the workload
+// crossed 120s. A follow-up sweep found the identical unwired gap in ten more
+// standalone cron handlers. Both classes are structural: a declared budget in
+// vercel.json that the handler never actually receives. This script closes
+// that gap for every current and future cron, not just the twelve found so
+// far.
+//
+// A handler passes when it statically exports a `maxDuration` constant equal
+// to vercel.json's declared value for its route, and its source text wires
+// that same constant into wrapCron's `maxDurationMs` option. The second half
+// matters: a file can export the right number and still forget to pass it
+// (exactly what happened twice), so exports alone are not enough to trust.
+//
+// Usage:
+// node scripts/check-cron-budget-wiring.mjs # human-readable
+// node scripts/check-cron-budget-wiring.mjs --json # machine-readable
+//
+// Exits non-zero when any in-scope cron is missing the wiring, so it can gate
+// a deploy (wired into the `gate` script in package.json).
+
+import { readFileSync } from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath, pathToFileURL } from 'node:url';
+import { globSync } from 'glob';
+import { DEFAULT_CRON_MAX_DURATION_MS } from '../api/_lib/http.js';
+
+const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
+const DEFAULT_CRON_MAX_DURATION_S = DEFAULT_CRON_MAX_DURATION_MS / 1000;
+
+const argv = process.argv.slice(2);
+const AS_JSON = argv.includes('--json');
+
+// Routes whose declared budget legitimately differs from what the handler
+// itself wires (not the wiring bug this script hunts), named here instead of
+// weakening the general check. Keep this list empty unless a real exception
+// is found; add a one-line reason next to any entry.
+const KNOWN_EXCEPTIONS = new Set([]);
+
+const isCronFile = (p) => p.startsWith('api/cron/') && p.endsWith('.js');
+
+// vercel.json spells a dynamic route segment the Next.js/Vercel way, e.g.
+// `api/cron/[name].js`. Those brackets are never a glob character class in
+// this file's keys (confirmed: every bracketed key in vercel.json is one of
+// this naming convention), but glob() parses `[name]` as "one of n/a/m/e" and
+// silently matches nothing. Escape them so the literal filename survives.
+const escapeBrackets = (pattern) => pattern.replace(/\[/g, '\\[').replace(/\]/g, '\\]');
+
+/**
+ * Every `api/cron/*.js` path vercel.json grants more than the 120s default,
+ * mapped to its declared seconds.
+ *
+ * vercel.json's `functions` object resolves by specificity, not by key order:
+ * the broad catch-all `"api/**\/*.js": { maxDuration: 30 }` at the bottom
+ * covers every route, but a named/exact route elsewhere overrides it for the
+ * files it lists. Applying wildcard keys first and letting named keys win
+ * (never the reverse) mirrors that: a plain last-key-wins merge would let the
+ * 30s catch-all stomp every real 300s declaration.
+ */
+function declaredCronBudgets() {
+ const { functions } = JSON.parse(readFileSync(path.join(ROOT, 'vercel.json'), 'utf8'));
+ const entries = Object.entries(functions || {}).filter(([, c]) => typeof c?.maxDuration === 'number');
+ const [named, wildcard] = [entries.filter(([k]) => !k.includes('*')), entries.filter(([k]) => k.includes('*'))];
+
+ const budgets = new Map();
+ for (const [key, config] of wildcard) {
+ for (const match of globSync(escapeBrackets(key), { cwd: ROOT })) {
+ if (isCronFile(match)) budgets.set(match, config.maxDuration);
+ }
+ }
+ for (const [key, config] of named) {
+ for (const match of globSync(escapeBrackets(key), { cwd: ROOT })) {
+ if (isCronFile(match)) budgets.set(match, config.maxDuration);
+ }
+ }
+ return budgets;
+}
+
+/** Find the exported constant (any name) whose value equals the declared seconds. */
+async function wiredExport(cronPath, declaredSeconds) {
+ const mod = await import(pathToFileURL(path.join(ROOT, cronPath)).href);
+ if (mod.maxDuration === declaredSeconds) return 'maxDuration';
+ return Object.keys(mod).find((k) => mod[k] === declaredSeconds) || null;
+}
+
+async function main() {
+ const budgets = declaredCronBudgets();
+ const inScope = [...budgets].filter(([, s]) => s > DEFAULT_CRON_MAX_DURATION_S);
+ const problems = [];
+ const clean = [];
+
+ for (const [cronPath, declaredSeconds] of inScope) {
+ if (KNOWN_EXCEPTIONS.has(cronPath)) continue;
+
+ const exportName = await wiredExport(cronPath, declaredSeconds);
+ if (!exportName) {
+ problems.push({
+ path: cronPath,
+ declared: declaredSeconds,
+ reason: `declares ${declaredSeconds}s in vercel.json but exports no constant equal to it (wrapCron will fall back to the ${DEFAULT_CRON_MAX_DURATION_S}s default)`,
+ });
+ continue;
+ }
+
+ const src = readFileSync(path.join(ROOT, cronPath), 'utf8');
+ const wiredPattern = new RegExp(`maxDurationMs\\s*:\\s*${exportName}\\s*\\*\\s*1000`);
+ if (!wiredPattern.test(src)) {
+ problems.push({
+ path: cronPath,
+ declared: declaredSeconds,
+ reason: `exports ${exportName} = ${declaredSeconds} but its wrapCron(...) call never passes { maxDurationMs: ${exportName} * 1000 }, so wrapCron still falls back to the ${DEFAULT_CRON_MAX_DURATION_S}s default`,
+ });
+ continue;
+ }
+
+ clean.push({ path: cronPath, declared: declaredSeconds, exportName });
+ }
+
+ if (AS_JSON) {
+ console.log(JSON.stringify({ checked: inScope.length, clean, problems }, null, 2));
+ process.exit(problems.length ? 1 : 0);
+ }
+
+ console.log(
+ `Checked ${inScope.length} cron route(s) declared above the ${DEFAULT_CRON_MAX_DURATION_S}s default; ${clean.length} correctly wired.`,
+ );
+ if (problems.length) {
+ console.log(`\nUNWIRED budget: ${problems.length}`);
+ for (const p of problems) console.log(` ${p.path} (declared ${p.declared}s)\n ${p.reason}`);
+ } else {
+ console.log('No unwired cron budgets: every declared maxDuration above the default reaches wrapCron.');
+ }
+
+ process.exit(problems.length ? 1 : 0);
+}
+
+if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
+ await main();
+}
diff --git a/tests/cron-budget-wiring-sweep.test.js b/tests/cron-budget-wiring-sweep.test.js
new file mode 100644
index 000000000..f507aacfb
--- /dev/null
+++ b/tests/cron-budget-wiring-sweep.test.js
@@ -0,0 +1,73 @@
+// Parametrized regression test for the 2026-10-24 cron-budget-wiring bug class,
+// found first in api/cron/x402-ring-leak-scan.js and api/cron/[name].js
+// (tests/x402-ring-leak-scan-run.test.js, tests/cron-dispatcher-routing.test.js):
+// vercel.json declared `maxDuration: 300` for a route, but the handler never
+// passed `maxDurationMs` into wrapCron() (api/_lib/http.js), so wrapCron fell
+// back to its DEFAULT_CRON_MAX_DURATION_MS (120s) and answered 503 cron_timeout
+// on every run once the workload crossed 120s.
+//
+// A follow-up sweep found the identical gap, unfixed, in ten more standalone
+// cron handlers that each declare 300s in vercel.json. This file pins all ten
+// so the class cannot regress silently; scripts/check-cron-budget-wiring.mjs
+// generalizes the same check across the whole api/cron/ tree for every future
+// cron.
+
+import { describe, it, expect } from 'vitest';
+import { readFileSync } from 'node:fs';
+import { pathToFileURL } from 'node:url';
+import { join } from 'node:path';
+import { globSync } from 'glob';
+
+import { DEFAULT_CRON_MAX_DURATION_MS } from '../api/_lib/http.js';
+
+const ROOT = join(import.meta.dirname, '..');
+
+const FILES = [
+ 'api/cron/economy-reconcile.js',
+ 'api/cron/x402-prepaid-settle.js',
+ 'api/cron/fact-check-benchmark.js',
+ 'api/cron/avaturn-seed-cron.js',
+ 'api/cron/strategy-fanout.js',
+ 'api/cron/gmgn-seed.js',
+ 'api/cron/recompute-reputation.js',
+ 'api/cron/smart-money-graph.js',
+ 'api/cron/sketchfab-showcase.js',
+ 'api/cron/forge-smoke.js',
+];
+
+/**
+ * vercel.json's declared maxDuration for a cron route. `functions` resolves by
+ * specificity, not key order (the broad `api/**\/*.js` catch-all at the bottom
+ * covers every route at 30s; a named/exact key elsewhere overrides it for the
+ * files it lists), so named keys are applied after wildcard keys and win.
+ */
+function declaredMaxDuration(cronPath) {
+ const { functions } = JSON.parse(readFileSync(join(ROOT, 'vercel.json'), 'utf8'));
+ const entries = Object.entries(functions).filter(([, c]) => typeof c.maxDuration === 'number');
+ const [wildcard, named] = [entries.filter(([k]) => k.includes('*')), entries.filter(([k]) => !k.includes('*'))];
+
+ let declared;
+ for (const [key, config] of [...wildcard, ...named]) {
+ const pattern = key.replace(/\[/g, '\\[').replace(/\]/g, '\\]');
+ if (globSync(pattern, { cwd: ROOT }).includes(cronPath)) declared = config.maxDuration;
+ }
+ if (declared == null) throw new Error(`no vercel.json functions entry declares a maxDuration for ${cronPath}`);
+ return declared;
+}
+
+describe.each(FILES)('cron budget wiring: %s', (cronPath) => {
+ it('declares a maxDuration matching vercel.json and wires it into wrapCron, so wrapCron does not truncate the run at the 120s default', async () => {
+ const declaredSeconds = declaredMaxDuration(cronPath);
+ expect(declaredSeconds * 1000).toBeGreaterThan(DEFAULT_CRON_MAX_DURATION_MS);
+
+ const mod = await import(pathToFileURL(join(ROOT, cronPath)).href);
+ expect(mod.maxDuration, `${cronPath} must export a maxDuration constant`).toBe(declaredSeconds);
+ expect(mod.maxDuration * 1000).toBeGreaterThan(DEFAULT_CRON_MAX_DURATION_MS);
+
+ const src = readFileSync(join(ROOT, cronPath), 'utf8');
+ expect(
+ /maxDurationMs\s*:\s*maxDuration\s*\*\s*1000/.test(src),
+ `${cronPath} exports maxDuration but never passes { maxDurationMs: maxDuration * 1000 } into its wrapCron(...) call`,
+ ).toBe(true);
+ });
+});