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(llm): tight per-lane timeout for the NVIDIA NIM queue
fudjiaa4662c0fa519
diff --git a/api/_lib/llm.js b/api/_lib/llm.jsindex ed64d545c..a0f3d42e2 100644--- a/api/_lib/llm.js+++ b/api/_lib/llm.js@@ -69,9 +69,12 @@ const NVIDIA_NEMOTRON_MODEL = 'nvidia/nvidia-nemotron-nano-9b-v2';// request far longer than a fallback rung should block the chain (observed live// 2026-07-12: 25s hang on a 900-token compose prompt while groq/openrouter// 402/429'd in <0.5s). As a fallback it gets a tight per-lane cap so the chain-// fails over to the reliable Vertex anchor in seconds; env-tunable, floored so a-// bad value can't disable the guard, and never longer than a real completion needs.-const NVIDIA_LANE_TIMEOUT_MS = Math.max(2_000, Number(process.env.NVIDIA_LANE_TIMEOUT_MS) || 6_000);+// fails over to the reliable Vertex anchor in seconds. Read per-call (not a+// load-time const) so it's tunable via env without a redeploy; floored so a bad+// value can't disable the guard.+function nvidiaLaneTimeoutMs() {+ return Math.max(2_000, Number(process.env.NVIDIA_LANE_TIMEOUT_MS) || 6_000);+}const ANTHROPIC_MODEL = 'claude-haiku-4-5-20251001';// Paid last-resort tail (see policy above). Mini keeps the backstop cheap; the// repo-wide OpenAI default (api/_lib/chat-models.js) uses the same model.@@ -263,7 +266,7 @@ export function providerChain({ anthropicKey, anthropicModel, preferNvidia = fal// When a caller opts to LEAD with NVIDIA it wants that model to produce// the result, so give the lane a longer leash than the fallback rung —// but still bounded so a NIM queue stall can't hang the whole request.- timeoutMs: Math.max(NVIDIA_LANE_TIMEOUT_MS, 15_000),+ timeoutMs: Math.max(nvidiaLaneTimeoutMs(), 15_000),}));}if (anthropicKey) chain.push(anthropicProvider(anthropicKey, anthropicModel));@@ -326,7 +329,7 @@ export function providerChain({ anthropicKey, anthropicModel, preferNvidia = fal// NIM free tier queues under load (observed hanging 25s on a 900-token// prompt while every other free lane failed fast); cap it tight so the// chain reaches the reliable Vertex anchor in seconds instead of blocking.- timeoutMs: NVIDIA_LANE_TIMEOUT_MS,+ timeoutMs: nvidiaLaneTimeoutMs(),}));}// Gemini Flash-Lite, twice: the AI Studio free tier when a key isdiff --git a/tests/api/llm.test.js b/tests/api/llm.test.jsindex d6c407f22..36b1cff30 100644--- a/tests/api/llm.test.js+++ b/tests/api/llm.test.js@@ -246,6 +246,53 @@ describe('llmComplete — a hung provider fails over within the cap, not the whodelete process.env.LLM_PER_PROVIDER_TIMEOUT_MS;}, 15_000);++ // The NVIDIA free NIM lane queues under load and was observed hanging 25s while+ // the reliable Vertex anchor sat one rung later. It carries a tight per-lane cap+ // so the chain fails over fast, independent of the (looser) chain-wide cap.+ it('the NVIDIA lane honors its tight per-provider cap and fails over fast', async () => {+ // openrouter (402, fast) → nvidia (hangs) → … → openai (paid tail, serves).+ process.env.OPENROUTER_API_KEY = 'or';+ process.env.NVIDIA_API_KEY = 'nvapi-x';+ process.env.OPENAI_API_KEY = 'sk-openai';+ process.env.NVIDIA_LANE_TIMEOUT_MS = '2000'; // its own tight cap++ const order = [];+ globalThis.fetch = vi.fn((url, opts) => {+ const u = String(url);+ if (u.includes(OPENROUTER_HOST)) {+ order.push('openrouter');+ return Promise.resolve(errResp(402, 'insufficient credits'));+ }+ if (u.includes(NVIDIA_HOST)) {+ order.push('nvidia');+ return new Promise((_, reject) => {+ opts.signal?.addEventListener('abort', () => {+ reject(Object.assign(new Error('aborted'), { name: 'AbortError' }));+ });+ });+ }+ if (u.includes(OPENAI_HOST)) {+ order.push('openai');+ return Promise.resolve(openaiShape('served by the tail'));+ }+ throw new Error(`unexpected fetch: ${u}`);+ });++ const t0 = Date.now();+ // 30s budget; the NVIDIA lane's own 2s cap must bound its hang, not the budget.+ const out = await llm.llmComplete({ system: 's', user: 'u', timeoutMs: 30_000 });+ const elapsed = Date.now() - t0;++ expect(order).toContain('nvidia'); // it was tried+ expect(out.provider).toBe('openai'); // …and the chain failed over past it+ expect(out.text).toBe('served by the tail');+ // NVIDIA hung, but its 2s cap (read per-call from env, not the 30s budget)+ // bounded the stall.+ expect(elapsed).toBeLessThan(5_000);++ delete process.env.NVIDIA_LANE_TIMEOUT_MS;+ }, 15_000);});describe('llmComplete — BYOK Anthropic leads when supplied', () => {