{"record":{"id":"11c1245db851e4b1","repo":"FlowiseAI/Flowise","slug":"error-chatmessagescontroller-removeallchatmessage-11c124","errorCode":null,"errorMessage":"Error: chatMessagesController.removeAllChatMessages - organization ${orgId} not found!","messagePattern":"Error: chatMessagesController\\.removeAllChatMessages - organization (.+?) not found!","errorType":"exception","errorClass":"InternalFlowiseError","httpStatus":404,"severity":"error","filePath":"packages/server/src/controllers/chat-messages/index.ts","lineNumber":156,"sourceCode":"        )\n        return res.json(parseAPIResponse(apiResponse))\n    } catch (error) {\n        next(error)\n    }\n}\n\nconst removeAllChatMessages = async (req: Request, res: Response, next: NextFunction) => {\n    try {\n        const appServer = getRunningExpressApp()\n        if (typeof req.params === 'undefined' || !req.params.id) {\n            throw new InternalFlowiseError(\n                StatusCodes.PRECONDITION_FAILED,\n                'Error: chatMessagesController.removeAllChatMessages - id not provided!'\n            )\n        }\n        const orgId = req.user?.activeOrganizationId\n        if (!orgId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: chatMessagesController.removeAllChatMessages - organization ${orgId} not found!`\n            )\n        }\n        const workspaceId = req.user?.activeWorkspaceId\n        if (!workspaceId) {\n            throw new InternalFlowiseError(\n                StatusCodes.NOT_FOUND,\n                `Error: chatMessagesController.removeAllChatMessages - workspace ${workspaceId} not found!`\n            )\n        }\n        const chatflowid = req.params.id\n        const chatflow = await chatflowsService.getChatflowByIdForWorkspace(req.params.id, workspaceId)\n        if (!chatflow) {\n            return res.status(404).send('Chatflow not found')\n        }\n        const flowData = chatflow.flowData\n        const parsedFlowData: IReactFlowObject = JSON.parse(flowData)","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/server/src/controllers/chat-messages/index.ts#L138-L174","documentation":"Thrown by removeAllChatMessages with HTTP 404 after the id guard passes, when orgId = req.user?.activeOrganizationId is falsy. The interpolated message reads 'organization undefined not found'. The handler then also requires a workspace (a third guard), so satisfying the org check is necessary but not sufficient. The organization id is provided by the auth/session middleware; its absence means the caller has no active org context.","triggerScenarios":"Authenticated DELETE /api/v1/chatmessage/<id> from a session whose JWT has no activeOrganizationId — user not in any org, or org claim never set.","commonSituations":"User provisioned without an org; SSO/JIT that omits org assignment; token minted without the org claim; non-enterprise deployment where this enterprise-guarded delete route is reached anyway.","solutions":["Ensure the user belongs to an organization and the session/JWT carries activeOrganizationId before clearing messages.","Have the client switch into an org, then retry.","Verify auth middleware populates activeOrganizationId; note a workspace will also be required next."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"const hasActiveOrg = (u: unknown): u is { activeOrganizationId: string } =>\n  !!u && typeof u === 'object' &&\n  typeof (u as any).activeOrganizationId === 'string' &&\n  (u as any).activeOrganizationId.length > 0","tryCatchPattern":"try {\n  await removeAllChatMessages(id)\n} catch (err) {\n  if (err?.statusCode === 404 && /organization .* not found/i.test(err.message)) {\n    await selectOrganization()\n    return removeAllChatMessages(id)\n  }\n  throw err\n}","preventionTips":["Require an active organization before enabling destructive message clears.","On 404 'organization ... not found', run org selection then retry once.","Remember a workspace guard follows, so also ensure a workspace is selected."],"tags":["authentication","session","organization","not-found","express","flowise","chat-messages"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}