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.

feat: add external cron failover heartbeat driving all vercel.json crons from GitHub Actions

nrpo2c2ea63c8268
diff --git a/.github/workflows/economy-heartbeat.yml b/.github/workflows/economy-heartbeat.yml
new file mode 100644
index 000000000..79d06bd1f
--- /dev/null
+++ b/.github/workflows/economy-heartbeat.yml
@@ -0,0 +1,67 @@
+name: economy-heartbeat
+
+# External failover scheduler for the platform's Vercel crons
+# (scripts/economy-heartbeat.mjs — see docs/economy-heartbeat.md).
+#
+# Vercel Cron is the primary scheduler. When the Vercel project cannot fire
+# crons (account block, paused project), this workflow keeps every /api/cron/*
+# endpoint ticking on the schedule declared in vercel.json: each run lasts ~5
+# minutes and wakes at every UTC minute boundary, so minute-level crons
+# (x402-seed-cron) still fire every minute even though GitHub's scheduler
+# minimum is 5 minutes. Runs are queued, never cancelled, for gap-free coverage.
+#
+# Safe to leave enabled while Vercel crons are healthy: the endpoints are the
+# same ones Vercel calls, each tick is capped server-side, and double ticks are
+# absorbed by the engines' per-tick and daily caps.
+#
+# Requires repo secret CRON_SECRET (the same bearer secret set on Vercel).
+
+on:
+ workflow_dispatch:
+ inputs:
+ duration_minutes:
+ description: 'How many minutes this run should keep ticking'
+ required: false
+ default: '5'
+ only:
+ description: 'Optional regex filter on cron paths (e.g. pulse|x402)'
+ required: false
+ default: ''
+ schedule:
+ - cron: '*/5 * * * *'
+
+concurrency:
+ group: economy-heartbeat
+ cancel-in-progress: false
+
+permissions:
+ contents: read
+
+jobs:
+ heartbeat:
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ sparse-checkout: |
+ vercel.json
+ scripts/economy-heartbeat.mjs
+ sparse-checkout-cone-mode: false
+
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 24
+
+ - name: Tick all due crons
+ env:
+ CRON_SECRET: ${{ secrets.CRON_SECRET }}
+ BASE_URL: https://three.ws
+ DURATION_MINUTES: ${{ inputs.duration_minutes || '5' }}
+ ONLY: ${{ inputs.only || '' }}
+ run: |
+ if [ -z "$CRON_SECRET" ]; then
+ echo "::warning::Repo secret CRON_SECRET is not set — heartbeat is idle. Add it (same value as the Vercel CRON_SECRET env var) to activate the failover."
+ exit 0
+ fi
+ node scripts/economy-heartbeat.mjs
diff --git a/docs/circulation-engine.md b/docs/circulation-engine.md
index 288351fb6..c71ecfe66 100644
--- a/docs/circulation-engine.md
+++ b/docs/circulation-engine.md
@@ -100,6 +100,10 @@ up to `CIRCULATION_GROWTH_PER_TICK` agents and runs `CIRCULATION_ACTIONS_PER_TIC
everyday actions (plus any heavyweight action that wins first refusal). Cron
functions are bounded to a 120-second `maxDuration`.
+If Vercel's scheduler itself stops firing (account block, paused project), the
+[economy heartbeat](economy-heartbeat.md) drives the same cron endpoints on the
+same schedules from GitHub Actions.
+
## Configuration
| Env var | Default | Range | Purpose |
diff --git a/docs/economy-heartbeat.md b/docs/economy-heartbeat.md
new file mode 100644
index 000000000..e0c354e68
--- /dev/null
+++ b/docs/economy-heartbeat.md
@@ -0,0 +1,73 @@
+# Economy heartbeat (external cron failover)
+
+Every scheduled job on the platform — the circulation engine tick, the x402
+seed and autonomous loops, treasury top-ups, payouts, sweeps, reconciliation —
+is a Vercel Cron entry in `vercel.json` calling an authed `/api/cron/*`
+endpoint. That makes Vercel's scheduler a single point of failure: if the
+Vercel project stops firing crons (account block, paused project, migration),
+every money rail halts at once while the deployed site keeps serving traffic.
+That exact failure happened on 2026-06-29 and flatlined the Money Pulse.
+
+The heartbeat removes that single point of failure. It is a second, independent
+scheduler that drives the same endpoints on the same schedules from GitHub
+Actions.
+
+## Pieces
+
+| Piece | Path |
+| --- | --- |
+| Scheduler script | `scripts/economy-heartbeat.mjs` |
+| GitHub Actions workflow | `.github/workflows/economy-heartbeat.yml` |
+| Schedule source of truth | the `crons` array in `vercel.json` (never duplicated) |
+
+The script reads `vercel.json`, wakes at each UTC minute boundary for
+`DURATION_MINUTES` (default 5), and fires every cron whose schedule matches
+that minute — concurrently, with the same `Authorization: Bearer $CRON_SECRET`
+header Vercel sends. The workflow runs it every 5 minutes with queued,
+never-cancelled runs, so minute-level crons (`x402-seed-cron`) still tick every
+minute despite GitHub's 5-minute scheduler floor.
+
+## Activation
+
+One step: add the repo secret `CRON_SECRET` (Settings → Secrets and variables →
+Actions) with the same value as the `CRON_SECRET` env var on the Vercel
+project. Until the secret exists, every run exits idle with a warning and
+touches nothing.
+
+## Safety properties
+
+- **No new money paths.** The heartbeat only calls the same authed cron
+ endpoints Vercel calls. All spend caps, registry allowlists, and ledger
+ recording live server-side and apply identically.
+- **Double-scheduling is harmless.** While Vercel crons are healthy the
+ endpoints simply tick more often; every engine enforces per-tick and daily
+ caps, so leave the heartbeat enabled permanently as insurance.
+- **Undeployed endpoints are tolerated.** A cron present in the repo's
+ `vercel.json` but missing from the deployed build reports `missing 404` and
+ never fails the run.
+- **Loud on real outage.** A run fails only when every attempted call fails —
+ bad secret or site down — so a red workflow means a genuine problem.
+
+## Manual runs
+
+```bash
+# One-off from anywhere (also how the workflow_dispatch trigger works):
+CRON_SECRET=… node scripts/economy-heartbeat.mjs
+
+# Longer run, economy rails only:
+CRON_SECRET=… DURATION_MINUTES=10 ONLY='pulse|x402|treasury|economy' node scripts/economy-heartbeat.mjs
+```
+
+## Caveats
+
+- GitHub's scheduler is best-effort; runs can start several minutes late under
+ load. High-frequency crons self-heal on the next window, but a cron pinned to
+ one exact minute per day (e.g. `45 9 * * *`) can miss its minute on a badly
+ delayed run — fire it via `workflow_dispatch` with an `only` filter if it
+ matters that day.
+- The heartbeat is a failover, not the fix. When Vercel cron scheduling is
+ down, restore it — the platform's primary scheduler should be the deploy
+ target itself.
+
+Related: [circulation engine](circulation-engine.md) ·
+[economy funding root](economy-master.md) · [money map](money-map.md)
diff --git a/docs/economy-master.md b/docs/economy-master.md
index 62bf670c5..e876838ce 100644
--- a/docs/economy-master.md
+++ b/docs/economy-master.md
@@ -107,6 +107,10 @@ The JSON response reports `configured`, `master_sol`, `funded`, `failed`,
`skipped`, `rejected`, and `spent_sol`. A non-empty `rejected` array means an
off-registry target reached the sweep and was blocked — investigate the caller.
+If the cron never fires because Vercel's scheduler is down, the
+[economy heartbeat](economy-heartbeat.md) keeps it (and every other cron)
+ticking from GitHub Actions.
+
## Audit, accounting & breach monitoring
This is real money, so every movement is recorded to a durable, tamper-evident
diff --git a/scripts/economy-heartbeat.mjs b/scripts/economy-heartbeat.mjs
new file mode 100644
index 000000000..226a9040d
--- /dev/null
+++ b/scripts/economy-heartbeat.mjs
@@ -0,0 +1,149 @@
+// @ts-check
+// scripts/economy-heartbeat.mjs — external failover scheduler for Vercel crons.
+//
+// Vercel Cron is the primary scheduler for every /api/cron/* endpoint. When the
+// Vercel project cannot run crons (account block, paused project, migration),
+// this script drives the exact same endpoints on the exact same schedules,
+// reading the single source of truth: the `crons` array in vercel.json.
+//
+// It runs for DURATION_MINUTES (default 5), waking at each UTC minute boundary,
+// firing every cron whose schedule matches that minute, concurrently, with the
+// same `Authorization: Bearer $CRON_SECRET` header Vercel would send.
+//
+// Usage:
+// CRON_SECRET=… node scripts/economy-heartbeat.mjs
+// BASE_URL=https://three.ws CRON_SECRET=… DURATION_MINUTES=5 node scripts/economy-heartbeat.mjs
+// ONLY='pulse|x402' CRON_SECRET=… node scripts/economy-heartbeat.mjs # filter by path regex
+//
+// Exit codes: 0 = at least one call succeeded (or nothing was due);
+// 1 = calls were attempted and every single one failed (outage/bad secret).
+//
+// Endpoints that 404 are reported but never fail the run — the deployed build
+// may lag the repo's vercel.json (new crons exist here before they deploy).
+
+import { readFile } from 'node:fs/promises';
+import { fileURLToPath } from 'node:url';
+import { dirname, join } from 'node:path';
+
+const BASE_URL = (process.env.BASE_URL || 'https://three.ws').replace(/\/+$/, '');
+const CRON_SECRET = process.env.CRON_SECRET;
+const DURATION_MINUTES = Math.max(1, Math.min(30, Number(process.env.DURATION_MINUTES) || 5));
+const ONLY = process.env.ONLY ? new RegExp(process.env.ONLY) : null;
+const CALL_TIMEOUT_MS = 115_000; // Vercel cron maxDuration is 120s
+
+if (!CRON_SECRET) {
+ console.error('CRON_SECRET is required (the Vercel cron bearer secret).');
+ process.exit(1);
+}
+
+const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..');
+const vercelConfig = JSON.parse(await readFile(join(repoRoot, 'vercel.json'), 'utf8'));
+const crons = (vercelConfig.crons || []).filter((c) => !ONLY || ONLY.test(c.path));
+
+if (!crons.length) {
+ console.error(`No crons matched${ONLY ? ` ONLY=${ONLY}` : ''} in vercel.json.`);
+ process.exit(1);
+}
+
+// Parse one field of a 5-field cron expression into a Set of matching values.
+// Supports the forms used in vercel.json: *, */N, A, A-B, A-B/N, and comma lists.
+function parseField(field, min, max) {
+ const values = new Set();
+ for (const part of field.split(',')) {
+ const [rangePart, stepPart] = part.split('/');
+ const step = stepPart ? Number(stepPart) : 1;
+ let lo = min;
+ let hi = max;
+ if (rangePart !== '*') {
+ const [a, b] = rangePart.split('-').map(Number);
+ lo = a;
+ hi = b === undefined ? (stepPart ? max : a) : b;
+ }
+ if (!Number.isInteger(step) || step < 1 || !Number.isInteger(lo) || !Number.isInteger(hi)) {
+ throw new Error(`unsupported cron field: ${field}`);
+ }
+ for (let v = lo; v <= hi; v += step) values.add(v);
+ }
+ return values;
+}
+
+function compileSchedule(schedule) {
+ const fields = schedule.trim().split(/\s+/);
+ if (fields.length !== 5) throw new Error(`unsupported cron expression: ${schedule}`);
+ const [minute, hour, dom, month, dow] = fields;
+ return {
+ minute: parseField(minute, 0, 59),
+ hour: parseField(hour, 0, 23),
+ dom: parseField(dom, 1, 31),
+ month: parseField(month, 1, 12),
+ dow: parseField(dow, 0, 6),
+ };
+}
+
+const compiled = crons.map((c) => ({ path: c.path, schedule: c.schedule, match: compileSchedule(c.schedule) }));
+
+function dueAt(date) {
+ const m = date.getUTCMinutes();
+ const h = date.getUTCHours();
+ const dom = date.getUTCDate();
+ const mon = date.getUTCMonth() + 1;
+ const dow = date.getUTCDay();
+ return compiled.filter(
+ (c) => c.match.minute.has(m) && c.match.hour.has(h) && c.match.dom.has(dom) && c.match.month.has(mon) && c.match.dow.has(dow),
+ );
+}
+
+async function callCron(path) {
+ const started = Date.now();
+ const controller = new AbortController();
+ const timer = setTimeout(() => controller.abort(), CALL_TIMEOUT_MS);
+ try {
+ const res = await fetch(`${BASE_URL}${path}`, {
+ headers: { authorization: `Bearer ${CRON_SECRET}` },
+ signal: controller.signal,
+ });
+ const body = (await res.text()).slice(0, 200).replace(/\s+/g, ' ');
+ return { path, status: res.status, ms: Date.now() - started, body };
+ } catch (err) {
+ return { path, status: 0, ms: Date.now() - started, body: String(err?.message || err) };
+ } finally {
+ clearTimeout(timer);
+ }
+}
+
+const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
+
+let succeeded = 0;
+let missing = 0;
+let failed = 0;
+
+console.log(`economy-heartbeat: ${compiled.length} crons from vercel.json → ${BASE_URL}, ${DURATION_MINUTES} minute(s)`);
+
+for (let tick = 0; tick < DURATION_MINUTES; tick++) {
+ const now = new Date();
+ const due = dueAt(now);
+ const stamp = now.toISOString().slice(0, 16) + 'Z';
+ if (due.length) {
+ console.log(`[${stamp}] firing ${due.length} due cron(s)`);
+ const results = await Promise.all(due.map((c) => callCron(c.path)));
+ for (const r of results) {
+ const tag = r.status >= 200 && r.status < 300 ? 'ok' : r.status === 404 ? 'missing' : 'FAIL';
+ if (tag === 'ok') succeeded++;
+ else if (tag === 'missing') missing++;
+ else failed++;
+ console.log(` ${tag.padEnd(7)} ${String(r.status).padEnd(3)} ${String(r.ms).padStart(6)}ms ${r.path} ${tag === 'ok' ? '' : `— ${r.body}`}`);
+ }
+ } else {
+ console.log(`[${stamp}] nothing due`);
+ }
+ if (tick < DURATION_MINUTES - 1) {
+ const msToNextMinute = 60_000 - (Date.now() % 60_000);
+ await sleep(msToNextMinute + 250);
+ }
+}
+
+console.log(`economy-heartbeat done: ${succeeded} ok, ${missing} not deployed (404), ${failed} failed`);
+if (failed > 0 && succeeded === 0) {
+ console.error('Every attempted cron call failed — check CRON_SECRET and site availability.');
+ process.exit(1);
+}