fix(relay): serve the relay endpoint from the API
The client half of this shipped in canary while the server half never merged — host.relayEndpoint 404s in production, so every host and client falls back to the Fly relay. This is that missing server half (the commit was pushed to #6204's branch two hours after that PR merged, so it went nowhere).
Client-side flag evaluation was the root cause of tonight's rollout failures, reproduced under controlled conditions: with the same active flag and the same machine, old code resolved the fallback relay and new code resolved the flag's URL. The desktop resolves the relay when spawning host-service, and getRelayUrl() silently returns the default when PostHog hasn't identified the user yet — a cold start usually loses that race and never re-checks, so a host sits on the wrong relay through any number of restarts. Clients read the flag live while hosts read it at spawn, so the two also drift apart on any change.
host.relayEndpoint resolves the flag server-side, once, for host-service, the renderer, and the CLI. The host-service asks for itself after authenticating rather than trusting what spawned it, so there is no identification to race. env.RELAY_URL remains the fallback for an unreachable API, and the host-service now logs the relay it chose.
Verified locally end-to-end: a dev-project flag pointing at a distinct port, cold start of the whole stack, all three host-services resolved the flag's URL and connected — where the same setup on main used the fallback.
Summary by cubic
Serve host.relayEndpoint from the API and move desktop, CLI, and host-service to use it so hosts and clients land on the same relay. Removes client-side flag races; falls back to env.RELAY_URL if needed.
- Bug Fixes
- Added
host.relayEndpointon the API to resolverelay-url-overrideper user; defaults toenv.RELAY_URL. - Host-service now resolves the relay after authenticating, logs the chosen URL, and uses it for protocol detection.
- Desktop renderer fetches the endpoint via
@tanstack/react-query(cached, retries); desktop main and CLI stop reading PostHog and only useenv.RELAY_URLas fallback. - Fixed the production 404 so clients don’t fall back to the Fly relay and hosts/clients stay aligned.
- Added
Summary by CodeRabbit
- Improvements
- Relay connections now retrieve the latest available endpoint when connecting.
- Added reliable fallback to the configured relay URL when endpoint retrieval is unavailable.
- Improved consistency of relay endpoint handling across desktop, CLI, and host-service connections.
- Endpoint requests are cached briefly and retried automatically to improve responsiveness and reliability.