Skip to content

detail: Play from Start on the hero, and Play relabels to Resume - #5

Merged
GLinnik21 merged 1 commit into
mainfrom
unit-8-play-from-start
Jul 30, 2026
Merged

GLinnik21 merged 1 commit into
mainfrom
unit-8-play-from-start

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Jul 29, 2026 •

Copy link
Copy Markdown
Collaborator

Unit 8 — Play from Start, and Play→Resume on the detail hero

Closes the docs/parity-gaps.md §5c row 2 (↺ Play from start) and the appendix entry
"No 'Play from Start' anywhere outside the player, and the detail Play button silently resumes".

The gap

detail.rs's hero had exactly two controls (NBTN = 2): a Play pill whose label was the hard-coded
literal c"Play", and the watched disc. Both play arms applied Plex's resume rule
unconditionally — the movie arm (:1191) and the episode arm (:1389) — so a part-watched item
could only ever be resumed from its own page, never restarted. The app's one existing restart is
info_panel.rs:49 "From Beginning", and that is a request_seek(0) on something already playing:
you had to start at the resume point in order to reach the control that undoes it.

What changed

One predicate drives both halves. hero_resume_ns() answers what the play arm would actually
hand app.rs — a movie's own viewOffset, or, on a show page, episodes[0] of the selected season,
because that is the leaf the hero plays — and puts it through metadata::resume_ns, the same rule
the action applies
, rather than the raw resume_ms > 0 the home hero keys on. That distinction is
load-bearing: a 4-second offset, or one past the 95% end-of-item mark, resumes from 0, and there a
"Resume" label would be a lie and a restart disc a second Play.

  1. The pill relabels to Resume exactly when the press will resume.
  2. A ↺ disc sits at index 1 whenever there is a resume point, and plays the same item from 00:00.
    The watched toggle stays last and shifts to index 2.

Wording — "Resume", not home's "Continue" (deliberate, as asked). Home's row belongs to the
Continue Watching shelf and takes the shelf's word; home.rs:425 is left alone. On an item page the
control has a sibling, and Resume + a restart mark are a pair the eye reads together — "Continue"
next to a ↺ disc does not read as a pair. This is also how the reference clients word the item page.

The restart arm is the normal play arm with last_resume_ns zeroed after it. app.rs reads
that field only once on_ok() has returned, so one override covers the movie path and the episode
path at once — instead of threading a from-start flag through two call sites that would then have to
be kept in step forever.

The row's indices now move, so nothing hard-codes them. hero_action() maps an index to its
action; hero_col() resolves the focus against the live set and writes the result back. An index
alone is not a stable name for a control when the set is derived from an item that arrives
asynchronously, and both directions are reachable by hand:

  • It shrinks — the watched toggle is the control that deletes the restart disc from under the
    focus, because scrobbling clears the server's viewOffset. A focus left at index 2 of a
    two-button row draws nothing focused and makes every later OK inert.
  • It grows — open_rk clears current() for the whole 2-5 round-trip fetch, so a RIGHT pressed
    in that window parks on the watched toggle of a two-button row; when a part-watched item then
    lands, index 1 has quietly become the restart disc, and that press would start playback instead
    of marking the item watched.

So the focus travels with its control: the disc is inserted at (and removed from) BTN_RESTART,
and everything at or after it shifts by one when the set flips. The clamp catches anything else.

Supporting pieces

  • widgets::pill_w — the ONE hero-pill width formula. Both hero rows relabel their pill from item
    state, so the frame has to be measured from the label ("Resume" was cramped inside "Play"'s fixed
    168px). home.rs is switched onto it — it computes the identical value, so home's recorded pointer
    hit rects are unchanged to the pixel — and Button's own icon ratio/gap are now named constants so
    the measure and the paint cannot drift. PW survives as the pill's minimum.
  • Icon::Restart + assets/icons/restart.svg. The mask was verified by rasterizing it through the
    app's own nanosvg path at the 32px the disc actually draws (CD * DISC_ICON_RATIO), not eyeballed
    as source.
  • metadata::set_current_for_test — a #[cfg(test)] seam, compiled out of the shipped binary. The
    screens' label/focus math reads current(), and the only real way to populate it is a PMS round
    trip.

No new colour literal, no raw font size, no hand-placed text; the two new controls are the existing
Button/CircleButton family. No new PMS endpoint.

Verification

  • Host: make check — 63 pass (58 baseline +5). The new tests cover the resume predicate
    including both Plex-rule edges (sub-floor offset, 95% tail) and the show path; the index→action
    mapping in both control sets; the focus surviving a set that shrinks and one that grows under it;
    and the resume each play path bakes in versus what restart leaves behind. All hold
    crate::testlock::serial() — metadata::CURRENT and detail's VIEW are crate-wide globals. The
    two new behavioural assertions were mutation-checked: deleting commit_resume's body, and
    deleting the index-shift in hero_col, each fails exactly its own test.
  • Independent review: a correctness-only pass over the diff raised three items, all fixed here —
    a vacuous test (the restart override is now the extracted commit_resume, which the test actually
    calls), the grow-under-focus misfire described above, and two documentation gaps (focus() is now
    a write on the draw path; pill_w assumes an icon-bearing pill).
  • Build: make (ARM cross-build) green, no new warnings.
  • Device: NOT RUN — deferred to the coordinator, who is centralising TV access. The full
    recipe (seed/reset, the one-boot trigger sequence for each path, and the exact log lines that
    decide it) is the last section of this description.

Note

docs/parity-gaps.md still cites detail.rs:88 NBTN = 2 in several places. Left untouched on
purpose: eight sibling units are editing that audit concurrently and it is a point-in-time snapshot.


Device verification: deferred to coordinator

Not run — the shared TV was held for the whole window and queuing for it was not a good use of
budget. Everything below is prepared and ready to paste; the host tier and the cross-build are green.

0. Prerequisites

cd <repo root>                     # NOT the worktree — or copy src/config.local.h into it
export TOKEN=$(sed -n 's/.*#define[[:space:]]*PMS_TOKEN[[:space:]]*"\([^"]*\)".*/\1/p' src/config.local.h)
export PMS=192.168.0.3:32400       # tests/manifest.json
export SSH='sshpass -p alpine ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=8 [email protected]'
make deploy                        # ships the new binary + the new restart.svg is compiled in

1. The server-state trap, first

The resume point is server state that outlives the run, and the app's timeline reporter posts
progress every 10s while playing — so each boot below must be preceded by its own reset+seed, or the
next case inherits wherever the previous one stopped.

The reset must be /:/unscrobble. PUT /:/progress?time=0 returns 200 and changes nothing
(verified live; time=1 too) — which is exactly what makes this look already handled.
PUT /:/progress is how you seed a non-zero offset; it is only the reset it cannot do.

reset() { curl -sS -o /dev/null -w "unscrobble $1 -> %{http_code}\n" \
  "http://$PMS/:/unscrobble?key=$1&identifier=com.plexapp.plugins.library&X-Plex-Token=$TOKEN"; }

seed()  { curl -sS -X PUT -o /dev/null -w "seed $1=$2ms -> %{http_code}\n" \
  "http://$PMS/:/progress?key=$1&identifier=com.plexapp.plugins.library&time=$2&state=stopped&X-Plex-Token=$TOKEN"; }

# always confirm the offset actually landed — a 200 alone proves nothing here
check() { curl -sS "http://$PMS/library/metadata/$1?X-Plex-Token=$TOKEN" | grep -o 'viewOffset="[0-9]*"'; }

2. One-boot proof driver

boot() {  # boot <ratingKey> <col>   col 0 = the Play/Resume pill, col 1 = the new restart disc
  $SSH 'for f in /tmp/plxnative-*; do case "$f" in *.log) ;; *) rm -f "$f";; esac; done'
  printf '%s' "$TOKEN" | $SSH 'cat > /tmp/plxnative-token'      # own round trip, never on a cmdline
  $SSH "printf '%s' '$1' > /tmp/plxnative-detail; printf '%s' '$2' > /tmp/plxnative-detailcol; touch /tmp/plxnative-detailplay"
  make run RUN_SECS=25 > /tmp/unit8-$1-$2.log 2>/dev/null
  grep -E 'detail: rk=' /tmp/unit8-$1-$2.log | head -1
  grep -E 'ff: seek|resume\(transcode\)|scrobble|Playing error|reload_at' /tmp/unit8-$1-$2.log | head -6
  grep -oE 'route=[a-z]+' /tmp/unit8-$1-$2.log | sort -u | tr '\n' ' '; echo
  echo -n 'pos= : '; grep -oE 'pos=[0-9]+s' /tmp/unit8-$1-$2.log | head -6 | tr '\n' ' '; echo
}

plxnative-detail=<rk> opens that page (blocking load), plxnative-detailcol=N steps focus RIGHT N
times, plxnative-detailplay activates the focused control — so col 1 is the new disc, and the
step itself proves the LEFT/RIGHT walk reaches it.

3. Movie path — rk 4 (The Substance, dur 8469000 ms)

reset 4; seed 4 1800000; check 4      # must print viewOffset="1800000"
boot 4 0                              # the pill  -> must RESUME
reset 4; seed 4 1800000; check 4      # re-seed: the run above advanced the server offset
boot 4 1                              # the ↺ disc -> must RESTART

4. Episode path — show rk 437 (The Morning Show), whose S1E1 is rk 439 (dur 3818112 ms)

The show page's hero plays episodes[0] of the selected season, and cur_season is 0 on open — so
the resume point that matters is S1E1's, not the show's. Seed 439, open 437.

reset 439; seed 439 900000; check 439
boot 437 0                            # the pill  -> must RESUME the episode
reset 439; seed 439 900000; check 439
boot 437 1                            # the ↺ disc -> must RESTART the episode

5. What the log must show

Line col 0 (pill) col 1 (↺ disc)
ff: seek <N>s rv=0 (direct play) or resume(transcode): restart at offset <N>s present, N ≈ 1800 (movie) / 900 (episode) absent, or ff: seek 0s
pos= samples off the once/sec FPS= heartbeat start ≈ the seeded offset start at 0 and climb
route= reaches player reaches player
Playing error, reload_at: fresh Load none none

That table is the assertion: the restart disc must start the same item at 0 rather than at the
seeded offset, on both paths.

Two ways to be fooled, both checkable in the same output:

  1. detail: rk=437 … eps=0. If the episode list is empty the hero row is only two controls, so
    detailcol=1 lands on the watched toggle and detailplay scrobbles instead of playing.
    Symptom: no route=player, a scrobble line, and the item comes back marked watched. The movie
    line should read show=false; the show line must read eps=10.
  2. A seed that did not take. Same failure shape — no resume point means no restart disc, so
    index 1 is again the toggle. This is why check runs before every boot.

6. Screenshot + the UI tier

tools/tv-session.sh up --screen detail=4      # clears triggers, injects the token, verifies the deploy
tools/capture-screen.sh /tmp/unit-8.png DISPLAY

With rk 4 seeded, the hero must read ▶ Resume on the pill, with the ↺ disc between it and
the existing ✓ watched disc — three controls, not two. Clear the seed (reset 4) and re-capture: the
pill must fall back to ▶ Play with the ↺ disc gone (two controls).

./tests/run.py --fps        # UI tier; detail-transition is the scene this change can move

7. Hand back

reset 4; reset 439          # leave no seeded resume points behind
tools/tv-session.sh down    # strips the injected token + every trigger, relaunches interactive

🤖 Generated with Claude Code

https://claude.ai/code/session_018GuSHrq9oydnX7nhKE1Hvc

Copilot AI review requested due to automatic review settings July 29, 2026 17:53

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.

…esume

The detail page's Play pill was the literal c"Play" whatever the item's state,
and both play arms ran metadata::resume_ns over the item unconditionally
(the movie arm and the episode arm), so a part-watched movie or episode could
only ever be RESUMED from its own page. The one restart in the app is the
in-player Info card's "From Beginning", and that is a request_seek(0) on
something already playing — you had to start at the resume point to reach the
control that undoes it.

One predicate now drives both halves. hero_resume_ns() answers what the play
arm would ACTUALLY hand app.rs: a movie's own viewOffset, or, on a show page,
episodes[0] of the selected season, because that is the leaf the hero plays.
It puts that through metadata::resume_ns — the same Plex rule the action
applies — rather than the raw `resume_ms > 0` the home hero keys on. That
distinction is the point: a 4-second offset, or one past the 95% end-of-item
mark, resumes from 0, and there a "Resume" label would be a lie and a restart
disc a second Play.

So the pill reads "Resume" exactly when the press will resume, and a counter-
clockwise disc appears beside it that plays the same item from 00:00. "Resume"
rather than home's "Continue": home's row belongs to the Continue Watching
shelf and takes the shelf's word, while on an item page the control has a
sibling, and Resume + a restart mark are a pair the eye reads together.

The restart arm is deliberately the normal play arm with last_resume_ns zeroed
AFTER it: app.rs reads that field only once on_ok has returned, so one override
covers the movie path and the episode path at once, instead of threading a
from-start flag through two call sites that would then have to be kept in step.

The row's indices now move, so nothing may hard-code them: hero_action() maps
an index to its action, and hero_col() resolves the focus against the live set
and writes the result back. An index alone is not a stable name for a control
when the set is derived from an item that arrives asynchronously, and both
directions are reachable by hand. It SHRINKS: the watched toggle is the control
that deletes the restart disc from under the focus, because scrobbling clears
the server's viewOffset, and a focus left at index 2 of a two-button row draws
nothing focused and makes every later OK inert. It GROWS: open_rk clears
current() for the whole 2-5 round-trip fetch, so a RIGHT pressed in that window
parks on the watched toggle of a two-button row, and when a part-watched item
lands, index 1 has quietly become the restart disc — that press would start
playback instead of marking the item watched. So the focus travels with its
CONTROL: the disc is inserted at and removed from BTN_RESTART, and everything
at or after it shifts by one when the set flips.

Also here, because the change needed them: widgets::pill_w is the ONE hero-pill
width formula (both hero rows relabel their pill from item state, so the frame
has to be measured from the label — "Resume" cramped inside "Play"'s 168px),
with home.rs switched onto it and Button's own icon ratio/gap named so the
measure and the paint cannot drift; and Icon::Restart with its SVG mask, the
mask verified by rasterizing it through the app's own nanosvg path at the 32px
the disc actually draws.

Tests: +5 host (63)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_018GuSHrq9oydnX7nhKE1Hvc
@GLinnik21
GLinnik21 force-pushed the unit-8-play-from-start branch from 9220938 to 0bc8c95 Compare July 29, 2026 17:58
@GLinnik21
GLinnik21 merged commit 741be07 into main Jul 30, 2026
@GLinnik21
GLinnik21 deleted the unit-8-play-from-start branch August 2, 2026 18:37
GLinnik21 added a commit that referenced this pull request Aug 23, 2026
… real socket

CI was red on Linux with `thread '<unknown>' has overflowed its stack`,
at a different point in the output each run, while `make check` passed on
the dev Mac. The mechanism is not serde_json and not the session file.

`moving_a_server_to_https_re_points_its_slot` called the public
`register_origin`, where every other test in this module deliberately
goes through `register_with_client_id`. The public path fires
`serverinfo::refresh`, which spawns a `task::spawn_small` worker that
really opens a socket — and in a DEBUG build `stream::http_stream_boxed`
materialises its 64 KiB `HttpStream` as a STACK temporary before it ever
reaches the heap, despite the comment above it promising the opposite
("box it off the caller's stack"). lldb caught it on the guard page:

    frame #0  stream::http_stream_boxed
    frame #1  stream::http_get(host="10.0.0.1", port=32400, …)
    frame #2  Client::get_json
    frame #3  Client::server_root
    frame #4  serverinfo::fetch_once
    frame #5  serverinfo::refresh::{closure#0}   <- spawn_small, 256 KiB

Measured on this branch by varying `SMALL_STACK`: debug overflows at 48,
128 and 192 KiB on ARM64 and needs more than 256 KiB on x86-64, which is
exactly why one host passed and the other did not. **`--release` passes at
48 KiB**, so the optimizer elides the temporary and the television — which
ships `cargo build --release` (Makefile:438) — is not affected. It is a
latent debug-only hazard in `stream.rs`, pre-existing and not this
branch's to fix; the base simply had no host test that reached
`http_get` from a `spawn_small` worker. Reported on the PR.

The fix is the test, which was wrong on its own terms: `register` also
mints and PERSISTS a client-id uuid, and that seam's doc has said since it
was written that a host test must not write one. It gains an origin-taking
sibling (the pair-shaped one cannot express a scheme, which is what this
test is about) and a second documented reason nobody had paid for yet.

Verified with the same differential that found it: at `SMALL_STACK = 48 *
1024` the branch was 3/3 aborts and is now 3/3 clean, 997 tests, both
`--test-threads=1` and parallel. `task.rs` is untouched.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G
GLinnik21 added a commit that referenced this pull request Aug 23, 2026
… and never rebuilt from one (#53)

* transport: an Origin is what a server's address IS, and it is parsed from a URL

Everything below the transport carried a server's address as a bare
`(host, port)` pair. That pair cannot say `https`, and — the half that
matters — it cannot be *made* to say it afterwards, because the host a
`plex.direct` certificate is issued for is the HOSTNAME plex.tv puts in
`Connection.uri`, while `Connection.address` stays the dotted quad behind
it. `probe.rs` has said so in prose since it was written ("https to the
bare IP fails validation by design"), and `auth::resolve_roster` then
threw `Candidate::url` away and wrote `address` into the session file. A
later lane adding a `scheme` field on top of that would have produced a
control plane that looks like it speaks TLS and fails hostname validation
on every real server.

So: `plex::Origin` — scheme + host + port, parsed from a URL by
`Origin::parse`, never assembled from an address. `Candidate::origin()`
is the one derivation; `Candidate::address` is documented down to what it
actually is, the diagnostic half.

Threaded through every site that passed a bare pair: `Client` (with
`host()`/`port()` kept as views, so the ~30 call sites below the layer
are untouched), `StreamUrl` and its two construction sites,
`register_origin`/`install`, `SourceRef`/`ServerRef`, `ReadyCreds`,
`app.rs`'s boot gate and `install_pms`, and the engine's URL splitter.
`dev::DevServer` gains an optional `scheme`, which is how an https origin
can be exercised headlessly through the `plxnative-servers` trigger by
anyone who has no such server to discover.

Two invariants are pinned by tests rather than left to prose.
`Origin::host()` is ALWAYS unbracketed — it is the `getaddrinfo` node —
and `Origin::authority()` ALWAYS brackets a v6 literal, because it is URL
serialization; `probe::host_of` returned the bracketed spelling and is
gone, replaced by one shared reading of a URL. And a session file written
by 0.4.1, carrying `address`/`port` and no origin, must still boot as
`http://{address}:{port}`: `Session::server` is not a soft-parsed roster
entry, so dropping it is a silent sign-out at every boot for every
existing user. Both have a test with a literal 0.4.1-shaped JSON string.

NO BEHAVIOUR CHANGE. Every origin is still `http://` and dials the same
address: `dial_target` accepts only a plain-http IPv4 candidate, whose
URL `probe::candidates` synthesized as `http://{address}:{port}`, so the
parsed origin and the old pair are equal today — asserted, not assumed.
The registry's two log lines now print `origin.authority()`, which is
byte-identical for every http/IPv4 origin and correct for a v6 literal,
which `{host}:{port}` could not spell at all.

996 host tests pass. A simulator boot against a real PMS produces an
event log identical to the pre-change one on all 30 non-heartbeat lines;
the three `loop=`/`fps=` lines vary run to run on an unchanged binary.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* docs: name what the origin model made stale, rather than leaving it to rot

`plex/CLAUDE.md` and `servers.rs`/`client.rs`'s module docs described the
registry in terms of `(host, port)`, which is the shape the change
replaced. `docs/plex-api-design.md` is a design note whose sketches were
the implementation of their day — it gets a banner naming the one thing
in it that would now mislead (rule 9, "Numeric host, no DNS", and the
two struct sketches), not a rewrite. `docs/shared-servers.md` §7 gains
the `plxnative-servers` trigger's new `scheme` field, which is the only
way to put a TLS origin through the registry without an account that
has one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* session: the stored origin field is `origin_url`, so it cannot be mistaken for `origin()`

`SourceRef`/`ServerRef` had a FIELD `origin` (the serialized string) beside
a METHOD `origin()` (the parsed value). Rust puts those in different
namespaces so it compiles either way, which is exactly the problem: two
characters separate "the raw JSON string" from "the thing to dial", at
every use, forever. The field takes the `_url` suffix; `#[serde(rename)]`
keeps the FILE's key spelled `origin`, which is what a human editing a
session file on the television reads, and the round-trip test proves the
rename applies to both halves of serde.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* review: close the gap between the origin that was DIALLED and the one recorded

Eight findings from `/code-review high`; six fixed, two answered in prose.

**The one that mattered.** `resolve_roster` recorded `Candidate::origin()`
while `probe_server` dialled `(&c.address, dial_port(c.port))`, and the
comment justifying that divergence was wrong about its own gate:
`dial_target` checks `is_ipv4_literal(&c.address)`, which admits a
plex.tv-advertised `uri` candidate and not only the synthesized twin. A
connection whose `uri` names a different port from `port` would be
verified at one and written into the session file as the other, and every
later request would go somewhere nothing ever answered from. So
`dial_target` now returns the ORIGIN, `probe_server` dials that origin's
host and port, and `Reach::At` carries it back beside the candidate — one
value, so what answered and what is recorded cannot be two addresses. The
candidate stays for the diagnostic fields. Its fixture had `url` and
`port` disagreeing, which is what let the old shape look consistent; it
builds both from one pair now, as `probe::candidates` does.

**The silent-instrument trap, twice.** `dev::DevServer`'s `scheme` field
exists so a lane with no TLS server of its own can put an https origin
through the registry — and both registry log lines and `DevServer::
describe` printed `host:port`, so such a run was byte-identical to an
http one. `Origin::log_form()` is the shared answer: the bare authority
for a plaintext origin (an archived log stays comparable, and the
byte-identical gate holds) and the whole URL as soon as the scheme is
worth saying.

**`player::engine` REFUSES a TLS stream target** instead of silently
downgrading it, which is what the code did while its comment claimed the
opposite. It is reachable today: a client registered at an https origin
copies that origin into `direct_play_url`/`transcode_start_url`, so
`route` would store an https URL and the engine would open a plaintext
socket to it.

Also: an EMPTY port (`http://h:`) is a port that was WRITTEN and cannot
be dialled, so `Origin::parse` refuses it rather than defaulting to 32400
— a truncated write of the session file is exactly the "port nobody wrote
down" case `dial_port` exists for. And `reconcile_primary` no longer logs
"primary now answers at …" when the only thing that changed was the
stored origin going from empty to populated, which is what the FIRST BOOT
after this lands does on every existing install — a false DHCP-churn
report in the file this project treats as its primary evidence surface.

Answered rather than changed: `Origin::port`'s doc claimed a narrowing one
constructor does not perform (`ServerRef::origin`'s legacy `port as i32`),
so the doc now says where the narrowing really lives; and
`Session::can_go_local` still asks "is there an address written down"
rather than "can THIS build's transport open it" — gating it would send a
user to a QR code for a transport gap that is not theirs, and the
half-landed state it exposes is named in the doc and refused out loud one
layer down, in the engine.

997 host tests pass. The simulator event log is still identical to the
pre-change one on all 30 non-heartbeat lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* tests: a registry test must not call the PUBLIC register — it opens a real socket

CI was red on Linux with `thread '<unknown>' has overflowed its stack`,
at a different point in the output each run, while `make check` passed on
the dev Mac. The mechanism is not serde_json and not the session file.

`moving_a_server_to_https_re_points_its_slot` called the public
`register_origin`, where every other test in this module deliberately
goes through `register_with_client_id`. The public path fires
`serverinfo::refresh`, which spawns a `task::spawn_small` worker that
really opens a socket — and in a DEBUG build `stream::http_stream_boxed`
materialises its 64 KiB `HttpStream` as a STACK temporary before it ever
reaches the heap, despite the comment above it promising the opposite
("box it off the caller's stack"). lldb caught it on the guard page:

    frame #0  stream::http_stream_boxed
    frame #1  stream::http_get(host="10.0.0.1", port=32400, …)
    frame #2  Client::get_json
    frame #3  Client::server_root
    frame #4  serverinfo::fetch_once
    frame #5  serverinfo::refresh::{closure#0}   <- spawn_small, 256 KiB

Measured on this branch by varying `SMALL_STACK`: debug overflows at 48,
128 and 192 KiB on ARM64 and needs more than 256 KiB on x86-64, which is
exactly why one host passed and the other did not. **`--release` passes at
48 KiB**, so the optimizer elides the temporary and the television — which
ships `cargo build --release` (Makefile:438) — is not affected. It is a
latent debug-only hazard in `stream.rs`, pre-existing and not this
branch's to fix; the base simply had no host test that reached
`http_get` from a `spawn_small` worker. Reported on the PR.

The fix is the test, which was wrong on its own terms: `register` also
mints and PERSISTS a client-id uuid, and that seam's doc has said since it
was written that a host test must not write one. It gains an origin-taking
sibling (the pair-shaped one cannot express a scheme, which is what this
test is about) and a second documented reason nobody had paid for yet.

Verified with the same differential that found it: at `SMALL_STACK = 48 *
1024` the branch was 3/3 aborts and is now 3/3 clean, 997 tests, both
`--test-threads=1` and parallel. `task.rs` is untouched.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
GLinnik21 added a commit that referenced this pull request Aug 26, 2026
… and never rebuilt from one (#53)

* transport: an Origin is what a server's address IS, and it is parsed from a URL

Everything below the transport carried a server's address as a bare
`(host, port)` pair. That pair cannot say `https`, and — the half that
matters — it cannot be *made* to say it afterwards, because the host a
`plex.direct` certificate is issued for is the HOSTNAME plex.tv puts in
`Connection.uri`, while `Connection.address` stays the dotted quad behind
it. `probe.rs` has said so in prose since it was written ("https to the
bare IP fails validation by design"), and `auth::resolve_roster` then
threw `Candidate::url` away and wrote `address` into the session file. A
later lane adding a `scheme` field on top of that would have produced a
control plane that looks like it speaks TLS and fails hostname validation
on every real server.

So: `plex::Origin` — scheme + host + port, parsed from a URL by
`Origin::parse`, never assembled from an address. `Candidate::origin()`
is the one derivation; `Candidate::address` is documented down to what it
actually is, the diagnostic half.

Threaded through every site that passed a bare pair: `Client` (with
`host()`/`port()` kept as views, so the ~30 call sites below the layer
are untouched), `StreamUrl` and its two construction sites,
`register_origin`/`install`, `SourceRef`/`ServerRef`, `ReadyCreds`,
`app.rs`'s boot gate and `install_pms`, and the engine's URL splitter.
`dev::DevServer` gains an optional `scheme`, which is how an https origin
can be exercised headlessly through the `plxnative-servers` trigger by
anyone who has no such server to discover.

Two invariants are pinned by tests rather than left to prose.
`Origin::host()` is ALWAYS unbracketed — it is the `getaddrinfo` node —
and `Origin::authority()` ALWAYS brackets a v6 literal, because it is URL
serialization; `probe::host_of` returned the bracketed spelling and is
gone, replaced by one shared reading of a URL. And a session file written
by 0.4.1, carrying `address`/`port` and no origin, must still boot as
`http://{address}:{port}`: `Session::server` is not a soft-parsed roster
entry, so dropping it is a silent sign-out at every boot for every
existing user. Both have a test with a literal 0.4.1-shaped JSON string.

NO BEHAVIOUR CHANGE. Every origin is still `http://` and dials the same
address: `dial_target` accepts only a plain-http IPv4 candidate, whose
URL `probe::candidates` synthesized as `http://{address}:{port}`, so the
parsed origin and the old pair are equal today — asserted, not assumed.
The registry's two log lines now print `origin.authority()`, which is
byte-identical for every http/IPv4 origin and correct for a v6 literal,
which `{host}:{port}` could not spell at all.

996 host tests pass. A simulator boot against a real PMS produces an
event log identical to the pre-change one on all 30 non-heartbeat lines;
the three `loop=`/`fps=` lines vary run to run on an unchanged binary.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* docs: name what the origin model made stale, rather than leaving it to rot

`plex/CLAUDE.md` and `servers.rs`/`client.rs`'s module docs described the
registry in terms of `(host, port)`, which is the shape the change
replaced. `docs/plex-api-design.md` is a design note whose sketches were
the implementation of their day — it gets a banner naming the one thing
in it that would now mislead (rule 9, "Numeric host, no DNS", and the
two struct sketches), not a rewrite. `docs/shared-servers.md` §7 gains
the `plxnative-servers` trigger's new `scheme` field, which is the only
way to put a TLS origin through the registry without an account that
has one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* session: the stored origin field is `origin_url`, so it cannot be mistaken for `origin()`

`SourceRef`/`ServerRef` had a FIELD `origin` (the serialized string) beside
a METHOD `origin()` (the parsed value). Rust puts those in different
namespaces so it compiles either way, which is exactly the problem: two
characters separate "the raw JSON string" from "the thing to dial", at
every use, forever. The field takes the `_url` suffix; `#[serde(rename)]`
keeps the FILE's key spelled `origin`, which is what a human editing a
session file on the television reads, and the round-trip test proves the
rename applies to both halves of serde.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* review: close the gap between the origin that was DIALLED and the one recorded

Eight findings from `/code-review high`; six fixed, two answered in prose.

**The one that mattered.** `resolve_roster` recorded `Candidate::origin()`
while `probe_server` dialled `(&c.address, dial_port(c.port))`, and the
comment justifying that divergence was wrong about its own gate:
`dial_target` checks `is_ipv4_literal(&c.address)`, which admits a
plex.tv-advertised `uri` candidate and not only the synthesized twin. A
connection whose `uri` names a different port from `port` would be
verified at one and written into the session file as the other, and every
later request would go somewhere nothing ever answered from. So
`dial_target` now returns the ORIGIN, `probe_server` dials that origin's
host and port, and `Reach::At` carries it back beside the candidate — one
value, so what answered and what is recorded cannot be two addresses. The
candidate stays for the diagnostic fields. Its fixture had `url` and
`port` disagreeing, which is what let the old shape look consistent; it
builds both from one pair now, as `probe::candidates` does.

**The silent-instrument trap, twice.** `dev::DevServer`'s `scheme` field
exists so a lane with no TLS server of its own can put an https origin
through the registry — and both registry log lines and `DevServer::
describe` printed `host:port`, so such a run was byte-identical to an
http one. `Origin::log_form()` is the shared answer: the bare authority
for a plaintext origin (an archived log stays comparable, and the
byte-identical gate holds) and the whole URL as soon as the scheme is
worth saying.

**`player::engine` REFUSES a TLS stream target** instead of silently
downgrading it, which is what the code did while its comment claimed the
opposite. It is reachable today: a client registered at an https origin
copies that origin into `direct_play_url`/`transcode_start_url`, so
`route` would store an https URL and the engine would open a plaintext
socket to it.

Also: an EMPTY port (`http://h:`) is a port that was WRITTEN and cannot
be dialled, so `Origin::parse` refuses it rather than defaulting to 32400
— a truncated write of the session file is exactly the "port nobody wrote
down" case `dial_port` exists for. And `reconcile_primary` no longer logs
"primary now answers at …" when the only thing that changed was the
stored origin going from empty to populated, which is what the FIRST BOOT
after this lands does on every existing install — a false DHCP-churn
report in the file this project treats as its primary evidence surface.

Answered rather than changed: `Origin::port`'s doc claimed a narrowing one
constructor does not perform (`ServerRef::origin`'s legacy `port as i32`),
so the doc now says where the narrowing really lives; and
`Session::can_go_local` still asks "is there an address written down"
rather than "can THIS build's transport open it" — gating it would send a
user to a QR code for a transport gap that is not theirs, and the
half-landed state it exposes is named in the doc and refused out loud one
layer down, in the engine.

997 host tests pass. The simulator event log is still identical to the
pre-change one on all 30 non-heartbeat lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* tests: a registry test must not call the PUBLIC register — it opens a real socket

CI was red on Linux with `thread '<unknown>' has overflowed its stack`,
at a different point in the output each run, while `make check` passed on
the dev Mac. The mechanism is not serde_json and not the session file.

`moving_a_server_to_https_re_points_its_slot` called the public
`register_origin`, where every other test in this module deliberately
goes through `register_with_client_id`. The public path fires
`serverinfo::refresh`, which spawns a `task::spawn_small` worker that
really opens a socket — and in a DEBUG build `stream::http_stream_boxed`
materialises its 64 KiB `HttpStream` as a STACK temporary before it ever
reaches the heap, despite the comment above it promising the opposite
("box it off the caller's stack"). lldb caught it on the guard page:

    frame #0  stream::http_stream_boxed
    frame #1  stream::http_get(host="10.0.0.1", port=32400, …)
    frame #2  Client::get_json
    frame #3  Client::server_root
    frame #4  serverinfo::fetch_once
    frame #5  serverinfo::refresh::{closure#0}   <- spawn_small, 256 KiB

Measured on this branch by varying `SMALL_STACK`: debug overflows at 48,
128 and 192 KiB on ARM64 and needs more than 256 KiB on x86-64, which is
exactly why one host passed and the other did not. **`--release` passes at
48 KiB**, so the optimizer elides the temporary and the television — which
ships `cargo build --release` (Makefile:438) — is not affected. It is a
latent debug-only hazard in `stream.rs`, pre-existing and not this
branch's to fix; the base simply had no host test that reached
`http_get` from a `spawn_small` worker. Reported on the PR.

The fix is the test, which was wrong on its own terms: `register` also
mints and PERSISTS a client-id uuid, and that seam's doc has said since it
was written that a host test must not write one. It gains an origin-taking
sibling (the pair-shaped one cannot express a scheme, which is what this
test is about) and a second documented reason nobody had paid for yet.

Verified with the same differential that found it: at `SMALL_STACK = 48 *
1024` the branch was 3/3 aborts and is now 3/3 clean, 997 tests, both
`--test-threads=1` and parallel. `task.rs` is untouched.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
GLinnik21 added a commit that referenced this pull request Aug 27, 2026
… and never rebuilt from one (#53)

* transport: an Origin is what a server's address IS, and it is parsed from a URL

Everything below the transport carried a server's address as a bare
`(host, port)` pair. That pair cannot say `https`, and — the half that
matters — it cannot be *made* to say it afterwards, because the host a
`plex.direct` certificate is issued for is the HOSTNAME plex.tv puts in
`Connection.uri`, while `Connection.address` stays the dotted quad behind
it. `probe.rs` has said so in prose since it was written ("https to the
bare IP fails validation by design"), and `auth::resolve_roster` then
threw `Candidate::url` away and wrote `address` into the session file. A
later lane adding a `scheme` field on top of that would have produced a
control plane that looks like it speaks TLS and fails hostname validation
on every real server.

So: `plex::Origin` — scheme + host + port, parsed from a URL by
`Origin::parse`, never assembled from an address. `Candidate::origin()`
is the one derivation; `Candidate::address` is documented down to what it
actually is, the diagnostic half.

Threaded through every site that passed a bare pair: `Client` (with
`host()`/`port()` kept as views, so the ~30 call sites below the layer
are untouched), `StreamUrl` and its two construction sites,
`register_origin`/`install`, `SourceRef`/`ServerRef`, `ReadyCreds`,
`app.rs`'s boot gate and `install_pms`, and the engine's URL splitter.
`dev::DevServer` gains an optional `scheme`, which is how an https origin
can be exercised headlessly through the `plxnative-servers` trigger by
anyone who has no such server to discover.

Two invariants are pinned by tests rather than left to prose.
`Origin::host()` is ALWAYS unbracketed — it is the `getaddrinfo` node —
and `Origin::authority()` ALWAYS brackets a v6 literal, because it is URL
serialization; `probe::host_of` returned the bracketed spelling and is
gone, replaced by one shared reading of a URL. And a session file written
by 0.4.1, carrying `address`/`port` and no origin, must still boot as
`http://{address}:{port}`: `Session::server` is not a soft-parsed roster
entry, so dropping it is a silent sign-out at every boot for every
existing user. Both have a test with a literal 0.4.1-shaped JSON string.

NO BEHAVIOUR CHANGE. Every origin is still `http://` and dials the same
address: `dial_target` accepts only a plain-http IPv4 candidate, whose
URL `probe::candidates` synthesized as `http://{address}:{port}`, so the
parsed origin and the old pair are equal today — asserted, not assumed.
The registry's two log lines now print `origin.authority()`, which is
byte-identical for every http/IPv4 origin and correct for a v6 literal,
which `{host}:{port}` could not spell at all.

996 host tests pass. A simulator boot against a real PMS produces an
event log identical to the pre-change one on all 30 non-heartbeat lines;
the three `loop=`/`fps=` lines vary run to run on an unchanged binary.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* docs: name what the origin model made stale, rather than leaving it to rot

`plex/CLAUDE.md` and `servers.rs`/`client.rs`'s module docs described the
registry in terms of `(host, port)`, which is the shape the change
replaced. `docs/plex-api-design.md` is a design note whose sketches were
the implementation of their day — it gets a banner naming the one thing
in it that would now mislead (rule 9, "Numeric host, no DNS", and the
two struct sketches), not a rewrite. `docs/shared-servers.md` §7 gains
the `plxnative-servers` trigger's new `scheme` field, which is the only
way to put a TLS origin through the registry without an account that
has one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* session: the stored origin field is `origin_url`, so it cannot be mistaken for `origin()`

`SourceRef`/`ServerRef` had a FIELD `origin` (the serialized string) beside
a METHOD `origin()` (the parsed value). Rust puts those in different
namespaces so it compiles either way, which is exactly the problem: two
characters separate "the raw JSON string" from "the thing to dial", at
every use, forever. The field takes the `_url` suffix; `#[serde(rename)]`
keeps the FILE's key spelled `origin`, which is what a human editing a
session file on the television reads, and the round-trip test proves the
rename applies to both halves of serde.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* review: close the gap between the origin that was DIALLED and the one recorded

Eight findings from `/code-review high`; six fixed, two answered in prose.

**The one that mattered.** `resolve_roster` recorded `Candidate::origin()`
while `probe_server` dialled `(&c.address, dial_port(c.port))`, and the
comment justifying that divergence was wrong about its own gate:
`dial_target` checks `is_ipv4_literal(&c.address)`, which admits a
plex.tv-advertised `uri` candidate and not only the synthesized twin. A
connection whose `uri` names a different port from `port` would be
verified at one and written into the session file as the other, and every
later request would go somewhere nothing ever answered from. So
`dial_target` now returns the ORIGIN, `probe_server` dials that origin's
host and port, and `Reach::At` carries it back beside the candidate — one
value, so what answered and what is recorded cannot be two addresses. The
candidate stays for the diagnostic fields. Its fixture had `url` and
`port` disagreeing, which is what let the old shape look consistent; it
builds both from one pair now, as `probe::candidates` does.

**The silent-instrument trap, twice.** `dev::DevServer`'s `scheme` field
exists so a lane with no TLS server of its own can put an https origin
through the registry — and both registry log lines and `DevServer::
describe` printed `host:port`, so such a run was byte-identical to an
http one. `Origin::log_form()` is the shared answer: the bare authority
for a plaintext origin (an archived log stays comparable, and the
byte-identical gate holds) and the whole URL as soon as the scheme is
worth saying.

**`player::engine` REFUSES a TLS stream target** instead of silently
downgrading it, which is what the code did while its comment claimed the
opposite. It is reachable today: a client registered at an https origin
copies that origin into `direct_play_url`/`transcode_start_url`, so
`route` would store an https URL and the engine would open a plaintext
socket to it.

Also: an EMPTY port (`http://h:`) is a port that was WRITTEN and cannot
be dialled, so `Origin::parse` refuses it rather than defaulting to 32400
— a truncated write of the session file is exactly the "port nobody wrote
down" case `dial_port` exists for. And `reconcile_primary` no longer logs
"primary now answers at …" when the only thing that changed was the
stored origin going from empty to populated, which is what the FIRST BOOT
after this lands does on every existing install — a false DHCP-churn
report in the file this project treats as its primary evidence surface.

Answered rather than changed: `Origin::port`'s doc claimed a narrowing one
constructor does not perform (`ServerRef::origin`'s legacy `port as i32`),
so the doc now says where the narrowing really lives; and
`Session::can_go_local` still asks "is there an address written down"
rather than "can THIS build's transport open it" — gating it would send a
user to a QR code for a transport gap that is not theirs, and the
half-landed state it exposes is named in the doc and refused out loud one
layer down, in the engine.

997 host tests pass. The simulator event log is still identical to the
pre-change one on all 30 non-heartbeat lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* tests: a registry test must not call the PUBLIC register — it opens a real socket

CI was red on Linux with `thread '<unknown>' has overflowed its stack`,
at a different point in the output each run, while `make check` passed on
the dev Mac. The mechanism is not serde_json and not the session file.

`moving_a_server_to_https_re_points_its_slot` called the public
`register_origin`, where every other test in this module deliberately
goes through `register_with_client_id`. The public path fires
`serverinfo::refresh`, which spawns a `task::spawn_small` worker that
really opens a socket — and in a DEBUG build `stream::http_stream_boxed`
materialises its 64 KiB `HttpStream` as a STACK temporary before it ever
reaches the heap, despite the comment above it promising the opposite
("box it off the caller's stack"). lldb caught it on the guard page:

    frame #0  stream::http_stream_boxed
    frame #1  stream::http_get(host="10.0.0.1", port=32400, …)
    frame #2  Client::get_json
    frame #3  Client::server_root
    frame #4  serverinfo::fetch_once
    frame #5  serverinfo::refresh::{closure#0}   <- spawn_small, 256 KiB

Measured on this branch by varying `SMALL_STACK`: debug overflows at 48,
128 and 192 KiB on ARM64 and needs more than 256 KiB on x86-64, which is
exactly why one host passed and the other did not. **`--release` passes at
48 KiB**, so the optimizer elides the temporary and the television — which
ships `cargo build --release` (Makefile:438) — is not affected. It is a
latent debug-only hazard in `stream.rs`, pre-existing and not this
branch's to fix; the base simply had no host test that reached
`http_get` from a `spawn_small` worker. Reported on the PR.

The fix is the test, which was wrong on its own terms: `register` also
mints and PERSISTS a client-id uuid, and that seam's doc has said since it
was written that a host test must not write one. It gains an origin-taking
sibling (the pair-shaped one cannot express a scheme, which is what this
test is about) and a second documented reason nobody had paid for yet.

Verified with the same differential that found it: at `SMALL_STACK = 48 *
1024` the branch was 3/3 aborts and is now 3/3 clean, 997 tests, both
`--test-threads=1` and parallel. `task.rs` is untouched.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
GLinnik21 added a commit that referenced this pull request Aug 28, 2026
… and never rebuilt from one (#53)

* transport: an Origin is what a server's address IS, and it is parsed from a URL

Everything below the transport carried a server's address as a bare
`(host, port)` pair. That pair cannot say `https`, and — the half that
matters — it cannot be *made* to say it afterwards, because the host a
`plex.direct` certificate is issued for is the HOSTNAME plex.tv puts in
`Connection.uri`, while `Connection.address` stays the dotted quad behind
it. `probe.rs` has said so in prose since it was written ("https to the
bare IP fails validation by design"), and `auth::resolve_roster` then
threw `Candidate::url` away and wrote `address` into the session file. A
later lane adding a `scheme` field on top of that would have produced a
control plane that looks like it speaks TLS and fails hostname validation
on every real server.

So: `plex::Origin` — scheme + host + port, parsed from a URL by
`Origin::parse`, never assembled from an address. `Candidate::origin()`
is the one derivation; `Candidate::address` is documented down to what it
actually is, the diagnostic half.

Threaded through every site that passed a bare pair: `Client` (with
`host()`/`port()` kept as views, so the ~30 call sites below the layer
are untouched), `StreamUrl` and its two construction sites,
`register_origin`/`install`, `SourceRef`/`ServerRef`, `ReadyCreds`,
`app.rs`'s boot gate and `install_pms`, and the engine's URL splitter.
`dev::DevServer` gains an optional `scheme`, which is how an https origin
can be exercised headlessly through the `plxnative-servers` trigger by
anyone who has no such server to discover.

Two invariants are pinned by tests rather than left to prose.
`Origin::host()` is ALWAYS unbracketed — it is the `getaddrinfo` node —
and `Origin::authority()` ALWAYS brackets a v6 literal, because it is URL
serialization; `probe::host_of` returned the bracketed spelling and is
gone, replaced by one shared reading of a URL. And a session file written
by 0.4.1, carrying `address`/`port` and no origin, must still boot as
`http://{address}:{port}`: `Session::server` is not a soft-parsed roster
entry, so dropping it is a silent sign-out at every boot for every
existing user. Both have a test with a literal 0.4.1-shaped JSON string.

NO BEHAVIOUR CHANGE. Every origin is still `http://` and dials the same
address: `dial_target` accepts only a plain-http IPv4 candidate, whose
URL `probe::candidates` synthesized as `http://{address}:{port}`, so the
parsed origin and the old pair are equal today — asserted, not assumed.
The registry's two log lines now print `origin.authority()`, which is
byte-identical for every http/IPv4 origin and correct for a v6 literal,
which `{host}:{port}` could not spell at all.

996 host tests pass. A simulator boot against a real PMS produces an
event log identical to the pre-change one on all 30 non-heartbeat lines;
the three `loop=`/`fps=` lines vary run to run on an unchanged binary.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* docs: name what the origin model made stale, rather than leaving it to rot

`plex/CLAUDE.md` and `servers.rs`/`client.rs`'s module docs described the
registry in terms of `(host, port)`, which is the shape the change
replaced. `docs/plex-api-design.md` is a design note whose sketches were
the implementation of their day — it gets a banner naming the one thing
in it that would now mislead (rule 9, "Numeric host, no DNS", and the
two struct sketches), not a rewrite. `docs/shared-servers.md` §7 gains
the `plxnative-servers` trigger's new `scheme` field, which is the only
way to put a TLS origin through the registry without an account that
has one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* session: the stored origin field is `origin_url`, so it cannot be mistaken for `origin()`

`SourceRef`/`ServerRef` had a FIELD `origin` (the serialized string) beside
a METHOD `origin()` (the parsed value). Rust puts those in different
namespaces so it compiles either way, which is exactly the problem: two
characters separate "the raw JSON string" from "the thing to dial", at
every use, forever. The field takes the `_url` suffix; `#[serde(rename)]`
keeps the FILE's key spelled `origin`, which is what a human editing a
session file on the television reads, and the round-trip test proves the
rename applies to both halves of serde.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* review: close the gap between the origin that was DIALLED and the one recorded

Eight findings from `/code-review high`; six fixed, two answered in prose.

**The one that mattered.** `resolve_roster` recorded `Candidate::origin()`
while `probe_server` dialled `(&c.address, dial_port(c.port))`, and the
comment justifying that divergence was wrong about its own gate:
`dial_target` checks `is_ipv4_literal(&c.address)`, which admits a
plex.tv-advertised `uri` candidate and not only the synthesized twin. A
connection whose `uri` names a different port from `port` would be
verified at one and written into the session file as the other, and every
later request would go somewhere nothing ever answered from. So
`dial_target` now returns the ORIGIN, `probe_server` dials that origin's
host and port, and `Reach::At` carries it back beside the candidate — one
value, so what answered and what is recorded cannot be two addresses. The
candidate stays for the diagnostic fields. Its fixture had `url` and
`port` disagreeing, which is what let the old shape look consistent; it
builds both from one pair now, as `probe::candidates` does.

**The silent-instrument trap, twice.** `dev::DevServer`'s `scheme` field
exists so a lane with no TLS server of its own can put an https origin
through the registry — and both registry log lines and `DevServer::
describe` printed `host:port`, so such a run was byte-identical to an
http one. `Origin::log_form()` is the shared answer: the bare authority
for a plaintext origin (an archived log stays comparable, and the
byte-identical gate holds) and the whole URL as soon as the scheme is
worth saying.

**`player::engine` REFUSES a TLS stream target** instead of silently
downgrading it, which is what the code did while its comment claimed the
opposite. It is reachable today: a client registered at an https origin
copies that origin into `direct_play_url`/`transcode_start_url`, so
`route` would store an https URL and the engine would open a plaintext
socket to it.

Also: an EMPTY port (`http://h:`) is a port that was WRITTEN and cannot
be dialled, so `Origin::parse` refuses it rather than defaulting to 32400
— a truncated write of the session file is exactly the "port nobody wrote
down" case `dial_port` exists for. And `reconcile_primary` no longer logs
"primary now answers at …" when the only thing that changed was the
stored origin going from empty to populated, which is what the FIRST BOOT
after this lands does on every existing install — a false DHCP-churn
report in the file this project treats as its primary evidence surface.

Answered rather than changed: `Origin::port`'s doc claimed a narrowing one
constructor does not perform (`ServerRef::origin`'s legacy `port as i32`),
so the doc now says where the narrowing really lives; and
`Session::can_go_local` still asks "is there an address written down"
rather than "can THIS build's transport open it" — gating it would send a
user to a QR code for a transport gap that is not theirs, and the
half-landed state it exposes is named in the doc and refused out loud one
layer down, in the engine.

997 host tests pass. The simulator event log is still identical to the
pre-change one on all 30 non-heartbeat lines.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

* tests: a registry test must not call the PUBLIC register — it opens a real socket

CI was red on Linux with `thread '<unknown>' has overflowed its stack`,
at a different point in the output each run, while `make check` passed on
the dev Mac. The mechanism is not serde_json and not the session file.

`moving_a_server_to_https_re_points_its_slot` called the public
`register_origin`, where every other test in this module deliberately
goes through `register_with_client_id`. The public path fires
`serverinfo::refresh`, which spawns a `task::spawn_small` worker that
really opens a socket — and in a DEBUG build `stream::http_stream_boxed`
materialises its 64 KiB `HttpStream` as a STACK temporary before it ever
reaches the heap, despite the comment above it promising the opposite
("box it off the caller's stack"). lldb caught it on the guard page:

    frame #0  stream::http_stream_boxed
    frame #1  stream::http_get(host="10.0.0.1", port=32400, …)
    frame #2  Client::get_json
    frame #3  Client::server_root
    frame #4  serverinfo::fetch_once
    frame #5  serverinfo::refresh::{closure#0}   <- spawn_small, 256 KiB

Measured on this branch by varying `SMALL_STACK`: debug overflows at 48,
128 and 192 KiB on ARM64 and needs more than 256 KiB on x86-64, which is
exactly why one host passed and the other did not. **`--release` passes at
48 KiB**, so the optimizer elides the temporary and the television — which
ships `cargo build --release` (Makefile:438) — is not affected. It is a
latent debug-only hazard in `stream.rs`, pre-existing and not this
branch's to fix; the base simply had no host test that reached
`http_get` from a `spawn_small` worker. Reported on the PR.

The fix is the test, which was wrong on its own terms: `register` also
mints and PERSISTS a client-id uuid, and that seam's doc has said since it
was written that a host test must not write one. It gains an origin-taking
sibling (the pair-shaped one cannot express a scheme, which is what this
test is about) and a second documented reason nobody had paid for yet.

Verified with the same differential that found it: at `SMALL_STACK = 48 *
1024` the branch was 3/3 aborts and is now 3/3 clean, 997 tests, both
`--test-threads=1` and parallel. `task.rs` is untouched.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G

---------

Co-authored-by: Claude Opus 5 (1M context) <[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