{"record":{"id":"c9857f502134cb6a","repo":"abhigyanpatwari/GitNexus","slug":"initembedder-should-not-be-called-in-http-mode","errorCode":null,"errorMessage":"initEmbedder() should not be called in HTTP mode. Use embedText()/embedBatch() which handle HTTP transparently.","messagePattern":"initEmbedder\\(\\) should not be called in HTTP mode\\. Use embedText\\(\\)/embedBatch\\(\\) which handle HTTP transparently\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus/src/core/embeddings/embedder.ts","lineNumber":74,"sourceCode":" */\nexport const getCurrentDevice = (): 'dml' | 'cuda' | 'cpu' | 'wasm' | null => currentDevice;\n\n/**\n * Initialize the embedding model\n * Uses singleton pattern - only loads once, subsequent calls return cached instance\n *\n * @param onProgress - Optional callback for model download progress\n * @param config - Optional configuration override\n * @param forceDevice - Force a specific device\n * @returns Promise resolving to the embedder pipeline\n */\nexport const initEmbedder = async (\n  onProgress?: ModelProgressCallback,\n  config: Partial<EmbeddingConfig> = {},\n  forceDevice?: 'dml' | 'cuda' | 'cpu' | 'wasm',\n): Promise<FeatureExtractionPipeline> => {\n  if (isHttpMode()) {\n    throw new Error(\n      'initEmbedder() should not be called in HTTP mode. ' +\n        'Use embedText()/embedBatch() which handle HTTP transparently.',\n    );\n  }\n\n  // Fail fast on platforms where the bundled native ONNX Runtime binding is not\n  // shipped (macOS Intel, #1515). Must run before any transformers.js /\n  // onnxruntime-node import or resolution — otherwise the native module load\n  // crashes with a raw \"Cannot find module ...onnxruntime_binding.node\" that\n  // ONNX_WEB_BACKEND=wasm cannot rescue (#1516). HTTP mode was already handled\n  // above, so this only blocks the local-runtime path.\n  const runtimeBlocker = getLocalEmbeddingRuntimeBlocker();\n  if (runtimeBlocker) {\n    throw new Error(runtimeBlocker);\n  }\n\n  // Return existing instance if available\n  if (embedderInstance) {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus/src/core/embeddings/embedder.ts#L56-L92","documentation":"Thrown by initEmbedder() when isHttpMode() is true — i.e. both GITNEXUS_EMBEDDING_URL and GITNEXUS_EMBEDDING_MODEL are set. In HTTP mode the local ONNX Runtime pipeline is intentionally never loaded; embedText() and embedBatch() detect HTTP mode internally and dispatch to httpEmbed() transparently. Calling initEmbedder() would bypass that and try to load a native model, so it is rejected at the top of the function before any native import.","triggerScenarios":"Any code path that calls initEmbedder() (or the MCP embedder entry point that mirrors it) while GITNEXUS_EMBEDDING_URL and GITNEXUS_EMBEDDING_MODEL are both exported. Typically a custom integration or a forked analyze flow that unconditionally initializes the local pipeline without checking isHttpMode() first.","commonSituations":"A user sets the two HTTP env vars to route embeddings through an OpenAI-compatible endpoint but has a wrapper script that still calls initEmbedder(); migrating from local to HTTP mode and forgetting to remove the init call; an MCP client that calls both init and embed.","solutions":["Replace initEmbedder() calls with embedText()/embedBatch() — they handle both HTTP and local modes.","If you must branch, gate on isHttpMode() from http-client.js and skip init in HTTP mode.","Run `gitnexus embeddings status` or check the two env vars to confirm which mode you are in."],"exampleFix":"// before\nconst pipe = await initEmbedder();\nconst vec = await embedText(text);\n// after — no init needed in either mode\nconst vec = await embedText(text);","handlingStrategy":"type-guard","validationCode":"import { isHttpMode } from 'gitnexus/src/core/embeddings/http-client.js';\n// Never call initEmbedder() in HTTP mode.\nif (!isHttpMode()) {\n  await initEmbedder(onProgress);\n}","typeGuard":"import { isHttpMode } from 'gitnexus/src/core/embeddings/http-client.js';\nconst shouldUseLocalPipeline = (): boolean => !isHttpMode();","tryCatchPattern":null,"preventionTips":["Prefer embedText()/embedBatch() over initEmbedder()+getEmbedder() — they work in both modes.","If you call initEmbedder(), gate it on !isHttpMode().","Run `gitnexus embeddings status` to confirm which mode is active."],"tags":["embeddings","http-mode","api-misuse"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}