[Bots] Accidentally converted the system-bot user to a bot

Hello,
I have a selfhosted mm-instance (1), whose data I have imported with the mmctl-cli into another also selfhosted mm-instance (2).

After the successful import, however, I get the following error message in the server logs of mm-instance (2) every 5 minutes:

{
  "caller": "app/post.go:2149",
  "error": "SqlBotStore.Get: Bot does not exist., resource: Bot id: dhqs6peui3yszqhtj4ore7x68y",
  "level": "error",
  "msg": "Failed to get system bot",
  "timestamp": "2024-06-07 21:00:00.003 Z"
}

I’ve had a look in the database: There is the user system-bot (table users), but no corresponding bot in the table bots. In the mm-instance (1), however, there are system-bot users and bots. So somehow something didn’t work during the data migration, I guess. By the way, I did not create the system-bot.

Now I wanted to create the bot manually in the mm-instance (2) with the mmctl-cli and used the command “user convert --bot”, which was obviously a mistake, because now the system-bot bot exists but no longer the corresponding user. The error message has not disappeared either.

Now my question is: How can I restore the system-bot user and fix the error message in the server logs? Or can I simply delete the system-bot bot? Or have I broken the instance completely (I hope not)?

Version Mattermost Team Edition (both instances): 9.9.0
Version PostgreSQL (both instances): 13.12

Thank you very much for your help!

To resolve the issue with your Mattermost instances:

  1. Restore System-Bot User: You need to manually recreate the system-bot user in mm-instance (2). You can do this by directly adding the user back to the users table in the database, ensuring you use the same ID as before.
  2. Check Bot Table: Verify that the bot entry in the bots table corresponds to the recreated user. The bot must have a matching user ID in the users table.
  3. Delete System-Bot Bot: If you created the bot using the user convert --bot command, you can delete that bot entry in the bots table if you don’t need it. This won’t affect your instance negatively.
  4. Re-import Data: If necessary, consider re-importing the data from mm-instance (1) to ensure everything aligns correctly.
  5. Check Logs: After making these changes, monitor the server logs for any remaining errors. If the error persists, verify that both the bot and user are correctly linked in the database.

By following these steps, you should be able to restore the system-bot functionality without breaking your instance. Let me know if you need further assistance!

1 Like