Skip to content

Trailer preview: stop at its end and off its page, never write watch state; follow media redirects - #239

Merged
GLinnik21 merged 5 commits into
mainfrom
fix/trailer-preview-lifecycle
Sep 25, 2026
Merged

GLinnik21 merged 5 commits into
mainfrom
fix/trailer-preview-lifecycle

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes release-blocking trailer-preview playback bugs from the 0.7.0 device pass. Nothing here has been verified on the TV yet.

Root causes and fixes

1. A trailer ended but its preview did not stop, and the film's Play then failed with live Engine belongs to another Load attempt.

  • Cause: the EOS teardown ran only while the player page was mounted. The preview's own settle step ran only while an engine was started, and only if the preview machine was not idle, so an engine the machine had lost track of was never stopped.
  • Cause: a refused preview landing returned None from pump_play, so its handling code could never run. The machine stayed in Fetching forever and no later detail page autoplayed.
  • Fix: player::preview::after_pump now settles every frame through one pure decision, settle(PumpFacts) -> Nothing | Ended | Failed | Stale | Refused. It only ever stops a preview's own engine. A preview landing that nobody is waiting for is discarded.
  • Fix: a Play from any page first clears the engine through content::clear_engine_for_play, which retires an off-route engine that no page owns. This covers the page Play, the held-feature drain and the item menu's Play Trailer.

2. An autoplayed trailer posted timeline playing to the viewer's account.

  • Cause: pump::finish_preview_open_failure cleared the session's preview flag while the preview's Load was still in flight and still held the engine (the Load is deferred, not joined). The next pump frame saw an ordinary session, switched it to an HLS transcode, and that reload started a timeline reporter.
  • Fix: preview::retire is now the single path by which every preview exit stops its engine (EOS, failed Load or open, failed seek, halt, abandoned Load). The flag is cleared only once the engine is gone.
  • Fix: the session also records, at landing, that it was resolved for a preview (route::preview_request). Nothing but the next landing clears that. The timeline lease, the stop scrobble and the pump's Original→HLS fallback all check it. A preview's Original stream is never watched for automatic fallback to HLS.
  • There is no transcode ping in production code.

3. A trailer kept playing after the viewer left the detail page.

  • Cause: a preview was stopped only by the page's own requests. Home, Account/Settings, another title and app suspend are not among them.
  • Fix: a preview now runs only while the page that started it owns input. This is checked every frame after the navigation commit.
  • Fix: app suspend halts the preview and never parks it for the foreground reload.

4. Plex-hosted trailers failed with http_open FAILED status=302.

  • Cause: the plaintext socket client makes exactly one request per open and never reads Location.
  • Fix: new stream::redirect::open_following follows 301/302/303/307/308 for at most 5 hops. It handles relative Locations. The token and credential headers are sent only to the original origin. An https hop is handed to curl.
  • It is used by the progressive first open, the AVIO seek reopen and the HLS open.
  • HLS sets same_origin_only, which keeps its contract that it only fetches from the PMS origin. It also resolves playlist children against the URL the fetch actually landed on.

Consumers migrated or proven unaffected

  • Watch-state writes: the timeline lease and the stop scrobble are gated. The PlayQueue POST and put_selection were already unreachable for a preview (plan.rs).
  • Engine stops: every preview exit now goes through retire. The remaining clear_preview calls run only with no live engine.
  • Play entry points: page Play, held feature and item-menu trailer all go through clear_engine_for_play.
  • Plaintext media opens: all three go through open_following. The control plane (crate::http) keeps its own opt-in redirect policy.

Tests (RED → GREEN)

  • Preview machine, settle decision and play clearance: 6 tests failed before the fix and pass after.
  • a_session_resolved_for_a_preview_never_reports_a_timeline: failed before (the lease was granted), passes after.
  • a_preview_is_halted_once_its_page_no_longer_owns_input: failed before, passes after.
  • Redirects: 5 of 5 ff::redirect_tests failed on the base commit. The two HLS tests added after review (redirected master rebase: /old/variant.m3u8 vs /new/variant.m3u8; refusing a hop off the PMS origin) also failed first. All pass now.
  • The loopback servers in the new redirect tests accept through Player: BACK/Stop/EOS return to the page playback was started from #238's shared crate::testnet::accept.

Gates (committed tree, rebased on main)

  • make check:
    • test result: ok. 4396 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out
    • test result: ok. 4452 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out (hostsim)
    • test result: ok. 101 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
  • cargo +nightly check --lib --no-default-features: Finished, no errors.
  • make (ARM cross-build): succeeded.
  • fw-compat review of the redirect change: PASS. It adds no FFI, symbols or libraries.

Review

  • Round 1 found that HLS playlists were parsed against the requested URL rather than the one the redirect landed on. Fixed and tested.
  • Round 2 found that the https HLS path lets libcurl follow redirects across origins and still parses against the requested URL. This is not fixed here:
    • The behaviour predates this branch (curl already had FOLLOWLOCATION on).
    • Fixing it needs a new curl_easy_getinfo for the effective URL, or turning off curl's following for HLS. Either is an FFI change.
    • Two review rounds were the limit for this PR. Left as a follow-up.

Known follow-up

  • https HLS cross-origin redirects. On an https PMS origin, libcurl follows a playlist redirect itself (it already had FOLLOWLOCATION on before this PR). It does not check the target's origin, and the playlist is still parsed against the requested URL, not the redirect target. The plaintext path enforces both. Closing the gap needs the effective URL from curl (a new curl_easy_getinfo binding and its fw-compat review), or turning off curl's own redirect following for HLS. Deliberately left out of this PR.

Not verified

  • TV verification is still pending: trailer EOS, leaving the page mid-trailer, suspend, and a real Plex-hosted trailer's 302 through a real CDN (the https hop is covered only by a loopback test that checks curl starts a TLS handshake).
  • Resolving HLS segments against a redirected media playlist is covered only by the shared code path, not by its own test.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-25T03:43:10.710526Z ba0cf11 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

GLinnik21 and others added 5 commits September 25, 2026 06:22
A detail-page trailer ran past its end for three minutes, the film's Play then
failed against its still-live engine ("live Engine belongs to another Load
attempt"), and no later page autoplayed. Every preview decision was keyed on
the preview Machine's phase, and several paths let that phase drift from the
session actually installed:

- after_pump only stopped a preview at EOS or failure while the machine was
  non-Idle, and only ran while an engine was started, so a machine that lost
  track of its session never stopped it, and a refused preview landing (no URL,
  pump_play returns nothing) left the machine in Fetching forever, which made
  occupies() true and blocked every later dwell.
- A machine left non-Idle after its session was replaced acted on the FILM's
  engine: a film Load failure or EOS was read as the preview's.
- halt() stopped whatever engine was installed whenever the machine was
  non-Idle, film or not, and a halt during the resolve let the landing start
  an engine nothing tracked.
- A Play from a page only pre-empted a preview; a live engine nothing owns
  (neither a preview nor the player page's) refused the Load, and at its EOS
  nothing stopped it because the teardown is player-page gated.

after_pump now runs every playback frame and asks one pure function, settle(),
which decides from the installed session: a preview engine's end or failure is
stopped whatever the machine says; a machine whose session is gone is reset
without touching the engine; a preview landing with no engine is remembered
as refused. halt() stops only a preview's engine and keeps the machine
Abandoning while a returned-too-late Load is still installed; a landing the
machine is no longer waiting for is discarded. Every page Play (ordinary Play,
held-play drain, item menu Play Trailer) goes through clear_engine_for_play,
which also retires an off-route orphan engine, and the EOS loop stops such an
orphan when no player page exists.

Preview logging: start result and phase, the blocked reason once per change,
every machine phase change with its cause, EOS, and a discarded landing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A preview whose Original open failed was retired by clearing the
session's preview flag while its deferred Load still held the engine.
The next pump then read an ordinary session, rescued it onto an HLS
transcode and started a timeline reporter: the trailer played off-screen
and posted `timeline playing` to the viewer's account every ten seconds.

- `preview::retire` is the one way every preview exit stops its engine
  (EOS, failed Load or open, failed seek, halt, abandoned Load). The
  flag is cleared only once the engine is gone; otherwise the machine
  stays Abandoning until after_pump finishes it. A failed open is
  handled once, not every frame.
- The session records that it was resolved for a preview
  (`route::preview_request`), fixed at landing. The timeline lease, the
  stop scrobble and the pump's Original->HLS rescue all ask it, and a
  preview's Original is never ABR-watched.
- A preview lives only while the page that started it owns input,
  checked every frame after the navigation commit, so Home, another
  title, Account/Settings, menus and BACK all end it. An app suspend
  halts it and never parks it for the foreground reload.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A Plex-hosted trailer's Part URL answers 302 to a presigned CDN URL on
another origin (usually https, sometimes a relative Location). The
socket client made exactly one request per open, so the progressive
open logged `ff: http_open FAILED status=302` and the demuxer produced
no access units.

stream::redirect::open_following wraps the socket open in a bounded
loop (5 hops) for every plaintext media open the demux thread makes:
the progressive first open, the AVIO seek reopen and the HLS source
open. It resolves absolute, scheme-relative and relative Locations,
forwards the X-Plex-Token query pair and any credential header block
only to the original scheme+host+port, keeps a Range on every hop, and
stops at the first https hop so the caller opens it on the curl source.
The effective target is stored in Src::Socket, so later Range seeks
start from it. The response head's Location is captured into
HttpStream before the socket closes. Log lines carry origin and
query-less path only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review finding: a redirected playlist was parsed against the URL it was
requested from, so a relative child resolved under the old directory.

- `stream::redirect::Request::same_origin_only`: a caller confined to
  one origin refuses any hop elsewhere before dialling it. HLS sets it,
  which is the `hls.rs` contract that the media worker never fetches
  from anywhere but the PMS origin; progressive opens keep following
  CDN redirects.
- `hls_open_source` returns the resource the open landed on (token
  removed again, `Resource::from_request_path`), and both master and
  media playlists resolve their children against it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21
GLinnik21 force-pushed the fix/trailer-preview-lifecycle branch from 9d016d9 to ba0cf11 Compare September 25, 2026 03:38
@GLinnik21
GLinnik21 merged commit 3a30a01 into main Sep 25, 2026
5 checks passed
@GLinnik21
GLinnik21 deleted the fix/trailer-preview-lifecycle branch September 25, 2026 03:53
GLinnik21 added a commit that referenced this pull request Sep 25, 2026
#234, #235, #236, #237 and #239 passed on the television on a debug build
of 3a30a01, each with the log lines behind it; #238 stays pending (it
needs real playback), and #237's new focus-on-Sign-out finding is pending
its own fix. Records the second pass's harness results and marks the
0.6.6 -> 0.7.0 in-place upgrade as blocked, with what unblocks it and what
was observed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GLinnik21 added a commit that referenced this pull request Sep 25, 2026
ci/build-ffmpeg.sh: the firmware database fwsym holds spans platform
releases 1.2.0 to 11.2.0, not webOS 3 to 10; libz.so.1 is in every image.
docs/trailer-ux-plan.md: the deferred just_finished proposal names the
preview machine's current transitions, Machine::eos and Machine::stopped,
as docs/TODOS.md already does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GLinnik21 added a commit that referenced this pull request Sep 25, 2026
#234, #235, #236, #237 and #239 passed on the television on a debug build
of 3a30a01, each with the log lines behind it; #238 stays pending (it
needs real playback), and #237's new focus-on-Sign-out finding is pending
its own fix. Records the second pass's harness results and marks the
0.6.6 -> 0.7.0 in-place upgrade as blocked, with what unblocks it and what
was observed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GLinnik21 added a commit that referenced this pull request Sep 25, 2026
…brary firmware gate (#241)

* docs: correct two claims #235 and #239 left stale

ci/build-ffmpeg.sh: the firmware database fwsym holds spans platform
releases 1.2.0 to 11.2.0, not webOS 3 to 10; libz.so.1 is in every image.
docs/trailer-ux-plan.md: the deferred just_finished proposal names the
preview machine's current transitions, Machine::eos and Machine::stopped,
as docs/TODOS.md already does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 0.7.0 release note and audit: cover #234-#240

The note gains the image-subtitle fix, the trailer stop/reporting/redirect
behaviour, the art-crop, library-seat and profiles read-out fixes, and a
line for nightly users about BACK from the player. The audit records the
seven changes as host-verified and pending the device pass, the bundled
FFmpeg's new libz.so.1 dependency with its firmware evidence, and the
https HLS cross-origin redirect gap as a known follow-up.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* ci: the audit lint refuses an unfilled placeholder in the authored half

Nothing substitutes into a release audit's authored half; gen-release-audit
only replaces the generated block, so a __PLACEHOLDER__ left there
publishes literally. Watched red on the v0.7.0 audit's __GATES__ row before
it was filled; every existing audit and the template pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* v0.7.0 audit: record the gates run on the release-prep tree

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* v0.7.0 audit: fold in the second device pass over #234-#240

#234, #235, #236, #237 and #239 passed on the television on a debug build
of 3a30a01, each with the log lines behind it; #238 stays pending (it
needs real playback), and #237's new focus-on-Sign-out finding is pending
its own fix. Records the second pass's harness results and marks the
0.6.6 -> 0.7.0 in-place upgrade as blocked, with what unblocks it and what
was observed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 0.7.0 release note and audit: #242 fixes the device pass's Sign-out focus finding

The audit lists #242 among the changes landed after the device pass,
host-verified and pending the device, and marks #237's focus-on-Sign-out
finding fixed by it. The note's smaller fixes gain the menu-focus line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* v0.7.0 audit: the gate row names the tree rebased onto #242

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 0.7.0 note and audit: scope the trailer and library promises, record the pass's account writes

Review findings on #241:
- A trailer started with Play Trailer is an ordinary playback
  (request_play, preview: false) and reports a timeline; only the
  background preview, full-screen mode included, never reports.
- The library DOWN fix holds only when the reader has not moved before
  the shelves load.
- The device-pass summary counts #236 as passed only for shelves-first.
- The pass wrote to the Guest profile: the explicit PGS pick's
  PUT /library/parts selection, and the harness's unscrobble, progress
  seeds and playback timelines.
- The gate row states that every commit after b99e79f is note/audit
  only and which checks were re-run on the head.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fwcompat: grade the bundled FFmpeg libraries, and put their DT_NEEDED in the audit

#235 gave libavformat-plx a DT_NEEDED on libz.so.1, and nothing graded it:
the libraries are dlopen'd, webosbrew-ipk-verify grades only the app and
service executables, and fwcompat on a bundled library reported every
firmware FAIL for the sibling libav*-plx names no firmware carries.

tools/fwcompat.py --shipped DIR takes DT_NEEDED names that are files in DIR
off the firmware's list and counts what they export as resolved. Watched:
bare, libavformat-plx FAILs everywhere on its siblings; with --shipped pkg
all three pass from 4.4.2 to 11.2.0; against a copy of the 4.4.2 database
with libz removed it FAILs on libz.so.1 (4 symbols) and exits 1.

CI's firmware load matrix and the build's fwcompat gate now run it over
each bundled library; the build appends the matrix to pkg/ipk-verify.md,
which gen-release-audit.py embeds, and gen-release-audit.py lists each
bundled library's DT_NEEDED. Review finding on #241: the zlib verdict is
now read from the published package instead of typed into the audit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* v0.7.0 audit: the zlib entry defers to the generated half; the gate row names the tooling commits

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fwcompat review: row() takes its cells, and --shipped says what it trusts

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* build-package: the bundled-library matrix goes into ipk-verify.md unfenced

gen-release-audit.py already wraps that whole file in one code fence; a nested
fence closed it. Only the step summary fences the aligned columns now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

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.

1 participant