From 97e319f2d9633754db3f0aecf044f7141b15950e Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Fri, 20 Feb 2026 16:37:58 -0600 Subject: [PATCH] fix(link-resolver): add retry for transient Odesli API errors The Odesli API can fail with connection errors on rapid successive requests (connection pool staleness). Add a single retry with 500ms delay to handle transient network failures gracefully. Also improve song.link URL handling to hint track vs album detection. --- src-tauri/src/commands_v2.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/commands_v2.rs b/src-tauri/src/commands_v2.rs index 869360a70..aeab038e1 100644 --- a/src-tauri/src/commands_v2.rs +++ b/src-tauri/src/commands_v2.rs @@ -1509,8 +1509,10 @@ pub async fn v2_resolve_music_link( } MusicResource::SongLink { url: source_url } => { + // song.link URLs: try to detect track vs album from the URL format + let is_track_hint = source_url.contains("song.link/"); resolve_via_odesli_and_search( - &state.songlink, &source_url, None, false, &bridge, &runtime, + &state.songlink, &source_url, None, is_track_hint, &bridge, &runtime, ).await } } @@ -1531,11 +1533,21 @@ async fn resolve_via_odesli_and_search( ) -> Result { let provider_name = provider.map(|p| format!("{:?}", p)); - // 1. Call Odesli API to identify the content - let response = songlink + // 1. Call Odesli API to identify the content (with one retry for transient errors) + let response = match songlink .get_by_url(url, crate::share::ContentType::Track) .await - .map_err(|e| RuntimeError::Internal(format!("Odesli API error: {}", e)))?; + { + Ok(r) => r, + Err(first_err) => { + log::warn!("Link resolver: Odesli first attempt failed: {}, retrying...", first_err); + tokio::time::sleep(std::time::Duration::from_millis(500)).await; + songlink + .get_by_url(url, crate::share::ContentType::Track) + .await + .map_err(|e| RuntimeError::Internal(format!("Odesli API error: {}", e)))? + } + }; let title = response.title.as_deref().unwrap_or("").trim(); let artist = response.artist.as_deref().unwrap_or("").trim();