{"record":{"id":"a556da8cd01d8d6b","repo":"Mintplex-Labs/anything-llm","slug":"resolvedmode-is-not-a-valid-mode-a556da","errorCode":null,"errorMessage":"${resolvedMode} is not a valid mode.","messagePattern":"(.+?) is not a valid mode\\.","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"server/endpoints/api/workspaceThread/index.js","lineNumber":435,"sourceCode":"        });\n        if (!thread) {\n          response.status(404).json({\n            id: uuidv4(),\n            type: \"abort\",\n            textResponse: null,\n            sources: [],\n            close: true,\n            error: `Thread ${threadSlug} not found.`,\n          });\n          return;\n        }\n\n        const resolvedMode = mode ?? workspace.chatMode;\n        if (\n          (!message?.length || !VALID_CHAT_MODE.includes(resolvedMode)) &&\n          !reset\n        ) {\n          response.status(400).json({\n            id: uuidv4(),\n            type: \"abort\",\n            textResponse: null,\n            sources: [],\n            close: true,\n            error: !message?.length\n              ? \"Message is empty\"\n              : `${resolvedMode} is not a valid mode.`,\n          });\n          return;\n        }\n\n        const user = userId ? await User.get({ id: Number(userId) }) : null;\n        const result = await ApiChatHandler.chatSync({\n          workspace,\n          message,\n          mode: resolvedMode,\n          user,","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/api/workspaceThread/index.js#L417-L453","documentation":"HTTP 400 from POST /api/v1/workspace/:slug/thread/:threadSlug/chat when the effective mode (request mode ?? workspace.chatMode) is outside VALID_CHAT_MODE = ['automatic','chat','query']. Because the fallback reads the workspace's stored chatMode, the request can be well-formed and still fail if the workspace row holds a stale value.","triggerScenarios":"mode:'agent' sent by legacy clients; mode omitted while the workspace's chatMode column contains an outdated/invalid value from an older AnythingLLM build; case or whitespace mismatches like 'Query'.","commonSituations":"Upgrading an instance with old workspaces; code samples predating the 'automatic' mode; hand-edited database rows.","solutions":["Send mode explicitly as 'automatic', 'chat', or 'query'","If omitting mode, repair the workspace's chatMode via the workspace update endpoint","Validate mode against the allowed list before sending","After instance upgrades, run a quick chat against each workspace to smoke-test stored modes"],"exampleFix":"// before\nbody: JSON.stringify({ message, mode: 'agent' })\n// after\nconst MODES = ['automatic', 'chat', 'query'];\nbody: JSON.stringify({ message, mode: MODES.includes(mode) ? mode : 'chat' })","handlingStrategy":"type-guard","validationCode":"const VALID = ['automatic', 'chat', 'query'];\nconst body = { message, mode: VALID.includes(mode) ? mode : 'chat' };","typeGuard":"function isValidChatMode(m) { return ['automatic', 'chat', 'query'].includes(m); }","tryCatchPattern":null,"preventionTips":["Always set mode explicitly in API calls","If mode omitted and this error fires, repair the workspace's stored chatMode","Keep the allowed list in shared client code"],"tags":["anythingllm","developer-api","workspace-thread","chat","chat-mode","http-400","enum-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}