Skip to content

Player foreground lifecycle: one step(event) machine with private state - #977

Merged
GLinnik21 merged 7 commits into
mainfrom
sansio/lifecycle-events
Oct 24, 2026
Merged

GLinnik21 merged 7 commits into
mainfrom
sansio/lifecycle-events

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #976

The player's foreground lifecycle (ForegroundLifecycle, media/src/player/lifecycle.rs) now has one writer:

step(&ForegroundEvent, &mut Vec<ForegroundEffect>) -> Handled

Its fifteen pub mutators and its pub state field are gone. This is step 3 of the Sans-IO series (docs/sans-io.md). The change preserves behaviour and leaves every ledger and pin as it was.

What changed

Events. Eight ForegroundEvents replace the mutators:

Event Replaces
Park{saved_ns, viewer_paused} suspend + clock_for_suspend_now
ParkFlight park_pending_flight
Input(ForegroundInput) claim
PrepareAnswered finish_prepare*
LoadAnswered finish_load_*
FlightStale release_stale_flight
LoadStatus settle_load
ClockAnswered finish_clock

PlayKeyOffPlayer. This new ForegroundInput turns discard_started_state + claim(PlayKey) into one event. key_play sends it exactly when PLAY arrives off the player.

Effects. AfterLoad, Launched and DropFlight are new; Retire stays separate, so the #853 tables are unchanged.

Purity. The pause flag arrives as a value on Park. clock_for_suspend_now, the helper that read the transport's global, is deleted, and clock_for_suspend is private. The machine reads no global, clock or IO.

State. The state is private. Callers read it through awaiting_load, claimable_clock, pending_flight and pending_load_attempt, plus state() under test/test-support.

Drivers. drive_foreground, poll_foreground_flight, poll_foreground_load and park_pending_foreground_flight now share one loop:

  • it holds a single Option<ForegroundEvent> slot;
  • it runs each step's effects through the ForegroundActuator;
  • it feeds the one answering effect's answer back as the next event;
  • a debug_assert! checks that a step emits at most one answering effect;
  • a frame that only polls allocates nothing.

Ordering. Two orderings change, and the actuator cannot observe either: it holds only the adapter and repause_at, never the machine.

  • In LoadAnswered's Failed/AlreadyRunning/Terminal arms, after_load now runs after the state write.
  • In ParkFlight, suspend_bufferfeed now runs after the park.

Tests

  • New:
    • every_state_meets_every_event_as_the_table_says: 12 rows over all 8 state kinds × 29 events. Every cell pins Handled, the next state, the exact effects in order and next_id. An unlisted cell must be "unchanged, no effects, No".
    • play_off_player_is_one_event.
  • Existing: the driver tests, foreground_flight_tests.rs, the claim_hold suspend tests and the app's lifecycle_regression_tests changed only in spelling or added assertions; no expectation changed.
    • One test used to assign the state directly. It now drives Park then DidForeground through a test-only RefusedLoad actuator to reach the same Prepared{id:1, 0, Paused}, and asserts that state.

Gates, run on the committed tree

Gate Result
make check exit 0. plx_media 1708 passed (default features), 1869 passed (hostsim); no test result: line reports a failure.
make check-nodef exit 0, no warnings
make check-replay all three fixtures × resolve/targets verdict=SAME, every *_diffs=0; no fixture changed
make (ARM, tvdev) linked

Review

One review, verdict MERGE. It mapped every deleted mutator and its call sites on main to the replacing event, and found the same state, effects and IO order apart from the two reorderings above. It also checked the driver loop's id matching and its release-build fallbacks, and confirmed no test expectation changed.

Device check

The PR head's binary ran on the dev TV: a mock server (version=…-synthetic, owned=1) with an H264 direct play. The running exe's md5 matched the local build.

  • Background, then foreground once, while playing:
    • It saved at 35 s and resumed at 31 s, the 5 s rewind for a playing save.
    • It was playing afterwards (play=999..1000pm).
    • There was exactly one restore Load: SMP: calling Load appears twice in the log, for the first play and the restore.
    • It played to EOS, with no panic and no WARN.
  • Decoder release (the screensaver path): not reached on the TV.
    • With the panel off, the firmware refuses turnOnScreenSaver (Invalid State change Request from Screen Off).
    • With the panel on, the screensaver came up over a paused direct play (getPowerState read Screen Saver), but the pipeline did not take the decoder back within about 80 s. There was no type=18 callback, so nothing parked and the press restore was not exercised.
    • Decoder release parks through the same park_playback → Park step the background run exercised.
    • a_decoder_released_by_the_pipeline_parks_until_the_next_press_restores_it (hostsim, real Engine) passes.
  • Not exercised on the TV: the two reorderings above (a refused or terminal restore Load, and a second background during a restore flight).
  • Vendor teardown noise: the four GStreamer-CRITICAL … still has a parent lines at sf_destroy also appear in a day-old release build's stderr on the set, so they predate this change.

Follow-up (separate PR): move the transport readers and drivers out of lifecycle.rs, extend the ledgers and widen the wall gate.

🤖 Generated with Claude Code

GLinnik21 and others added 6 commits October 24, 2026 09:12
The 15 public mutators become the ForegroundEvent arms of one private-state
step(&ForegroundEvent, &mut Vec<ForegroundEffect>) -> Handled. The drivers are a loop
that feeds each answering effect's answer back as the next event, held in one
Option slot. PlayKeyOffPlayer folds key_play's discard_started_state into the
same event as the PLAY it precedes; Park carries the viewer's pause as a value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
play_off_player_is_one_event: a started session's pending clock goes to Idle and the
press answers Ordinary in one event; every other state answers it as PlayKey.
every_state_meets_every_event_as_the_table_says: next state, effects and Handled
for all eight states against all 29 events.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The transport_pause_contract_tests park through Park, and claim_hold's two suspend
tests name the lifecycle's attempt type, which clock_for_suspend_now used to pin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The module doc of player/lifecycle.rs now says how the machine is driven (ForegroundEvents through
`step`, private state, the read accessors and the drivers' single-slot loop), and the player guide
points at `ForegroundLifecycle::step` for the per-state table and says to add no event outside
`ForegroundEvent` instead of "no mutator beside `claim`", which no longer exists.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GLinnik21 added a commit that referenced this pull request Oct 24, 2026
… worker job (#979)

Since #973, every app frame can run the session owner's cache refill. While the process-global
cache was Unloaded, SessionAdapter::begin_cache_refresh submitted a real storage-worker job even
under Resources::Fixture. Its CacheRefreshed answer landed on whichever frame the worker beat, so
fixture Bridge tests depended on timing: home_worker_results_cross_the_addressed_dispatcher_ingest_once
failed with "wrong result type" in three of four CI jobs on #977. A fixture-Bridge test with no
TempSession could also install a developer's real auth.json into the cache for later tests.

A fixture adapter now parks refresh_cache_job in FixtureResources, as StoreRunner::Held parks store
jobs, and runs it only when a test asks (run_held_cache_refresh). cache_refresh_req covers a parked
refresh, so the reconcile reads it as held. Live adapters are unchanged.

Tests: a_fixture_adapter_submits_no_storage_worker_job_for_a_cache_refresh; the Home test starts
from an Unloaded cache (premise asserted) and drains the worker between frames with its tap strict;
a_live_adapter_begins_a_cache_refresh_without_taking_the_session_io_lock keeps the live IO-lock
coverage that a fixture can no longer give; a debug_assert catches an overwritten parked refresh.

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.

Player foreground lifecycle: one step(event) entry point, private state

1 participant