fix: don't count unsent messages toward hourly rate limit#54
Merged
toddr merged 1 commit intocpan-authors:mainfrom Mar 20, 2026
Merged
Conversation
_send_individual_message was incrementing the hourly message counter before checking IsConnected. Messages attempted during disconnection inflated the counter without actually being sent, which could exhaust the hourly limit and block legitimate messages after reconnection. Move the IsConnected check before the counter increment so only messages that actually reach the server count toward the limit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
toddr
approved these changes
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Move the
IsConnectedcheck before the hourly message counter increment in_send_individual_message.Why
When the bot is disconnected, any call to
SendPersonalMessage/SendGroupMessagewould increment the hourly counter even though the message never reaches the server. After reconnection, the inflated counter could exhaust the hourly limit (max_messages_per_hour) and block legitimate messages — the bot thinks it's been chatty, but it hasn't said a word.How
Moved the
IsConnectedguard to the top of_send_individual_message(after the basic param checks), before the counter logic. Only messages that pass the connection check now count toward the hourly limit.Testing
t/07-test_disconnect_message_count.t: disconnects bot, sends 5 messages (all rejected), verifies the hourly counter didn't budge.🤖 Generated with Claude Code