{"record":{"id":"56774cb6902fb902","repo":"Mintplex-Labs/anything-llm","slug":"internal-server-error-56774c","errorCode":null,"errorMessage":"Internal Server Error","messagePattern":"Internal Server Error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/api/workspaceThread/index.js","lineNumber":106,"sourceCode":"          workspace,\n          userId ? Number(userId) : null,\n          { name, slug }\n        );\n\n        await Telemetry.sendTelemetry(\"workspace_thread_created\", {\n          multiUserMode: multiUserMode(response),\n          LLMSelection: process.env.LLM_PROVIDER || \"openai\",\n          Embedder: process.env.EMBEDDING_ENGINE || \"inherit\",\n          VectorDbSelection: process.env.VECTOR_DB || \"lancedb\",\n          TTSSelection: process.env.TTS_PROVIDER || \"native\",\n        });\n        await EventLogs.logEvent(\"api_workspace_thread_created\", {\n          workspaceName: workspace?.name || \"Unknown Workspace\",\n        });\n        response.status(200).json({ thread, message });\n      } catch (e) {\n        console.error(e.message, e);\n        response.sendStatus(500).end();\n      }\n    }\n  );\n\n  app.post(\n    \"/v1/workspace/:slug/thread/:threadSlug/update\",\n    [validApiKey],\n    async (request, response) => {\n      /*\n      #swagger.tags = ['Workspace Threads']\n      #swagger.description = 'Update thread name by its unique slug.'\n      #swagger.parameters['slug'] = {\n          in: 'path',\n          description: 'Unique slug of workspace',\n          required: true,\n          type: 'string'\n      }\n      #swagger.parameters['threadSlug'] = {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/endpoints/api/workspaceThread/index.js#L88-L124","documentation":"Returned by POST /v1/workspace/:slug/thread/new when WorkspaceThread.new, Telemetry.sendTelemetry, or EventLogs.logEvent throws after the workspace is successfully found. The handler at server/endpoints/api/workspaceThread/index.js:104 catches errors from the thread creation pipeline. WorkspaceThread.new creates a Prisma record in the workspace_threads table — it can fail on DB constraints (duplicate slug if a custom thread slug collides with an existing one). As with error 585, if Telemetry.sendTelemetry throws after the thread is created, the thread exists in the DB but the client sees a 500 — a silent partial-success state.","triggerScenarios":"POST /v1/workspace/valid-slug/thread/new with a body `slug` value that already exists for a thread in the same workspace (unique constraint violation). Also when userId references a non-existent user (the code passes userId to WorkspaceThread.new which creates the thread with a foreign key to users — if the user does not exist, the FK constraint fires). When Telemetry.sendTelemetry throws due to network restrictions. When EventLogs.logEvent fails (DB issue). In single-user mode, passing a userId is nullified (line 85), but in multi-user mode an invalid userId is passed through.","commonSituations":"Air-gapped deployments where telemetry is blocked, causing the thread to be created but the response to be 500. Passing a custom thread slug that duplicates an existing thread slug in the same workspace. Passing a userId that was deleted or never existed (FK violation). Database connection issues during the Prisma create.","solutions":["Check server logs to determine whether WorkspaceThread.new, Telemetry.sendTelemetry, or EventLogs.logEvent threw.","If providing a custom thread `slug` in the body, ensure it is unique within the workspace.","If providing a `userId`, ensure it references a valid user (in multi-user mode): GET /v1/users to verify.","After a 500, check if the thread was actually created via GET /v1/workspace/:slug — it may exist as a partial-success artifact.","If telemetry is the culprit, disable telemetry events if your environment blocks outbound network calls.","Omit the body `slug` to let WorkspaceThread.new auto-generate a unique slug."],"exampleFix":"// before — custom slug that may collide\nawait fetch('/v1/workspace/my-ws/thread/new', {\n  method: 'POST',\n  body: JSON.stringify({ slug: 'my-thread', userId: 999 })\n});\n\n// after — let the system generate the slug, verify userId exists\nawait fetch('/v1/workspace/my-ws/thread/new', {\n  method: 'POST',\n  body: JSON.stringify({ name: 'My Thread' })\n});","handlingStrategy":"validation","validationCode":"// Validate thread creation body and verify workspace/user exist\nasync function validateThreadCreation(slug, body, apiKey) {\n  const wsRes = await fetch('/v1/workspaces', { headers: { Authorization: `Bearer ${apiKey}` } });\n  const { workspaces } = await wsRes.json();\n  if (!workspaces.some(w => w.slug === slug))\n    return { valid: false, error: 'Workspace not found' };\n  if (body.slug) {\n    // Custom slugs risk collision — warn the caller\n    console.warn('Custom thread slug provided — ensure it is unique within the workspace');\n  }\n  if (body.userId != null && typeof body.userId !== 'number')\n    return { valid: false, error: 'userId must be a number' };\n  return { valid: true };\n}","typeGuard":null,"tryCatchPattern":"try {\n  const check = await validateThreadCreation(slug, body, API_KEY);\n  if (!check.valid) throw new Error(check.error);\n  const res = await fetch(`/v1/workspace/${slug}/thread/new`, {\n    method: 'POST',\n    headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${API_KEY}` },\n    body: JSON.stringify(body)\n  });\n  if (res.status === 500) {\n    // CRITICAL: thread may have been created before telemetry threw.\n    // Verify via workspace thread listing\n    throw new Error('Thread creation may have partially succeeded — verify via GET endpoint');\n  }\n  return await res.json();\n} catch (e) { console.error(e); }","preventionTips":["After a 500 on thread creation, verify via GET /v1/workspace/:slug whether the thread was partially created.","Disable telemetry in air-gapped/firewalled environments to prevent telemetry-throws from masking successful operations.","Omit the body `slug` to let the system auto-generate a unique thread slug, avoiding collision errors.","If providing userId, verify it references a valid user in multi-user mode.","Do not confuse the workspace slug (URL param) with the thread slug (body param)."],"tags":["workspace-thread","express","anythingllm","telemetry","partial-success","prisma"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}