Skip to content

Conversation

@allenporter
Copy link
Contributor

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

Copilot AI review requested due to automatic review settings December 21, 2025 01:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SessionUnauthorizedHook callback type and unauthorized_hook parameter to MqttParams for notification of rate limit/unauthorized errors
  • Increases MAX_BACKOFF_INTERVAL from 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.

Lash-L
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
@allenporter allenporter merged commit e38bc9f into Python-roborock:main Dec 23, 2025
7 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