Skip to content

tiering: an unobtainable release is replaced by the next best copy; e2e for it and the other uses - #154

Merged
frindle merged 10 commits into
mainfrom
e2e-all-uses
Dec 1, 2026
Merged

frindle merged 10 commits into
mainfrom
e2e-all-uses

Conversation

@frindle

@frindle frindle commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Goal

When the release behind an offloaded file cannot be fetched back (NZB gone, articles missing, a failed restore), the next best copy takes its place and the viewer does not notice. This PR holds the product change for that, the CI tests of its code path, and the real-stack scenarios that prove it, together with the earlier scenarios for the other ways Plex and the arrs use an offloaded file.

The seven checks, before and after

# "Not noticed" means On main Here
1 The play goes on, no error; the wait is measured and inside the restore budget The flow existed; nothing measured it Unchanged flow; scenarios E, H, F measure it
2 Plex keeps the item: same key, same path, state kept, no duplicate By design; never checked Checked by E, H, F
3 The arr sees its file, starts no grab or upgrade A rescan was sent; nothing checked Checked by E, H, F
4 The pick is the next best copy; each refusal has a reason Highest resolution first; no rule for edition, run time or language; no reasons New pick rules, reasons in the events
5 The new row is a normal row (integrity hash, promote and demote work) No sha256: promote refused the row for good SHA-256 made in the hash build; scenario N
6 Only the owner is told Automatic path only; by hand wrote no alert One path, same alert
7 Nothing qualifies: loud to the owner, row untouched Automatic path only One path; scenario G

Product change (tiering/offload)

  • The pick (substitute.py, qualify.py, new probe.py, newznab.py): a candidate whose name says another edition or other language words is dropped; the nearest resolution is tried first (the same, then higher, then lower); the pick, the planned alternative too, is imported and its first bytes are probed beside our own head. The run times must agree within max(SUBSTITUTE_RUNTIME_TOL_S, run time * SUBSTITUTE_RUNTIME_TOL_FRAC) (20 s, 0.5 %) and the first sound track must have the same language. What cannot be proved is dropped. substitute_pick and substitute_failed carry the reason per dropped candidate.
  • The integrity record (substitute.py, runner.py): the hash build already reads the whole file once for the chunk list; it now also makes the whole file's SHA-256, so a substituted row has the same records as any other row and ops.promote keeps its one strict path. A substitute has no earlier copy to compare with, so the strongest statement available is "the promoted file is exactly what the release served when it was hashed, with no holes"; a second, weaker verify path in promote would have been a second trust rule. The runner waits with a promote while the manifest is pending, and never hashes a row that is retired or failed.
  • By hand is the automatic path (runner.py, switch_live.py): --switch-live <id> goes through Runner._switch, the same function the automatic switch uses: the substitute instead of a full local restore, the same auto_switch event, the same owner alerts. Exit 1 when nobody could be switched. This changes what --switch-live does by hand; --check is unchanged.
  • A search that could not be done or checked costs a ten-minute retry, no longer the six-hour cooldown.
  • The hash build opens its own database connection on its thread.

OFFLOAD_DESIGN.md and tiering/README.md describe the rules and the honest limits.

Tests

  • CI (tests/test_substitute_real_path.py, 8 tests): the real modules end to end with nothing stubbed between the steps: --mark-failed, --switch-live by hand, the hash build the runner resumes, then a real ops.promote of the substituted row; plus the refusals (bytes that were not hashed, a changed head, no candidate, a dry run, a build that must run once across processes). Real sqlite, stub, manifest, chunk list and library link in a temp dir; the bytes are made at run time. Only the two far ends are stand-ins, because CI has no Usenet and no Plex.
  • Real stack (tests/e2e/plex_e2e.py, never run by CI; run by signed jobs on the server, on the one test row, with the real player):
    • D: the release is unobtainable and nothing has replaced it: a play past the head waits.
    • G: nothing qualifies: the real search runs, every candidate is dropped, the owner is told, the row stays as it was.
    • E, H, F: the release is made unobtainable with --mark-failed, the row is played, --switch-live runs: checks 1 to 6 (E the planned alternative, H with the player paused, F a live search with the runner running).
    • N: the runner hashes the new row and then promotes it like any row, during a play.
    • offload_try_row.py: the runner's own single demote for the test row while the runner is paused, so a used row is cold again without waiting for a night.
    • Earlier in this PR: T transcode, S seeks, Z long pause, M two streams, P Plex's own tasks, R arr refresh, K tracks, W demote window, L shadow decisions, audit, and rearm_try_row.py.
  • The new pick and probe rules have no unit tests on made-up media. They are judged on the real stack by E, H, F and G.

Known limits (not fixed here)

  • The automatic switch starts only on a chunk mismatch or a bad_chunk. A release whose remote cannot be read at all stalls as a read error and is not switched by itself.
  • A watched substitute costs two whole-file reads (hash build, then promote).
  • A hash build that failed is tried again only after a runner restart.
  • Refused candidates stay imported in the download client.
  • An MP4 whose index is at the end cannot be probed from its first bytes and is dropped.
  • A substitute with another file extension gets another library path.

Deploy

Through update.sh. No setting changes its default.

…file

Adds to tests/e2e/plex_e2e.py, in the existing style (counts and states on the
PASS/FAIL/SKIP/INFO lines, ids only on DETAIL lines, changes put back in finally):

T  server transcode (lower bitrate, then another container), pulled as an HLS client
S  seek past the head, back before the fetch point, back into the head, forward again
Z  long pause past the slot, watched and read-wait timeouts, then resume
M  two streams at once (same file; a second file only when a role is named)
P  Plex's own analysis and folder scan must not fetch the whole file
R  arr refresh and rescan: same file record, the link is still ours, nothing fetched
K  audio and subtitle track switches during a play, selection put back
W  no demote starts while a watched file is fetched (read-only)
audit  nothing left dangling: link, stub and manifest of every row that is not whole

rearm_try_row.py makes the try-row re-arm a reusable step (dry unless REARM_APPLY=1).
llm_shadow_check.py checks, read-only, that the LLM layer is in shadow mode.
The README says what each scenario costs, what should happen per use, and why arr
rename, delete and upgrade stay a written plan.

Scenarios run only on the real server through runner jobs; nothing here runs in CI.
… that changes state

rearm_try_row.py no longer retires the consumed try row when no candidate passes, and
refuses before writing when the allowlist would grow. The audit does not judge a row
whose state changes while it is looked at (a fetch that ends mid-check). The harness
header now lists E2E_WINDOW_S.
…mote

A played row stays whole for the idle window, so a try row that a scenario
played while it still waited for its first demote would never be offloaded,
and the re-arm kept it forever. It now reads Plex first and retires such a
row like a consumed one. REARM_VERDICT_ONLY=1 stops after the verdict line,
so a job can ask what would happen to the old try row without a search.
With E2E_ATTACH_S set, W waits that long for a session of the try row before
it begins a play itself, so a job can start it beside S and have it sample
the runner during S's fetch.
…-live by hand uses it

When a release behind an offloaded file cannot be fetched, the next copy must take
its place without the viewer noticing, and the row must be a normal row afterwards.

- The pick: a candidate whose name says another edition or other language words is
  dropped, the nearest resolution is tried first (the same, higher, lower), and the
  pick (the planned alternative too) is imported and its first bytes are probed
  beside our own head: the run times must agree and the first sound track must be
  in the same language. What cannot be proved is dropped. substitute_pick and
  substitute_failed say why each candidate was dropped.
- The integrity record: the hash build that reads the whole middle once also makes
  the whole file's SHA-256, so a substituted row has the same records as any row
  and promote keeps its one strict path. Before this the row had no sha256 and
  promote refused it for good. The runner waits with a promote while the manifest
  is pending, and never hashes a row that is retired or failed.
- By hand: --switch-live goes through Runner._switch, the automatic switch's own
  path: the substitute instead of a full local restore, the same auto_switch event
  and the same owner alerts. Exit 1 when nobody could be switched.
- A search that could not be done or checked no longer costs the six-hour cooldown.
- The hash build opens its own database connection on its thread.

tests/test_substitute_real_path.py runs the real modules end to end over a local
remote: mark failed, switch by hand, hash build, promote, and the refusals.
… the try row now

- D, G, E, F, H make the release unobtainable the way the owner does (--mark-failed),
  play the row on the real player and run --switch-live by hand. They check that
  the play goes on and how long it took, that Plex keeps the item, that the arr
  keeps its file and grabs nothing, that the pick is the same cut, that the new row
  is a normal row, that only the owner is told, and that nothing changes when no
  candidate qualifies. N waits for the runner's hash build and promote of the new
  row. No event is injected any more.
- The try row is followed through a substitute to its newest row (harness, re-arm).
- offload_try_row.py runs the runner's own single demote for the try row while the
  runner is paused, so a used row is cold again without waiting for a night.
@frindle frindle changed the title e2e: scenarios for the other ways Plex and the arrs use an offloaded file tiering: an unobtainable release is replaced by the next best copy; e2e for it and the other uses Dec 1, 2026
@frindle
frindle merged commit f6f4693 into main Dec 1, 2026
11 checks passed
@frindle
frindle deleted the e2e-all-uses branch December 1, 2026 22:16
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