{"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/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/embed/index.js#L69-L105","documentation":"Catch-all 500 for the public embed endpoint GET /embed/:embedId/:sessionId (chat-widget history). EmbedChats.forEmbedByUser already swallows DB errors and returns [], so the 500 almost always comes from the subsequent conversion of rows into chat history (convertToChatHistory) or a hard DB read fault — e.g. a stored chat row with a corrupt JSON payload, or the sqlite file being locked/unreadable. The embed passed middleware, so the embedId itself is valid.","triggerScenarios":"A corrupt embed_chats row for that session (truncated JSON after a crash), database file locked by another process, storage volume read-only or full, schema drift after upgrading the server without migrating the DB.","commonSituations":"Embedded chat widgets on public sites failing silently after the server was hard-killed mid-write; multi-instance deployments sharing one storage dir; visiting an old session link after a major version upgrade.","solutions":["Check server console — console.error(e.message, e) names the failing row or DB error","If a specific session's data is corrupt, delete that session's chats (DELETE /embed/:embedId/:sessionId) and start a fresh session","Confirm the storage directory is writable and not shared by two running server instances","Restore storage/anythingllm.db from backup if corruption is systemic"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":"/** The widget's history fetch either works or 500s — no partial body. */\nfunction isHistoryUnavailable(res) {\n  return res.status === 500;\n}","tryCatchPattern":"try {\n  const { history } = await fetchEmbedHistory(embedId, sessionId);\n} catch {\n  // Public widget: never surface raw errors — start from empty history and let the user retry\n  return { history: [] };\n}","preventionTips":["Embed widgets should treat history 500s as 'start fresh' and silently retry on next message","Keep sessions short-lived and clear old sessions to reduce corrupt-row exposure","Monitor server logs for recurring ENOENT/SQLITE errors from /embed routes"],"tags":["http-500","embed","chat-history","prisma","public-endpoint"],"backgroundTag":"database-query-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}