Investigation (2026-08-25) into whether stream-time game pairing overcomplicates the fleet, and whether pairing should be set up proactively when a body or head joins a district.
Finding: every head type pairs on EVERY stream start (hydraheadflatscreen client.go:251 "Pair before every stream start"; iPad AppState.swift:326 "Always pair... no caching"). Nobody verifies stored trust, so trust is treated as disposable, which is also why hydrabody TrimPairedClients can unpair ALL clients. Cluster-orchestrated pairing (option a), sunshine_state.json seeding (option b), and shared district identity (option c) were assessed and rejected as primary mechanisms; the full analysis with file:line citations lives in the investigation report (sections 1-3), summarized below.
DECISION PROPOSED: proactive trust via a head-driven verify-then-pair reconcile loop. Stream start becomes discovery + launch; stream-time pairing remains only as a rarely-hit self-heal fallback.
Proactive pairing via a head-driven reconcile loop, using the existing native pair path, with a cheap verify step. Keep stream-time pairing as the self-heal fallback.
Concretely: each head periodically fetches its eligible-bodies list (the endpoint already exists and already encodes district + venue + owner policy, handlers_api.go:785-899) and, for each body, verifies the pairing (mutual-TLS GET https://host:47984/serverinfo with the client cert presented and the stored server cert pinned; PairStatus == 1 means both directions are healthy). Only on verify failure does it run the existing pairWithSunshine, with jitter and backoff to respect Sunshine's single pair session. Streams then start against an already-trusted body: discovery, launch, no pairing.
Why this over the alternatives:
The honest overcomplication answer: today's complexity is roughly half timing, half mechanism. Proactive pairing deletes the timing half (visitor-facing latency, pairing state machine branches, fail-count fallback, always-pair-fresh rules, trim-then-repair coupling). It does not delete the mechanism half: gamestream_pair.go stays, the Windows subprocess path stays until #278 lands native Windows cert storage, and drift handling is new code that did not exist before. The stream-time pair call should remain as a fallback branch (verify at stream start; if broken, pair on demand exactly as today), so a body that was wiped seconds ago still streams. What changes is that the fallback almost never runs.
New failure modes and their answers:
TrimPairedClients: change it from unpair-all to selective (unpair only certs not in the district mesh, or oldest-first beyond the cap). With a stable mesh the count equals the head count and never approaches 200; today's count explodes only because web/one-off clients accumulate.Phase 1: hydraheadflatscreen (no cluster or body changes required)
pkg/client/pair_reconcile.go: a loop on its own ticker (suggest 5 min, plus a run on config fetch and on discovery failure). For each body from GET /api/v1/bodies/eligible?head_id=...:
verifyPaired(host): mTLS serverinfo on 47984 using readClientCertKey() and the srvcert stored for the body's UUID; healthy = PairStatus 1 and cert match.pairWithSunshine(host) with random 0-30 s jitter.startStream (localapi.go:226-239) and the tick pair block (client.go:251-284) become verify-first: verify (fast, no side effects); only pair when verify fails. The pairing status stays as the rare fallback branch.paired_bodies (body ID, verified_at, ok/fail) in the existing heartbeat for observability.Phase 2: hydrabody
TrimPairedClients unpair-all with selective trim via UnpairClient(uuid) (go-sunshine already has it, client.go:144). Desired-set input: head names/uuids from the existing fetchHeadsForVenue loop, extended to district scope.GET /api/clients/list contents in body status so the cluster admin UI can render mesh health (desired vs actual per district).Phase 3: hydracluster (observability only, no orchestration)
Phase 4: other heads
startStream (AppState.swift:324-352); keep HydraPairSession as fallback. Optionally add its own background reconcile.PairWithSunshine.Migration: none needed. Already-paired heads verify clean on the first loop. Bodies keep their current trust stores. Rollout is head-agent version driven, per the normal release flow.
Omarchy marketplace plugin: unaffected by construction. Standalone mode drives stock moonlight-qt with a human-entered PIN and never talks to a cluster (/home/claude-user/omarchy-hydrahead/README.md:16-20, 42-47); the reconcile loop lives in the hydraheadflatscreen agent, which standalone mode does not run. ExperienceNet mode inherits the benefit automatically when it adopts the agent.
The HydraHead omarchy plugin (omarchy-hydrahead, commit dc7ce80) now implements exactly this issue's core principle at the UI level: its Pair action verifies first and pairs only on failure. Clicking Pair runs a cheap trust check (moonlight list succeeds only against a host that already trusts the client); when trust exists the plugin skips pairing entirely, tells the user "Already paired, no PIN needed", and loads the app list; only a genuinely unpaired host enters the PIN flow. This came from live user testing: the raw pair-always flow surfaced moonlight's confusing "already paired" toast whenever trust already existed.
Takeaways for this issue's implementation: (1) verify-then-pair works and the verify signal (a successful authenticated list/serverinfo) is reliable in practice; (2) the same confusion the reconcile loop prevents fleet-side was independently hit by a human user within minutes of manual testing, which strengthens the case; (3) the plugin's standalone implementation stays UI-triggered, while this issue remains the background reconcile for the managed fleet, so the two do not overlap.
src/nvhttp.cpp v2025.924.154138:
576 sess.client.cert = util::from_hex_vec(get_arg(args, "clientcert"), true);
579 auto ptr = map_id_sess.emplace(sess.client.uniqueID, std::move(sess)).first;
581 ptr->second.async_insert_pin.salt = std::move(get_arg(args, "salt"));
593 ptr->second.async_insert_pin.response = std::move(response);
emplace is NO-OVERWRITE. With a pending session already present for that uniqueid, the new client cert is silently discarded while the new salt and response ARE written onto the old session. New salt, old cert.
That is why it was unreadable: phases 2 and 3 only exercise the AES key from SHA256(salt||PIN), which is correct, so they return paired=1 and the client's own "incorrect PIN" check passes. Phase 4 is the only step verifying a signature against the stored CLIENT cert, so it alone fails.
Sessions never expire on 2025.924: map_id_sess is erased only by remove_session, so an abandoned handshake leaves its cert to poison the next head indefinitely. And every head shared uniqueid 0123456789ABCDEF and devicename roth, so any head's abandoned pair broke every other head's next one. On 2026.914 the same collision is a hard 409.
Proven live: a failed attempt clears the stale session, so the NEXT one succeeds.
15:08:20 clientpairingsecret rejected (paired=0)
15:47:41 pairing with 10.10.100.16 complete
hydraheadflatscreen d485de1 — gamestreamIdentity derives a per-head identity (uniqueid = first 8 bytes of SHA-256 over the head id as 16 uppercase hex, devicename = the head id). Pure function of the head id so other clients mirror it; the Quest has since shipped the identical derivation. Single-flight mutex on the handshake, since the head pairs from three unsynchronized call sites. status_code/status_message parsed off <root> and surfaced in every phase error: without them five distinct server refusals all printed as rejected (paired=0), which is the single biggest reason this took a day. submitPIN sends a name (2025.924 defaults it to empty, which is why every fleet cert is anonymous) and looks up the 2026.914 pairing_id.
hydraheadflatscreen 9acb6a4 — pending-pairing selection by SOURCE ADDRESS, never name (every head sends roth), refusing on any ambiguity rather than guessing. Mirrors hydraheadandroid deliberately.
hydraheadflatscreen df65a7e — this issue's design. verifyPaired asks over mutual TLS whether the body already trusts this head; Sunshine answers PairStatus 1 only for a cert in its paired set, so it proves stored trust without touching it. ensurePaired replaces the unconditional pair at both stream-start call sites. StartPairReconcile verifies every eligible body every five minutes and pairs only those that have forgotten this head, skipping while a stream is live. eligibleBodies split out of discoverBody. All verify failures report "not trusted": a false negative costs one needless pair, a false positive sends a visitor to a body that cannot serve them.
hydrabody f74ca31 — TrimPairedClients no longer calls UnpairAll. Eviction is oldest-first, anonymous entries before named, and never empties the body. This issue's sketch said selective UnpairClient(uuid) with a desired set keyed on head identity; that is unachievable as written while heads are indistinguishable, so it keys on what the body can observe. The #771 session's argument carried this: their per-device Android clients each contribute a cert, so they are the workload that walks the fleet to 200, and the wipe would take everyone else's trust with it.
"Drop the unpair-first step for healthy pairs" needs no code change. Pairing now only runs after a verify has failed, so the unpair-first is already scoped to the fallback re-pair, exactly where the sketch wanted it.
Committed, NOT released. Tagging hydraheadflatscreen auto-deploys to every venue kiosk within 6 hours, which is an owner decision. Until then the field still presents roth/0123456789ABCDEF, still posts a bare {"pin"}, and still destroys its own trust on every stream start. Retry-once remains the workaround.
I also caused an outage proving this: running Sunshine's unpair-all on chunky to clear a stuck session wiped all 25 certs and took the flat lane down for every head, because each was then doing a first pair. That is what f74ca31 prevents recurring.
This issue records the fleet-wide Sunshine credential as a known weakness. Here is the mechanism, traced on 2026-11-13, because it decides what a fix has to touch. No credential values appear below, and none should: this log is public.
The value is cluster-side, keyed by district. It lives in the providers: map of the cluster server's config.yaml. Server.providerConfigs is that map, passed straight through from cfg.Providers at internal/cli/cluster/serve.go:99.
Both halves of a session are handed the same value. Bodies receive it in handlers_body.go, heads in handlers_head.go. So a head and the body it streams from always share one credential by construction.
A node-side change breaks the body rather than securing it. hydrabody reads p.Config.SunshineUsername and p.Config.SunshinePassword for every Sunshine API call, and also writes the value INTO Sunshine with --creds during slot wiring. Change it on the node alone and hydrabody keeps presenting the cluster's value, taking a 401 on every management call. Measured against hydrabody v2.1.5, the deployed version.
A district now inherits its parent's entry. Since cluster v2.2.1, getProviderConfig no longer does an exact lookup. It walks outwards:
// Walk outwards: bxl1-mercator-39 -> bxl1-mercator -> bxl1.
So a district with no entry of its own silently takes its parent's credential, and logs a line saying so. That is convenient for provisioning and it is the mechanism by which one credential reaches a whole district tree.
Per-district credentials are the natural shape, and the inheritance above means they already have a scoping model. The change is an exact entry for the district in the cluster providers map, followed by a HydraBody restart on each node so --creds runs again and Sunshine is told the new value.
Two things are NOT established and should be settled before anyone relies on this:
providers: change without a server restartThe weakness recorded here is bounded while the only thing a credential protects is a kiosk streaming a chosen experience. There is now an intent to support an AGENT attaching to a head and driving the remote desktop as a capability. At that point the credential guards general-purpose control of a Windows desktop rather than a fixed experience, and POST /api/pin hijacking any pending handshake becomes a materially different risk.
No change has been made. The machine this was traced from is unchanged and still on the shared credential.
Field evidence 2026-10-15: first-pair is broken, and every success tonight was a RE-pair
Hit this while trying to get a working-stream baseline from cheeky-cactus-86 (hydraheadflatscreen v2.2.5, moved to mobile-kit) to chunky-turnip-23. Adds concrete failure data to the analysis already on this issue.
What succeeded, and why it does not count
The iPad streamed from chunky end to end at 01:43: 5
/pairrounds plus/api/pincompleting in 860ms, then/launch, thenRTSP/1.0 200 OKon rtspenc, audio, video and control, andRupelmonde.exeexecuting. A real working stream.But chunky held 25 paired client certs at that moment, nearly all with empty names and the same certificate. So that was a re-pair against trust chunky already had, which is the disposable-trust behaviour this issue describes.
I then ran
/api/clients/unpair-allon chunky to clear a stuck pending pairing. That removed all 25 certs — which is the manual equivalent of theTrimPairedClientshazard already noted in the summary above. It destroyed the only known-good pairing state in the system, and every attempt since has been a genuine first pair.Every first pair tonight failed, on two clients and two bodies
/pair=1,/api/pin=1, then nothing. Client never sends rounds 2-5getservercert: context deadline exceeded while awaiting headersclientpairingsecret rejected (paired=0)So no client has been shown to complete a first pair. That is a much more serious reading than "pairing is iffy": the re-pair path has been masking it, and clearing trust exposes it.
The chunky failure is the informative one
It reaches phase 4 of
gamestreamPairWithSunshine, which means a lot is already proven correct:getservercertreturned a server cert, so the pending-pair registered and the PIN was accepted.clientchallengeandserverchallengerespboth returnedpaired=1.expectedServerChallengeRespHash == serverResponseand it returns the error stringincorrect PINwhen it fails. It did not fail, so the PIN and the AES key derived from salt+PIN are correct.clientSecretis verified by Sunshine against the client cert sent in phase 1.Phase 4 is the only place the client's private key signs anything, which is why nothing earlier catches it.
What I ruled OUT, so nobody repeats it
certificateandkeyhave the same RSA modulus (EEF5BC205FC2E30B4B5634B40A31DFC96B5A17E523...). They are a matching pair. Note the key is PKCS#8 (BEGIN PRIVATE KEY), not the PKCS#1 thatgenerateAndStoreClientCertKeywrites, so this identity came from the real Moonlight app.gamestreamPairWithSunshinehandles both encodings correctly, and a wrong type would have errored rather than produced a bad signature.serverinfoanswers in 53ms./pairreturns HTTP 200 in ~15ms on both. My large-request A/B was confounded (I used an invalid dummy cert, so the two versions were just rejecting malformed input differently) and proves nothing either way.So the phase 4 signature rejection is not yet explained. The remaining candidates are the signature construction itself against what Sunshine's
verify256expects, or Sunshine binding the verification to a different session's client cert when a stale pending pair exists.Why this matters for the sequence on #796
#796's SEQUENCE already calls #549 "the highest-value item in #663 that is not blocked on the design ruling", because every head re-pairs on every stream start and nobody verifies stored trust. Tonight is that prediction landing: the moment stored trust was cleared, no head could pair at all, and the flat lane went down on two bodies at once. A verify-then-pair reconcile loop does not help until a first pair works, so the phase 4 bug is the prerequisite for #549's own design, and worth splitting out.