Skip to content

fix: don't count unsent messages toward hourly rate limit#54

Merged
toddr merged 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-message-count-when-disconnected
Mar 20, 2026
Merged

fix: don't count unsent messages toward hourly rate limit#54
toddr merged 1 commit intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-message-count-when-disconnected

Conversation

@toddr-bot
Copy link
Collaborator

What

Move the IsConnected check before the hourly message counter increment in _send_individual_message.

Why

When the bot is disconnected, any call to SendPersonalMessage/SendGroupMessage would 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 IsConnected guard 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

  • New test t/07-test_disconnect_message_count.t: disconnects bot, sends 5 messages (all rejected), verifies the hourly counter didn't budge.
  • Full suite passes (308 tests).

🤖 Generated with Claude Code

_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 toddr marked this pull request as ready for review March 20, 2026 19:50
@toddr toddr merged commit f092474 into cpan-authors:main Mar 20, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants