Skip to content

Playback: stop when the server ends the session - #1265

Merged
GLinnik21 merged 7 commits into
plxnative:mainfrom
PilaScat:feat/honour-server-stop
Nov 6, 2026
Merged

GLinnik21 merged 7 commits into
plxnative:mainfrom
PilaScat:feat/honour-server-stop

Conversation

@PilaScat

@PilaScat PilaScat commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

When an admin stops a stream (Tautulli, Tracearr, POST /status/sessions/terminate), PMS closes the session at once and says so on the answer to the next timeline report: terminationCode and terminationText on the MediaContainer. Client::timeline threw that answer away, so the set went on reporting playing and playing its buffer.

Measured on a real set (LG 32LQ63006LA, PlxNative 0.9.0, PMS 1.43.5.11079), direct-playing an episode:

time what happened
12:08:27 Tracearr sends the stop with reason prova; PMS terminates the session
12:08:32, :42, :52 the set reports playing three more times
12:09:00 the buffer runs out, and PMS answers 503: Denying access to direct play of part … due to terminated session

So the stop took 33 s and depends on how much is buffered. The set then showed the generic interruption, without the reason, with Try Again. Try Again started a fresh session that PMS accepted, so one key undid the stop.

What changes

  • Client::timeline_answer reads the answer to a periodic report. report_timeline uses it, and a termination ends the reporter, so no more playing goes out.
  • The reporter raises SHARED.server_stopped with the server's text and the playback it reported for: the logical session, which an adaptive reload keeps. The pump checks it ahead of the recovery landing and every failure branch, for that playback only, and fails the Engine with no recovery. An outstanding recovery flight ends, and its landing is discarded. The stop lands on the next tick, within the 10 s report interval. A reload keeps the signal; only a new playback clears it.
  • FailureKind::ServerStopped (server_stopped) offers only Back. The read-out keeps the existing "stopped" wording and quotes the server's sentence in detail, the way a /decision refusal does, so no catalog key is added.
  • The ended session also gets stopped&continuing=1 at once, the report Playback: a retired PMS session gets its stopped timeline (#1236) #1254 measured, so its row leaves the dashboard without waiting for the viewer to leave the read-out. On 0.9.0 the row stayed listed as playing with a frozen position. The final stopped still goes out when the viewer leaves.
  • server_stopped joins the closed playback.failed vocabulary in classes.rs, diag/schema.rs and PRIVACY.md, and the new request site is in ci/plex-requests.ini.

Verified

  • make check is green on the branch, based on main at 5b9ff4a: 35 suites, 24283 passed, 0 failed, 198 ignored, all 126 steps ok. The host runs were on WSL2 under setarch -R, because ci/test_check_collisions.py fails at random there with "ThreadSanitizer: unexpected memory mapping", on main as well.
  • make check-nodef is clean.
  • a_termination_on_the_answer_ends_the_reporter_and_keeps_the_server_s_reason fails without the change to report_timeline and passes with it.
  • a_stop_from_the_server_ends_the_playback_with_its_reason_and_only_back runs the pump under hostsim: Error, Engine released, no recovery, the server's reason, only Back.
  • After Copilot's review, three more tests. Each failed before its change:
    • a_stop_from_the_server_during_a_recovery_flight_ends_it_and_reloads_nothing: Error on the stop's frame, the rollback's flight ended, its replacement encoder stopped, nothing reloaded;
    • a_reload_keeps_the_server_s_stop_and_the_next_session_drops_it;
    • a_stop_the_server_sent_for_another_playback_leaves_this_one_playing.
  • cargo check --target armv7-unknown-linux-gnueabi on plx_plex and plx_telemetry is clean. The package was not built: there is no webOS NDK for linux-x86_64 here.

Not verified

  • Not run on a television. I have SSH to the set above, so I can repeat the measurement on a nightly after a merge.
  • The JSON shape of a real termination. The fixture follows the fields Plezy reads from PMS (terminationCode, terminationText), and I haven't captured a real answer. An answer that doesn't parse leaves today's behaviour.
  • The viewer can still press Play again. A new session is a new session: only the server can refuse it.

🤖 Generated with Claude Code

An admin's stop (Tautulli, Tracearr, /status/sessions/terminate) closes the
session at once, and PMS says so on the answer to the next timeline
report: terminationCode and terminationText on the MediaContainer. The
reporter threw that answer away, so the set went on reporting `playing`
and playing its buffer. It stopped only when the next read was refused,
33 s later on a real set, and then showed the generic interruption with
Try Again, which starts a fresh session the server accepts.

The periodic report now reads the answer. A termination ends the reporter
and raises a signal the pump turns into a failed Engine, with no recovery
attempted. The read-out keeps the existing wording, quotes the server's
reason the way a /decision refusal does, and offers only Back. No catalog
key is added. The ended session also gets `stopped&continuing=1`
at once, the report plxnative#1254 measured, so its row leaves the dashboard
without waiting for the viewer to leave the read-out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Filippo Scatigna <[email protected]>
Copilot AI lite review requested due to automatic review settings November 6, 2026 17:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical unresolved issues remain in server-stop ordering, terminal-signal preservation during reloads, and stale-reporter validation, allowing recovery or retired sessions to continue incorrectly.

3 open issues
What changed in this PR

This pull request makes playback stop promptly when PMS terminates the active session, preserves the server-provided reason, retires the dashboard session, and adds terminal failure handling and telemetry coverage.

Changes:

  • Parse termination details from Plex timeline responses and stop further reporting.
  • Propagate server stops through the playback pump as a terminal, Back-only failure.
  • Send a final stopped status, update telemetry and privacy schemas, account for the new request, and add regression coverage.
File Summary
rust-modules/​telemetry/​src/​telemetry/​classes.rs Adds the server_stopped failure telemetry class.
rust-modules/​telemetry/​src/​diag/​schema.rs Extends the documented playback failure vocabulary.
rust-modules/​plex/​src/​plex/​timeline.rs Parses timeline responses and detects server termination.
rust-modules/​plex/​src/​plex/​params.rs Defines timeline answer and server-stop result types.
rust-modules/​plex/​src/​plex/​client.rs Adds a JSON-preserving POST helper for timeline responses.
rust-modules/​media/​src/​route/​decision.rs Handles termination answers, retires the PMS session row, and signals playback failure.
rust-modules/​media/​src/​route/​decision_timeline_tests.rs Adds regression coverage for termination handling and final timeline reports.
rust-modules/​media/​src/​route/​decision_test_support.rs Extends the recording PMS fixture with configurable response bodies.
rust-modules/​media/​src/​player/​shared.rs Stores and resets server-stop state and reason.
rust-modules/​media/​src/​player/​pump.rs Fails the active engine when a server-stop signal is observed.
rust-modules/​media/​src/​player/​mod.rs Adds failure classification, reason propagation, and Back-only actions.
PRIVACY.md Documents the new playback failure telemetry value.
ci/​plex-requests.ini Accounts for the new JSON timeline request site.

This pull request requires changes.

Review effort: Lite

Comment thread rust-modules/media/src/player/pump.rs Resolved
Comment thread rust-modules/media/src/player/shared.rs Resolved
Three gaps Copilot found in the review of plxnative#1265:

- The pump read the stop after the recovery landing and the
  outstanding-flight wait, so a stop during a failed open's recovery
  waited for the flight, and its landing could reload onto a new PMS
  session. The check now runs as soon as the Engine is borrowed.
  fail_current_engine ends the flight, and a landing already parked is
  discarded, which stops the encoder its worker registered.
- reset_session_for_reload cleared the signal, so a stop that arrived
  while an adaptive reload was in flight was lost. Only a full reset
  clears it now.
- A reporter can publish after its lease was invalidated. The stop now
  carries the logical session it was reported for, the playback
  generation an adaptive reload keeps, and applies only to that
  playback. Revalidating the Engine lease instead would drop a genuine
  stop in the reload window above, since every reload bumps the epoch.

Each of the three new tests failed before its change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Filippo Scatigna <[email protected]>
Copilot AI lite review requested due to automatic review settings November 6, 2026 17:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Copilot AI lite review requested due to automatic review settings November 6, 2026 23:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

Copilot AI lite review requested due to automatic review settings November 6, 2026 23:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@GLinnik21
GLinnik21 merged commit 96be5e2 into plxnative:main Nov 6, 2026
13 checks passed
@PilaScat
PilaScat deleted the feat/honour-server-stop branch November 7, 2026 00:36
GLinnik21 added a commit that referenced this pull request Nov 7, 2026
#1265 added FailureKind::ServerStopped. The server ending the session is
not the backend's refusal, so it maps to an unknown presentation failure
and arms no backend fallback.

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

Copy link
Copy Markdown
Collaborator

Thanks

GLinnik21 added a commit that referenced this pull request Nov 7, 2026
…nto lane/merge-1265

#1265 lands where integ keeps that code: the neutral parts (timeline reply, terminal-for-the-logical-
playback, recovery cancel, read-out) stay in media; the physical Feed parts (deferred cleanup of an
in-flight native Load, the off-frame release of the stopped engine) are play-feed's, reached through
`FeedStop::stop_begin(terminal)`. A server stop is terminal for whichever backend plays: the
backend-neutral `route_start::retire_if_server_stopped` releases a Feed engine or a URI attempt.

#1268's paths take integ's side (integ is the superset); `backend_metrics.rs` gains main's
`ServerStopped` arm, and the contract's `RuntimeFailure` gains the variant.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GLinnik21 added a commit that referenced this pull request Nov 7, 2026
GLinnik21 added a commit that referenced this pull request Nov 7, 2026
…io, plx_base::clock, LoadVideo in platform, contract landing plan (#1272)

Moves the lower-layer pieces the backend-neutral media code reads below `plx_media`, with no
backend named:

- The HTTP range transport moves from `media/src/curlio.rs` to `plx_net::range_io`, with its
  `curl_multi_*` `dynlib!` table (same symbols, candidates and one `Once`). `media::curlio` stays
  as the Plex credential facade over it, so its callers are unchanged.
- `plx_base::clock` holds the monotonic clock `player::vclock_ms` now delegates to.
- `LoadVideo` moves to `plx_platform::devcaps`; media's `engine::LoadVideo` re-uses it.
- Plex `MediaPart.duration` and data `PlayingItem.duration_ms`.
- The playback contract gains the Dolby Vision landing plan and withdrawal, `dv_landing_due`,
  `DvStandDown`, `stop_begin(terminal)` and `ServerStopped`, matching #1263 and #1265 on the
  integration branch; nothing on main calls them yet.

`range_io` now asks the URL authorizer again at the start of a seek or reopen. That has no
production effect today (curl sources are https, and a TLS origin is always allowed). With it, a
start that returns early resets the attempt state, so a read after a refused seek fails instead
of returning stale bytes and a clean end of stream.

Related: #1064

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nphil added a commit to nphil/Marquee that referenced this pull request Nov 18, 2026
The timeline answer is now read for a server stop (an admin ending the stream
from the dashboard). Playback ends at once, shows the server's own reason with
Back as the only action, and the dashboard row is retired. A stop for another
playback, or one that arrives after Back, changes nothing.

Ported from upstream 96be5e2 (Playback: honor Plex server stops (plxnative#1265)).
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.

3 participants