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
fix(studio): timed-out generations return a pollable handle, not an error
nirholas600018ee9287
diff --git a/api/_mcp-studio/forge-client.js b/api/_mcp-studio/forge-client.jsindex 24dbbd4f9..54dd23fed 100644--- a/api/_mcp-studio/forge-client.js+++ b/api/_mcp-studio/forge-client.js@@ -203,21 +203,25 @@ export async function pollJob(base, jobId, { timeoutMs, intervalMs } = {}) {}// Run a submit→poll cycle end to end, returning the terminal job payload.+// A timed-out payload keeps `job_id` so the caller can hand the (still+// running) job back to the client as a pollable handle instead of an error.export async function generate(base, submitArgs, { timeoutEnv } = {}) {const job = await startForge(base, submitArgs);if (job.status === 'done' && job.glb_url) return job;- return pollJob(base, job.job_id, {+ const out = await pollJob(base, job.job_id, {timeoutMs: timeoutEnv ? envNum(timeoutEnv, DEFAULT_TIMEOUT_MS) : DEFAULT_TIMEOUT_MS,intervalMs: envNum('STUDIO_POLL_MS', DEFAULT_POLL_MS),});+ return out._timedOut ? { ...out, job_id: job.job_id } : out;}export async function rig(base, glbUrl, { timeoutEnv } = {}) {const job = await startRig(base, glbUrl);- return pollJob(base, job.job_id, {+ const out = await pollJob(base, job.job_id, {timeoutMs: timeoutEnv ? envNum(timeoutEnv, DEFAULT_TIMEOUT_MS) : DEFAULT_TIMEOUT_MS,intervalMs: envNum('STUDIO_POLL_MS', DEFAULT_POLL_MS),});+ return out._timedOut ? { ...out, job_id: job.job_id } : out;}// IBM Granite prompt director. Rewrites a rough idea into a tight single-subjectdiff --git a/api/_mcp-studio/gpt-forge-client.js b/api/_mcp-studio/gpt-forge-client.jsindex 73ec6d01f..1f30c0a2d 100644--- a/api/_mcp-studio/gpt-forge-client.js+++ b/api/_mcp-studio/gpt-forge-client.js@@ -189,21 +189,25 @@ export async function pollJob(base, jobId, { timeoutMs, intervalMs } = {}) {}// Run a submit→poll cycle end to end, returning the terminal job payload.+// A timed-out payload keeps `job_id` so the caller can hand the (still+// running) job back to the client as a pollable handle instead of an error.export async function generate(base, submitArgs, { timeoutEnv } = {}) {const job = await startForge(base, submitArgs);if (job.status === 'done' && job.glb_url) return job;- return pollJob(base, job.job_id, {+ const out = await pollJob(base, job.job_id, {timeoutMs: timeoutEnv ? envNum(timeoutEnv, DEFAULT_TIMEOUT_MS) : DEFAULT_TIMEOUT_MS,intervalMs: envNum('STUDIO_POLL_MS', DEFAULT_POLL_MS),});+ return out._timedOut ? { ...out, job_id: job.job_id } : out;}export async function rig(base, glbUrl, { timeoutEnv } = {}) {const job = await startRig(base, glbUrl);- return pollJob(base, job.job_id, {+ const out = await pollJob(base, job.job_id, {timeoutMs: timeoutEnv ? envNum(timeoutEnv, DEFAULT_TIMEOUT_MS) : DEFAULT_TIMEOUT_MS,intervalMs: envNum('STUDIO_POLL_MS', DEFAULT_POLL_MS),});+ return out._timedOut ? { ...out, job_id: job.job_id } : out;}// IBM Granite prompt director. Rewrites a rough idea into a tight single-subjectdiff --git a/api/_mcp-studio/tools.js b/api/_mcp-studio/tools.jsindex d38701b7e..4d503da18 100644--- a/api/_mcp-studio/tools.js+++ b/api/_mcp-studio/tools.js@@ -7,8 +7,11 @@// anchored to the prior model, returning a revertable/branchable version lineage.// Responses carry ONLY what a client needs// to show the model — a GLB URL, a viewer link, the kind, and the prompt — with-// every internal identifier (job id, creation id, prediction id, backend name,-// trace) stripped, per OpenAI's data-minimization policy. Each tool links the+// every internal identifier (creation id, prediction id, backend name, trace)+// stripped, per OpenAI's data-minimization policy. One deliberate exception:+// a job that outlives the inline wait budget returns its PUBLIC poll handle+// (the same job token the auth-free /api/forge REST lane hands any anonymous+// caller) — without it the still-running work would be unreachable. Each tool links the// Apps SDK widget via _meta["openai/outputTemplate"] and returns structuredContent// the widget renders. No coin, token, wallet, or payment surface anywhere.@@ -130,6 +133,30 @@ function toolError(message) {};}+// Success envelope for a job that outlived the inline wait budget but IS still+// running. This used to be an error, which threw away real work: with the+// self-host TRELLIS lane as forge primary a generation takes 4-6 minutes, the+// inline wait is 3, so every hosted studio call "failed" while its model+// quietly finished minutes later and the caller never learned. The job handle+// is public (the free /api/forge poll endpoint takes it with no auth), so hand+// it over and let the caller collect the result.+function pendingResult({ base, jobId, what, prompt }) {+ const pollUrl = `${base}/api/forge?job=${encodeURIComponent(jobId)}`;+ const message =+ `The ${what} is still rendering (heavier scenes take a few minutes). ` ++ `It keeps running — poll ${pollUrl} until status is "done", then use its glb_url ` ++ `(view at ${base}/viewer?src=<glb_url>).`;+ return {+ content: [{ type: 'text', text: message }],+ structuredContent: {+ status: 'pending',+ jobId,+ pollUrl,+ ...(prompt ? { prompt } : {}),+ },+ };+}+// Success envelope for a conversational refinement. Carries the same minimal,// identifier-free fields as ok() PLUS the version lineage the widget renders as// a version strip. The lineage is the durable record the client passes back on@@ -259,6 +286,7 @@ async function handleForgeFree(args, _auth, req) {} catch (err) {return toolError(failureMessage(err));}+ if (job._timedOut && job.job_id) return pendingResult({ base, jobId: job.job_id, what: 'model', prompt });if (job._timedOut || !job.glb_url) return toolError('Generation is taking longer than expected. Please try again.');return ok({ glbUrl: job.glb_url, base, kind: 'model', prompt, referenceImageUrl: job.preview_image_url });}@@ -296,6 +324,7 @@ async function handleTextToAvatar(args, _auth, req) {} catch (err) {return toolError(failureMessage(err));}+ if (job._timedOut && job.job_id) return pendingResult({ base, jobId: job.job_id, what: 'avatar', prompt: prompt || undefined });if (job._timedOut || !job.glb_url) return toolError('Generation is taking longer than expected. Please try again.');return ok({ glbUrl: job.glb_url, base, kind: 'avatar', prompt: prompt || undefined, referenceImageUrl: job.preview_image_url });}@@ -347,6 +376,7 @@ async function handleMeshForge(args, _auth, req) {} catch (err) {return toolError(failureMessage(err));}+ if (job._timedOut && job.job_id) return pendingResult({ base, jobId: job.job_id, what: 'mesh', prompt: prompt || undefined });if (job._timedOut || !job.glb_url) return toolError('Generation is taking longer than expected. Please try again.');return ok({ glbUrl: job.glb_url, base, kind: 'mesh', prompt: prompt || undefined, referenceImageUrl: job.preview_image_url });}@@ -366,6 +396,7 @@ async function handleRigMesh(args, _auth, req) {} catch (err) {return toolError(failureMessage(err));}+ if (job._timedOut && job.job_id) return pendingResult({ base, jobId: job.job_id, what: 'rigged model' });if (job._timedOut || !job.glb_url) return toolError('Rigging is taking longer than expected. Please try again.');return ok({ glbUrl: job.glb_url, base, kind: 'rigged model', rigged: true });}@@ -406,6 +437,7 @@ async function handleForgeAvatar(args, _auth, req) {} catch (err) {return toolError(failureMessage(err));}+ if (gen._timedOut && gen.job_id) return pendingResult({ base, jobId: gen.job_id, what: 'avatar mesh (rig it with rig_mesh once done)', prompt: prompt || undefined });if (gen._timedOut || !gen.glb_url) return toolError('Generation is taking longer than expected. Please try again.');// Stage 2 — auto-rig the generated mesh.@@ -431,6 +463,7 @@ async function handleForgeAvatar(args, _auth, req) {},};}+ if (rigged._timedOut && rigged.job_id) return pendingResult({ base, jobId: rigged.job_id, what: 'avatar rig', prompt: prompt || undefined });if (rigged._timedOut || !rigged.glb_url) return toolError('Rigging is taking longer than expected. Please try again.');return ok({ glbUrl: rigged.glb_url, base, kind: 'avatar', prompt: prompt || undefined, rigged: true, referenceImageUrl: gen.preview_image_url });}@@ -514,6 +547,7 @@ async function handleRefineModel(args, _auth, req) {} catch (err) {return toolError(failureMessage(err));}+ if (job._timedOut && job.job_id) return pendingResult({ base, jobId: job.job_id, what: 'refined model', prompt: prompt || undefined });if (job._timedOut || !job.glb_url) return toolError('Refinement is taking longer than expected. Please try again.');const lineage = appendVersion(baseLineage, {diff --git a/tests/mcp-studio-pending.test.js b/tests/mcp-studio-pending.test.jsnew file mode 100644index 000000000..4e5cbed60--- /dev/null+++ b/tests/mcp-studio-pending.test.js@@ -0,0 +1,71 @@+// A studio generation that outlives the inline wait budget must return a+// pollable pending handle, never an error.+//+// With FORGE_SELFHOST_PRIMARY set in production, the free forge lane runs on+// self-host TRELLIS at 4-6 minutes per model while the studio's inline wait is+// 3 minutes (STUDIO_FORGE_TIMEOUT_MS default 180s) — so every hosted+// forge_free call answered "Generation is taking longer than expected" while+// its model quietly completed minutes later and the caller never learned the+// job existed. The timed-out path now carries the job_id forward and the tool+// hands back { status: 'pending', jobId, pollUrl } as a SUCCESS result; the+// /api/forge?job= poll endpoint is public, so the handle is directly usable.++import { describe, it, expect, vi } from 'vitest';++vi.mock('../api/_mcp-studio/gpt-forge-client.js', async (importOriginal) => {+ const real = await importOriginal();+ return {+ ...real,+ // Generation submits fine but outlives the wait budget: the shape+ // generate() returns after the pollJob deadline with the job_id attached.+ generate: vi.fn(async () => ({ status: 'processing', _timedOut: true, job_id: 'job-abc123' })),+ rig: vi.fn(async () => ({ status: 'processing', _timedOut: true, job_id: 'rig-xyz789' })),+ // The prompt director is irrelevant here; keep it inert.+ directPrompt: vi.fn(async () => null),+ };+});++import { dispatch } from '../api/_mcp-studio/dispatch.js';++const req = { headers: { host: 'three.ws', 'x-forwarded-proto': 'https' } };++async function call(name, args) {+ const res = await dispatch(+ { jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name, arguments: args } },+ {},+ req,+ );+ return res.result;+}++describe('studio pending handles', () => {+ it('forge_free returns a pollable pending result instead of an error', async () => {+ const result = await call('forge_free', { prompt: 'a red ceramic teapot with gold trim' });++ expect(result.isError).toBeFalsy();+ expect(result.structuredContent.status).toBe('pending');+ expect(result.structuredContent.jobId).toBe('job-abc123');+ expect(result.structuredContent.pollUrl).toBe('https://three.ws/api/forge?job=job-abc123');+ expect(result.content[0].text).toContain('still rendering');+ expect(result.content[0].text).toContain(result.structuredContent.pollUrl);+ });++ it('rig_mesh returns a pollable pending result instead of an error', async () => {+ const result = await call('rig_mesh', { glb_url: 'https://three.ws/cdn/models/example.glb' });++ expect(result.isError).toBeFalsy();+ expect(result.structuredContent).toMatchObject({+ status: 'pending',+ jobId: 'rig-xyz789',+ pollUrl: 'https://three.ws/api/forge?job=rig-xyz789',+ });+ });++ it('still errors when the timeout carries no job handle', async () => {+ const { generate } = await import('../api/_mcp-studio/gpt-forge-client.js');+ generate.mockResolvedValueOnce({ _timedOut: true });++ const result = await call('forge_free', { prompt: 'a small wooden rowboat' });+ expect(result.isError).toBe(true);+ });+});