Skip to content

home: a failed hub fetch says so, and retries, instead of blanking the screen - #11

Merged
GLinnik21 merged 1 commit into
parity-stagingfrom
unit11-home-loading-error-retry
Jul 29, 2026
Merged

GLinnik21 merged 1 commit into
parity-stagingfrom
unit11-home-loading-error-retry

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Closes the parity-gap appendix entry "Home has no loading, empty or error state, and never retries a failed hub fetch" (docs/parity-gaps.md:397).

Rebased onto origin/parity-staging (base changed from main). Host suite 132/132 — staging's 122 plus this unit's 10. One conflict was a real API collision, resolved below.

What was wrong

pms_fetch_hubs built new_cat/new_hubs/new_pool and committed all three unconditionally, so a failed GET /hubs committed an empty catalog — the old doc line said so outright: "A failed fetch commits empty, blanking the home consistently." One bare dark screen then stood in for three entirely different situations (still fetching / server unreachable / library genuinely empty), with no spinner, no message, no affordance, and nothing that would ever try again: the only ways out were an app restart or a playback session happening to end.

What this does

  • pms.rs gained a fetch state machine — HubState::{Loading, Ready, Failed} — modelled on browse.rs's page store, which had already learned both lessons this needed: a failed fetch must never overwrite a populated store (a wifi hiccup once blanked a whole grid permanently), and a fast-failing network must be held off by a countdown instead of re-spawning a worker every frame. A failure now keeps the catalog it already had; only an identity change (pms::reset, called from install_pms beside the existing browse::reset) wipes it.
  • ui/home.rs draws the read-out from that state through the shared widgets::StatusOverlay — spinner + "Loading your library…", danger-tinted "Can't reach your Plex server", or a neutral "Nothing on this server yet" — with one pill under it. It appears only when there are no shelves at all: a background refresh that fails behind a populated Home stays silent and heals underneath rather than throwing an error over content the user can still use.
  • widgets.rs gained StatusKind::Empty (neutral tint, no spinner) rather than a fourth hand-rolled empty-state Label, plus Button::pill_w so the +68 pill-padding rule lives on the button instead of being re-derived at each call site.
  • app.rs is two one-line hooks: pms::reset() in install_pms, and home::status_activate(hf) at the top of the one home activation.

Retry: both, and why

Automatic on an exponential backoff (2 → 4 → 8 → 16 → 30s, then 30s) and a focusable control. Neither alone is enough on this product:

  • Automatic alone fails the person watching it. This is a television: the likeliest cause is a server that was asleep and is now awake, or a router that just finished rebooting — the user knows the server is back before we do, and making them sit out a 30-second ladder with no way to say "now" is the same dead feeling this gap is about.
  • A button alone fails everyone else. A TV is left on. The most valuable behaviour here is that Home is populated when someone walks back into the room without anyone having pressed anything — and a failed boot fetch is exactly the case where nobody is at the remote yet.

So the ladder runs unattended, and Try Again / Refresh kicks a fetch now, from the bottom of the ladder. The 30s cap means a server coming back is picked up within half a minute; the 2s floor means a transient blip costs nothing.

The retry is off-thread (task::spawn_small → mailbox → pump on the main thread), unlike the blocking boot fetch. That is what makes a live loading state possible at all: a blocking fetch on the SDL loop draws no frames while it runs, so the spinner it is meant to be spinning would never reach the panel. pump(dt) is driven from home_update, so the machine ticks exactly while Home is the screen that cares, and nothing spawns a background fetch behind the player.

Invariants preserved

  • Focus clamps into the LIVE hub bounds (home.rs:65-75, :740-749) — untouched. A retry that repopulates the shelves lands through commit, and every focus read re-clamps against the new bounds, so focus is valid by construction. pump's commit also runs detail::reselect(), the same post-mutation ritual refetch_hubs_reconcile performs.
  • A landing carries the generation it was spawned in (HUB_GEN, bumped by reset and by the blocking fetch): a retry still in flight across a profile switch is dropped whole — neither committed nor blamed — instead of putting the old account's hubs over the new one's.
  • "No shelves means no grid" is one pure rule (pinned_snap) applied in two places. set_snap_target refuses a new dive, and home_update re-applies it every frame because a catalog can empty under a snap already committed. That second half is load-bearing: left at 1.0, app.rs's pointer gate (snap_pos() < 0.5) routes clicks to the empty grid's hit-test instead of the hero rects, which would leave the Retry control — the one way back — silently unclickable. Found by review, not by luck.
  • The escapes stay live. The profile chip and the library tab pills keep their own activations while the read-out is up; only Retry takes the press. The status screen reuses the hero action row's focus slot and pointer rects, which is sound because the two can never be on screen together (a status state means an empty catalog, which means hero_item() is None and Hero::draw returns before recording anything).

Rebase: two pill_ws became one

The only conflict worth a paragraph. Unit 8 added a free widgets::pill_w(label, sz) — "the ONE hero-pill width formula" — and I had independently added Button::pill_w(label, sz, icon). Two width formulas for one control is precisely the drift ui/CLAUDE.md exists to prevent.

Kept mine, on Button, reading unit 8's named metrics. The deciding factor is not authorship but that unit 8's own doc names its gap: "Assumes the pill CARRIES an icon … an icon-less button measured through this gets an icon box of air it will not fill. Size that one from text::text_width directly." That sentence is a second sizing path, and this unit's Retry pill is exactly the caller it sends down it. The icon flag closes it, so there is one formula for every pill in the product.

It lives on Button because the icon box and gap are Button's private layout, and it now reads BTN_ICON_RATIO/BTN_ICON_GAP/BTN_PILL_AIR — the same constants Button::draw lays out with, so measurer and renderer cannot disagree rather than being asked to stay in step.

  • Every caller goes through it: home's hero pill and detail's Play/Resume pill pass icon: true, Home's Retry passes false. The free function is gone; no widgets::pill_w call site remains.
  • No pixel change for the two hero pills — with icon: true the expression is byte-identical to unit 8's, which matters because staging notes detail's pill is deliberately pixel-identical to home's.
  • Two strays fixed while there: the TabPill banner comment claimed pill_w(label, sz) sizes a tab (it doesn't — TabPill::width does, and a tab has no icon box), and staging's ui/CLAUDE.md had picked up two widgets.rs table rows from parallel merges. Folded into one row carrying every unit's clauses.

The other three conflicts were mechanical: Button's icon metrics (took staging's named constants), home_draw's call order (staging deliberately moved draw_chip on top of the tab track — the status read-out slots into the content layer above both), and one test that looped over the now-deleted widgets::MAX_TABS, which unit 10 replaced with an uncapped scrolling strip.

Verification

Tests: +10 host — 132/132 on the staging base (122 before this branch). make check (which now also runs make lint, the clippy shadowed-branch gate) is green, and make cross-builds clean with no new warnings.

  • pms.rs (7): the backoff ladder doubles then holds at the ceiling; a failed landing never blanks a populated Home; a successful landing commits and retires the backoff; a server with no hubs lands Ready-and-empty rather than Failed; the countdown fires when the backoff elapses; a landing from before a reset is dropped whole; reset wipes the catalog and re-arms the fetch.
  • ui/home.rs (3): the read-out tells Loading/Empty/Failed apart and content silences it; the status screen takes OK but never the top band; no shelves means no grid snap.
  • One existing test (vert_cannot_walk_past_the_shelf_array) now also takes testlock::serial() — it reads pms's catalog statics, which this change makes other modules' tests write, and commit frees the old HUBS buffer. That is a use-after-free, not a flaky assertion.

A correctness review over the full diff found one real bug (the snap/pointer interaction above), one test-isolation bug (that lock), and six nits; all are fixed in this branch.

Device verification: deferred to coordinator

Not run here — no TV time was taken, and PMS_PORT in src/config.local.h was never modified. Everything below is exactly what I would have run; please run it and nothing more.

Setup (host).

  1. Edit PMS_PORT → 32499 in the gitignored src/config.local.h. Restore it to 32400 when done — a stale port there silently breaks every later run. Never commit that file.
  2. Port-collision trap: do NOT use 32401. Plex binds 127.0.0.1:32401 itself and the more specific bind wins, so the proxy is silently bypassed and a "failure" test quietly passes against a healthy server. 32499 is free (verified on this host).
  3. Start the proxy with a private control file so it cannot collide with another agent's (32499 is the port the root CLAUDE.md now documents as netcond's default, so this matches the tree):
    python3 tools/netcond.py --listen 32499 --target 127.0.0.1:32400 --mode pass --control /tmp/netcond-unit11.mode
    (it binds 0.0.0.0, so the TV reaches it at PMS_HOST:32499.)
  4. make && make deploy.

Boot deterministically. tests/run.py is not involved. Write the owner token from src/config.local.h to /tmp/plxnative-token on the TV — that installs the client and, being a plxnative-* trigger, suppresses the who's-watching picker, so the boot lands on Home. rm it afterwards.

The three states, in one app run (make run RUN_SECS=170 in the background; capture with tools/capture-screen.sh <out>.png DISPLAY):

# Arm Wait Expect on screen Expect in /tmp/plxnative-events.log
1 echo reject > /tmp/netcond-unit11.mode before launch ~20s after boot ERROR — centred red-tinted "Can't reach your Plex server", no spinner, a focused Try Again pill ~64px below it; tab pills still drawn at the top hubs: fetch FAILED (attempt N) — retrying in Ns repeating on the 2/4/8/16/30 ladder, interleaved with hubs: retrying (off-thread)
2 echo blackhole > /tmp/netcond-unit11.mode up to 30s for the next kick, then capture within 15s of the hubs: retrying line LOADING — rotating spinner above "Loading your library…", and no button a hubs: retrying (off-thread) with no FAILED for ~15s (the app's SO_RCVTIMEO)
3 echo pass > /tmp/netcond-unit11.mode ≤30s (the ladder cap) — press nothing RECOVERED — normal Home, hero + shelves, entirely on its own hubs: retry landed — N items, M shelves

Timing to expect. First retry 2s after the boot failure, then 4/8/16/30, capped. Step 3 must heal with no input — that is the auto-retry half of the feature. Pressing OK on Try Again at any point should fire a fetch immediately (a hubs: retrying line within a frame), which is the manual half.

Worth a glance while you are there: with the error state up, LEFT/RIGHT keeps the single pill lit (never a dead focus slot), UP reaches the profile chip, and the tab pills still enter a library section — those are the escapes from a dead Home.

Then: restore PMS_PORT to 32400, make && make deploy, stop netcond, rm /tmp/plxnative-token on the TV.

FPS gate. ./tests/run.py --fps (UI tier) on the restored build. This change adds one pms::pump call per Home frame (a mailbox take plus a few reads) and one draw call that early-returns whenever there is content, so home-hero / home-grid should be unchanged against a real server.

🤖 Generated with Claude Code

https://claude.ai/code/session_018GuSHrq9oydnX7nhKE1Hvc

Copilot AI review requested due to automatic review settings July 29, 2026 18:07

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 reached their quota limit.

…e screen

`pms_fetch_hubs` built the catalog, the shelves and the hero pool and committed
all three unconditionally, so a failed GET /hubs committed an EMPTY catalog —
the doc line said so outright: "A failed fetch commits empty, blanking the home
consistently." One bare dark screen then stood in for three entirely different
situations (still fetching / server unreachable / library genuinely empty), and
nothing ever tried again: the only ways out were an app restart or a playback
session happening to end.

The fetch now has a state machine — Loading / Ready / Failed — modelled on
browse.rs's page store, which had already learned both lessons this needed. A
failure keeps the catalog it already had rather than overwriting it (one wifi
hiccup must not blank a populated Home), and a fast-failing network is held off
by a countdown instead of re-spawning a worker every frame. Only an identity
change still wipes the catalog: pms::reset, called from install_pms beside the
browse::reset that was already there — without it a profile switch whose fetch
failed would leave the previous user's shelves on screen.

Home draws that state through the shared StatusOverlay, and only when there are
no shelves at all. A background refresh that fails behind a populated Home stays
silent and heals underneath, rather than throwing an error over content the user
can still use. StatusKind gains Empty — neutral, no spinner — because a library
with nothing in it is an answer, not a fault, and must not wear the danger tint.

Retry is both automatic and manual, because on a television neither alone is
enough. The ladder (2 -> 4 -> 8 -> 16 -> 30s) runs unattended, so Home is
populated when someone walks back into the room without anyone having pressed
anything — a failed boot fetch is precisely the case where nobody is at the
remote yet. The control kicks a fetch now, from the bottom of the ladder,
because the likeliest cause is a server that was asleep and is now awake: the
user knows it is back before we do. The retry runs off-thread, unlike the
blocking boot fetch, which is what makes a live loading state possible at all —
a blocking fetch on the SDL loop draws no frames while it runs, so its spinner
would never reach the panel.

Two invariants the change had to earn rather than assume. A landing carries the
generation it was spawned in, so a retry still in flight across a profile switch
is dropped whole instead of committing the old account's hubs over the new one's.
And "no shelves means no grid" is now one pure rule applied in two places: DOWN
cannot dive into an empty grid, and a catalog that empties UNDER a committed snap
is pinned back — left at 1.0, app.rs's pointer gate sends clicks to the empty
grid's hit-test instead of the hero rects, which would leave the Retry control,
the one way back, silently unclickable.

Rebasing onto the parity staging branch collided with a second width formula:
unit 8 had added a free `widgets::pill_w(label, sz)` that assumes the pill
carries an icon, and told icon-less callers to measure themselves from
`text::text_width` — a second sizing path, which is the drift ui/CLAUDE.md
exists to prevent, and Home's new Retry pill is exactly such a caller. The two
collapse into one `Button::pill_w(label, sz, icon)` reading the same named
metrics `Button::draw` lays out with, so the measurer and the renderer cannot
disagree. Both hero pills pass icon: true and are byte-identical to before;
detail's pill moves to it, and the free function is gone. The stale TabPill
comment pointing at `pill_w` now names `TabPill::width`, which is what a tab
actually uses.

Device verification is deferred to the coordinator (netcond recipe in the PR).

Tests: +10 host (132)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_018GuSHrq9oydnX7nhKE1Hvc
@GLinnik21
GLinnik21 force-pushed the unit11-home-loading-error-retry branch from 6b39550 to ef3ccb0 Compare July 29, 2026 18:28
@GLinnik21
GLinnik21 changed the base branch from main to parity-staging July 29, 2026 18:28
@GLinnik21
GLinnik21 merged commit ef3ccb0 into parity-staging Jul 29, 2026
@GLinnik21
GLinnik21 deleted the unit11-home-loading-error-retry branch August 2, 2026 18:37
GLinnik21 added a commit that referenced this pull request Aug 3, 2026
The catalog fetch was movies-only (section 1, hardcoded). Make it discover the
section keys from /library/sections and fetch every movie AND show library —
movies first (the hero stays a movie), shows appended into the later grid rows.

- New PmsMovie.kind field (0=movie, 1=show).
- fetch_section() appends a section's items at an offset (extracted from the old
  single-shot loop); shows carry no Media/Part (you play episodes, not the show),
  so the keep-condition is title && (part || is_show) instead of title && part.
- pms_fetch_movies() drops the `sec` arg; iterates movie sections then show
  sections. Verified on-device: nmovies 23 -> 35 (23 movies + 12 shows), grid
  renders show posters in the lower rows, 59fps.

First step toward the detail page (#11): a show card will open the show detail
(seasons/episodes); a movie card opens movie detail.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018QbpQTKYjwp6fDNLdXzGzr
GLinnik21 added a commit that referenced this pull request Aug 3, 2026
…ility)

The final detail-page section — the About footer at the bottom of the scroll.

- metadata.rs: extracted parse_streams(item, &mut Detail); load_detail now backfills
  a SHOW's audio/subs from its first episode's full metadata (shows carry no streams
  at the show level), so the Languages/Accessibility columns populate for shows and
  movies alike.
- ui/detail.rs: section 5 = About (always present). draw_about: an "About" heading +
  a rounded card (title, comma-joined genres, wrapped summary + MORE), then three
  columns — Information (Released / Run Time / Rated / Regions of Origin), Languages
  (Original Audio + the audio-track list "Lang (CODEC)"), Accessibility (CC/SDH/AD
  badges + standard descriptions, shown only when present). ABOUT_Y spaced so the
  footer clears the cast row when focused.

Verified on the TV (Severance): footer matches the Apple-TV reference — card, and
all three columns populated (18 Feb 2022 / 0 hr 50 min / TV-MA / United States;
Русский + full audio list from episode 1; CC with its description).

Completes the detail page (#11): hero -> season tabs + episodes -> related -> cast
-> about, all scrolling as one page, with movie + show playback wired.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018QbpQTKYjwp6fDNLdXzGzr
GLinnik21 added a commit that referenced this pull request Aug 26, 2026
The catalog fetch was movies-only (section 1, hardcoded). Make it discover the
section keys from /library/sections and fetch every movie AND show library —
movies first (the hero stays a movie), shows appended into the later grid rows.

- New PmsMovie.kind field (0=movie, 1=show).
- fetch_section() appends a section's items at an offset (extracted from the old
  single-shot loop); shows carry no Media/Part (you play episodes, not the show),
  so the keep-condition is title && (part || is_show) instead of title && part.
- pms_fetch_movies() drops the `sec` arg; iterates movie sections then show
  sections. Verified on-device: nmovies 23 -> 35 (23 movies + 12 shows), grid
  renders show posters in the lower rows, 59fps.

First step toward the detail page (#11): a show card will open the show detail
(seasons/episodes); a movie card opens movie detail.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018QbpQTKYjwp6fDNLdXzGzr
GLinnik21 added a commit that referenced this pull request Aug 26, 2026
…ility)

The final detail-page section — the About footer at the bottom of the scroll.

- metadata.rs: extracted parse_streams(item, &mut Detail); load_detail now backfills
  a SHOW's audio/subs from its first episode's full metadata (shows carry no streams
  at the show level), so the Languages/Accessibility columns populate for shows and
  movies alike.
- ui/detail.rs: section 5 = About (always present). draw_about: an "About" heading +
  a rounded card (title, comma-joined genres, wrapped summary + MORE), then three
  columns — Information (Released / Run Time / Rated / Regions of Origin), Languages
  (Original Audio + the audio-track list "Lang (CODEC)"), Accessibility (CC/SDH/AD
  badges + standard descriptions, shown only when present). ABOUT_Y spaced so the
  footer clears the cast row when focused.

Verified on the TV (Severance): footer matches the Apple-TV reference — card, and
all three columns populated (18 Feb 2022 / 0 hr 50 min / TV-MA / United States;
Русский + full audio list from episode 1; CC with its description).

Completes the detail page (#11): hero -> season tabs + episodes -> related -> cast
-> about, all scrolling as one page, with movie + show playback wired.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018QbpQTKYjwp6fDNLdXzGzr
GLinnik21 added a commit that referenced this pull request Oct 8, 2026
…loor, no secret echo) (#557)

CodeQL py/* alerts #4-8, #10, #11, #16-20. serve_fixtures resolves and checks containment before isfile; every dev SSLContext sets minimum_version TLS 1.2; gen-release-audit parses the DSN host instead of a substring test; the census arm regex no longer backtracks; plxnative-lab start stops echoing the session secret (pkg/lab.json, 0600, carries it); remote-dpad echoes only a password it generated.

Co-Authored-By: Claude Sonnet 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.

2 participants