fix(client): Improve resilience on transient network and auth failures - #2233
Open
dansrogers wants to merge 3 commits into
Open
fix(client): Improve resilience on transient network and auth failures#2233dansrogers wants to merge 3 commits into
dansrogers wants to merge 3 commits into
Conversation
21 tasks
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.
Summary & Overview
This pull request hardens
OverkizClientagainst transient network drops, socket timeouts, and session expirations. It adds automatic exponential backoff retry decorators toregister_event_listener(), introduces defensive error trapping inrelogin()andrefresh_listener()backoff callbacks, and ensures_event_listener_idis consistently invalidated and reset upon re-authentication.Motivation & Problem Statement
During periods of network instability or Overkiz/Somfy cloud maintenance:
register_event_listener()was only decorated with@retry_on_concurrent_requests. A socket timeout, DNS failure, or transient 401NotAuthenticatedErrorduring listener registration raised an immediate exception instead of triggering retry backoff and automated session recovery.relogin()andrefresh_listener()backoff callbacks, if a network outage was ongoing when the backoff handler fired, unhandledClientError,TimeoutError, orOSErrorexceptions crashed the backoff lifecycle prematurely._event_listener_idcould be retained, preventing clean event listener re-registration.Changes Made
register_event_listener():Decorated
register_event_listener()with@retry_on_connection_failureand@retry_on_auth_erroralongside@retry_on_concurrent_requestsinpyoverkiz/client.py.Wrapped
client.login()inrelogin()andclient.register_event_listener()inrefresh_listener()withtry/except (TimeoutError, ClientError, OSError)blocks to log warnings without terminating backoff sequences.reset_event_listener_id(self) -> NoneonOverkizClient.login()and withinrelogin()/refresh_listener()handlers.tests/test_client.pyfor retry policies onregister_event_listenerand error handling during backoff callbacks.tests/test_adversarial_transport_auth.pycovering cascading faults, prolonged outages, 502/503 server maintenance, and fast-failure on non-retryable bad credentials (BadCredentialsError).Test Coverage & Verification
prek/ruff/mypy/tychecks passed cleanly.Pre-commit & Static Analysis Verification Log
Cross-Repository Context & Companion PR
python-overkiz-api): Hardens low-level HTTP transport retries, session backoff, and event listener lifecycle management.home-assistant/core): Implements coordinator state self-healing, execution TTL cleanup (EXECUTION_TTL = 60s), and full device state resynchronization (_need_full_resync).