Retry MusicBrainz work search instead of reporting an outage as no re… - #223
Merged
Merged
Conversation
…sults
MusicBrainz sheds load with a 503 ("The MusicBrainz web server is currently
busy") a few percent of the time. search_works_multi was the one fetch in
the client with no retry: it called raise_for_status(), the HTTPError fell
into the broad RequestException handler, and the caller got an empty list.
The route then returned a healthy 200 with zero results, so the app told
users the song did not exist in MusicBrainz whenever the service hiccuped.
Backend:
- Add MusicBrainzUnavailable, raised only after the retry budget is spent.
- Give the work search three attempts with 1s/2s backoff, shorter than the
importers' 2s/4s because a user is waiting on a search sheet. Retry 503,
429, timeouts and connection errors; do not retry other 4xx, which are
our own bad query.
- Return 503 from /musicbrainz/works/search when MusicBrainz is unreachable,
keeping 200-with-empty-results to mean "answered, no matches".
- Fix the apostrophe normalization next to it. It read replace("'", "'")
with ASCII on both sides, an editor autocorrect having flattened the curly
one, so it did nothing. Now maps the five variants using \u escapes, as
normalize_title already does.
Apps:
- searchMusicBrainzWorks returns MusicBrainzSearchResult rather than
collapsing every failure into an empty array.
- Both search sheets gain a "Search Unavailable" state with Try Again,
distinct from the empty state that links out to musicbrainz.org.
Old app builds are unaffected: they already treated any non-200 as an empty
result, and they pick up the server-side retry without changing.
Tests: eight cases covering persistent 503, transient 503, timeout, genuine
empty result, un-retried 400, the apostrophe substitution, and both route
status codes.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
…sults
MusicBrainz sheds load with a 503 ("The MusicBrainz web server is currently busy") a few percent of the time. search_works_multi was the one fetch in the client with no retry: it called raise_for_status(), the HTTPError fell into the broad RequestException handler, and the caller got an empty list. The route then returned a healthy 200 with zero results, so the app told users the song did not exist in MusicBrainz whenever the service hiccuped.
Backend:
Apps:
Old app builds are unaffected: they already treated any non-200 as an empty result, and they pick up the server-side retry without changing.
Tests: eight cases covering persistent 503, transient 503, timeout, genuine empty result, un-retried 400, the apostrophe substitution, and both route status codes.