Skip to content

fix(desktop): offer shared relay agents in @ mention autocomplete (#3971) - #4058

Open
iroiro147 wants to merge 1 commit into
block:mainfrom
iroiro147:claude/issue3971-20260801
Open

fix(desktop): offer shared relay agents in @ mention autocomplete (#3971)#4058
iroiro147 wants to merge 1 commit into
block:mainfrom
iroiro147:claude/issue3971-20260801

Conversation

@iroiro147

Copy link
Copy Markdown

Summary

Fixes #3971 — the @ mention autocomplete never offered remotely-hosted agents, even when they were channel members, appeared in the members panel, and were registered in the relay agent directory with respond_to=anyone.

Root cause

In desktop/src/features/messages/lib/useMentions.ts, addCandidate 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 that share a channel with the user and advertise respond_to=anyone or an allowlist match) is precisely the machinery meant to make shared relay agents mentionable. The early local-only filter made that set 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 runs downstream and independently consults mentionableAgentPubkeys, so noise-gating is preserved: a remote agent that is not relay-shared with the user is still dropped.

Verification

  • pnpm typecheck — clean
  • pnpm exec biome check — clean (both touched files)
  • node --import ./test-loader.mjs --experimental-strip-types --test src/features/agents/lib/agentAutocompleteEligibility.test.mjs20/20 pass (18 baseline + 2 new pinning tests)
  • Mention suites (mentionCandidates.test.mjs, mentionRanking.test.mjs) — green

Tests added

agentAutocompleteEligibility.test.mjs, pinning the new admit condition:

  • a shared relay agent not in the local managed list is admitted;
  • a non-shared non-local agent is still rejected.

Impact

Multi-device / team setups where an agent runs on one machine and users chat from another now get real @Name autocomplete → p-tag delivery. Workarounds (thread replies to p-tag the parent author, agent-side content-matching rules) are no longer needed.

…ock#3971)

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#3971

Signed-off-by: iroiro147 <sarthak.singh@juspay.in>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mention autocomplete never offers remotely-hosted agents (shared relay agent eligibility is unreachable)

1 participant