fix(desktop): connect managed agents to the configured relay, not the normalized loopback identity - #4664
fix(desktop): connect managed agents to the configured relay, not the normalized loopback identity#4664spkaplan wants to merge 1 commit into
Conversation
… normalized loopback identity
Managed agents came up "online" but discovered 0 channels and sat idle
whenever the workspace relay was addressed as `localhost` (the desktop
default and the seeded dev community).
Root cause: the relay is multi-tenant, keyed by the literal request Host,
so `localhost:3000` and `127.0.0.1:3000` are distinct communities.
`buzz_core::relay::normalize_relay_url` intentionally folds all loopback
spellings to `127.0.0.1` for the runtime *identity* key -- its own doc
says "connection code may retain the configured URL; this canonical form
is for identity, receipts, status and deduplication." But the spawn path
reused that normalized URL as the child's actual BUZZ_RELAY_URL, so agents
connected to the empty `127.0.0.1:3000` tenant while the human and their
channels lived on `localhost:3000`; subscribe resolved 0 channels and the
agent never woke.
Fix: connect via the configured relay URL at every spawn site, keeping the
normalized ManagedAgentRuntimeKey solely as the dedup identity (receipts,
pid files, logs):
- spawn_agent_child: use the raw `relay_url` param for BUZZ_RELAY_URL
- start_managed_agent_process / start_pair: pass the configured
`relay_url`, not `key.relay_url`
- reconcile start loop: pass the raw requested community URL
Honors normalize_relay_url's documented contract and restores channel
discovery for loopback-addressed local communities.
Signed-off-by: Sam Kaplan <samuel.kaplan@salesforce.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c071752d1c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // joined on `localhost`, leaving it "online" but discovering 0 channels. | ||
| // `normalize_relay_url`'s own contract says connection code must retain the | ||
| // configured URL; this honors that. | ||
| let effective_relay_url = relay_url.to_string(); |
There was a problem hiding this comment.
Keep restart hashes on a consistent relay URL
For relay URLs whose configured form differs from the normalized runtime key (the fixed localhost case, [::1], default ports, etc.), this raw assignment also changes the value stamped into process.spawn_config_hash; later build_managed_agent_summary recomputes the hash with key.relay_url (the normalized value), so a freshly started agent is reported as needs_restart immediately even though no config changed. Split the connection URL from the hash input, or make the summary recompute with the same configured URL.
Useful? React with 👍 / 👎.
Summary
Desktop-managed agents came up online but discovered 0 channels and sat idle whenever the workspace relay was addressed as
localhost(the desktop default and the seeded local-dev community). They only worked when the community was addressed as127.0.0.1.Root cause. The relay is multi-tenant, keyed by the literal request
Host, solocalhost:3000and127.0.0.1:3000are distinct communities with isolated channels/members.buzz_core::relay::normalize_relay_urlintentionally folds all loopback spellings to127.0.0.1for the runtime identity key — its own doc says:But the spawn path reused that normalized
ManagedAgentRuntimeKey::relay_urlas the child's actualBUZZ_RELAY_URL. So an agent for a community joined onlocalhost:3000connected to the empty127.0.0.1:3000tenant:subscriberesolved 0 channels and the agent never woke.Fix
Connect via the configured relay URL at every spawn site, keeping the normalized
ManagedAgentRuntimeKeysolely as the dedup identity (receipts, pid files, logs). Four sites indesktop/src-tauri/src/managed_agents/:runtime.rsspawn_agent_child: use the rawrelay_urlparam forBUZZ_RELAY_URL(notruntime_key.relay_url).runtime.rsstart_managed_agent_process: pass the configuredrelay_url, notkey.relay_url.runtime_commands.rsstart_pair: same.runtime_commands.rsreconcile start loop: pass the raw requested community URL, notkey.relay_url.This honors
normalize_relay_url's documented contract and restores channel discovery for loopback-addressed local communities. No change to identity/dedup/receipts, which still use the normalized form.Validation
Reproduced and verified end-to-end on a local self-hosted stack (relay on
localhost:3000):relay=ws://127.0.0.1:3000 -> "discovered 0 channel(s)" -> "no channel subscriptions resolved -- agent will sit idle".relay=ws://localhost:3000 -> "discovered 1 channel(s)" -> "subscribed to channel <spike>", and two managed agents (a Codex harness and a cursor-agent harness) each replied to an owner@mentionin-channel.branch-skewanddesktop-tauri-checks(clippy + Tauri crate tests) pass locally against currentmain.Test plan
localhost:<port>, attach it to a channel,@mentionit as owner — it should discover the channel and reply.127.0.0.1) identity (no dedup regression across loopback spellings).