Skip to content

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

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

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
Contributor

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>
@iroiro147
iroiro147 requested a review from a team as a code owner August 1, 2026 04:44
wesbillman added a commit that referenced this pull request Aug 5, 2026
## Summary

- admit relay-discovered agents to autocomplete when their response
policy authorizes the viewer
- require authorization in the exact active stream/forum channel for
mentions, while keeping community-wide discovery for member invitation
- fail closed for relay-only agents in DMs and unresolved composer
contexts
- re-authorize cached autocomplete rows after policy/channel changes so
stale agent suggestions cannot leak back in
- preserve managed-agent behavior and explicitly reject stale
agent-marked channel members absent from both live directories

## Validation

- `pnpm --dir desktop test` — 4,288 passed
- `pnpm --dir desktop typecheck`
- `pnpm --dir desktop check`
- `pnpm --dir desktop build:e2e`
- focused Playwright mention matrix — 12 passed
- focused Playwright member-invitation matrix — 2 passed
- pre-push hooks after rebase to current `origin/main` — desktop check
and 4,288 tests passed
- independent correctness/privacy re-review cleared with no remaining
blocker

## Related competing PRs

This supersedes or overlaps #2333, #3056, #4242, #4137, #2314, #4058,
and #2605. This version adds exact-channel authorization, fail-closed
DM/context handling, cached-row reauthorization, forum coverage,
outbound mention-tag coverage, explicit stale-member coverage, and
add-member discovery coverage.

Signed-off-by: Wes <wesbillman@users.noreply.github.com>
Co-authored-by: Carl <c7ebe626f000404285d3686e1dc74cc07cc60a9754a150041ba132e14bd3e2ec@buzz.block.builderlab.xyz>
@iroiro147

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #4913, which landed this with broader scope.

For anyone tracing it later: the root cause identified here — addCandidate filtering isAgent candidates against the local managed-agent list before shouldHideAgentFromMentions could run, leaving the shared relay-agent eligibility path unreachable — is resolved on main. That gate is now isAgentIdentityInAllowedList(candidate, mentionableAgentPubkeys), and getMentionableAgentPubkeys admits relay agents in channel scope via relayAgentCanRespondInChannel.

Thanks @wesbillman. One note: #3971 still appears open and looks resolved by #4913.

@iroiro147 iroiro147 closed this Aug 6, 2026
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