Skip to content

Playback: a new play never blocks the UI on the previous player's Unload; a hung Unload fails typed after 10 s - #1116

Merged
GLinnik21 merged 10 commits into
mainfrom
fix/player-release-nonblocking
Oct 28, 2026
Merged

GLinnik21 merged 10 commits into
mainfrom
fix/player-release-nonblocking

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

Closes #1114

What changes

  • Release machine. The new pure machine player/release.rs (NativeRelease) has the states Idle, Releasing{epoch, since, queued} and Overdue. Its events are UnloadHandedOff, StartRequested, UnloadReturned, Tick, Exit and CancelQueued. It is registered in MACHINES. The runner (poll_release / poll_release_frame, once per frame) joins the sf-unload worker only after is_finished().
  • Deferred starts. A start that arrives during a release returns BufferfeedStartOutcome::Deferred and the screen shows Connecting. The start runs on the frame the Unload's tail retires. The foreground restore gets ForegroundLoadStart::Deferred, re-polled in RecoveryPending. settle_release and the blocking waits are removed.
  • Deadline. After RELEASE_DEADLINE (10 s) the play fails with the typed FailureKind::ReleaseTimeout (release_timeout), and Try Again is offered. The overdue object is never destroyed. A late Unload return still runs the full tail. native_start_refused is now Option<StartRefusal> (LoadTimeout | ReleaseTimeout).
  • Fence. While a release is in flight, player::sink() returns the new shared RefusingSink from plx_platform::tv::sink. It refuses control verbs and forwards the memoized window queries. The release tail uses raw_sink().
  • Exit. exit_native returns Clean or WorkerInFirmware.
    • On Clean, shutdown runs SDL_Quit as before.
    • On WorkerInFirmware (a pending Unload or an abandoned Load still inside the firmware), the parked objects are leaked. Shutdown finishes its flushes (scrobble drain, capture, poster, telemetry session, crash guard) and then ends the process with libc::_exit. That way neither the App drop nor libc's C++ finalizers run under the hung firmware call.
  • Preview admission. A deferred preview counts as admitted only when it actually launches.

Tests

New tests (hostsim):

  • a_start_over_an_unload_that_never_returns_does_not_block_and_fails_typed_at_the_deadline
    • Red on main: the start blocked the UI thread for 3.01 s. test result: FAILED. 0 passed; 1 failed
    • Green: test result: ok. 1 passed; 0 failed
  • exit_after_a_load_timeout_never_quits_the_display_under_a_hung_load
    • Red on main: test result: FAILED. 0 passed; 1 failed
    • Green: passes.
  • a_foreground_start_over_a_held_unload_parks_without_blocking_then_lands
  • a_foreground_start_over_an_overdue_unload_fails_typed
  • a_stop_after_a_landing_replaced_the_session_still_cancels_the_queued_start
  • a_deferred_preview_start_is_settled_when_it_runs_not_when_queued
  • a_worker_still_in_firmware_ends_the_process_without_unwinding
  • the exit-leak assertions, plus pure unit tests for NativeRelease

Suite results:

  • plx_media hostsim: 2165 passed; 0 failed
  • plx_media: 1943 passed; 0 failed
  • plx_platform: 337 passed; 0 failed
  • app crate: 1085 passed; 0 failed
  • app hostsim lifecycle: 89 passed; 0 failed
  • --no-default-features: clean
  • ci/check-deps.sh: green
  • module layers: green

Reviews

  • pr-reviewer: 7 findings (2 major, 5 minor), all fixed.
  • fw-compat-reviewer: no FFI, linkage or src/ change, so start-up on every gated image is unchanged. Its exit-path finding (libc exit() running finalizers under the worker) is fixed by the _exit.
  • doc-claim-auditor: one stale sentence in player/CLAUDE.md, fixed.

Not verified

Gates

make check and the ARM build were not run locally; this PR's CI is the gate.

🤖 Generated with Claude Code

GLinnik21 and others added 10 commits October 28, 2026 15:45
… release has a deadline and a typed failure, and the exit does not quit SDL under a worker in firmware

WIP: machine, runner, fence, plumbing; tests being extended.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…store defers instead of blocking, queued start lives only in the release machine

- exit_native leaks the parked PendingRelease / AbandonedLoad (mem::forget) when a worker is still in firmware
- ForegroundLoadStart::Deferred replaces the blocking wait_for_release
- PlaybackSession: native_start_refused is Option<StartRefusal>; native_start_deferred and native_release_refused removed; teardown always sends CancelQueued; Resolving derives from the adapter-published SHARED.start_queued
- RefusingSink in plx_platform::tv::sink (verbs written once, shared with NoSink)
- a deferred preview start is admitted/settled when it runs
- stale prose follows poll_release / the fence

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d a worker still in firmware ends the process with _exit

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A test that ends with its sf-unload worker still held (a leaked release, a dropped
adapter) leaves a detached thread. When it wakes, host sf_unload reads the
process-global ACTIVE_EPOCH AFTER its hold, which by then names the NEXT test's
session, and delivers UNLOADCOMPLETED into it: Active becomes Unloaded and the
next test's backdate precondition ('the epoch must still own Active') fails at
random (CI: exit_after_a_load_timeout_never_quits_the_display_under_a_hung_load).

Workers are now counted from before spawn until they end, and
reset_native_lifecycle_for_test (opened and closed by every serial test) releases
the hold and waits, bounded, for the count to reach zero.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ffi_host only exists under the hostsim feature, so the plain make test-crate build
could not name it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed-open recovery settled

Every rig engine's media URL answers JSON, so its source open fails and the pump flies a
recovery (land_recovery_flight -> reload_transcode) before the engine settles on Error. The
reload resets the session, and with it SHARED.ended. The tests stored ended right after the
play landed, so when the worker's recovery landing fell in the very pump that precedes the EOS
check (slow CI, 100 s vs 33 s locally), the end was cleared before it was acted on and the
player stayed on top: issue_680 saw EntryId(3) instead of the detail page, and
an_end_of_stream_without_up_next failed the same way. Reproduced under CPU load as ended=false
with a reload_transcode backtrace out of land_recovery_flight. end_the_stream waits for the
flight to land and the engine to settle before it stores the end.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 merged commit 1d603b1 into main Oct 28, 2026
22 of 23 checks passed
@GLinnik21
GLinnik21 deleted the fix/player-release-nonblocking branch October 28, 2026 17:01
GLinnik21 added a commit that referenced this pull request Oct 29, 2026
…uctions (#1131)

Agents get a how-to for Sans-IO code at the moment they write it, placed where each tool loads instructions. Prose only: no code, CI or ledger change.

docs/sans-io-guide.md is the how-to beside the design record. It covers:
- which files are machine code, and which bodies in them may do IO (job bodies, `&OffFrame` functions, the runner, the Bridge, actuators, a seam only a job body calls);
- what counts as IO: a principle first, then the names, including the registry readers the ledgers do not match (`server_ids()` and the `server_*` generation readers, `peek_settled()`, `current_gen()`, `tape::active()`);
- six moves, each with a snippet from a merged migration: emit a store job, the Bridge reads and the step takes the value, a stepped machine returns effects, time is the `dt` it is handed, a seam instead of a `cfg(test)` branch, refuse a command that lacks its input;
- where `task::beside` belongs, the ledger rule (a new line or a raised count is never the fix; a one-for-one rename like #1116's changes only a key) and an 8-item checklist.
It names the Watchlist's `LiveIo` seam and `build_stream`'s registry reads as leftovers, not models.

rust-modules/data/src/AGENTS.md is the store recipe: the store, runner and Bridge split, and nine rules. Beside it, data/src/CLAUDE.md imports that file and the guide: Claude Code loads a subfolder CLAUDE.md and expands `@`, OpenCode loads a subfolder AGENTS.md, and Codex reads only the root chain. Root AGENTS.md points at both new files from the "Logic never performs IO" bullet and from "Load the right context".

The ui, screens and player guides each gain a short Sans-IO section that imports the guide. The ui guide's "move the work to a worker" now says: in machine code, emit an effect or store job; start a worker only in the IO layer. The doc-claim-auditor and pr-reviewer agents list the new guides, and docs/sans-io.md's Scope list gains release.rs, as ci/check-deps.sh has it.

Closes #1130

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UI freezes forever when a new play waits on a previous player's Unload that never returns (Sentry PLX-NATIVE-1Q)

1 participant