buzz icon indicating copy to clipboard operation
buzz copied to clipboard

Relay-discovered agent with respond_to=anyone still never appears in @-mention autocomplete (regression/incomplete case of #4913)

Open Cyberworkshop opened this issue 3 months ago • 2 comments

Summary

After PR #4913 ("fix(desktop): allow shared agent mentions", merged into main 2026-08-05) was expected to let non-owners @-mention a relay-discovered agent when its respond_to policy authorizes them, the agent still never appears in the @-mention autocomplete — even when every precondition the fix relies on is independently confirmed correct on the relay.

This reproduces with two independent agents, two different owning accounts, and two different channels, so it isn't specific to one agent's config.

Environment

  • Buzz Desktop: 0.5.8 (macOS), built from a commit including #4913
  • Relay: self-hosted, upgraded to current main (5bf78671f) specifically to rule out a version gap — no change
  • Both the mentioning user and the agent owner are members of the same community

Repro steps

  1. Owner A creates/edits an agent, sets "Who can talk to this agent" to Anyone via channel members sidebar → agent card → "Manage agent access" (not the top-level Edit Agent dialog, which is the known #2501 persistence bug).
  2. Confirmed via the relay's own event log that this actually published a fresh kind:30177 event with "respond_to":"anyone" (superseding the prior owner-only event) — see raw events below.
  3. Agent is added as a member (role: bot) of a stream-type channel.
  4. A different user (not the agent's owner), already a genuine member of that same channel, opens the channel and types @ + the agent's name.
  5. Expected: agent appears in the autocomplete per #4913's stated behavior ("admit relay-discovered agents to autocomplete when their response policy authorizes the viewer... require authorization in the exact active stream/forum channel for mentions").
  6. Actual: agent never appears, regardless of search string used (tried exact name substrings that should match, e.g. typing "ben" against an agent named "Bens Fizz").

Confirmed NOT the cause (ruled out one at a time)

  • Relay code version — upgraded relay from a pre-#4913 commit to current main; no change.
  • respond_to not actually persisting — verified directly against the relay's Postgres events table (not the Desktop UI) that a kind:30177 event with respond_to: "anyone" was published and is the latest event for the agent's d-tag.
  • Channel membership — verified via channel_members that the agent has an active (removed_at IS NULL) bot row in the exact channel, and the mentioning user has an active member row in the same channel.
  • Channel type — verified channel_type = 'stream' (the type #4913 explicitly scopes exact-channel mention authorization to).
  • Relay connectivity — confirmed active websocket connections from the mentioning user's client in the relay's own connection logs at the time of testing.
  • Relay-side access control — read get_accessible_channel_ids directly (buzz-db/src/channel.rs): grants access via real membership OR open-visibility fallback; both users have real membership rows, so the relay has no basis to withhold channel-scoped events.
  • Stale local client cache — fully quit the app, cleared ~/Library/Caches/xyz.block.buzz.app and ~/Library/WebKit/xyz.block.buzz.app (WebView cache/IndexedDB/localStorage), relaunched. Same result. (Note: this cache also apparently held session/identity data not backed by the Keychain-stored secrets — recovered via the existing-key flow, but worth flagging separately: clearing WebView storage shouldn't be able to desync a user from their Keychain-stored identity in the first place.)

Raw evidence

Relay events table, latest two kind:30177 rows for one of the test agents (pubkey redacted per-agent, available on request):

{"name":"Grokola","persona_id":"7f87a3ac-aaa7-4c59-8d44-032846410fa1","parallelism":10,"respond_to":"anyone"}      | 2026-08-08 23:47:24+00
{"name":"Grokola","persona_id":"7f87a3ac-aaa7-4c59-8d44-032846410fa1","parallelism":10,"respond_to":"owner-only"} | 2026-08-08 09:15:31+00

channel_members for the same channel:

channel_type = stream
<agent pubkey>  role=bot     removed_at=NULL
<mentioner pubkey> role=member removed_at=NULL

Suspected area

Given every server-side precondition is verifiably correct, this points at the client-side eligibility computation in desktop/src/features/agents/lib/agentAutocompleteEligibility.ts / desktop/src/features/messages/lib/useMentions.ts (added/modified in #4913) — possibly in how relayAgentsQuery data is fetched/kept fresh, or in getMentionableAgentPubkeys's channel-scoped branch (relayAgentCanRespondInChannel). I wasn't able to get a live JS-console trace to pin down the exact line (release build has no reachable WebView inspector — Safari's Develop menu shows "No inspectable applications," and no in-app devtools shortcut/setting was found either), so filing with full server-side evidence instead in case someone with build access can reproduce with pnpm --dir desktop dev and step through it directly.

Related

  • #2950 (original picker-visibility report this traces back to)
  • #2501 (respond_to persistence bug — ruled out here since we verified the published event directly, but worth keeping in view since it's the same feature area)
  • #4913 (the fix this appears to be a regression in / incomplete case of)

Cyberworkshop avatar Aug 09 '26 00:08 Cyberworkshop

Adding an independent reproduction with a few data points that narrow the failure beyond the original report.

New signal: reproduces for the agent's owner, not just non-owners

The repro above is a non-owner mentioning a shared agent, so it exercises the respond_to-authorization branch (relayAgentCanRespondInChannel). In our setup the owner of the relay-discovered agents cannot mention them either — from the same account that owns them, in a channel where the owner is an active member.

An owner should be trivially authorized by any policy branch, yet the relay-discovered agents still never appear in autocomplete. That suggests the failure is upstream of the authorization check — i.e. relay-discovered agents aren't entering the mentionable set at all (getMentionableAgentPubkeys' relay branch / relayAgentsQuery freshness), rather than being admitted-then-rejected by policy. Locally managed agents (spawned by this Desktop instance) appear normally in the same picker, consistent with #4913's "preserve managed-agent behavior" — only the relay-discovered path is dark.

iOS works against the identical relay state

Same account, same relay, same channels: the iOS client lists and mentions the relay-discovered agents correctly, while Desktop does not. Since both clients read the same server-side data, this isolates the regression to the Desktop webview eligibility path added in #4913 (agentAutocompleteEligibility.ts / useMentions.ts) and rules out any relay/data cause.

Version bracket

#4913 merged 2026-08-05T18:15:11Z. Desktop v0.5.5 was released 2026-08-05T01:23:40Z (pre-merge); v0.5.6 (2026-08-07) is the first release built after the merge. Our affected build is 0.5.8 (current latest). So the candidate affected range is v0.5.6+, and downgrading to v0.5.5 restores the old autocomplete behavior as a stopgap.

Second self-hosted relay confirms server side is clean

Independent of the original reporter's relay, ours (buzz.infinitek.pe) is on current main (commit 005b5b8, newer than the 5bf78671f already ruled out here). We verified the agents' latest kind:30177 carries respond_to:"anyone" and is the current event, channel membership is active (role: bot, removed_at IS NULL) in a stream channel, and readiness is 200. No relay-side change moves the symptom — matching the original report.

Net: two independent relays, owner-and-non-owner both affected, iOS unaffected → the defect is confined to the Desktop client-side eligibility computation from #4913, and appears to drop relay-discovered agents before the policy branch is even consulted.

rmichelena avatar Aug 09 '26 16:08 rmichelena

We hit this too and traced a root cause that sits below the eligibility layer. PR up: #5483.

The eligibility patches can't fix this — the data never arrives

The Tauri command that builds the relay-agent directory, list_relay_agents (desktop/src-tauri/src/commands/agent_discovery.rs), queries only kind:10100. But an agent's respond_to policy is published as kind:30177 (KIND_MANAGED_AGENT, d-tag = agent pubkey) and its channel membership as kind:39002 (NIP-29 members list, one event per channel). agents_from_events (nostr_convert.rs) does parse respond_to / channel_ids when they're embedded in the 10100 content — but agents that publish policy and membership in the dedicated 30177 / 39002 events (as ours do) arrive with respond_to: null and channel_ids: [].

Result: relayAgentCanRespondInChannel returns false, shouldHideAgentFromMentions hides the agent even for a channel member — and even for the agent's owner. Owner-affected reproduces here, which rules out the authorization branch as the sole cause.

That explains why the symptom survives #4913 and the several open TS-side attempts (#3292, #5084, #4603, #4517, #2693, #4047, #4137; #4546 touches the Rust types but not the directory query): they all patch the eligibility computation, but the directory feeding it is missing the policy and membership data.

Fix (data layer) — #5483

  • Rust (core): list_relay_agents now enriches the 10100 directory by merging kind:30177 (policy, batched, scoped by owner-verified kind:0 so policy can't be spoofed) and kind:39002 (#p → channel_ids). Best-effort: a relay error during enrichment degrades to 10100-only rather than emptying autocomplete. Unit tests for the merge/dedup helpers included. Rationale for merging vs. requiring a fatter 10100: 39002 is the relay-authoritative NIP-29 membership (stronger than a self-reported channel_ids) and 30177 is the live policy event.
  • TS (optional hardening, separate commits): a channel-membership fallback for the 39002 propagation window, kept fail-closed (only admits respond_to: "anyone"; owner-only/allowlist still hidden, with a test). Happy to drop this if maintainers prefer a Rust-only change.

E2E result

Verified end-to-end on a self-hosted relay (main + this branch, locally built desktop client, stream channel):

  • Before: relay-discovered agents running on remote hosts never appeared after typing @ — while the same agents were mentionable from the iOS client against the same relay and the same channel, which is what pinned this to the desktop directory query rather than to relay state.
  • After: all relay agents appear in the @ list, and mention delivery works — the mentioned remote agents received the events and replied in-channel.

Also green: pnpm --dir desktop check (exit 0), typecheck (exit 0), test (4540 passed / 0 failed).

Feedback on the shape is welcome — in particular whether maintainers want Rust-only or Rust + the TS fallback.

rmichelena avatar Aug 10 '26 15:08 rmichelena