Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,26 @@ test("shouldHideAgentFromMentions: shows member agents with unknown invocability
);
});

test("shouldHideAgentFromMentions: #4187 shows a channel-member agent managed by another Desktop instance", () => {
// Regression for #4187: a managed agent running on another Desktop instance
// appears here as a channel member (isAgent via role "bot") that is neither
// in this client's managed-agent list nor in the relay directory
// (mentionableAgentPubkeys/directoryAgentPubkeys both empty). It MUST remain
// visible in the mention picker. The mention path (useMentions) must rely on
// this policy alone and not additionally pre-filter with
// isAgentIdentityInManagedList, which would drop it.
assert.equal(
shouldHideAgentFromMentions({
isAgent: true,
isMember: true,
pubkey: PUB_A,
mentionableAgentPubkeys: new Set(),
directoryAgentPubkeys: new Set(),
}),
false,
);
});

test("shouldHideAgentFromMentions: normalizes the pubkey before lookup", () => {
const mixedCase = "Ab".repeat(32);
const normalized = mixedCase.toLowerCase();
Expand Down
15 changes: 10 additions & 5 deletions desktop/src/features/messages/lib/useMentions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
coalesceAutocompleteCandidatesByKey,
getMentionableAgentPubkeys,
getSharedChannelIds,
isAgentIdentityInManagedList,
shouldHideAgentFromMentions,
} from "@/features/agents/lib/agentAutocompleteEligibility";
import {
Expand Down Expand Up @@ -246,9 +245,16 @@ export function useMentions(
if (isArchivedDiscovery(pubkey)) {
return;
}
if (!isAgentIdentityInManagedList(candidate, managedAgentPubkeys)) {
return;
}
// Agent visibility in the mention picker is governed solely by
// `shouldHideAgentFromMentions` (the "Option B" member/directory policy
// below). We deliberately do NOT pre-filter with
// `isAgentIdentityInManagedList` here: that gate keeps only *locally*
// managed agents, which drops channel-member agents managed by another
// Desktop instance before the member/directory policy can show them —
// the root cause of #4187 (cross-desktop managed agents missing from the
// `@mention` autocomplete). `isAgentIdentityInManagedList` still belongs
// in the "add member" search (MembersSidebar), where you may only add
// agents you manage; it does not belong on the mention path.
if (
shouldHideAgentFromMentions({
isAgent: candidate.isAgent === true,
Expand Down Expand Up @@ -420,7 +426,6 @@ export function useMentions(
managedAgentNamesByPubkey,
managedAgentPersonaIds,
managedAgentPersonaIdsByPubkey,
managedAgentPubkeys,
managedAgentsQuery.data,
memberPubkeys,
members,
Expand Down