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: schedule the garment orphan-job sweep

nirholas4e1cbd9702b3
diff --git a/api/cron/garment-job-sweep.js b/api/cron/garment-job-sweep.js
new file mode 100644
index 000000000..291a2e961
--- /dev/null
+++ b/api/cron/garment-job-sweep.js
@@ -0,0 +1,77 @@
+// @ts-check
+// GET /api/cron/garment-job-sweep — re-drive orphaned garment generation jobs.
+//
+// The garment-forge worker claims work at EXECUTION time against a durable
+// GCS record (see workers/garment-forge/main.py "Durable work claiming"), so
+// a job whose instance is reclaimed mid-pipeline — scale-to-zero, a revision
+// rollout, a crash — stays recoverable instead of dying in the instance's
+// in-process queue. Recovery is not automatic though: something has to ask a
+// live instance to look. That is this cron.
+//
+// Without it the worker's whole claim/retry machinery is inert: an orphaned
+// job sits at "queued" until the stale watchdog buries it, which is exactly
+// the failure the claiming work was built to prevent (observed 2026-07-26:
+// 12 of 22 batch jobs lost to a reclaimed instance).
+//
+// Every 10 minutes: one authenticated POST to the worker's /sweep, which
+// takes a lock, lists claimable records, and re-drives them under the normal
+// concurrency limit. Overlapping ticks and live instances cannot double-run a
+// job — the claim is an atomic generation-matched write.
+
+import { error, json, method, reportServerError, wrapCron } from '../_lib/http.js';
+import { env } from '../_lib/env.js';
+import { constantTimeEquals } from '../_lib/crypto.js';
+
+function requireCron(req, res) {
+ const secret = process.env.CRON_SECRET || env.CRON_SECRET;
+ if (!secret) {
+ error(res, 503, 'not_configured', 'CRON_SECRET unset');
+ return false;
+ }
+ const auth = req.headers['authorization'] || '';
+ const presented = auth.startsWith('Bearer ') ? auth.slice(7) : '';
+ if (!constantTimeEquals(presented, secret)) {
+ error(res, 401, 'unauthorized', 'invalid cron secret');
+ return false;
+ }
+ return true;
+}
+
+export default wrapCron(async (req, res) => {
+ if (!method(req, res, ['GET'])) return;
+ if (!requireCron(req, res)) return;
+
+ const base = (process.env.GCP_GARMENT_FORGE_URL || '').replace(/\/$/, '');
+ const key = process.env.GCP_RECONSTRUCTION_KEY || '';
+ if (!base || !key) {
+ // Not an error: a deployment without the garment lane configured simply
+ // has nothing to sweep.
+ return json(res, 200, { ok: true, skipped: 'not_configured' });
+ }
+
+ const upstream = await fetch(`${base}/sweep`, {
+ method: 'POST',
+ headers: { authorization: `Bearer ${key}`, 'content-type': 'application/json' },
+ body: '{}',
+ }).catch((err) => {
+ reportServerError(err instanceof Error ? err : new Error(String(err)), {
+ code: 'garment_sweep_unreachable',
+ context: { base },
+ });
+ return null;
+ });
+ if (!upstream) {
+ return error(res, 502, 'sweep_unreachable', 'garment-forge worker unreachable');
+ }
+ if (!upstream.ok) {
+ const detail = await upstream.text().catch(() => '');
+ reportServerError(new Error(`garment sweep returned ${upstream.status}: ${detail.slice(0, 200)}`), {
+ code: 'garment_sweep_failed',
+ context: { status: upstream.status },
+ });
+ return error(res, 502, 'sweep_failed', `worker returned ${upstream.status}`);
+ }
+
+ const result = await upstream.json().catch(() => ({}));
+ return json(res, 200, { ok: true, ...result });
+});
diff --git a/vercel.json b/vercel.json
index 48cac929d..ec71d1918 100644
--- a/vercel.json
+++ b/vercel.json
@@ -3241,8 +3241,8 @@
"dest": "/api/pump/[action]?action=launches"
},
{
- "src": "/api/launchpad/(config|quote|pool|launch-prep|launch-confirm|launches)",
- "dest": "/api/launchpad/[action]?action=$1"
+ "src": "/api/native-launch/(config|quote|pool|launch-prep|launch-confirm|launches)",
+ "dest": "/api/native-launch/[action]?action=$1"
},
{
"src": "/api/pump/coin",
@@ -5623,6 +5623,10 @@
{
"path": "/api/cron/garment-catalog-audit",
"schedule": "20 6 * * *"
+ },
+ {
+ "path": "/api/cron/garment-job-sweep",
+ "schedule": "*/10 * * * *"
}
]
}
diff --git a/workers/garment-forge/garment_glb.py b/workers/garment-forge/garment_glb.py
index 9cb19c44b..b46879a54 100644
--- a/workers/garment-forge/garment_glb.py
+++ b/workers/garment-forge/garment_glb.py
@@ -91,6 +91,19 @@ RIG_BONES_MIN_SHARE = 0.001
# its shoes nearly touching, so pair width says nothing about shoe size, while
# foot length is invariant to the pair gap. (Refbody feet, measured from skin
# weights: length 0.243, per-foot width 0.096, centers at x = +/-0.222.)
+#
+# Each slot's fit axis is the dimension that is INVARIANT for that kind of
+# item, which is why they differ and why contain-fit is not the universal
+# answer (it was the right fix for headwear alone, see below):
+# hair width tracks head width; length varies hugely by style, so a
+# contain-fit would crush shoulder-length hair into the box.
+# glasses width tracks face width; long temples would shrink a contain-fit
+# pair until it no longer spans the face.
+# accessory width is the least style-dependent axis (a bag's strap length is
+# not a size signal).
+# The walk-gait audit (npm run audit:garments) is the detector if any of these
+# ever drifts: 2026-07-27 baseline has all three comfortably inside their
+# ceilings (hair p95 13.4 of 20 cm, glasses 10.9 of 12, accessory 8.0 of 25).
SLOT_BOXES = {
"top": {"center": (0.0, 1.14, 0.03), "size": (0.90, 0.56, 0.45), "fit": 1},
"outerwear": {"center": (0.0, 1.05, 0.03), "size": (1.00, 0.80, 0.50), "fit": 1},