Skip to content

Playback: a refused audio format is learned only from a retry that proved it - #1061

Merged
GLinnik21 merged 33 commits into
mainfrom
series/learn-refusals
Oct 26, 2026
Merged

GLinnik21 merged 33 commits into
mainfrom
series/learn-refusals

Conversation

@GLinnik21

Copy link
Copy Markdown
Collaborator

Third PR of the playback-refusal series (#918). It is stacked on #1060 (S1a), so the diff shown is S2a only.

A refused audio format is now remembered only once a retry has proved that the TV refused that stream. A recovery that changed several things at once, or that never isolated the stream, no longer teaches anything.

Closes #1046

The proof rule

A request records a proof for audio facet F when all of these hold:

  • the facet rung's single conversion flight landed;
  • the landed flight's PMS /decision shows the audio lane as transcode and the video lane as copy or directplay;
  • that request reached its first picture.

There is no proof when any of these apply:

  • the request had already shown a picture before the flight (pictured);
  • another Load started before the proving picture (Proving { loaded });
  • PMS did not state the lanes.

Learning comes only from a proof. These never teach: the HLS rung, the rollback of an Original trial, a Load timeout, a source failure, and a refused flight.

The lanes come from decision_lanes (route/plan.rs), which reads the flight's own /decision body. They reach the machine as PreparedEncode → AppliedRetranscode → RecoveryLanding.lanes → FlightLanded { lanes }.

The machine (OpenRecovery)

  • New state Proving { facet, loaded }. FirstPicture in that state emits ConfirmRefusal { facet, evidence: Proof }.
  • Audio: per-TV Opus limits, and formats the player learns to avoid #1034's immediate learning is unchanged. A num=200 on natively fed audio, or the native stall, emits ConfirmRefusal { facet, Named } and picks the ladder rung in the same step.
  • Confirming and RefusalConfirmed are deleted. The recorder's answer never picked a rung.
  • The pump executes ConfirmRefusal through the injected recorder: session::record_named_refusal / record_refusal_proof. Each is one queue_update on the Install record, with the merge inside the queued closure. The machine still reads no global and performs no IO.

The stored row

NativeAudioRefusal keeps its preference key and gains proofs: Option<u32>.

  • None is a named refusal, which applies at once.
  • A counted row applies from LEARNED_REFUSAL_PROOFS = 2. That is D6: audio rows persist after a second proof.
  • A named refusal replaces a counted row, and a proof never downgrades a named row. A third proof writes nothing.
  • A proof of unknown width is not stored. Video facets are never stored.
  • The firmware build change still clears every row.
  • Rows written before this change read as named. Every one of them came from the num=200 or stall path, so no migration code is needed.
  • devcaps::learn_refusal is deleted. A refusal reaches caps() only when its write lands and the session projects the record (project_stored_refusals), which applies only the rows that apply.

Behaviour changes, and interim notes until S2b

  • A named refusal reaches the process-wide answer when its queued write lands, not synchronously. The conversion that follows plans from the request's own narrowed value (Route: one capability value per playback request; the planner reads no global #1054), so no play plans the refused stream in that window.
  • On a TV whose storage cannot be written, a named refusal is not remembered for the rest of the run, where S1a remembered it in memory. Each play then pays one refused Load. S2b's Caps::minus over the record removes this.
  • A rescue in which PMS also transcoded the video never proves, so such a file pays one refused Load per play. That is by design: the proof has to isolate the stream.
  • Under plxnative-nativeaudioforget, a refusal recorded during the run is stored but does not apply until a launch without the flag.
  • Known narrow gap: if the landing's own reload fails synchronously, the machine stays in Proving { loaded: false }. The viewer is on the failure read-out then, and cannot switch tracks.

Tests

Pure transition tests (recovery.rs):

  • every state × event pair pinned (25 distinct pairs);
  • one proof from a clean facet flight;
  • no proof from the both-facets, rollback, timeout or source-failure rungs;
  • no proof from a flight that did not change the facet alone;
  • no proof on a refused proving reload;
  • a_request_that_already_pictured_never_proves_a_facet_flight;
  • only_the_landings_own_reload_keeps_the_pending_proof;
  • a_reload_the_landing_did_not_ask_for_drops_the_pending_proof;
  • a named refusal confirming and picking its rung in one step.

Record tests (plx_plex):

  • the first proof is counted and not applied;
  • the second persists, and a third writes nothing;
  • named wins;
  • a build change clears counted and named rows;
  • a pre-S2a row reads as persisted;
  • an unknown width is not stored.

Hostsim rig (pump.rs):

  • a_dts_601_rescued_by_its_conversion_records_one_proof_not_applied, through the real projection;
  • a_second_rescued_play_persists_and_the_next_start_lacks_dts_surround;
  • an HLS-rescued, timeout-rescued or video-transcoded rescue records nothing;
  • a_named_opus_refusal_is_recorded_before_any_landing;
  • confirm_refusal_writes_only_through_the_injected_recorder, which runs the real recorder under a TempSession.

Other:

  • decision_lanes_reads_each_lane_and_never_the_contract;
  • the devcaps debug-flag test now runs through project_stored_refusals.

Red-first: the review's two fixes, pictured and Proving { loaded }, plus their table pins. The rest of the suite was written after the code. Its assertions were then tightened, as the review asked, so that they go through the real projection and can fail.

Crate suites on the committed tree:

  • make test-crate C=plx_media: test result: ok. 1802 passed; 0 failed; 64 ignored
  • make test-hostsim C=plx_media, run twice: test result: ok. 1988 passed; 0 failed; 64 ignored
  • make test-crate C=plx_plex: test result: ok. 741 passed; 0 failed
  • make test-crate C=plx_platform: test result: ok. 307 passed; 0 failed
  • make test-crate C=app: test result: ok. 1059 passed; 0 failed
  • make test-hostsim: test result: ok. 1174 passed; 0 failed
  • make check-nodef: clean.
  • check-deps, check-module-layers, check-machine-shape (with its self-test) and check-list-caps: green.

ci/allow/* is unchanged. make check and the ARM build are left to CI.

Docs

  • player/CLAUDE.md: the learning rule, the row, Proving, and what a reload does to a pending proof.
  • docs/sans-io.md.
  • The devcaps comments: refusals come from the stored record alone, and the debug-flag semantics.
  • The recovery.rs module doc and table.

🤖 Generated with Claude Code

GLinnik21 and others added 25 commits October 26, 2026 04:05
… recovery flight read it (wip, tests next)

PlaybackSession holds an Arc<Caps> read once where an attempt starts
(request_play_with_queue, and the native-audio conversion's dispatch);
ResolveEnv, the rebase/recovery/retranscode/ABR captures and TranscodeSpec
carry it, so the route's gates and the profile string PMS reads come from the
same value instead of two reads of the process-wide answer.

Refs #1044

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…d refusal reaching its flight)

Caps A (a DTS row) and B (= A.without(Audio dts)) pick differently and profile
differently with no global installed; the native-audio recovery flight's
replacement /decision carries the ceiling learned mid-attempt.

Refs #1044

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… none

The app's play start (request_movie / request_episode / the content and
queue paths) reads devcaps::caps() ONCE and hands it to the route's
request_play* entry points, which begin the attempt on it. The planner,
the resolve worker and every mid-film rebuild plan from that value
(PlaybackSession::caps, ResolveEnv::caps); route no longer reads the
process-wide answer to plan, and plan.rs holds no devcaps::caps( and no
zero-argument is_dp_audio( / is_dp_audio_track( (the cfg(test) pick
wrappers take the &Caps too).

The pump's ConvertNativeAudio no longer re-reads the global after the
lesson: dispatch_native_audio_conversion narrows the playing attempt by
what the demuxer fed (Caps::without), so the replacement /decision
carries the learned ceiling from the attempt's own value. The #1034
pin test (the refusal reaching its recovery flight) is unchanged.

ci/check-deps.sh: the `globals` rule is widened to devcaps::caps( and the
zero-argument is_dp_audio( / is_dp_audio_track( (qualified, or bare after
an import; the _with forms do not match). It is a coverage expansion, not
a shrink: no machine reads them, so zero ledger lines were seeded and
PINNED_LEDGER_TOTALS is unchanged. A self-test covers the shapes.

Refs #1044

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…, not only the conversion's

The failed-open recovery chose the Original trial's rollback over the conversion when both
applied, and only the conversion narrowed the attempt's Caps. The refusal was learned (the
process-wide answer lost the audio), but the attempt kept the value the play started on, so the
rollback's rebase profile, a later retry and a quality change offered native Opus again. The
pipeline refused it again, `learn` returned false (known combination), and a manual Original ended
on the read-out where main converted.

recover_failed_source_route now narrows the attempt (PlaybackSession::narrow_attempt) before it
picks the recovery, once per learned refusal; dispatch_native_audio_conversion no longer repeats it.
The pump rig test a_native_audio_refusal_learned_during_the_original_trial_reaches_the_rollbacks_profile
failed on the rollback's /decision profile before this and passes after.

Also: the docs the change made false (learn_native_audio_refusal, devcaps::learn_refusal, the Caps
struct, plex/mod.rs's allow list, webos5-port.md's codec-capability bullet, sans-io.md), and
FlightRig now begins its attempt on the thread's devcaps::caps() so rig tests plan from the table
they install rather than the pre-probe fallback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… does without HEVC

The previous wording said "H.264 alone" for a set whose table lists no HEVC decoder, which drops
the VP9 / AV1 copy lanes a table may still list. The direct-play list omits hevc
(direct_play_video_codecs) and the transcode target's encode head is h264 (Caps::encode_vcodec).

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

Step 0 of the playback-refusal S1 lane. Two hostsim rig tests drive the real foreground actuator
and the pump -> poll_foreground_load order of playback_tick:

- an asynchronous type=18 after the Load call returned (route Started, then load_failed): the
  lifecycle reads Started and lets go (Idle); the pump's failed-open ladder fails the Engine.
  This is the case OpenRecovery will own.
- a synchronous refusal (StartFailed together with load_failed, as threads.rs publishes it): the
  pump fails the Engine (read-out) AND the lifecycle then settles the same refusal as #1018's
  retry (Prepared, Engine retired). Two machines act on one refusal today; the test names say so,
  and the split that fixes it (the lifecycle keeps the Load call's own result) follows.

launch_restore is the first half of refuse_restore, extracted unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ng main's four arms

`open_failure_action` was a pure function over four booleans the pump gathered after it
had already run the install's learner and narrowed the attempt. It is now `OpenRecovery`
(`player/recovery.rs`): a tested `State + Event -> Effects` machine owned per request by
`PlaybackSession::recovery`, driven by `pump.rs` (`drive_open_recovery`) the way
`ForegroundLifecycle` is driven by `foreground.rs`.

Characterization only: the ladder is main's, in main's order (pending HLS->Original rollback,
the conversion of native audio the install just learned the pipeline refuses, a cold Auto
Original's HLS contingency, the read-out), and a native-audio STALL of a combination the
install already knew still only logs (that is the next change's bug, pinned by a test).

- Events `Refused{refusal, facts}`, `RefusalConfirmed{newly}`, `FlightLanded`, `FlightRefused`,
  `FirstPicture`; effects `ConfirmRefusal`, `Rollback`, `StartFlight`, `StartAutoHls`,
  `ShowError{refusal}`. The learner is IO, so the machine asks for it (`ConfirmRefusal`) and the
  pump answers with whether the combination was new, in the same drain; the rung is picked on
  that answer. `LoadRefusal` is the typed payload: `Refused{num}`, `TimedOut`, plus `Stalled` and
  `SourceFailed` for the watchdog and the demuxer/transport branches that share the ladder.
- The attempt's capabilities moved into the machine (`start` plus the audio facets excluded, the
  attempt always re-derived from `start`): `PlaybackSession::caps` and `narrow_attempt` are gone,
  `attempt_caps()` delegates, and the narrowing happens inside `step` on a newly learned refusal,
  on every arm, as `recover_failed_source_route` did.
- `FirstPicture` is stepped from the pump's decoded-frame branch; the machine is idempotent there.
- `ci/machines.ini` registers the machine; `player/recovery.rs` joins the workers/globals scope
  of `ci/check-deps.sh` with no ledger line. `open_failure_action`'s unit test moved into the
  machine's table tests with the same seven expectations.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…w ends on the read-out, not on "Buffering..."

TV run G (2026-10-26): a stored {opus, 6ch} refusal and a transcode fixture serving 1600 B
6-channel Opus again. `native_audio_stall_fired` returned false for a combination the install
already knew ("only logs"), so the pump neither failed the Engine nor showed a read-out, the
watchdog was spent, and the viewer stayed on the buffering spinner for good.

The stall is a refusal of the same class as `type=18` (`LoadRefusal::Stalled`). OpenRecovery
now runs the ladder on the learner's answer whatever the refusal: a known combination is a
refusal with no conversion left, so it takes the next rung (a pending Original trial's rollback,
a cold Auto Original's HLS contingency) and else `ShowError`.

Red first: the rig test (a stored {opus,6ch}, both AU queues holding data, nothing accepted for
NATIVE_AUDIO_STALL_MS, the watchdog's STALL line asserted as its precondition) failed with
"a stall of a combination the install already knew left the viewer on Connecting" before the
change and passes after it. player/CLAUDE.md's "a known refusal fails as before" held only for
the `type=18` path; it now says what both paths do.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…, owned by OpenRecovery

Comment-only. `PlaybackSession::caps` no longer exists (the value lives in the request's
`OpenRecovery`); three doc comments in plan.rs, devcaps.rs and session.rs still named the
field or the route as the narrower.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ecycle's alone; the ladder owns refusals observed after the call returned

The pump's failed-open ladder and the foreground lifecycle both acted on a synchronous
refusal of a foreground-resume Load (StartFailed + load_failed): the pump set Error, then the
lifecycle settled the same refusal as #1018's retry and retired the Engine.

Split by who observes the refusal. The foreground actuator marks the Engine whose exact Load
attempt it follows (Engine::foreground_follows_load, set where it starts or takes over following
an attempt). The pump decides before stepping the machine: a failed Load on a followed Engine
whose route_start_status is Failed is the Load call's own result, so it returns and the
lifecycle's Failed settlement owns it. A refusal seen after the call returned, and a fresh play's
synchronous refusal (no lifecycle behind it), stay the ladder's.

The step-0 SYNC test is flipped to the desired behaviour (red first: the pump left Error), the
ASYNC test is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-facets rung and a 2-flight cap

A pipeline refusal before the first picture now converts the suspect audio (a codec outside
aac/ac3/eac3, named by recovery::suspect from the stream the pipeline was fed) in one recovery
flight, then takes the HLS contingency of a cold Auto Original, then the read-out;
MAX_RECOVERY_FLIGHTS bounds the flights of one request. The learner's answer (newly) no longer
selects a rung: a facet the attempt's start already lacks narrows nothing and gets no flight.
Forced Direct Play ends on the read-out after a pending rollback. StartFlight is ConvertFacet and
dispatch_native_audio_conversion is dispatch_refusal_conversion.

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

The Retranscode landing of a recovery flight notes the delivery (and the app's own recovery as the
open's origin) through report::note_refusal_recovery_delivery; the reason joins the closed list,
the consent legend and PRIVACY.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… landing re-grades the Original candidate's audio; the #695 rig tests

plxnative-refuse601 (dev builds) publishes type=18 num=601 through sf_on_event once the Load
returned and before a picture, once per playback trace generation, so the converted reload of
the same request plays. The flag is read only inside that open window (a process-wide latch
cannot be armed per test).

The refusal-recovery landing calls regrade_original_audio, so the stored Original candidate's
audio is graded against the narrowed attempt and the ABR climb plans the remux, not the
refused audio's Part.

Hostsim tests: a DTS 601 converts in one flight (#695, with and without a sibling), an Auto
Original flies the conversion not HLS, a refused conversion ends on the read-out, the climb
after a rescue plans no DTS direct play, the landing notes its delivery reason and counts the
attempt once, refuse601 publishes once per request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…1a ladder made false is rewritten

ConvertFacet carries the facet and the flight ordinal, so the driver logs 'converting {facet}
(flight n/2)'. The learner's doc, the pump's refusal comments, dispatch_refusal_conversion's doc,
the type=18 callback comment and the player guide describe the ladder as it is: the facet rung is
chosen by suspect() and the loop guard, not by the learner's answer.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… the ladder did not ask for re-opens it; an unhandled refusal fails the Engine

The ladder lives per request but a picture is per Engine: the facet rung is gated on
the refusal's own Engine having no decoded frame (facts.no_frames), not on the
request's history, so a native-audio refusal on a reloaded Engine converts again.
RecoveryEvent::LoadStarted, raised by engine::start_bufferfeed_for (the funnel every
Engine start passes), takes a Flight or Failed machine back to Opening when a park and
restore re-Loaded the route without a landing; the recovery landing's own reload finds
the machine already in Opening and changes nothing. recover_failed_open fails the
Engine on a refusal the machine does not handle, as before the machine.

The stall branch gets the preview check the other failure branches have; the DTS rig
tests are renamed and tightened.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ladder change made false is corrected

The pure table now walks the full cap as a fixpoint over (state, flights, excluded) with
FirstPicture, a free RefusalConfirmed, FlightRefused, LoadStarted and a Refused of an Engine that
did show a picture, and pins every (state, event) pair once. The CLAUDE.md ladder paragraph, the
Sans-IO scope notes, the check-deps header, the pump and decision docs and parity-gaps item 5
now describe the per-Engine facet rung, the LoadStarted re-entry, and the driver failing the
Engine for a refusal the machine does not handle.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… proof (S2a, #1046)

A DTS 601 names no codec, so a refusal of it was never learned and a refusal
that does name one was applied from a single event. The OpenRecovery machine now
separates the two kinds of evidence:

- Named (num=200, the stall): ConfirmRefusal{Named} is emitted in the same step
  as the ladder's rung; there is no Confirming state and no RefusalConfirmed
  event. The row applies at once (no `proofs`).
- Proof: a facet flight whose /decision lanes are audio=transcode and
  video=copy|directplay (FlightLanded{lanes}) enters Proving; the first picture
  of the converted reload emits ConfirmRefusal{Proof}. Both-facets (HLS),
  rollback, timeout and source-failure rescues prove nothing.

The stored NativeAudioRefusal gains `proofs: Option<u32>` (absent = named or
pre-S2a row = applied). A counted row applies at LEARNED_REFUSAL_PROOFS (2);
named wins on merge, proofs add capped, a proof of unknown width is not stored.
The writers (record_named_refusal / record_refusal_proof) only read
devcaps::learning_firmware() and queue the merge on the storage worker; devcaps
no longer carries a write door (learn_refusal is gone), the row reaches the
capability answer through the record's projection of applied rows.

Lanes are parsed from /decision by route/plan.rs::decision_lanes and carried
PreparedEncode -> AppliedRetranscode -> RecoveryLanding -> FlightLanded.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ed proof, not devcaps::learn_refusal

Prose the S2a change made false: player/CLAUDE.md's learned-refusal section,
docs/sans-io.md and a test_harness docstring still named learn_refusal and
described a refusal as applying at once from the pump.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…rves it

The non-hostsim test build compiled decision_test_support.rs without the rig,
so MDE_TRANSCODE_BOTH was dead code there (-D warnings). Defined where it is used.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…e its picture, proves nothing (S2a, #1046)

A facet flight proved its conversion whenever PMS answered the lanes clean, even when the request had
already played the facet natively: the picture is per Engine, so the facet rung is reachable from
Playing (a Home, a return, a restore Load refused before its picture), and two such restores would
persist a wrong row. OpenRecovery now remembers that a picture showed (pictured) and enters Proving
only for a request that showed none.

A Load between the clean landing and the first picture (a track switch, a restore after Home, a seek
reload) read as the landing's own reload and kept the pending proof for a route whose lanes were never
read. FlightLanded moves the machine BEFORE the driver reloads, so Proving carries `loaded`: the first
LoadStarted is the landing's own reload, a second one drops to Opening and loses the proof.

Tests: the first_picture helper asserts its refusal flag arrived (5 s, not a silent 500 ms fall-through);
confirm_refusal's recorder test runs the real recorder under a temporary session and reads the answer
before the queued write lands; the proof and named-opus rig tests project the real record before their
capability assert; decision_lanes and Proving x named Refused get direct pins; the debug-flag test goes
through project_stored_refusals (nativeaudioforget applies NONE, so a row recorded during the run
reaches caps() on the next launch). Prose corrected where it described the old landing and the old
forget behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@GLinnik21 GLinnik21 added enhancement Planned improvement (ideas start in Discussions) playback Playback, the player and its controls labels Oct 26, 2026
GLinnik21 and others added 2 commits October 26, 2026 11:51
…fusal of their Load before the next frame

The rig's Engine is never built by a real sf_load (the rig forces the host object ready), so its teardown cannot prove
the release and quarantines the host sink; every Load a test then starts (the foreground restore, the facet landing's
reload) is refused by the stub from the MEDIA thread (ok=0, no type=18 callback, so a refusal with num=0). The tests
assert "not Error" after a frame that follows the start; they pass only while that frame beats the media thread. When
the media thread wins, the frame reads a second refusal of an open whose facet is spent and the ladder ends on the
read-out ("no rung left for type=18 num=0"). The CI hostsim job failed on S3 (#1063) in two of these tests with no
S3 code involved; a loop of only the pump tests failed the same way (1 of 60 and 4 of 250 runs under load).

pipeline_takes_the_load awaits the stub's refusal of the Load and takes it down, and is called after each Load these
tests go on to grade: park_and_restore (Scenario B), Scenario A's restore, and refuse601's reload. The refusal is now
always absorbed before the frame, so every run takes the ordering that used to lose; the test's own
pipeline_refuses_601 still ends the open. No production change: on a set the restore's Load returns ok=1 and the
pipeline then refuses it with 601.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
first_picture takes the hostsim sink's refusal through pipeline_takes_the_load
(S1a's helper) instead of repeating its wait-and-clear body.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Base automatically changed from series/open-recovery to main October 26, 2026 09:47
@GLinnik21
GLinnik21 merged commit 3b159ed into main Oct 26, 2026
19 checks passed
@GLinnik21
GLinnik21 deleted the series/learn-refusals branch October 26, 2026 10:15
GLinnik21 added a commit that referenced this pull request Oct 26, 2026
# Conflicts:
#	rust-modules/media/src/route/decision.rs
GLinnik21 added a commit that referenced this pull request Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Planned improvement (ideas start in Discussions) playback Playback, the player and its controls

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A refusal a retry proved is remembered for this firmware build

1 participant