{"record":{"id":"a8a78b6483aa38a1","repo":"Mintplex-Labs/anything-llm","slug":"internal-server-error-a8a78b","errorCode":null,"errorMessage":"Internal Server Error","messagePattern":"Internal Server Error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/embed/index.js","lineNumber":87,"sourceCode":"  app.get(\n    \"/embed/:embedId/:sessionId\",\n    [validEmbedConfig],\n    async (request, response) => {\n      try {\n        const { sessionId } = request.params;\n        const embed = response.locals.embedConfig;\n        const history = await EmbedChats.forEmbedByUser(\n          embed.id,\n          sessionId,\n          null,\n          null,\n          true\n        );\n\n        response.status(200).json({ history: convertToChatHistory(history) });\n      } catch (e) {\n        console.error(e.message, e);\n        response.sendStatus(500).end();\n      }\n    }\n  );\n\n  app.delete(\n    \"/embed/:embedId/:sessionId\",\n    [validEmbedConfig],\n    async (request, response) => {\n      try {\n        const { sessionId } = request.params;\n        const embed = response.locals.embedConfig;\n\n        await EmbedChats.markHistoryInvalid(embed.id, sessionId);\n        response.status(200).end();\n      } catch (e) {\n        console.error(e.message, e);\n        response.sendStatus(500).end();\n      }","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/endpoints/embed/index.js#L69-L105","documentation":"HTTP 500 from the catch-all of GET /embed/:embedId/:sessionId (public embed chat-history retrieval). EmbedChats.forEmbedByUser wraps Prisma in try/catch and returns [] on failure, so the realistic escape is convertToChatHistory throwing on a malformed embed chat row. The embed config itself is already validated by the validEmbedConfig middleware, so a missing embed yields a different (404/403) response, not this 500.","triggerScenarios":"An embed widget requests history for a sessionId whose stored chat row has a corrupt or unparsable JSON payload; or the DB drops during the query in a way that escapes the model's catch.","commonSituations":"Long-lived embed sessions whose rows predate a schema change; partial writes from a browser that disconnected mid-stream; storage-level corruption on the embed_chats table.","solutions":["Check the server log for the convertToChatHistory stack trace to locate the bad row.","Clear the affected session's history via DELETE /embed/:embedId/:sessionId (markHistoryInvalid) so the widget starts fresh.","If recurring, audit the embed_chats table for rows with NULL or non-JSON chat columns and repair them.","Verify DB connectivity if the error coincides with other DB-bound failures."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Embed history is best-effort — confirm the embed/session before relying on history.\nasync function safeEmbedHistory(embedBaseUrl, embedId, sessionId) {\n  const res = await fetch(`${embedBaseUrl}/embed/${embedId}/${sessionId}`);\n  if (!res.ok) return { history: [] };\n  return res.json();\n}","typeGuard":null,"tryCatchPattern":"// Embed widgets should treat a 500 as 'no recoverable history' and start fresh.\ntry {\n  const res = await fetch(`${embedBaseUrl}/embed/${embedId}/${sessionId}`);\n  if (res.ok) return await res.json();\n} catch (e) { /* network */ }\nreturn { history: [] }; // degrade silently for end users","preventionTips":["Treat embed history as non-critical: render an empty state on failure rather than blocking the widget.","Clear a persistently-failing session via DELETE /embed/:embedId/:sessionId so users get a clean slate.","Monitor for corrupt embed_chats rows after upgrades."],"tags":["embed","chat-history","data-corruption","express","api"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}