Add a hook for handling background rate limit errors#695
Merged
allenporter merged 2 commits intoPython-roborock:mainfrom Dec 23, 2025
Merged
Add a hook for handling background rate limit errors#695allenporter merged 2 commits intoPython-roborock:mainfrom
allenporter merged 2 commits intoPython-roborock:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a callback hook mechanism for handling MQTT unauthorized/rate-limit errors and increases the maximum backoff interval from 30 minutes to 6 hours to better handle persistent authentication issues.
Key Changes:
- Adds
SessionUnauthorizedHookcallback type andunauthorized_hookparameter toMqttParamsfor notification of rate limit/unauthorized errors - Increases
MAX_BACKOFF_INTERVALfrom 30 minutes to 6 hours, allowing the background reconnection loop to back off more aggressively for persistent failures - Invokes the hook when MQTT code 135 (unauthorized) is received, and sets backoff to maximum to prevent rapid retry attempts
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| roborock/mqtt/session.py | Defines the SessionUnauthorizedHook type alias and adds the unauthorized_hook field to MqttParams with documentation |
| roborock/mqtt/roborock_session.py | Updates max backoff interval to 6 hours, stores the hook from params, invokes it when unauthorized errors occur, and adds error-specific diagnostics |
| roborock/devices/device_manager.py | Adds mqtt_session_unauthorized_hook parameter to create_device_manager and propagates it to MQTT params |
| tests/mqtt/test_roborock_session.py | Refactors MQTT client fixtures for better testability and adds tests for unauthorized hook behavior during initial connection and reconnection |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b689326 to
ceb5548
Compare
Lash-L
previously approved these changes
Dec 23, 2025
When a rate limit error is received the background loop will jump to the maximum backoff (now 6 hours) and will also invoke a callback so that the caller can decide to re-authenticate or stop harder. The new backoff follows this trajectory, where the change in behavior is introduced after 15 attempts: - attempt 1: wait 10 seconds - attempt 5: waits 50 seconds - attempt 7: waits 2 minutes - attempt 10: waits 6 minutes - attempt 15: waits 32 minutes - attempt 17: waits 2 hours - attempt 20: waits 6 hours
ceb5548 to
c2e7086
Compare
Lash-L
approved these changes
Dec 23, 2025
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.
When a rate limit error is received the background loop will jump to the maximum backoff (now 6 hours) and will also invoke a callback so that the caller can decide to re-authenticate or stop harder.
The new backoff follows this trajectory, where the change in behavior is introduced after 15 attempts: