fix(relay): normalize loopback relay URL to localhost for managed agents - #4345
Open
yougeqiu wants to merge 1 commit into
Open
fix(relay): normalize loopback relay URL to localhost for managed agents#4345yougeqiu wants to merge 1 commit into
yougeqiu wants to merge 1 commit into
Conversation
Managed agents spawned by the desktop launcher dialed ws://127.0.0.1:PORT even when the operator configured ws://localhost:PORT, because normalize_relay_url collapsed loopback to 127.0.0.1. The relay resolves community by the connection Host header, and the dev seed registers localhost (not 127.0.0.1) as a community host, so agents landed in a separate empty community and discovered 0 channels — while the desktop UI, which dials the URL the operator entered, worked in the same instance. Canonicalize loopback to localhost so the agent's dial host matches the host the relay's community lookup resolves. This is the only non-test call site of normalize_relay_url (runtime_types.rs:22); the NIP-42 AUTH comparison helper in buzz-auth/src/nip42.rs is a separate function and is not touched. The relay-side normalize_host cannot collapse loopback without breaking NIP-98 (nip98_expected_url builds the expected URL from tenant.host(), which would diverge from the agent's signed u tag). Refs block#3505 block#3283 block#3033 block#2444 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On self-hosted dev, every Desktop-managed agent connects and authenticates, then discovers 0 channels and sits idle — while the Desktop UI itself works in the same instance. Reproduces #3505, #3283, #3033, #2444.
Root cause
buzz_core::relay::normalize_relay_urlcanonicalizes loopback hosts to127.0.0.1. The desktop's managed-agent launcher (ManagedAgentRuntimeKey::newindesktop/src-tauri/src/managed_agents/runtime_types.rs:22) feeds the agent spawn URL through this function, so an agent created againstws://localhost:PORTis spawned againstws://127.0.0.1:PORT.The relay resolves community by the connection
Hostheader, andbuzz_core::tenant::normalize_hostdoes not collapse loopback spellings —localhost:PORTand127.0.0.1:PORTresolve to two distinct communities. The dev seed (scripts/seed-local-community.sh) registers both as separatecommunitiesrows, so:localhost:PORT) → community A (has channels/members)127.0.0.1:PORT) → community B (empty) →discovered 0 channel(s)Agent log, every start:
```
INFO buzz_acp: connected to relay at ws://127.0.0.1:PORT
INFO buzz_acp: discovered 0 channel(s)
WARN buzz_acp: no channel subscriptions resolved — agent will sit idle
```
Fix
Canonicalize loopback to
localhostinstead of127.0.0.1. The dev seed registerslocalhostas a community host, so the canonical relay URL now matches the host the relay's community lookup resolves — managed agents land in the same community as the app UI.This is the sole non-test call site of
normalize_relay_url(verified: `grep -rn normalize_relay_url` — only `runtime_types.rs:22`). It is not the NIP-42 AUTH comparison helper in `buzz-auth/src/nip42.rs` (a separate function pinning to `127.0.0.1` for the AUTH security boundary); that function is untouched.Why not fix on the relay side
The relay's
normalize_hostcannot collapse loopback spellings without breaking NIP-98 HTTP auth:nip98_expected_url(bridge.rs:205) builds the expected URL fromtenant.host(), and the agent signs its NIP-98 event with the host it dials. If the relay rewrote127.0.0.1 → localhostat lookup time,tenant.host()would diverge from the agent's signedutag → 401. Client-side canonicalization is the safe place to fix this. (This is the same conclusion #2944 reached before pivoting to a caller-side fix.)Test
loopback_spellings_have_one_identityto assert the canonical form islocalhost.cargo fmt --checkandcargo clippyclean.windows-canaryworkflow, installed it, and confirmed 4 managed agents now dialws://localhost:3100and discover channels (previouslyws://127.0.0.1:3100→ 0 channels).Closes #3505 #3283 #3033 #2444