buzz icon indicating copy to clipboard operation
buzz copied to clipboard

Managed agents fail with 404: desktop spawns buzz-acp with ws://127.0.0.1:3000 while the community host is localhost:3000

Open jacostarre opened this issue 3 months ago • 5 comments

Describe the bug Every managed agent starts, initialises all its ACP subprocesses, then exits 1. The desktop app itself connects fine; only spawned agents fail.

buzz-acp starting: relay=ws://127.0.0.1:3000 ... agent_cmd=claude-agent-acp.cmd agent initialized ×10 agent_pool_ready agents=10 WARN buzz_acp::relay: initial relay connect failed with terminal error: WebSocket error: HTTP error: 404 Not Found

Expected behavior The spawned harness should receive the same relay URL that is stored on the agent record — or the relay should treat localhost and 127.0.0.1 as the same community host.

Version and platform Buzz Desktop v0.5.5 (Windows x64, unsigned build) Relay: self-hosted, ghcr.io/block/buzz@sha256:ce5811ab066b24ff6352961c6633f8e0a5b4a541febe56ce91a61d7c63467023 Docker Compose (deploy/compose), Windows 11 + WSL2

Logs / additional context Steps to reproduce:

  1. Self-host a relay via deploy/compose with RELAY_URL=ws://localhost:3000 (community host becomes localhost:3000)
  2. Connect Buzz Desktop to ws://localhost:3000 via "Join a community"
  3. Create or start any managed agent

The agent record stores the URL correctly: %APPDATA%\xyz.block.buzz.app\agents\managed-agents.json → "relay_url": "ws://localhost:3000"

But the spawn record shows what the harness actually gets: %APPDATA%\xyz.block.buzz.app\agents\agent-pids<pubkey>__.json → {"key":{"pubkey":"…","relayUrl":"ws://127.0.0.1:3000"},"pid":11344}

The relay resolves the community by Host header: curl -H "Host: localhost:3000" http://127.0.0.1:3000/ → 200 curl -H "Host: 127.0.0.1:3000" http://127.0.0.1:3000/ → 404

Note: /_liveness returns 200 on every host, so health checks stay green while every agent fails.

Workaround: change the community host to 127.0.0.1:3000 (update communities set host = …) plus the matching RELAY_URL in deploy/compose/.env.

jacostarre avatar Aug 05 '26 13:08 jacostarre

Confirmed on another real Windows + WSL2 self-hosted setup, using Buzz v0.5.2 and relay port 3210.

The Desktop connected to ws://localhost:3210; channels and the managed agent's kind:39002 membership were stored under the localhost:3210 community. The managed harness was nevertheless launched with:

relay=ws://127.0.0.1:3210

The database contained distinct community rows for the loopback host spellings. The agent therefore entered the empty 127.0.0.1:3210 tenant and reported:

discovered 0 channel(s)
no channel subscriptions resolved — agent will sit idle

The membership data itself was valid: the equivalent SQL query returned the expected event. An authenticated HTTP /query through the wrong host returned result_count=0, which initially looked like a relay read-path bug but was tenant isolation working as implemented.

Changing the agent record's stored relay_url did not affect the actual launch in v0.5.2; the Desktop launch path supplied the active/canonical workspace URL instead. A temporary launcher that changed only BUZZ_RELAY_URL from 127.0.0.1 to localhost immediately changed startup to:

relay=ws://localhost:3210
discovered 1 channel(s)
subscribed to channel <general-uuid>

The same agent identity and membership then worked without re-adding the agent or modifying relay data. This is strong confirmation that host canonicalization and host-based tenant resolution disagree, rather than a channel-membership or WSL failure.

al-osokin avatar Aug 07 '26 00:08 al-osokin

Confirmed on macOS with a self-hosted Docker Compose relay. Buzz version 0.5.8

Environment:

  • Relay image: ghcr.io/block/buzz:main
  • Relay configuration: RELAY_URL=ws://localhost:83
  • Desktop community URL: ws://localhost:83
  • Desktop app connects normally and channels/messages work

However, the managed-agent harness is launched with:

relay=ws://127.0.0.1:83

The harness then fails immediately:

WARN buzz_acp::relay: initial relay connect failed with terminal error: WebSocket error: HTTP error: 404 Not Found Error: relay connect error: WebSocket error: HTTP error: 404 Not Found The relay logs show the configured community was seeded as: localhost:83

The distinction is independently reproducible: ws://localhost:83 -> WebSocket connection succeeds ws://127.0.0.1:83 -> HTTP 404 Not Found

This is a host-based community mismatch. The relay correctly treats the two authorities as different communities, while the desktop managed-agent launcher canonicalizes loopback URLs to 127.0.0.1 before passing the URL to buzz-acp.

The desktop UI therefore works while every managed agent fails before authentication. Adding the agent as a relay member does not help because the request is rejected during community resolution.

The agent log is the only useful diagnostic; the desktop UI reports only the generic harness exit failure.

This reproduces the behavior described in this issue and confirms that the fix should preserve the configured community URL for the actual harness connection, using canonicalization only for runtime identity/deduplication.

Changing the relay community to 127.0.0.1:83 would avoid the 404 but would orphan/split the existing localhost:83 community.

plazareff avatar Aug 08 '26 17:08 plazareff

Same root cause, but a nastier variant on macOS worth documenting: with the dev flow (just relay from main @ be48ce9, Buzz Desktop 0.5.9), scripts/seed-local-community.sh seeds both loopback spellings as community rows. So the spawned harnesses (pointed at ws://127.0.0.1:3000 via normalize_relay_url, runtime.rs:501/:532) don't get a 404 like above — they connect successfully to the other, empty community, log discovered 0 channel(s) … agent will sit idle, and go silent. No error anywhere in the UI; the app (joined as ws://localhost:3000) and the agents simply live in two different tenants. During the failing window all channels/events sat in the localhost:3000 row while 127.0.0.1:3000 held no channels and no events.

Workaround that worked: leave the community and re-join as ws://127.0.0.1:3000 (the canonical spelling), then restart the app so the harnesses re-discover channels — the starter agents then discovered their channel and responded normally.

Independent of which fix direction wins (several PRs open), it might be worth surfacing "agent discovered 0 channels" in the agents UI — the silent-idle state is what makes this hard to diagnose.

konradtai77-web avatar Aug 11 '26 09:08 konradtai77-web

Confirmed independently on macOS with a self-hosted Docker Compose relay (ghcr.io/block/buzz:main + redis + postgres + minio), Buzz Desktop, relay on port 3001.

buzz_acp: buzz-acp starting: relay=ws://127.0.0.1:3001 pubkey=<pubkey> ...
WARN buzz_acp::relay: initial relay connect failed with terminal error: WebSocket error: HTTP error: 404 Not Found

Workspace was configured with ws://localhost:3001; community in Postgres was seeded under localhost:3001. Same code paths already identified in this thread: effective_agent_relay_url() in desktop/src-tauri/src/relay.rs, and runtime.rs:501/:532 handing normalize_relay_url()'s canonical (always-127.0.0.1) identity value to BUZZ_RELAY_URL, despite that function's own docstring saying the canonical form is for identity/dedup only.

Two things to add that might help whoever picks up the fix:

1. Isolated the 404 to Host-header tenant resolution, independent of the harness/WebSocket layer

Curl against the same running relay, same port, different Host header only:

$ curl -H "Host: localhost:3001" http://127.0.0.1:3001/
HTTP/1.1 200 OK

$ curl -H "Host: 127.0.0.1:3001" http://127.0.0.1:3001/
HTTP/1.1 404 Not Found

So the 404 comes purely from buzz-relay's bind_community/tenant::normalize_host() rejecting an unmapped host, before any WebSocket upgrade or auth logic runs. tenant::normalize_host() treats localhost and 127.0.0.1 as distinct hosts, while relay::normalize_relay_url() (used for the harness's BUZZ_RELAY_URL) treats them as the same. The two normalizers disagreeing is the whole bug, matches the analysis already given above.

2. A workaround for single-community docker-compose self-hosters that doesn't require leaving/rejoining or patching the launcher

Since communities.host is unique and this setup only has one community, repointing that one row to the spelling the desktop always sends fixes it with no client-side change and no data migration:

UPDATE communities SET host = '127.0.0.1:<port>' WHERE id = '<community-id>';

Confirmed working afterwards: managed agents connect and discover channels normally, no app restart beyond the normal agent restart needed. Obviously this just re-aligns which spelling wins rather than fixing the disagreement, and it would need to be reverted if runtime.rs starts using the configured URL instead of the canonicalized one, but it's a clean one-line stopgap for anyone hitting this via a plain docker-compose stack rather than the just relay dev flow.

basjes1977 avatar Aug 14 '26 07:08 basjes1977

Confirmed on macOS (Apple Silicon), Buzz Desktop v0.5.18 from the prebuilt release, relay ghcr.io/block/buzz:main via deploy/compose with RELAY_URL=ws://localhost:3000. The desktop joins and works; the built-in Welcome Team agents (Fizz/Honey/Pollen) each exit 1 immediately after agent_pool_ready.

Two things I did not see in the thread yet.

1. The host binding reproduces without the desktop involved at all. A bare WebSocket upgrade against the same relay, differing only in the authority:

$ curl -s -o /dev/null -w '%{http_code}\n' --http1.1 \
    -H 'Connection: Upgrade' -H 'Upgrade: websocket' \
    -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' \
    http://localhost:3000/
101
$ # same command, 127.0.0.1
404

The relay resolves the community from the Host header, and communities carries a unique index on lower(host), so the two loopback spellings can never resolve to a single community row:

                  id                  |      host
--------------------------------------+----------------
 0d2997f0-****-****-****-************ | localhost:3000
(1 row)

2. The repo already asserts the invariant that is being violated — on a sibling code path. At main @ e236329, desktop/src-tauri/src/relay.rs:

#[test]
fn loopback_ws_localhost_preserves_authority() {
    // Tenant host-binding keys off the HTTP Host/authority. The desktop must
    // not rewrite localhost to 127.0.0.1, or local dev HTTP calls target a
    // different unmapped community than the WebSocket URL.

That guard covers relay_http_base_url. The managed-agent spawn path bypasses it: ManagedAgentRuntimeKey::new runs the URL through buzz_core_pkg::relay::normalize_relay_url (crates/buzz-core/src/relay.rs:51-58, which rewrites every loopback host to 127.0.0.1), and managed_agents/runtime.rs:503 then reuses that canonical string as the wire URL — BUZZ_RELAY_URL at :534, and relay_http_base_url(&effective_relay_url) at :784.

So the canonical identity string — correct for de-duplicating runtime pairs, per loopback_spellings_have_one_identity in buzz-core — is doing double duty as the dial address, in a place where the authority is load-bearing.

Workaround, which preserved all existing data (channels, members and messages key off community_id, not the host):

UPDATE communities SET host = '127.0.0.1:3000' WHERE host = 'localhost:3000';

plus matching BUZZ_DOMAIN / RELAY_URL / BUZZ_CORS_ORIGINS in deploy/compose/.env, ./run.sh restart, and re-pointing the desktop at ws://127.0.0.1:3000. The managed agents start and connect after that.

A narrow fix would keep the canonical form as the pair identity and dial the workspace's configured authority whenever the two normalize to the same value, which preserves the "only relay this child may connect to" scoping property that runtime.rs:501-503 documents.

lansdaal avatar Aug 23 '26 14:08 lansdaal