{"record":{"id":"137a52bea9f33c17","repo":"ruvnet/ruflo","slug":"mcp-init-failed","errorCode":null,"errorMessage":"MCP init failed","messagePattern":"MCP init failed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ruflo/src/ruvocal/src/lib/wasm/wasm.worker.ts","lineNumber":266,"sourceCode":"\n\tloadPromise = (async () => {\n\t\t// TODO: load real rvagent_wasm.js via dynamic import once the static\n\t\t// bundle exposes a worker-friendly init. Mock is functionally complete\n\t\t// for the chat-ui's MCP integration test surface.\n\t\tmcpServer = createMockServer();\n\t\tgallery = createMockGallery();\n\n\t\tconst initReq = JSON.stringify({\n\t\t\tjsonrpc: \"2.0\",\n\t\t\tid: 1,\n\t\t\tmethod: \"initialize\",\n\t\t\tparams: {\n\t\t\t\tprotocolVersion: \"2024-11-05\",\n\t\t\t\tclientInfo: { name: \"ruvocal-ui-worker\", version: \"1.0.0\" },\n\t\t\t},\n\t\t});\n\t\tconst initRes = JSON.parse(mcpServer.handle_message(initReq));\n\t\tif (initRes.error) throw new Error(initRes.error.message ?? \"MCP init failed\");\n\t})();\n\n\tawait loadPromise;\n}\n\nctx.addEventListener(\"message\", async (event: MessageEvent<WorkerRequest>) => {\n\tconst { id, method, params } = event.data;\n\n\ttry {\n\t\tawait ensureLoaded();\n\t\tif (!mcpServer || !gallery) throw new Error(\"WASM not initialized\");\n\n\t\tswitch (method) {\n\t\t\tcase \"load\":\n\t\t\t\treply(id, true);\n\t\t\t\treturn;\n\n\t\t\tcase \"callMcp\": {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/ruflo/src/ruvocal/src/lib/wasm/wasm.worker.ts#L248-L284","documentation":"Fallback message thrown in the worker's ensureLoaded() when the WASM MCP server's initialize handle_message returned a JSON-RPC error whose .message is itself missing/falsy (initRes.error.message ?? \"MCP init failed\"). It indicates the initialize handshake failed inside the worker and the server did not provide a human-readable reason.","triggerScenarios":"Worker constructs the (mock) MCP server, sends the initialize JSON-RPC frame, and the parsed response has an error object with no message field — e.g. { error: { code: -32603 } } — so the nullish-coalescing falls through to the generic string.","commonSituations":"Worker WASM/glue version skew; the mock mcpServer.handle_message throws internally and the wrapper produces a code-only error; protocolVersion or clientInfo shape rejected without a descriptive message; worker memory/resource limits causing an opaque failure.","solutions":["Log the full initRes object (code + data) before the throw to recover the real reason.","Confirm protocolVersion \"2024-11-05\" and clientInfo { name, version } match the server's expectations.","Rebuild the worker glue and WASM binary together so handle_message's error contract is consistent.","If the underlying cause is transient (worker cold-start under load), retry ensureLoaded once before surfacing the error."],"exampleFix":"// before\nconst initRes = JSON.parse(mcpServer.handle_message(initReq));\nif (initRes.error) throw new Error(initRes.error.message ?? \"MCP init failed\");\n// after\nconst initRes = JSON.parse(mcpServer.handle_message(initReq));\nif (initRes.error) {\n  throw new Error(`MCP init failed: ${initRes.error.message ?? `code=${initRes.error.code} data=${JSON.stringify(initRes.error.data)}`}`);\n}","handlingStrategy":"try-catch","validationCode":"const PROTOCOL = \"2024-11-05\";\nfunction validInitParams(p: unknown): boolean {\n  return (\n    !!p &&\n    typeof (p as { protocolVersion?: string }).protocolVersion === \"string\" &&\n    typeof (p as { clientInfo?: { name?: string; version?: string } }).clientInfo?.name === \"string\" &&\n    typeof (p as { clientInfo?: { name?: string; version?: string } }).clientInfo?.version === \"string\"\n  );\n}\nif (!validInitParams({ protocolVersion: PROTOCOL, clientInfo: { name: \"ruvocal-ui-worker\", version: \"1.0.0\" } })) {\n  throw new Error(\"invalid initialize params\");\n}","typeGuard":"function hasRpcError(r: unknown): r is { error: { code?: number; message?: string; data?: unknown } } {\n  return typeof r === \"object\" && r !== null && \"error\" in (r as object) && typeof (r as { error: unknown }).error === \"object\";\n}","tryCatchPattern":"try {\n  await ensureLoaded();\n} catch (e) {\n  const msg = String((e as Error)?.message ?? e);\n  if (msg === \"MCP init failed\" || msg.startsWith(\"MCP init failed\")) {\n    // re-load the worker module once, then surface a richer error with initRes.error.code\n    await reloadWorker();\n    await ensureLoaded();\n  } else throw e;\n}","preventionTips":["Log the full initRes.error (code + data) before throwing so opaque failures become diagnosable.","Rebuild worker glue and WASM binary from the same commit so the error contract is stable.","Retry ensureLoaded once after a worker reload before surfacing failure to the user."],"tags":["wasm","worker","mcp","initialization","rpc"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}