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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat(ops): watch Forge 3D generation success rate, the outcome signal lane liveness misses
nirholas05b7ee84c529
diff --git a/api/_lib/ops/forge-health-sensor.js b/api/_lib/ops/forge-health-sensor.jsnew file mode 100644index 000000000..d145b0b8b--- /dev/null+++ b/api/_lib/ops/forge-health-sensor.js@@ -0,0 +1,156 @@+// @ts-check+// Forge generation success-rate sensor — the outcome signal that was missing,+// the twin of x402-settle-health.js for 3D generation.+//+// subsystem-health already reports forge lane LIVENESS (forge-lane-health.js:+// "can our GPU workers serve a generation right now, are they warm?"). But a+// live, warm lane can still FAIL generations — from 2026-07-09 the self-host+// image→3D lane failed ~48% of the time (task-not-found poll losses) while every+// liveness probe read healthy. That is the same blind spot the x402 rail had:+// "armed" is not "succeeding". This sensor reads the actual outcome ledger+// (forge_creations) and reports the generation SUCCESS RATE, so a failure burst+// pages instead of hiding.+//+// Metric: done / (done + failed) over a rolling window. Still-running and queued+// rows are excluded (not yet an outcome). The window is 6h because forge volume+// is modest (~7 image jobs/hour) — long enough to carry a judge-able sample and+// smooth the bursty failure pattern, short enough to surface a sustained+// regression. Below MIN_ATTEMPTS the verdict is `unknown` (neutral, never pages).+//+// The detail names WHERE the failures concentrate — the worst backend/path and+// the top error class — so a page is actionable, not just "generation is bad".+//+// Consumed via gatherSubsystemHealth() → /api/healthz, /status, and the+// uptime-cron escalation (pages on first sight, re-pages hourly, clears on+// recovery). No new cron, no new alert path.++const WINDOW_INTERVAL = '6 hours';+// Forge runs ~7 image jobs/hour; 15 outcomes in 6h is a trustworthy sample+// without letting a quiet stretch read as an outage.+const MIN_ATTEMPTS = 15;++// Rate bands. 3D generation legitimately fails sometimes (hard prompts/images),+// so the healthy bar is not 100%: ok ≥ 85%, degraded 60–85%, down < 60%. The+// 2026-07 image burst (~52% success) reads `down`; a 77% day reads `degraded`.+const OK_RATE = 0.85;+const DOWN_RATE = 0.6;++/**+ * Classify pre-aggregated forge outcome buckets into a subsystem verdict. Pure —+ * no DB, no clock — so thresholds and the failure-attribution are unit-testable+ * against the exact bucket shape the DB returns.+ * @param {Array<{ status: string, backend: string, path: string, reason: string, n: number }>} buckets+ * @param {{ minAttempts?: number }} [opts]+ * @returns {{ status: 'ok'|'degraded'|'down'|'unknown', done: number, failed: number,+ * attempts: number, rate: number|null, worstBackend: {backend:string,failed:number}|null,+ * worstPath: {path:string,failed:number}|null, topReason: {reason:string,n:number}|null,+ * detail: string, hint?: string }}+ */+export function classifyForgeBuckets(buckets, { minAttempts = MIN_ATTEMPTS } = {}) {+ let done = 0;+ let failed = 0;+ /** @type {Record<string, number>} */ const failByBackend = {};+ /** @type {Record<string, number>} */ const failByPath = {};+ /** @type {Record<string, number>} */ const failByReason = {};+ for (const b of Array.isArray(buckets) ? buckets : []) {+ const n = Number(b?.n) || 0;+ if (n <= 0) continue;+ if (b.status === 'done') {+ done += n;+ } else if (b.status === 'failed') {+ failed += n;+ failByBackend[b.backend || '(none)'] = (failByBackend[b.backend || '(none)'] || 0) + n;+ failByPath[b.path || '(none)'] = (failByPath[b.path || '(none)'] || 0) + n;+ if (b.reason && b.reason !== 'none') failByReason[b.reason] = (failByReason[b.reason] || 0) + n;+ }+ // Any other status (running/queued/…) is not yet an outcome — ignored.+ }+ const attempts = done + failed;+ const top = (m) => {+ const e = Object.entries(m).sort((a, b) => b[1] - a[1])[0];+ return e ? { key: e[0], n: e[1] } : null;+ };+ const wBackend = top(failByBackend);+ const wPath = top(failByPath);+ const wReason = top(failByReason);+ const worstBackend = wBackend ? { backend: wBackend.key, failed: wBackend.n } : null;+ const worstPath = wPath ? { path: wPath.key, failed: wPath.n } : null;+ const topReason = wReason ? { reason: wReason.key, n: wReason.n } : null;++ if (attempts < minAttempts) {+ return {+ status: 'unknown',+ done, failed, attempts, rate: null, worstBackend, worstPath, topReason,+ detail: `only ${attempts} finished generations in ${WINDOW_INTERVAL} — too few to judge`,+ };+ }++ const rate = done / attempts;+ const pct = (rate * 100).toFixed(0);+ const base = `${pct}% success (${done}/${attempts} finished, ${WINDOW_INTERVAL})`;+ if (rate >= OK_RATE) {+ return { status: 'ok', done, failed, attempts, rate, worstBackend, worstPath, topReason, detail: base };+ }+ const status = rate < DOWN_RATE ? 'down' : 'degraded';+ const where = [+ worstPath ? `${worstPath.path} path` : null,+ worstBackend ? `${worstBackend.backend} lane` : null,+ topReason ? `mostly "${topReason.reason}"` : null,+ ].filter(Boolean).join(', ');+ return {+ status,+ done, failed, attempts, rate, worstBackend, worstPath, topReason,+ detail: `${base}; ${failed} failed${where ? ` (${where})` : ''}`,+ hint:+ 'Generations are failing above the normal rate. Find the concentration: ' ++ 'forge_creations carries per-row backend/status/error/path. Check the worst ' ++ 'lane above and its worker health; a self-host lane failing on lost-task 404s ' ++ 'recovers via _lib/forge-selfhost-recovery.js, a vendor lane via its failover chain.',+ };+}++/**+ * Read the last WINDOW_INTERVAL of forge outcomes and classify them. Fail-soft:+ * a missing DB, absent table, or query error resolves to `unknown` so a health+ * read never throws. Pre-aggregates in SQL (bounded rows) so it is safe on the+ * per-request /api/healthz path.+ * @returns {Promise<{ name: 'forge_generation', label: string, status: string,+ * detail: string, hint?: string, metrics?: object }>}+ */+export async function gatherForgeHealth() {+ const base = { name: /** @type {const} */ ('forge_generation'), label: 'Forge 3D generation' };+ try {+ const { sql } = await import('../db.js');+ const buckets = /** @type {Array<{ status: string, backend: string, path: string, reason: string, n: number }>} */ (+ await sql`+ SELECT status,+ COALESCE(backend, '(none)') AS backend,+ COALESCE(path, '(none)') AS path,+ COALESCE(NULLIF(split_part(error, ':', 1), ''), 'none') AS reason,+ count(*)::int AS n+ FROM forge_creations+ WHERE created_at >= now() - ${WINDOW_INTERVAL}::interval+ GROUP BY status, backend, path, reason+ `+ );+ const v = classifyForgeBuckets(buckets);+ return {+ ...base,+ status: v.status,+ detail: v.detail,+ ...(v.hint ? { hint: v.hint } : {}),+ metrics: {+ windowHours: 6,+ done: v.done,+ failed: v.failed,+ attempts: v.attempts,+ rate: v.rate == null ? null : Math.round(v.rate * 1000) / 1000,+ worstBackend: v.worstBackend,+ worstPath: v.worstPath,+ topReason: v.topReason,+ },+ };+ } catch (err) {+ return { ...base, status: 'unknown', detail: err?.message || 'forge outcome ledger unreadable' };+ }+}diff --git a/api/_lib/ops/subsystem-health.js b/api/_lib/ops/subsystem-health.jsindex 4ce6063ef..3880612a6 100644--- a/api/_lib/ops/subsystem-health.js+++ b/api/_lib/ops/subsystem-health.js@@ -35,6 +35,7 @@ import { heliusHealth } from '../balances.js';import { rateLimiterHealth } from '../rate-limit.js';import { checkRingInvariants } from '../x402/ring-allowlist.js';import { gatherX402SettleHealth } from './x402-settle-health.js';+import { gatherForgeHealth } from './forge-health-sensor.js';const DB_PING_TIMEOUT_MS = 2_500;const DB_SLOW_MS = 1_000;@@ -345,6 +346,9 @@ export async function gatherSubsystemHealth({ probeDb = true } = {}) {// Settle SUCCESS RATE, not just "armed" — reads x402_autonomous_log. Needs// the DB, so it shares the probeDb gate; skipped-DB callers get `unknown`.probeDb ? gatherX402SettleHealth() : Promise.resolve({ name: 'x402_settle', label: 'x402 settlement success', status: 'unknown', detail: 'settle read skipped' }),+ // Generation SUCCESS RATE, not just lane liveness — reads forge_creations.+ // DB-gated like the settle sensor; skipped-DB callers get `unknown`.+ probeDb ? gatherForgeHealth() : Promise.resolve({ name: 'forge_generation', label: 'Forge 3D generation', status: 'unknown', detail: 'forge read skipped' }),checkWorld(),Promise.resolve(checkX402Config()),probeDb ? checkSniper() : Promise.resolve({ name: 'sniper', label: 'Sniper worker (Cloud Run)', status: 'unknown', detail: 'probe skipped' }),diff --git a/data/changelog.json b/data/changelog.jsonindex 444a3d1ff..f3eddc862 100644--- a/data/changelog.json+++ b/data/changelog.json@@ -1,6 +1,14 @@{"$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-17",+ "title": "Forge: one-tap variations of any model",+ "summary": "Every model you forge now shows a \"More like this\" row: one tap re-forges the same subject in a different material or finish (brushed brass, translucent glass, carved oak, and more), so you can explore a whole design space without retyping anything. A reshuffle button deals a fresh set of ideas. It appears for text prompts and runs on the free lane, so exploring costs nothing.",+ "tags": [+ "feature"+ ]+ },{"date": "2026-07-17","title": "One-tap Seed Vault sign-in on Solana Seeker",diff --git a/docs/forge-background-generation.md b/docs/forge-background-generation.mdindex 4fad5be5a..5653b146b 100644--- a/docs/forge-background-generation.md+++ b/docs/forge-background-generation.md@@ -76,6 +76,20 @@ pure decision ([api/_lib/forge-selfhost-recovery.js](../api/_lib/forge-selfhost-lane. Nothing here disables failover — it just stops firing it on transient404s.+## Generation success-rate health++Lane liveness ("can a worker serve right now?") is not the same as outcome+health ("are generations succeeding?"). A warm lane can still fail half its+jobs — the 404 burst above ran ~48% failure for days while every liveness probe+read healthy. The **Forge 3D generation** subsystem+([api/_lib/ops/forge-health-sensor.js](../api/_lib/ops/forge-health-sensor.js))+closes that: it reads `forge_creations` outcomes over a 6h window and reports the+success rate (`done / (done + failed)`; running/queued excluded), naming the+worst backend/path and top error class so a page is actionable. It rolls into+`/api/healthz`, `/status`, and the uptime-cron escalation. States: `ok` ≥ 85%,+`degraded` 60–85%, `down` < 60%, `unknown` below 15 finished generations+in-window. This is the forge twin of the x402 settlement-success sensor.+## Operational notes- The finalizer needs `CRON_SECRET` (standard cron auth), `DATABASE_URL`, thediff --git a/docs/ops/production-log-triage.md b/docs/ops/production-log-triage.mdindex a8ad85892..74c48d2bc 100644--- a/docs/ops/production-log-triage.md+++ b/docs/ops/production-log-triage.md@@ -31,7 +31,7 @@ var or add quota · 🟢 self-healing, no action needed.> self-reports internal-dependency health: **[/status](https://three.ws/status)**> renders it with a plain-language fix for each degradation, and> **`/api/healthz`** carries a machine-readable `subsystems` block (cache, database,-> Helius RPC, x402 ring, **x402 settlement success**, world, x402 config). The uptime cron+> Helius RPC, x402 ring, **x402 settlement success**, **Forge 3D generation**, world, x402 config). The uptime cron> ([api/cron/uptime-check.js](../../api/cron/uptime-check.js)) parks a snapshot> each tick and re-pages a degradation that persists. Source of the roll-up:> [api/_lib/ops/subsystem-health.js](../../api/_lib/ops/subsystem-health.js). Thisdiff --git a/tests/api/forge-health-sensor.test.js b/tests/api/forge-health-sensor.test.jsnew file mode 100644index 000000000..4388898cd--- /dev/null+++ b/tests/api/forge-health-sensor.test.js@@ -0,0 +1,87 @@+import { describe, it, expect } from 'vitest';+import { classifyForgeBuckets } from '../../api/_lib/ops/forge-health-sensor.js';++// The generation success-rate sensor — the outcome signal that would have caught+// the 2026-07 image→3D failure burst (~48%) that every liveness probe missed.+// Bucket shapes are the real forge_creations aggregation (status, backend, path,+// first `:`-token of error).++describe('classifyForgeBuckets — verdict from real outcome shapes', () => {+ it('reads the 502-wave burst (~52% success, image/trellis) as DOWN and names where', () => {+ const v = classifyForgeBuckets([+ { status: 'done', backend: 'nvidia', path: 'image', reason: 'none', n: 60 },+ { status: 'failed', backend: 'trellis_selfhost', path: 'image', reason: 'task not found on gcp service', n: 50 },+ { status: 'failed', backend: 'nvidia', path: 'image', reason: 'NVCF request not found or expired', n: 5 },+ { status: 'running', backend: 'nvidia', path: 'image', reason: 'none', n: 3 }, // not an outcome+ ]);+ expect(v.status).toBe('down'); // 60 / 115 = 52%+ expect(v.done).toBe(60);+ expect(v.failed).toBe(55);+ expect(v.rate).toBeCloseTo(0.52, 2);+ expect(v.worstBackend).toEqual({ backend: 'trellis_selfhost', failed: 50 });+ expect(v.worstPath).toEqual({ path: 'image', failed: 55 });+ expect(v.topReason.reason).toBe('task not found on gcp service');+ expect(v.detail).toMatch(/image path/);+ expect(v.hint).toMatch(/forge-selfhost-recovery/);+ });++ it('a 77% day reads DEGRADED', () => {+ const v = classifyForgeBuckets([+ { status: 'done', backend: 'nvidia', path: 'image', reason: 'none', n: 131 },+ { status: 'failed', backend: 'trellis_selfhost', path: 'image', reason: 'internal error', n: 39 },+ ]);+ expect(v.status).toBe('degraded'); // 131/170 = 77%+ expect(v.rate).toBeCloseTo(0.77, 2);+ });++ it('a healthy window reads OK (running/queued excluded from the rate)', () => {+ const v = classifyForgeBuckets([+ { status: 'done', backend: 'nvidia', path: 'image', reason: 'none', n: 29 },+ { status: 'failed', backend: 'nvidia', path: 'image', reason: 'internal error', n: 1 },+ { status: 'running', backend: 'nvidia', path: 'image', reason: 'none', n: 4 },+ { status: 'queued', backend: 'trellis_selfhost', path: 'image', reason: 'none', n: 2 },+ ]);+ expect(v.status).toBe('ok'); // 29/30 = 97%+ expect(v.attempts).toBe(30);+ expect(v.rate).toBeCloseTo(0.967, 2);+ });++ it('too few finished generations reads UNKNOWN and never pages', () => {+ const v = classifyForgeBuckets([+ { status: 'done', backend: 'nvidia', path: 'text', reason: 'none', n: 8 },+ { status: 'failed', backend: 'nvidia', path: 'text', reason: 'x', n: 2 },+ ]);+ expect(v.status).toBe('unknown');+ expect(v.rate).toBeNull();+ expect(v.detail).toMatch(/too few to judge/);+ });++ it('empty / malformed input is UNKNOWN, never a throw', () => {+ expect(classifyForgeBuckets([]).status).toBe('unknown');+ expect(classifyForgeBuckets(null).status).toBe('unknown');+ expect(classifyForgeBuckets(undefined).status).toBe('unknown');+ });++ it('boundary: exactly 85% is OK, just under is DEGRADED; 60% is DEGRADED, under is DOWN', () => {+ const ok = classifyForgeBuckets([+ { status: 'done', path: 'image', backend: 'nvidia', reason: 'none', n: 85 },+ { status: 'failed', path: 'image', backend: 'nvidia', reason: 'x', n: 15 },+ ]);+ expect(ok.status).toBe('ok');+ const degraded = classifyForgeBuckets([+ { status: 'done', path: 'image', backend: 'nvidia', reason: 'none', n: 84 },+ { status: 'failed', path: 'image', backend: 'nvidia', reason: 'x', n: 16 },+ ]);+ expect(degraded.status).toBe('degraded');+ const stillDegraded = classifyForgeBuckets([+ { status: 'done', path: 'image', backend: 'nvidia', reason: 'none', n: 60 },+ { status: 'failed', path: 'image', backend: 'nvidia', reason: 'x', n: 40 },+ ]);+ expect(stillDegraded.status).toBe('degraded'); // exactly 60%+ const down = classifyForgeBuckets([+ { status: 'done', path: 'image', backend: 'nvidia', reason: 'none', n: 59 },+ { status: 'failed', path: 'image', backend: 'nvidia', reason: 'x', n: 41 },+ ]);+ expect(down.status).toBe('down');+ });+});