feat: an unreachable track can no longer stop playback
Two owner requirements, one shape: something that cannot play must be skipped, and cleaned when there is nowhere left to skip to. The causes are outside our control — Qobuz withdraws a track overnight, or a local/Plex file sits on a share this network cannot see today. THE FUNNEL, which is where the real gap was. `play_current_if_local` returned a bool whose two `false`s meant opposite things: "not my row, run the Qobuz path" and "my row, and it cannot play". The caller could only act on the first, so an unreachable local file fell through to the Qobuz tier-walk, failed there with an unrelated error, and `auto_skip_unavailable` then declined it as non-terminal. One dead file stopped playback silently. It is now a three-state `LocalPlay`, and a local failure takes the SAME bounded walk a pulled Qobuz track takes — to the user they are the same event. CLEANING. Both dead ends of that walk (budget spent, queue edge) now call `purge_unavailable_upcoming`, which drops only rows `queue_track_unavailable` already refuses to play, walking backwards so a removal cannot shift an index still to be visited. A track on an unreachable share can never land there: it is Unreachable, not dead. PROBES THAT CANNOT HANG (`qbz-library/src/reachability.rs`, 4 tests). The machinery for network shares already existed — mount_info, `library_folders.is_network`, a populated `local_tracks.is_network_mount`, even an unreachable-folder guard in scan.rs. Every one of them probed with a bare blocking syscall, and a mounted-but-unreachable share does not make `exists()`/`read_dir()` fail, it makes them BLOCK for the mount's timeout. The guards could not fire; scan.rs hung on the very condition it existed to detect. Three states, not two, and that distinction is the whole safety property: `Missing` is the filesystem saying the file is gone and may be cleaned; `Unreachable` is it saying nothing, and may only ever be skipped. Collapsing them — which a bare `exists()` does — would delete a user's NAS library because they changed networks. The deadline goes on the PROBE only, never the transfer: a hi-res FLAC over a working-but-slow share legitimately takes longer than any probe budget, and timing the read out would turn "your network is slow" into "this track is gone". A blocked syscall cannot be cancelled, so a timed-out probe leaks its thread; the mount is therefore remembered with a cool-down, one probe per dead mount rather than one per track, which on a 2000-row queue is the difference between a defence and a thread bomb. PERSISTENCE. `busy_timeout=1000` on all 18 store pragmas. Deliberately NOT the 2-3s discussed: these writes run on the Qt thread, so a 3s wait would install exactly the stall this whole sweep has been removing, while today's 0 means contention loses a setting silently and instantly. One second resolves transient contention without a visible stall. `home_bridge::ui` announces both of its silent failure modes. Three builds went into proving it was NOT dropping the Home document during the launch freeze; one warn line would have answered it in one. Verified against the owner's real session state (1935-row queue): the app launches to a painted Discover with no QML errors and no dropped publishes. cc
This commit is contained in:
25 files changed
+408
-45
No files matched your search
@@ -394,9 +394,27 @@ static QT_THREAD: OnceLock<CxxQtThread<QbzHome>> = OnceLock::new();
|
||||
|
||||
/// Queue a home-bridge mutation onto the Qt event loop (no-op before
|
||||
/// boot registers the thread).
|
||||
/// Queue a home-bridge mutation onto the Qt event loop.
|
||||
///
|
||||
/// BOTH failure modes are announced, and that is not cosmetic. This function
|
||||
/// could previously lose a publish two different silent ways — an unregistered
|
||||
/// thread dropped the closure, and a failed `queue()` was swallowed by
|
||||
/// `let _ =` — so a document that never reached the UI looked exactly like a
|
||||
/// document that was never built. Three builds went into proving that was NOT
|
||||
/// what was happening during the 2026-08-17 launch freeze; a single warn line
|
||||
/// would have answered it in one.
|
||||
pub(crate) fn ui(f: impl FnOnce(Pin<&mut QbzHome>) + Send + 'static) {
|
||||
if let Some(thread) = QT_THREAD.get() {
|
||||
let _ = thread.queue(f);
|
||||
match QT_THREAD.get() {
|
||||
Some(thread) => {
|
||||
if thread.queue(f).is_err() {
|
||||
log::warn!(
|
||||
"[qbz-qt] home bridge: a publish was REJECTED by the Qt queue and is lost"
|
||||
);
|
||||
}
|
||||
}
|
||||
None => log::warn!(
|
||||
"[qbz-qt] home bridge: a publish was DROPPED — boot() has not registered the Qt thread yet"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ pub use crate::local_artwork::{fetch_plex_misses, resolve_window_blocking, Artwo
|
||||
|
||||
// --- playback --------------------------------------------------------------
|
||||
pub use crate::local_playback::{
|
||||
enqueue, local_queue_track, play_album, play_current_if_local, play_folder, play_folder_track,
|
||||
enqueue, local_queue_track, play_album, play_current_if_local, LocalPlay, play_folder, play_folder_track,
|
||||
play_local_file, play_plex_track, play_tracks_visible,
|
||||
};
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ use std::sync::Arc;
|
||||
|
||||
use qbz_app::shell::AppRuntime;
|
||||
use qbz_core::LoggingAdapter;
|
||||
use qbz_library::LocalTrack;
|
||||
use qbz_library::{LocalTrack, Reach};
|
||||
use qbz_models::QueueTrack;
|
||||
|
||||
use crate::local_albums::fetch_album_tracks_blocking;
|
||||
@@ -271,18 +271,42 @@ pub async fn play_local_file(runtime: &Runtime, row_id: u64) -> bool {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// BOUNDED PROBE, then an unbounded read — and the split is the whole
|
||||
// point. A mounted-but-unreachable share (the user is on a different
|
||||
// network today) does not make `exists()` fail, it makes it BLOCK for the
|
||||
// mount's timeout, so this await could never return: playing one dead file
|
||||
// wedged playback with no way out. The probe now stops WAITING.
|
||||
//
|
||||
// The READ deliberately keeps no deadline. A hi-res FLAC over a
|
||||
// working-but-slow share legitimately takes longer than any probe budget,
|
||||
// and timing the transfer out would turn "your network is slow today" into
|
||||
// "this track is gone" — worse than the bug being fixed.
|
||||
let read_path = path.clone();
|
||||
let bytes = tokio::task::spawn_blocking(move || {
|
||||
if !Path::new(&read_path).exists() {
|
||||
return None;
|
||||
}
|
||||
std::fs::read(&read_path).ok()
|
||||
let (reach, bytes) = tokio::task::spawn_blocking(move || {
|
||||
let reach = qbz_library::probe_default(Path::new(&read_path));
|
||||
let bytes = if reach == Reach::Present {
|
||||
std::fs::read(&read_path).ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
(reach, bytes)
|
||||
})
|
||||
.await
|
||||
.ok()
|
||||
.flatten();
|
||||
.unwrap_or((Reach::Unreachable, None));
|
||||
let Some(bytes) = bytes else {
|
||||
log::error!("[qbz-qt] local play: file not available at {path} (drive unmounted?)");
|
||||
// Missing and Unreachable are NOT the same answer and must not be
|
||||
// logged as one. `Missing` is the filesystem saying the file is gone —
|
||||
// a caller may clean on it. `Unreachable` is the filesystem saying
|
||||
// NOTHING; the file may be perfectly fine on a share this network
|
||||
// cannot see, so it may only ever be SKIPPED.
|
||||
match reach {
|
||||
Reach::Unreachable => log::warn!(
|
||||
"[qbz-qt] local play: {path} did not answer — share unreachable from this network; skipping, NOT removing"
|
||||
),
|
||||
_ => log::error!(
|
||||
"[qbz-qt] local play: file not available at {path} (drive unmounted?)"
|
||||
),
|
||||
}
|
||||
return false;
|
||||
};
|
||||
if let Err(e) = runtime.core().player().play_data(bytes, row_id) {
|
||||
@@ -437,22 +461,54 @@ async fn play_audible(runtime: &Runtime, track: &QueueTrack) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// Source-aware AUDIBLE step for the shared poll-loop advance: when the
|
||||
/// CURRENT queue track is a local file or a Plex row, play it here and report
|
||||
/// true; otherwise report false so the Qobuz tier-walk runs unchanged.
|
||||
/// What the local/Plex audible step did with a queue row.
|
||||
///
|
||||
/// This used to be a `bool`, and the two `false`s meant OPPOSITE things: "this
|
||||
/// row is not mine, go run the Qobuz walk" and "this row IS mine and it cannot
|
||||
/// play". The caller could only treat both as the first, so a local file on a
|
||||
/// share that had gone away fell through to the Qobuz tier-walk, failed there
|
||||
/// with an unrelated error ("No Qobuz client available"), and
|
||||
/// `auto_skip_unavailable` then declined to skip because that error is not
|
||||
/// terminal-unavailable. Net effect: one unreachable local file stopped
|
||||
/// playback dead, silently — the exact shape of "a track that cannot play must
|
||||
/// never be blocking".
|
||||
pub enum LocalPlay {
|
||||
/// Not a local/Plex row. The Qobuz path must run, unchanged.
|
||||
NotLocal,
|
||||
/// Playing.
|
||||
Played,
|
||||
/// Ours, and it cannot play. Carries a reason phrased so the shared skip
|
||||
/// walk recognises it as terminal (see `is_terminal_unavailable`).
|
||||
Unavailable(String),
|
||||
}
|
||||
|
||||
/// Source-aware AUDIBLE step for the shared poll-loop advance.
|
||||
///
|
||||
/// Without this seam, auto-advance to the next local/Plex track goes down
|
||||
/// `play_track_resolved` and fails with "No Qobuz client available".
|
||||
pub async fn play_current_if_local(runtime: &Runtime, track_id: u64) -> bool {
|
||||
pub async fn play_current_if_local(runtime: &Runtime, track_id: u64) -> LocalPlay {
|
||||
let Some(qt) = runtime.core().current_track().await else {
|
||||
return false;
|
||||
return LocalPlay::NotLocal;
|
||||
};
|
||||
if qt.id != track_id {
|
||||
return false;
|
||||
return LocalPlay::NotLocal;
|
||||
}
|
||||
match qt.source.as_deref() {
|
||||
Some("local") | Some("plex") => play_audible(runtime, &qt).await,
|
||||
_ => false,
|
||||
Some("local") | Some("plex") => {
|
||||
if play_audible(runtime, &qt).await {
|
||||
LocalPlay::Played
|
||||
} else {
|
||||
// The wording is load-bearing: `is_terminal_unavailable`
|
||||
// matches on "no longer available", which is what routes this
|
||||
// into the SAME bounded skip walk a pulled Qobuz track takes.
|
||||
// One seam for both, which is the point — to the user they are
|
||||
// the same failure.
|
||||
LocalPlay::Unavailable(format!(
|
||||
"local file no longer available (track {track_id})"
|
||||
))
|
||||
}
|
||||
}
|
||||
_ => LocalPlay::NotLocal,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -338,7 +338,7 @@ fn queue_track_blacklisted(track: &QueueTrack) -> bool {
|
||||
/// LOCAL / Plex rows can never be dropped here, and that is not luck: their
|
||||
/// builder (`local_playback::local_queue_track`) sets `streamable: true`
|
||||
/// because a file on disk is outside Qobuz's streaming rights entirely.
|
||||
fn queue_track_unavailable(track: &QueueTrack) -> bool {
|
||||
pub(crate) fn queue_track_unavailable(track: &QueueTrack) -> bool {
|
||||
// Clause 2 (D3): a track the player already found terminally unavailable
|
||||
// THIS RUN counts as dead even while the API keeps advertising it as
|
||||
// streamable — which is the owner's test case exactly, since `/album/get`
|
||||
@@ -1979,10 +1979,26 @@ async fn play_queue_track(
|
||||
// Source-aware audible step: a LOCAL file plays from disk through the
|
||||
// player's play_data seam. The Qobuz tier-walk below needs a client and
|
||||
// would fail with "No Qobuz client available" on every local advance.
|
||||
if crate::local_library_qt::play_current_if_local(runtime, track_id).await {
|
||||
refresh_now_playing(runtime).await;
|
||||
publish_queue(runtime).await;
|
||||
return;
|
||||
// ONE seam for both kinds of "cannot play". A local/Plex row that fails
|
||||
// must NOT fall through to the Qobuz walk below: it would fail there with
|
||||
// an unrelated error, `auto_skip_unavailable` would decline it as
|
||||
// non-terminal, and playback would stop dead on one unreachable file. To
|
||||
// the user a withdrawn Qobuz track and a file on a share that went away
|
||||
// are the same event, so they take the same bounded skip walk.
|
||||
match crate::local_library_qt::play_current_if_local(runtime, track_id).await {
|
||||
crate::local_playback::LocalPlay::Played => {
|
||||
refresh_now_playing(runtime).await;
|
||||
publish_queue(runtime).await;
|
||||
return;
|
||||
}
|
||||
crate::local_playback::LocalPlay::Unavailable(reason) => {
|
||||
log::warn!("[qbz-qt] playback: {reason} — skipping");
|
||||
refresh_now_playing(runtime).await;
|
||||
publish_queue(runtime).await;
|
||||
auto_skip_unavailable(runtime, reason, Some(track_id)).await;
|
||||
return;
|
||||
}
|
||||
crate::local_playback::LocalPlay::NotLocal => {}
|
||||
}
|
||||
if let Err(e) =
|
||||
play_resolved_offline_aware(runtime, track_id, start_position_secs)
|
||||
@@ -2076,13 +2092,18 @@ fn auto_skip_unavailable<'a>(
|
||||
crate::toast_qt::warning(qbz_i18n::t("No available tracks to play"));
|
||||
crate::now_playing::set_playing(false);
|
||||
UNAVAILABLE_SKIPS.store(0, Ordering::SeqCst);
|
||||
// Nowhere left to skip TO, so clean rather than leave the user a
|
||||
// queue of rows that each stop playback when reached.
|
||||
crate::queue_qt::purge_unavailable_upcoming(runtime).await;
|
||||
return;
|
||||
}
|
||||
let Some(track) = runtime.core().next_track().await else {
|
||||
// Queue edge reached while skipping — stop quietly, the warning
|
||||
// above already told the user why.
|
||||
// above already told the user why. Same clean-up as the budget
|
||||
// arm: the rows behind us cannot play either.
|
||||
crate::now_playing::set_playing(false);
|
||||
UNAVAILABLE_SKIPS.store(0, Ordering::SeqCst);
|
||||
crate::queue_qt::purge_unavailable_upcoming(runtime).await;
|
||||
return;
|
||||
};
|
||||
log::info!(
|
||||
|
||||
@@ -650,6 +650,45 @@ pub async fn remove_upcoming(runtime: &Arc<AppRuntime<LoggingAdapter>>, page_ind
|
||||
publish(runtime).await;
|
||||
}
|
||||
|
||||
/// Drop every UPCOMING row that cannot play, and report how many went.
|
||||
///
|
||||
/// The last half of "an unavailable track is never blocking": it is skipped,
|
||||
/// and when there is nowhere left to skip TO, the dead rows are cleaned out
|
||||
/// rather than left for the user to walk into one at a time. Called only from
|
||||
/// the dead ends of the skip walk — the budget running out, or the queue edge
|
||||
/// being reached — never speculatively.
|
||||
///
|
||||
/// Walks BACKWARDS so each removal cannot shift an index still to be visited.
|
||||
///
|
||||
/// It removes what `queue_track_unavailable` already refuses to play, so this
|
||||
/// can only delete rows that were unplayable anyway — never a track that is
|
||||
/// merely on a share this network cannot see, because an unreachable local row
|
||||
/// is `Unreachable`, not dead, and never enters that predicate.
|
||||
pub async fn purge_unavailable_upcoming(runtime: &Arc<AppRuntime<LoggingAdapter>>) -> usize {
|
||||
let doomed: Vec<usize> = {
|
||||
let state = runtime.core().get_queue_state_full().await;
|
||||
state
|
||||
.upcoming
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, t)| crate::playback_qt::queue_track_unavailable(t))
|
||||
.map(|(i, _)| i)
|
||||
.collect()
|
||||
};
|
||||
if doomed.is_empty() {
|
||||
return 0;
|
||||
}
|
||||
for index in doomed.iter().rev() {
|
||||
runtime.core().remove_upcoming_track(*index).await;
|
||||
}
|
||||
log::info!(
|
||||
"[qbz-qt] queue: purged {} unplayable upcoming row(s)",
|
||||
doomed.len()
|
||||
);
|
||||
publish(runtime).await;
|
||||
doomed.len()
|
||||
}
|
||||
|
||||
pub async fn remove_all_after(runtime: &Arc<AppRuntime<LoggingAdapter>>, page_index: usize) {
|
||||
let Some(&upcoming_index) = current_page_indices(runtime).await.get(page_index) else {
|
||||
log::warn!("[qbz-qt] queue: remove_all_after {page_index} out of range");
|
||||
|
||||
Reference in new issue
Block a user