ChatGPT-in-Slack
ChatGPT-in-Slack copied to clipboard
Possible race condition: back-to-back replies when deployed in production
I've noticed that running on dev never has this problem but main_prod.py on lambda might.

The way it's designed, the reply listener triggers for first time messages as well but should early terminate — https://github.com/seratch/ChatGPT-in-Slack/blob/main/app/bolt_listeners.py#L311
But something about the way it's deployed to prod seems to be causing multiple replies sometimes
Hi @abhinavsharma, thanks for reporting this! Quick question: Are you using main_prod.py as-is or have you customized some parts of that? Especially I am curious if you're using secure parameter store and/or any additional AWS services unlike the original version's simplicity (=accessing env variables) The most possible cause of this situation would be 3 second timeout for the ack function (and those modules tend to cause cold-start issues for Lambda functions more often). In the scenario, your app's reply to an app_mention event can be repeated (in other words, Slack retries the same event delivery as your app didn't respond within 3 seconds). The message event listener skips all the message events without thread_ts inside the code. So, I don't think it can be the cause.
Don't know what is causing this but I've been noticing it too.
It might be related to timeouts. I'm deploying with serverless and the AWS gateway times out after 30 seconds and I have OPENAI_TIMEOUT_SECONDS set to 30 seconds app has a timeout of 29 seconds.
Maybe OPENAI_TIMEOUT_SECONDS needs to be less than the app timeout.
I noticed this too when running the bot from AWS Lambda. It seems that the Lambda cold start took too long, so it couldn't respond within 3 seconds. As a result, Slack resent the event. You can notice this in the x-slack-retry-num value in the event.
To fix this, I tried increasing the memory size of Lambda to 2048 MB so it's a bit faster. This seems to help. Another possible solution is to ignore the event with x-slack-retry-num >= 1