{"record":{"id":"469815f579ee5761","repo":"Mintplex-Labs/anything-llm","slug":"cannot-update-a-preset-to-use-a-command-that-match","errorCode":null,"errorMessage":"Cannot update a preset to use a command that matches a system command","messagePattern":"Cannot update a preset to use a command that matches a system command","errorType":"http","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"server/endpoints/system.js","lineNumber":1353,"sourceCode":"        response.status(500).json({ message: \"Internal server error\" });\n      }\n    }\n  );\n\n  app.post(\n    \"/system/slash-command-presets/:slashCommandId\",\n    [validatedRequest, flexUserRoleValid([ROLES.all])],\n    async (request, response) => {\n      try {\n        const user = await userFromSession(request, response);\n        const { slashCommandId } = request.params;\n        const { command, prompt, description } = reqBody(request);\n        const formattedCommand = SlashCommandPresets.formatCommand(\n          String(command)\n        );\n\n        if (isReservedCommand(formattedCommand)) {\n          return response.status(400).json({\n            message:\n              \"Cannot update a preset to use a command that matches a system command\",\n          });\n        }\n\n        // Valid user running owns the preset if user session is valid.\n        const ownsPreset = await SlashCommandPresets.get({\n          userId: user?.id ?? null,\n          id: Number(slashCommandId),\n        });\n        if (!ownsPreset)\n          return response.status(404).json({ message: \"Preset not found\" });\n\n        const updates = {\n          command: formattedCommand,\n          prompt: String(prompt),\n          description: String(description),\n        };","sourceCodeStart":1335,"sourceCodeEnd":1371,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/endpoints/system.js#L1335-L1371","documentation":"Thrown by PUT /system/slash-command-presets/:slashCommandId when the submitted command, after normalization by SlashCommandPresets.formatCommand (lowercase, leading '/', invalid chars replaced with '-'), equals a key of VALID_COMMANDS (the built-in system commands loaded from server/utils/chats). The 400 response prevents user presets from shadowing reserved commands like /reset or /exit. This is a business-rule rejection, not a library error.","triggerScenarios":"PUT /system/slash-command-presets/12 with body {\"command\": \"reset\", ...} — formatCommand turns it into \"/reset\", which exists in VALID_COMMANDS, so the endpoint returns 400 before touching the database. Any casing/spacing variant (\"Reset\", \"/RESET\", \"re set\") normalizes into the same collision.","commonSituations":"Renaming a preset to a short common word that happens to match a system command; importing preset packs from the community hub whose commands collide with built-ins; frontend forms that don't validate against the reserved list before submit.","solutions":["Pick a different command name that is not one of the built-in system commands (check Object.keys(VALID_COMMANDS) in server/utils/chats/index.js).","Add a prefix to make it unique, e.g. '/my-reset' instead of '/reset'.","In the UI, validate the formatted command client-side against the system command list before enabling Save."],"exampleFix":"// before\nawait fetch(`/system/slash-command-presets/${id}`, {\n  method: 'PUT',\n  body: JSON.stringify({ command: 'reset', prompt, description }),\n});\n\n// after\nconst formatted = `/${String(command).toLowerCase().replace(/[^a-z0-9_-]/g, '-')}`;\nif (SYSTEM_COMMANDS.includes(formatted)) {\n  showToast(`\"${formatted}\" is reserved — choose another name`);\n  return;\n}\nawait fetch(`/system/slash-command-presets/${id}`, {\n  method: 'PUT',\n  body: JSON.stringify({ command: formatted, prompt, description }),\n});","handlingStrategy":"validation","validationCode":"const CMD_REGEX = /[^a-zA-Z0-9_-]/g;\nconst formatCommand = (c) => `/${String(c).toLowerCase().replace(CMD_REGEX, '-')}`.replace(/^\\/\\/+/, '/');\nconst isSystemCommand = (c, systemCommands) => systemCommands.includes(formatCommand(c));\n// systemCommands = Object.keys(VALID_COMMANDS) fetched from the backend/system list","typeGuard":"function isSafePresetCommand(command, systemCommands) {\n  if (typeof command !== 'string' || command.length < 2) return false;\n  return !systemCommands.includes(formatCommand(command));\n}","tryCatchPattern":null,"preventionTips":["Mirror the server's formatCommand normalization client-side so validation matches what the backend will compute.","Keep the system-command list in shared config instead of duplicating it in the frontend.","Suggest a prefixed name (e.g. /my-*) when the chosen command collides."],"tags":["slash-commands","presets","validation","reserved-names"],"backgroundTag":"reserved-name-conflict","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-09-01T05:04:15.951Z","contentChangedAt":"2026-09-01T05:04:15.951Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}