Skip to content

transport: an Origin is what a server's address IS, parsed from a URL and never rebuilt from one - #53

Merged
GLinnik21 merged 5 commits into
mainfrom
worktree-agent-af0cb2962fa674089
Aug 23, 2026
Merged

GLinnik21 merged 5 commits into
mainfrom
worktree-agent-af0cb2962fa674089

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Aug 23, 2026 •

Copy link
Copy Markdown
Collaborator

T1 of the transport chain: plex::Origin — a server's address as ONE value, parsed from a URL.
A behaviour-preserving refactor that deliberately changes nothing a user can see, and exists so the
lanes above it cannot build the one bug that would make TLS look done and be broken.

Why it has to land before any scheme field

plex/probe.rs builds ranked connection Candidates from /api/v2/resources. A Candidate carries
both url and address, and the two are deliberately different: plex.tv advertises the
plex.direct hostname 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"
— because the certificate is issued for the name.

auth::resolve_roster then threw Candidate::url away and wrote c.address into SourceRef, which
became plex::register(host, port) and then Client { host, port }. 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 — including the LG reviewer's, which is the whole point of the
project.

So the origin is parsed from a URL, never rebuilt from an address, and Candidate::address is
documented down to what it actually is: diagnostic metadata for the log and the Sources panel.

The shape

pub struct Origin { scheme: Scheme, host: String, port: i32 }

Origin::parse(url) -> Option<Origin>   // the front door; the ONLY way an https origin exists
Origin::http(host, port) -> Origin     // the plaintext constructor, named so it is GREPPABLE
origin::split(url) -> (Origin, &str)   // total sibling, for StreamUrl::parse

o.host()       // ALWAYS UNBRACKETED — the getaddrinfo node, and the name a cert must match
o.authority()  // ALWAYS brackets a v6 literal — URL serialization
o.base()       // "{scheme}://{authority}" — no path, no trailing slash
o.log_form()   // authority for http, base otherwise — see below

The bracket rule is an invariant, not a detail, and it is pinned by a round-trip test:
http://[::1]:32400 → host() == "::1" → authority() == "[::1]:32400" → base() identical to the
input. Without it the failure is silent in the worst direction — URL construction keeps looking right
while name resolution quietly stops working. probe's own host_of returned the bracketed
spelling, correct for a URL and wrong for a resolver, so it is gone: there is now exactly one reading
of a URL in the layer (origin::url_host).

Threaded through every site that passed a bare (host, port): 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 install_pms
and boot gate, and the engine's URL splitter.

dev::DevServer gains an optional "scheme". That is how every other lane and the integrator can
put a TLS origin through the whole control plane headlessly
, with no account that has one — and a
value that is neither http nor https fails the trigger loudly rather than silently meaning http.

The two hard gates

(a) A 0.4.1 session file must still boot. Session::server is not a soft-parsed roster entry —
de_soft_vec covers the lists beside it and cannot cover a missing field meaning something else — so
dropping it is a silent sign-out at every boot for every existing user. ServerRef::origin() is
deliberately TOTAL (the roster's SourceRef::origin() is Option, because usable() gates every
caller there); the test uses a literal 0.4.1-shaped JSON string and asserts can_go_local() plus
http://{address}:{port}. Two more pin the other side: a stored origin beats the address pair beside
it, and an undialable stored origin is refused rather than repaired (…:4294999696 must not
become 32400, which is what that number wraps to).

(b) No behaviour change. Every origin is still http:// and dials the same address, and the
equality is asserted rather than assumed: the only candidates this transport dials are plain-http
IPv4 ones, whose URL probe::candidates synthesized as http://{address}:{port}.

Verification

  • make check: 997 pass, 0 fail (nightly, plus the three named clippy lints, ci/flavor.py --selftest and tests/test_harness.py). ~24 of those are new.
  • RELEASE=1 / --no-default-features type-checks clean — the PostToolUse hook ran after every
    edit and blocked several intermediate states, correctly.
  • Simulator boot against a real PMS, before and after: the event log is IDENTICAL on all 30
    non-heartbeat lines
    , including plex: server slot 0 registered at <pms-host>:32400. The only
    diff is the three loop=/fps= heartbeat lines, and those vary run-to-run on an unchanged
    binary too (two consecutive AFTER runs differ on one of them), so they are sampling noise. Home
    renders correctly: hero, shelves, posters, tab strip.

No device tier was run and none is needed: no FFI, no linkage, no dynlib!, no playback path, no
pixels. This is control-plane plumbing plus one URL parser, and the simulator exercises all of it
against a real PMS.

/code-review high — 8 findings, 6 fixed, 2 answered

The two that were worth the review on their own:

The origin recorded was not provably the origin dialled. resolve_roster wrote
Candidate::origin() while probe_server dialled (&c.address, dial_port(c.port)) — and my comment
justifying that 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 down as the
other. Now dial_target returns the Origin, probe_server dials that origin's host and port,
and Reach::At hands it back beside the candidate — one value, so the two cannot diverge. (Its
fixture had url and port disagreeing, which is exactly what let the old shape look consistent; it
builds both from one pair now.)

The silent-instrument trap, twice. The scheme trigger exists so a lane can exercise an https
origin — 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 (archived logs stay comparable, and gate (b) holds) and the whole URL as soon as the
scheme is worth saying.

Also fixed: player::engine now refuses a TLS stream target with a logged reason instead of
silently opening a plaintext socket to it (reachable today — a client at an https origin copies that
origin into direct_play_url); Origin::parse refuses an empty port (http://h:) rather than
defaulting to 32400, since that is a truncated write, not a request for the default; and
reconcile_primary no longer logs "primary now answers at …" when the only change was the stored
origin going from empty to populated — which is what the first boot after this lands does on every
existing install, i.e. a one-shot false DHCP-churn report in the primary evidence surface.

Answered in prose rather than changed: Origin::port's doc claimed a narrowing one constructor does
not perform, so it 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. The half-landed state that
exposes (discovery accepting https before stream.rs speaks it) is named in the doc and refused out
loud one layer down, in the engine.

What a later lane inherits

  • rust-modules/src/ui/alt_sources.rs's dev stand-in is the one remaining (host, port) caller
    that has an origin and discards it (register(&name, c.host(), c.port(), &token)). It is
    #[cfg(not(test))] and needs dev::read("token"), so it is dev-only and cannot mis-dial a real
    server. The fix is one line — register_origin(&name, c.origin(), &token) — and it is written down
    in plex/CLAUDE.md rather than done here, because that file is not in this unit's ownership.
  • SourceRef::describe() still prints the address pair, not the origin. That is right for a
    diagnostic today; the TLS lane may want it to say the origin.
  • register, register_with_client_id and Origin::http are kept as explicitly plaintext
    spellings. That is the point: Origin::http( is the grep that finds every remaining cleartext
    assumption
    , and today they are all correct because stream.rs speaks nothing else.

Docs

plex/CLAUDE.md, servers.rs and client.rs described the registry in (host, port) terms and were
updated. 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 trigger's
new scheme field.

One place the plan and the tree disagreed

The plan put client.rs's StreamUrl at :363-395; it is :362-395. Everything else checked out,
including both probe.rs line references and the session.rs:124 de_soft_vec note.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GovTtrsD9P7Ld7DnLCMK2G


CI was red on Linux, and the mechanism was not where anyone was looking

make check passed on the dev Mac while the x86-64 Linux runner aborted twice with
thread '<unknown>' has overflowed its stack, at a different point in the output each run.

It was 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 that module deliberately goes
through the register_with_client_id seam. 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
reaches the heap, despite the comment directly 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, path="/?X-Plex-Token=…")
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 stack

Measured, by varying SMALL_STACK on this branch: 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. The margin was always razor-thin; the base just had no host test that reached http_get from a
spawn_small worker.

Does it bite in production? No — measured, not assumed

--release passes at 48 KiB, where debug aborts. At release opt-level the zeroing goes straight
into the heap allocation and the temporary never exists. The television ships
cargo build --release (Makefile:438), so its 256 KiB spawn_small stacks are unaffected and
SMALL_STACK keeps the headroom task.rs measured (3745 threads against RLIMIT_NPROC).

It is still a latent hazard worth someone's attention, and it is not this PR's to fix —
stream.rs is another lane's file and the code is unchanged from the base. For whoever picks it up:
the fix is to allocate zeroed on the heap instead of copying a stack temporary into it
(Box::new_uninit() + write_bytes, or alloc_zeroed), which makes the comment true in every
profile and costs nothing. Until then, no test in this crate may call register/register_origin
— that is now written into the seam's doc, with this run as the reason.

The fix here

The test was wrong on its own terms regardless of the stack: 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 seam 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 this branch was 3/3
aborts and is now 3/3 clean — 997 tests, both --test-threads=1 and parallel. task.rs is untouched.

GLinnik21 and others added 5 commits August 23, 2026 12:56
…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
…o 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
…taken 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
… 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
… 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
GLinnik21 merged commit 735c27a into main Aug 23, 2026
2 checks passed
GLinnik21 added a commit that referenced this pull request Aug 26, 2026
The checklist is a submission DOCUMENT, not a private rubric, and its own preamble
is the reason this file exists: every item must be Pass or N/A, and marking one
Pass when it should be N/A — or vice versa — is a stated rejection ground. So
"we never tested it" is not a markable state, which makes the UNTESTED column
matter as much as the failing one. Eleven items sit there today.

Four fail outright, and three of those are one root cause: `stream.rs::http_open`
builds a `sockaddr_in` from four decimal octets, so no TLS, no DNS, IPv4 only —
which takes out #20, #43 and #47 together the moment a QA bench is not on the same
LAN as a plaintext PMS. Plus no ABR (#43 CASE1) and factory reset (#53), which is
undefined for a sideloaded app.

§4 records the four items that moved on 2026-08-22 and why they are worth reading
together: every one was found by LOOKING AT THE PANEL, and not one was visible in
a green test run. Subtitles rendering `.notdef` tofu because neither Inter nor the
television has U+2669-U+266C; transport keys bound to CEA-2014-A web keyCodes
instead of the native scancodes the app actually receives; a splash 63% black
against LG's "should not be black"; and `requiredMemory` asking for less headroom
than declaring nothing would have.

§5 records the two items that are DECISIONS rather than defects — no on-screen
transport button row, and English-only — because a future reader of the checklist
will otherwise try to "fix" the first one, and item 45's own remark ("refer to UX
scenario for movement details") is what makes the UX scenario document, not code,
the place that answer belongs.

§7 names the defect class rather than the bug: the music note was the visible tip
of "any codepoint outside Inter tofus", which is CJK, Hebrew, Arabic and Thai
titles and subtitles, hits the same two items, and nothing in the host suite can
see.

Co-Authored-By: Claude Opus 5 <[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
The checklist is a submission DOCUMENT, not a private rubric, and its own preamble
is the reason this file exists: every item must be Pass or N/A, and marking one
Pass when it should be N/A — or vice versa — is a stated rejection ground. So
"we never tested it" is not a markable state, which makes the UNTESTED column
matter as much as the failing one. Eleven items sit there today.

Four fail outright, and three of those are one root cause: `stream.rs::http_open`
builds a `sockaddr_in` from four decimal octets, so no TLS, no DNS, IPv4 only —
which takes out #20, #43 and #47 together the moment a QA bench is not on the same
LAN as a plaintext PMS. Plus no ABR (#43 CASE1) and factory reset (#53), which is
undefined for a sideloaded app.

§4 records the four items that moved on 2026-08-22 and why they are worth reading
together: every one was found by LOOKING AT THE PANEL, and not one was visible in
a green test run. Subtitles rendering `.notdef` tofu because neither Inter nor the
television has U+2669-U+266C; transport keys bound to CEA-2014-A web keyCodes
instead of the native scancodes the app actually receives; a splash 63% black
against LG's "should not be black"; and `requiredMemory` asking for less headroom
than declaring nothing would have.

§5 records the two items that are DECISIONS rather than defects — no on-screen
transport button row, and English-only — because a future reader of the checklist
will otherwise try to "fix" the first one, and item 45's own remark ("refer to UX
scenario for movement details") is what makes the UX scenario document, not code,
the place that answer belongs.

§7 names the defect class rather than the bug: the music note was the visible tip
of "any codepoint outside Inter tofus", which is CJK, Hebrew, Arabic and Thai
titles and subtitles, hits the same two items, and nothing in the host suite can
see.

Co-Authored-By: Claude Opus 5 <[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
The checklist is a submission DOCUMENT, not a private rubric, and its own preamble
is the reason this file exists: every item must be Pass or N/A, and marking one
Pass when it should be N/A — or vice versa — is a stated rejection ground. So
"we never tested it" is not a markable state, which makes the UNTESTED column
matter as much as the failing one. Eleven items sit there today.

Four fail outright, and three of those are one root cause: `stream.rs::http_open`
builds a `sockaddr_in` from four decimal octets, so no TLS, no DNS, IPv4 only —
which takes out #20, #43 and #47 together the moment a QA bench is not on the same
LAN as a plaintext PMS. Plus no ABR (#43 CASE1) and factory reset (#53), which is
undefined for a sideloaded app.

§4 records the four items that moved on 2026-08-22 and why they are worth reading
together: every one was found by LOOKING AT THE PANEL, and not one was visible in
a green test run. Subtitles rendering `.notdef` tofu because neither Inter nor the
television has U+2669-U+266C; transport keys bound to CEA-2014-A web keyCodes
instead of the native scancodes the app actually receives; a splash 63% black
against LG's "should not be black"; and `requiredMemory` asking for less headroom
than declaring nothing would have.

§5 records the two items that are DECISIONS rather than defects — no on-screen
transport button row, and English-only — because a future reader of the checklist
will otherwise try to "fix" the first one, and item 45's own remark ("refer to UX
scenario for movement details") is what makes the UX scenario document, not code,
the place that answer belongs.

§7 names the defect class rather than the bug: the music note was the visible tip
of "any codepoint outside Inter tofus", which is CJK, Hebrew, Arabic and Thai
titles and subtitles, hits the same two items, and nothing in the host suite can
see.

Co-Authored-By: Claude Opus 5 <[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]>
@GLinnik21
GLinnik21 deleted the worktree-agent-af0cb2962fa674089 branch September 3, 2026 18:09
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