From 5ab53db0dfca4ffc8b4e1bd0399066b5fdf81082 Mon Sep 17 00:00:00 2001 From: iroiro147 Date: Sat, 1 Aug 2026 10:14:16 +0530 Subject: [PATCH] fix(desktop): offer shared relay agents in @ mention autocomplete (#3971) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a multi-device or team setup, an agent hosted on machine A (buzz-acp, NIP-OA attested, channel member, in the relay directory with respond_to=anyone) never appeared in the @ autocomplete on machine B even though the members panel showed it. The composer had no way to send it a p-tag mention. Root cause: addCandidate in useMentions.ts dropped any isAgent candidate not in the LOCAL managed-agent list: if (!isAgentIdentityInManagedList(candidate, managedAgentPubkeys)) return; This ran BEFORE shouldHideAgentFromMentions, whose mentionableAgentPubkeys set (built from relayAgentIsSharedWithUser — directory agents sharing a channel with respond_to=anyone/allowlist) is exactly what is meant to make shared relay agents mentionable. The early local-only filter made that machinery unreachable dead code for any agent hosted on another machine. Fix: admit the candidate when it is either locally managed OR in the relay-mentionable set: if (!isAgentIdentityInManagedList(candidate, managedAgentPubkeys) && !mentionableAgentPubkeys.has(pubkey)) return; shouldHideAgentFromMentions still applies downstream (it independently consults mentionableAgentPubkeys), so noise-gating is preserved: remote agents NOT relay-shared with the user are still dropped. Pinned: 2 tests in agentAutocompleteEligibility.test.mjs — a shared relay agent not in the local managed list is admitted, and a non-shared non-local agent is still rejected. Verified: pnpm typecheck clean, biome clean, 20/20 eligibility tests + mention suite pass. Fixes block/buzz#3971 Signed-off-by: iroiro147 --- .../lib/agentAutocompleteEligibility.test.mjs | 36 +++++++++++++++++++ .../src/features/messages/lib/useMentions.ts | 5 ++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/desktop/src/features/agents/lib/agentAutocompleteEligibility.test.mjs b/desktop/src/features/agents/lib/agentAutocompleteEligibility.test.mjs index 4e02b7bd68..4d3651f0d4 100644 --- a/desktop/src/features/agents/lib/agentAutocompleteEligibility.test.mjs +++ b/desktop/src/features/agents/lib/agentAutocompleteEligibility.test.mjs @@ -306,3 +306,39 @@ test("coalesceAgentAutocompleteCandidates: leaves non-agents alone", () => { assert.deepEqual(coalesce([first, second]), [first, second]); }); + + +test("shared relay agent not in local managed list is admitted (#3971)", () => { + // #3971: an agent hosted on another machine is a channel member and appears + // in the relay directory with respond_to=anyone, but is NOT in the local + // managed-agent list. The old addCandidate gate dropped it before + // shouldHideAgentFromMentions could consult mentionableAgentPubkeys, making + // remote shared agents unreachable. The fixed admit condition is: + // admit iff isAgentIdentityInManagedList(...) || mentionableAgentPubkeys.has(pubkey) + const managedAgentPubkeys = new Set(); // agent is remote-only, not local + const mentionableAgentPubkeys = new Set([PUB_B]); // relay-shared + const pubkey = PUB_B; + + const admitCondition = + isAgentIdentityInManagedList( + { isAgent: true, pubkey }, + managedAgentPubkeys, + ) || mentionableAgentPubkeys.has(pubkey); + + assert.equal(admitCondition, true); +}); + +test("non-shared non-local agent is still rejected (#3971)", () => { + // A remote agent NOT in the relay mentionable set must still be dropped. + const managedAgentPubkeys = new Set(); + const mentionableAgentPubkeys = new Set(); + const pubkey = PUB_C; + + const admitCondition = + isAgentIdentityInManagedList( + { isAgent: true, pubkey }, + managedAgentPubkeys, + ) || mentionableAgentPubkeys.has(pubkey); + + assert.equal(admitCondition, false); +}); diff --git a/desktop/src/features/messages/lib/useMentions.ts b/desktop/src/features/messages/lib/useMentions.ts index 0c73b75339..b46e745561 100644 --- a/desktop/src/features/messages/lib/useMentions.ts +++ b/desktop/src/features/messages/lib/useMentions.ts @@ -246,7 +246,10 @@ export function useMentions( if (isArchivedDiscovery(pubkey)) { return; } - if (!isAgentIdentityInManagedList(candidate, managedAgentPubkeys)) { + if ( + !isAgentIdentityInManagedList(candidate, managedAgentPubkeys) && + !mentionableAgentPubkeys.has(pubkey) + ) { return; } if (