feat(rpc): add bounded retry for transient GET failures - #104
Merged
Conversation
CiderRpcClient._request previously made a single HTTP attempt per Cider call, so transient local failures (Cider restarting, brief network hiccup) turned into user-visible errors even for idempotent reads. Add a small, bounded retry that mirrors the existing historian retry pattern (cider_retry_count setting, injectable sleep, exponential backoff 0.1 * 2**attempt). Only safe, idempotent GET requests are retried; POST writes (play, next, volume, queue) and 4xx client errors are never retried. Transient failures are connection errors and 5xx server errors; the failure callback now fires once after retries are exhausted rather than per attempt. Closes #85.
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
Closes #85.
CiderRpcClient._requestmade a single HTTP attempt per Cider call, so transient local failures (Cider restarting, a brief network hiccup) turned into user-visible errors even for idempotent reads likeGETplayback status. This adds a small, bounded retry for transient failures on safe read methods.Behavior
5xxserver errors) using exponential backoff (0.1 * 2**attempt), up tocider_retry_countretries (default2, for 3 total attempts).run_amapi_v3POSTs (including catalog/library searches) are stateful and not known to be idempotent, so a retry could duplicate a side effect.failure_callbacknow fires once after retries are exhausted, rather than per attempt, so a transient blip doesn't flood failure reports.Implementation
This mirrors the existing retry pattern in
vesper/historian.py(HttpHistorianSink):cider_retry_count: int = Field(default=2, ge=0)setting inSettings, surfaced insanitized(), analogous tohistorian_retry_count.CiderRpcClient.__init__takes an injectablesleep: Callable[[float], None](defaults totime.sleep) so tests run without real delays._requestwraps a single-attempt helper_send_once. A private_TransientRequestErrorsignals retriable failures (connection errors + 5xx); definitive failures (4xx, non-JSON) raiseCiderRpcErrorimmediately from_send_once.Test commands run
13 new tests in
tests/test_rpc.pycover: GET retry on connection error / 5xx then success, retry exhaustion, exponential backoff timing, POST never retried (connection error and 5xx), 4xx never retried, 204 handling, single failure-callback invocation after exhaustion, andcider_retry_count=0disabling retries.