From 006e535909545f29b23867f61cdeb933120fd149 Mon Sep 17 00:00:00 2001 From: Gleb Linnik Date: Tue, 17 Nov 2026 18:17:40 +0300 Subject: [PATCH] Play Version and Also available act on a pick again: a closing surface no longer blocks its page's command Since #1392 a page's app command runs at the head of the dispatcher FIFO, in the drain ahead of the frame's NAV COMMIT. Play Version and Also available are surfaces that close on a pick and report the row to their Detail page (`Fx::Nav(Dismiss)`, then a delivery to the page), and the page answers with `ContentReq::Play` / `ContentReq::Present`. That dismissal is only PARKED until the commit, so `content_command`'s gate, `input_owner() == Entry(sender)`, still saw the closing surface holding input and answered `Refused`: the panel closed and nothing played or opened. Before #1392 the commands ran after the frame's commit and never met the closing surface. The five page-command gates (content, Home, Search, Watchlist, Library) now ask one read-only question of the dispatcher, `input_owner_after_dismissals`: who holds input once the Dismiss ops already parked commit. A surface that stays open still covers its page, so the covered-page refusal and RetiredSender for a dead sender are unchanged, and nothing about the FIFO, its order or its hashed state moves. Tests: the reporter's Play Version case and the Also available picker through the real dispatcher and runner (both Refused before, Completed after), a page under a picker that stays open still refused, and the container query itself. Closes #1424 Co-Authored-By: Claude Sonnet 5.5 --- rust-modules/src/app/content.rs | 24 ++- rust-modules/src/app/detail_panel_tests.rs | 237 +++++++++++++++++++++ rust-modules/ui/src/containers/mod.rs | 8 +- rust-modules/ui/src/containers/modal.rs | 8 +- rust-modules/ui/src/containers/tests.rs | 26 +++ rust-modules/ui/src/dispatch.rs | 13 ++ 6 files changed, 307 insertions(+), 9 deletions(-) diff --git a/rust-modules/src/app/content.rs b/rust-modules/src/app/content.rs index 206d3d530f..e2057d4618 100644 --- a/rust-modules/src/app/content.rs +++ b/rust-modules/src/app/content.rs @@ -578,6 +578,18 @@ pub(crate) fn content_requests(app: &mut App, fr: &mut Frame) { bridge.metadata_view(), bridge.marker_preferences()); } +/// **May the page `entry`'s command run now?** Only the page that holds input acts: a page a +/// surface still covers, or a page beneath another, is refused (a command it queued before it was +/// covered must not navigate for it). A surface whose own `Dismiss` is already parked counts as +/// closed. The FIFO runner executes a head in the drain, ahead of NAV COMMIT, so a picker that +/// closes on its pick and reports to its page (*Play Version*, *Also available*) has only PARKED its +/// dismissal when the page's command for that pick arrives. Before the runner (#1392) these gates ran +/// after the frame's commit and never saw the closing surface; asked of the container alone they +/// refused the pick (#1424). One answer for the five page-command families below. +fn holds_input(pages: &plx_ui::dispatch::Dispatcher, entry: EntryId) -> bool { + pages.input_owner_after_dismissals() == Some(InputOwner::Entry(entry)) +} + fn halt_screen_preview(app: &mut ScreenCommandApp<'_, '_>) { halt_preview_now(&mut app.player.session, &mut app.adapters.player); } @@ -590,7 +602,7 @@ fn content_command(app: &mut ScreenCommandApp<'_, '_>, source: MachineId, reques let _ = now; let MachineId::Instance(instance) = source else { return AppCommandOutcome::Refused }; let Some(entry) = app.pages.nav.entry_of_instance(instance) else { return AppCommandOutcome::RetiredSender }; - if app.pages.nav.input_owner() != Some(InputOwner::Entry(entry)) { return AppCommandOutcome::Refused; } + if !holds_input(app.pages, entry) { return AppCommandOutcome::Refused; } match request { ContentReq::Push(arg) => { halt_screen_preview(app); @@ -742,7 +754,7 @@ fn home_command(app: &mut ScreenCommandApp<'_, '_>, source: MachineId, request: use plx_machine::machine::AppCommandOutcome; let MachineId::Instance(instance) = source else { return AppCommandOutcome::Refused }; let Some(entry) = app.pages.nav.entry_of_instance(instance) else { return AppCommandOutcome::RetiredSender }; - if app.pages.nav.input_owner() != Some(InputOwner::Entry(entry)) || app.route() != AppArg::Home { + if !holds_input(app.pages, entry) || app.route() != AppArg::Home { return AppCommandOutcome::Refused; } match request { @@ -813,8 +825,7 @@ pub(crate) fn execute_search_command( use plx_screens::registry::SearchReq; let MachineId::Instance(instance) = source else { return AppCommandOutcome::Refused }; let Some(entry) = pages.nav.entry_of_instance(instance) else { return AppCommandOutcome::RetiredSender }; - if pages.top_arg() != Some(&AppArg::Search) - || pages.nav.input_owner() != Some(InputOwner::Entry(entry)) { return AppCommandOutcome::Refused; } + if pages.top_arg() != Some(&AppArg::Search) || !holds_input(pages, entry) { return AppCommandOutcome::Refused; } match &request { SearchReq::Back => bridge::nav_tab(pages, rig, HomeTab::Home, None, Some(ret)), SearchReq::Tab(tab) => { @@ -863,8 +874,7 @@ pub(crate) fn execute_watchlist_command( let Some(entry) = pages.nav.entry_of_instance(instance) else { return AppCommandOutcome::RetiredSender }; // Options come from a surface over the page, so its live sender need not be the page. if !matches!(request, WatchlistOut::SetOptions(_)) - && (pages.top_arg() != Some(&AppArg::Watchlist) - || pages.nav.input_owner() != Some(InputOwner::Entry(entry))) { + && (pages.top_arg() != Some(&AppArg::Watchlist) || !holds_input(pages, entry)) { return AppCommandOutcome::Refused; } watchlist_request(pages, rig, entry, request, ret); @@ -987,7 +997,7 @@ fn library_command(app: &mut ScreenCommandApp<'_, '_>, source: MachineId, library_publish_shelves(app.pages, app.bridge, entry, target, hidden_page, at_head); return AppCommandOutcome::Completed; } - if app.pages.nav.input_owner() != Some(InputOwner::Entry(entry)) || !app.route().is_library_family() { + if !holds_input(app.pages, entry) || !app.route().is_library_family() { return AppCommandOutcome::Refused; } if let Some(ret) = library_navigation(app.pages, app.bridge, &request, ret) { diff --git a/rust-modules/src/app/detail_panel_tests.rs b/rust-modules/src/app/detail_panel_tests.rs index dc6868fa34..d3b1cd1279 100644 --- a/rust-modules/src/app/detail_panel_tests.rs +++ b/rust-modules/src/app/detail_panel_tests.rs @@ -210,3 +210,240 @@ fn an_alt_sources_anchor_travels_on_its_arg() { "and the same anchor is the same state" ); } + + +// ---- a pick that closes its panel (#1424) ---------------------------------------------------- +// +// *Play Version* and *Also available* are surfaces that close on a pick and REPORT the row to the +// Detail page that opened them (`Fx::Nav(Dismiss)`, then a delivery to the page). The page answers +// with an app command, and the FIFO runner (#1392) gates every page command on "the sender holds +// input". The surface's own dismissal is only parked until NAV COMMIT, so that gate saw the closing +// surface still holding input and refused the page: the panel closed and nothing played, or opened. + +/// What each app command asked and how the runner ended it, read off the dispatcher's own tap: the +/// runner's terminal outcome, not a copy of it. A command's `Fx::App` effect is tapped as it leaves +/// the FIFO, and the runner holds exactly one command at a time, so the next `command_done` is that +/// command's. +#[derive(Default)] +struct PickTap { + last: Option, + /// `(what was asked, who asked, how it ended)`, in the order the runner finished them. + commands: Vec<(Asked, MachineId, plx_machine::machine::AppCommandOutcome)>, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +enum Asked { + Play(Option), + Present(plx_plex::plex::ServerId, String), + /// Any other app command, named by family: not what these tests grade, but a failure prints it. + /// (The Play Version page also asks for a hero `PreviewStart` while the panel covers it; that one + /// IS refused, rightly, before and after the fix: a covered page starts nothing.) + Other(&'static str), +} + +impl plx_ui::dispatch::Tap for PickTap { + fn effect(&mut self, _: u64, stamped: &plx_machine::machine::Stamped) { + use plx_screens::registry::{AppFx, ContentArg, ContentReq, PlayIntent}; + if let Fx::App(app) = &stamped.fx { + self.last = Some(match app { + AppFx::Content(ContentReq::Play { play, .. }) => Asked::Play(match play { + PlayIntent::Item { version, .. } | PlayIntent::Movie { version, .. } => *version, + }), + AppFx::Content(ContentReq::Present(ContentArg::Detail { sid, rk })) => Asked::Present(*sid, rk.clone()), + AppFx::Content(ContentReq::PreviewStart { .. }) => Asked::Other("content:PreviewStart"), + AppFx::Content(_) => Asked::Other("content"), + AppFx::Store(..) => Asked::Other("store"), + _ => Asked::Other("app"), + }); + } + } + fn command_done(&mut self, _: u64, _: plx_machine::machine::AppCommandId, from: MachineId, + outcome: plx_machine::machine::AppCommandOutcome) { + let asked = self.last.take().unwrap_or(Asked::Other("none")); + self.commands.push((asked, from, outcome)); + } +} + +impl PickTap { + /// How the commands `host` asked that equal `asked` ended, in order. + fn ended(&self, host: InstanceId, asked: &Asked) -> Vec { + self.commands.iter() + .filter(|(what, from, _)| what == asked && *from == MachineId::Instance(host)) + .map(|(_, _, outcome)| *outcome) + .collect() + } + + /// Every command of the run, for a failure message. + fn account(&self) -> String { + format!("{:?}", self.commands) + } +} + +/// One key (both edges) and the frames after it, through the product frame with `tap` watching. +/// No `goto`: a pick that enters the player must not be walked back to the page by the driver. +fn pick_key(d: &mut Dispatcher, rig: &mut Bridge, t: &mut u32, key: Key, tap: &mut PickTap) { + *t += 1; + let at = tick(*t); + super::frame_with_tap(d, rig, at, script_key(key, at), tap); + pick_frames(d, rig, t, 28, tap); +} + +fn pick_frames(d: &mut Dispatcher, rig: &mut Bridge, t: &mut u32, n: u32, tap: &mut PickTap) { + for _ in 0..n { + *t += 1; + super::frame_with_tap(d, rig, tick(*t), vec![], tap); + } +} + +fn page_instance(d: &Dispatcher) -> InstanceId { + d.nav.top_page().and_then(|e| e.inst.as_ref()).expect("the page mounted").id +} + +/// **Play Version, the reporter's case (#1424):** a title with two versions, the panel open, the +/// second row picked. The page's play command for THAT version is executed and the Player is +/// entered. +/// +/// Red first on `origin/main` (`3878e4f55`): the page asked for the second version and the runner +/// answered `Refused` (`content_command`'s input-owner gate, run before the panel's `Dismiss` +/// committed), so no Player was ever pushed. +#[test] +fn a_picked_version_plays_that_version_though_its_panel_is_still_closing() { + use plx_machine::machine::AppCommandOutcome; + let versions = plx_appkit::version_list::sample(); + let pick = versions[1].id; + let mut w = World::detail_page("play-version-pick", plx_data::metadata::Detail { + sid: plx_plex::plex::ServerId::UNSET, + rk: "movie".into(), + kind: "movie".into(), + title: "Movie".into(), + part: "/library/parts/movie".into(), + versions, + ..Default::default() + }); + let host = page_instance(&w.d); + open_content_panel( + &mut w.d, + host, + Some((plx_plex::plex::ServerId::UNSET, "movie")), + plx_screens::registry::ContentPanel::Versions { anchor: [300.0f32, 800.0, 300.0, 60.0].map(f32::to_bits) }, + ); + w.frames(40); + assert_eq!(w.d.nav.modals.surfaces.len(), 1, "premise: the Play Version panel is up"); + let mut tap = PickTap::default(); + let mut t = w.frame; + let mut bridge = w.bridge.bridge(); + pick_key(&mut w.d, &mut bridge, &mut t, Key::Down, &mut tap); + pick_key(&mut w.d, &mut bridge, &mut t, Key::Ok, &mut tap); + assert_eq!( + tap.ended(host, &Asked::Play(Some(pick))), [AppCommandOutcome::Completed], + "the page asked to play the SECOND version, once, and the runner executed it: {}", tap.account()); + assert!(w.d.nav.modals.surfaces.is_empty(), "the panel closed"); + assert!(matches!(w.d.top_arg(), Some(AppArg::Player)), "the pick entered the player"); +} + +/// The two-copy *Also available* rig of `a_detail_panel_parks_across_a_push_and_returns_with_the_same_instance`: +/// the page on `m1` of server `here`, the picker up over it, its cursor on the first copy. +struct AltRig { + d: Dispatcher, + owner: crate::app::runtime_owners::Harness, + t: u32, + host: InstanceId, + other: plx_plex::plex::ServerId, +} + +impl AltRig { + fn open() -> Self { + let here = plx_plex::plex::register_for_test("alt-pick-here", "127.0.0.1", 1, "t", "c1"); + let other = plx_plex::plex::register_for_test("alt-pick-other", "127.0.0.2", 2, "t", "c2"); + let mut d = Dispatcher::::new(); + let mut owner = crate::app::runtime_owners::Harness::new(|| 0); + let mut t = 0u32; + let host = { + let mut rig = owner.bridge(); + rig.metadata_run(plx_data::stores::metadata::MetadataCmd::AltInstall { + sid: here, + rk: "m1".into(), + copies: vec![ + plx_data::metadata::AltCopy { sid: here, rk: "m1".into(), library: "Movies".into(), ..Default::default() }, + plx_data::metadata::AltCopy { sid: other, rk: "copy".into(), library: "Shared".into(), ..Default::default() }, + ], + }); + for _ in 0..4 { + t += 1; + frame(&mut d, &mut rig, detail_arg("m1"), tick(t), vec![]); + } + let host = page_instance(&d); + open_content_panel( + &mut d, + host, + Some((here, "m1")), + plx_screens::registry::ContentPanel::AltSources { anchor: [300.0f32, 800.0, 300.0, 60.0].map(f32::to_bits) }, + ); + for _ in 0..40 { + t += 1; + frame(&mut d, &mut rig, detail_arg("m1"), tick(t), vec![]); + } + host + }; + assert_eq!(d.nav.modals.surfaces.len(), 1, "premise: the picker is up"); + Self { d, owner, t, host, other } + } +} + +struct ResetServers; +impl Drop for ResetServers { + fn drop(&mut self) { + plx_plex::plex::reset_servers_for_test(); + } +} + +/// **Also available, the same shape (#1424):** picking the other copy closes the picker and the +/// page presents that copy's own page. The page's `ContentReq::Present` met the same gate. +/// +/// Red first on `origin/main`: the page asked to present the other copy and the runner answered +/// `Refused`, so the picker closed and the page stayed where it was. +#[test] +fn a_picked_alternative_source_opens_that_copy_though_its_picker_is_still_closing() { + use plx_machine::machine::AppCommandOutcome; + let _guard = plx_base::testlock::serial(); + let _reset = ResetServers; + plx_plex::plex::reset_servers_for_test(); + let mut s = AltRig::open(); + let mut tap = PickTap::default(); + let mut rig = s.owner.bridge(); + pick_key(&mut s.d, &mut rig, &mut s.t, Key::Down, &mut tap); + pick_key(&mut s.d, &mut rig, &mut s.t, Key::Ok, &mut tap); + assert_eq!( + tap.ended(s.host, &Asked::Present(s.other, "copy".into())), [AppCommandOutcome::Completed], + "the page asked to present the other copy, once, and the runner executed it: {}", tap.account()); + let copy = AppArg::Content(plx_screens::registry::ContentArg::Detail { sid: s.other, rk: "copy".into() }); + assert!( + s.d.nav.modals.surfaces.iter().any(|surface| surface.entry.arg == copy && surface.phase != Phase::Closing), + "the other copy's page is up over the first" + ); +} + +/// **The gate still refuses a page that a SURFACE COVERS (#1424's negative control).** The same +/// report, delivered to the page while the picker is open and nothing has dismissed it: the page +/// does not hold input, so its command is still refused. Only a surface whose own `Dismiss` is +/// already parked counts as closed. +#[test] +fn a_page_under_a_picker_that_stays_open_is_still_refused() { + use plx_machine::machine::AppCommandOutcome; + use plx_screens::registry::AppMsg; + let _guard = plx_base::testlock::serial(); + let _reset = ResetServers; + plx_plex::plex::reset_servers_for_test(); + let mut s = AltRig::open(); + let mut tap = PickTap::default(); + let mut rig = s.owner.bridge(); + s.d.emit(MachineId::Nav, Fx::Deliver( + MachineId::Instance(s.host), + Delivery::Screen(ScreenEvent::App(AppMsg::AltSourceOpen( + plx_screens::registry::ContentArg::Detail { sid: s.other, rk: "copy".into() }))))); + pick_frames(&mut s.d, &mut rig, &mut s.t, 4, &mut tap); + assert_eq!( + tap.ended(s.host, &Asked::Present(s.other, "copy".into())), [AppCommandOutcome::Refused], + "the page asked, and a covered page is refused: {}", tap.account()); + assert_eq!(s.d.nav.modals.surfaces.len(), 1, "the picker is still up, and nothing was presented over it"); +} diff --git a/rust-modules/ui/src/containers/mod.rs b/rust-modules/ui/src/containers/mod.rs index a153ffcfa9..67fce7ba25 100644 --- a/rust-modules/ui/src/containers/mod.rs +++ b/rust-modules/ui/src/containers/mod.rs @@ -189,8 +189,14 @@ impl Navigation { /// The input owner (ยง2.2): the shared modal stack first, then the top page. pub fn input_owner(&self) -> Option { + self.input_owner_unless(|_| false) + } + + /// [`input_owner`](Self::input_owner) with every surface `dismissed` names counted as already + /// closed: who holds input once those dismissals commit. Page ops are never read. + pub fn input_owner_unless(&self, dismissed: impl Fn(EntryId) -> bool) -> Option { self.modals - .input_owner() + .input_owner_unless(dismissed) .or_else(|| self.top_page().map(|e| InputOwner::Entry(e.id))) } diff --git a/rust-modules/ui/src/containers/modal.rs b/rust-modules/ui/src/containers/modal.rs index f77140397d..e06c83d65b 100644 --- a/rust-modules/ui/src/containers/modal.rs +++ b/rust-modules/ui/src/containers/modal.rs @@ -745,10 +745,16 @@ impl ModalStack { /// The topmost Opening|Open surface owns input. pub fn input_owner(&self) -> Option { + self.input_owner_unless(|_| false) + } + + /// [`input_owner`](Self::input_owner) with every surface `dismissed` names counted as already + /// closed: the owner a parked `Dismiss` is about to leave behind. + pub fn input_owner_unless(&self, dismissed: impl Fn(EntryId) -> bool) -> Option { self.surfaces .iter() .rev() - .find(|s| matches!(s.phase, Phase::Opening | Phase::Open)) + .find(|s| matches!(s.phase, Phase::Opening | Phase::Open) && !dismissed(s.entry.id)) .map(|s| InputOwner::Entry(s.entry.id)) } diff --git a/rust-modules/ui/src/containers/tests.rs b/rust-modules/ui/src/containers/tests.rs index 146894bfbd..d1dc3e92d8 100644 --- a/rust-modules/ui/src/containers/tests.rs +++ b/rust-modules/ui/src/containers/tests.rs @@ -2742,3 +2742,29 @@ fn a_page_opened_over_a_closing_surface_returns_to_a_live_host() { let last = |name: &str| ev.rfind(&format!("\"{name}\"")); assert!(last("uncover") > last("cover"), "the host ends uncovered: {ev}"); } + +/// **`input_owner_after_dismissals`: who holds input once the dismissals already parked commit +/// (#1424).** A surface that closes on a pick parks its own `Dismiss` and reports the pick to the +/// page, whose command reaches the FIFO head before NAV COMMIT: `input_owner` still names the +/// closing surface there, this names the page. Nothing parked, or only a `Dismiss` of another entry, +/// changes nothing; after the commit the two agree. +#[test] +fn the_owner_after_dismissals_is_the_page_once_the_surfaces_dismiss_is_parked() { + let (mut d, mut rig, _) = booted(); + let home = d.nav.top_page().unwrap().id; + let menu = open_modal(&mut d, &mut rig, Style::Compact, 16); + assert_eq!(d.nav.input_owner(), Some(InputOwner::Entry(menu)), "premise: the surface holds input"); + assert_eq!(d.input_owner_after_dismissals(), Some(InputOwner::Entry(menu)), "nothing parked: the same owner"); + + d.request(MachineId::Nav, NavOp::Dismiss(EntryId(menu.0 + 100))); + assert_eq!(d.input_owner_after_dismissals(), Some(InputOwner::Entry(menu)), "another entry's dismissal is not this surface's"); + + d.request(MachineId::Nav, NavOp::Dismiss(menu)); + assert_eq!(d.nav.input_owner(), Some(InputOwner::Entry(menu)), "parked, not committed: the container still says the surface"); + assert_eq!(d.input_owner_after_dismissals(), Some(InputOwner::Entry(home)), "the page, once the dismissal commits"); + + d.frame(&mut rig, tick(32), vec![], vec![], &mut NoTap); + assert_eq!(d.nav.modals.surface(menu).map(|s| s.phase), Some(Phase::Closing), "committed"); + assert_eq!(d.nav.input_owner(), Some(InputOwner::Entry(home))); + assert_eq!(d.input_owner_after_dismissals(), d.nav.input_owner(), "after the commit the two agree"); +} diff --git a/rust-modules/ui/src/dispatch.rs b/rust-modules/ui/src/dispatch.rs index 648901e426..eb5bc0cc6f 100644 --- a/rust-modules/ui/src/dispatch.rs +++ b/rust-modules/ui/src/dispatch.rs @@ -2468,6 +2468,19 @@ where } } + /// **Who holds input once the dismissals already parked this drain have committed.** A surface + /// that closes on a pick pushes its own `Nav(Dismiss)` and then reports the pick to the page + /// that opened it. The dismissal stays PARKED until NAV COMMIT (step 7), so the page's command + /// for that report reaches the FIFO head while [`Navigation::input_owner`] still names the + /// closing surface. A runner that gates a page's command on "the sender holds input" asks this + /// instead: a surface whose `Dismiss` is parked no longer counts. Read-only; only a parked + /// `Dismiss` is read, never a page op, so a page under a surface that stays up is still not + /// the owner. + pub fn input_owner_after_dismissals(&self) -> Option { + self.nav.input_owner_unless(|id| self.parked.iter() + .any(|(item, _)| matches!(&item.fx, Fx::Nav(NavOp::Dismiss(target)) if *target == id))) + } + /// Revalidate immediately before IO if a runner invokes lifecycle operations after take. /// Admission/execution is synchronous on the main thread, never held until async completion. pub fn app_command_sender_is_live(&self, id: AppCommandId) -> bool {