Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(mobile): keep own agents mentionable until the list is known
While the owned-agent directory was loading, failed, or the session was
offline, mention completion treated it as an empty list, so the user's
own listed agents counted as unlisted. They disappeared from the picker,
and a restored draft that mentioned one was rejected.

The directory now stays loading while the session is not connected, and
mention completion takes it as unknown (null) until it loads. While it
is unknown, no owned agent is held back as unlisted.

Signed-off-by: Tom Brow <[email protected]>
  • Loading branch information
brow committed Oct 31, 2026
commit 02b56f671fe8d7240187dea66b11a4536ada9175
6 changes: 4 additions & 2 deletions mobile/lib/features/agents/agents_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ class AgentsPage extends HookConsumerWidget {
}, [flow.stage]);
final community = ref.watch(activeCommunityProvider).asData?.value;
final ownedDirectory = ref.watch(ownedAgentDirectoryProvider);
// Remote agents stay listed while a deletion that already removed their
// registration is retried; every other agent comes from its registration.
// The account's remote agents with a verified owner profile here are
// listed too, so one stays listed while a deletion that already removed
// its registration is retried. Every other agent comes from its listed
// registration.
final candidates = {
if (controller.owner == community?.pubkey)
for (final agent in controller.agents) agent['agent_pubkey'] as String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ class ComposeBar extends HookConsumerWidget {
userCache: userCache,
ownerByAgentPubkey: agentOwners ?? const {},
currentPubkey: currentPubkey,
ownedAgents: ownedAgents ?? const [],
ownedAgents: ownedAgents,
offerOwnedAgents:
composeChannel != null &&
(composeChannel.isStream || composeChannel.isForum),
Expand Down
20 changes: 12 additions & 8 deletions mobile/lib/features/channels/mentions/mention_candidates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ String? formatOwnerLabel(
/// non-member relay agents, then global user-search results.
///
/// [ownedAgents] are the viewer's agents as desktop's Agents tab lists them
/// (`ownedAgentDirectoryProvider`). Outside the channel, an agent the viewer
/// owns is offered only when it is one of these: one only an earlier Buzz
/// runs cannot answer until desktop imports it, which mobile cannot do.
/// [offerOwnedAgents] offers them unprompted, as desktop does in streams and
/// forums.
/// (`ownedAgentDirectoryProvider`), or null while that list is unknown.
/// Outside the channel, an agent the viewer owns is offered only when it is
/// listed. An unlisted one is an agent of an earlier Buzz, which cannot
/// answer until desktop imports it, and mobile cannot import. While the list
/// is unknown, owned agents are not held back. [offerOwnedAgents] offers the
/// listed agents unprompted, as desktop does in streams and forums.
List<MentionCandidate> buildMentionCandidates({
required List<ChannelMember> members,
required List<AgentDirectoryEntry> relayAgents,
Expand All @@ -58,14 +59,17 @@ List<MentionCandidate> buildMentionCandidates({
required Map<String, String> ownerByAgentPubkey,
List<UserProfile> searchResults = const [],
String? currentPubkey,
List<OwnedAgentDirectoryEntry> ownedAgents = const [],
List<OwnedAgentDirectoryEntry>? ownedAgents,
bool offerOwnedAgents = false,
}) {
final candidates = <MentionCandidate>[];
final seen = <String>{};
final currentLower = currentPubkey?.toLowerCase();
final listedOwned = {for (final agent in ownedAgents) agent.pubkey};
final listedOwned = ownedAgents == null
? null
: {for (final agent in ownedAgents) agent.pubkey};
bool unlistedOwnAgent(String pubkey, String? ownerPubkey) =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker: an unknown owned directory is treated as "no listed agents".

Every caller passes ownedAgentDirectoryProvider.asData?.value ?? const [] (compose_bar_widget.dart, mention_candidates_provider.dart). ownedAgentDirectoryProvider also returns [] as data whenever the session isn't connected. So during first load, AsyncError, disconnects and reconnects, listedOwned is empty, and this predicate drops every own non-member agent from the directory and search passes. Before this PR those agents were admitted from search.

Impact:

  • Restored drafts: on cold start, or on the reconnect that follows almost every foreground (fix(mobile): keep loaded timeline visible while reconnecting #8864), sending a restored draft that mentions your own listed non-member agent fails with "Saved mention is no longer available. Select it again from the picker." The picker hides the same agent, so the user can't recover until the directory loads.
  • On a directory query error, own agents can't be mentioned outside the channel until something invalidates the provider, and nothing tells the user. Desktop shows "Could not load agents" with a retry.

Fix: pass ownedAgents as nullable and skip the unlisted filter when it is unknown (or block with a loading/retry message). Make the provider stay loading, or throw, when disconnected instead of returning [] as data.

Test gap: the compose-bar tests never override ownedAgentDirectoryProvider, so the new unlisted-own-agent row passes because the directory is empty, not because the agent is unlisted. Add a table row where a listed own agent is admitted, alongside the unlisted one.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Fixed in 02b56f6. I also corrected the buildMentionCandidates doc sentence and the agents_page.dart comment, and the PR body now says that every remote agent with a verified owner profile here stays listed.

  • buildMentionCandidates now takes ownedAgents as nullable. Null means the list is unknown, and then no owned agent is held back as unlisted (and none are offered unprompted). Both callers pass ownedAgentDirectoryProvider.asData?.value, which is null while loading and after an error (a reload keeps the previous list).
  • ownedAgentDirectoryProvider stays loading while the session isn't connected instead of returning [] as data, and loads once the session connects.
  • Tests: the compose-bar restore table now binds the owned directory through ownedAgentDirectoryProvider, with a listed own non-member agent that's admitted (it gets the usual "not in this channel" prompt), an unlisted one that's rejected against a known list, and one that's admitted while the list is still unknown. Also added a candidates case for an unknown list and a provider test that stays loading until connected. Each new guard test fails with the fix reverted.

listedOwned != null &&
currentLower != null &&
ownerPubkey?.toLowerCase() == currentLower &&
!listedOwned.contains(pubkey);
Expand Down Expand Up @@ -93,7 +97,7 @@ List<MentionCandidate> buildMentionCandidates({
}

if (offerOwnedAgents) {
for (final agent in ownedAgents) {
for (final agent in ownedAgents ?? const <OwnedAgentDirectoryEntry>[]) {
final pk = agent.pubkey;
if (!seen.add(pk)) continue;
final profile = userCache[pk];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,8 @@ final mentionCandidatesProvider = Provider.family
ref.watch(agentDirectoryProvider).asData?.value ??
const <AgentDirectoryEntry>[];
final owners = ref.watch(agentOwnersProvider).asData?.value ?? const {};
final ownedAgents =
ref.watch(ownedAgentDirectoryProvider).asData?.value ??
const <OwnedAgentDirectoryEntry>[];
// Null while loading or failed: nothing is known to be unlisted.
final ownedAgents = ref.watch(ownedAgentDirectoryProvider).asData?.value;
final channels = channelsAsync.asData?.value ?? const <Channel>[];
final userCache = ref.watch(userCacheProvider);
final currentPubkey = ref.watch(currentPubkeyProvider);
Expand Down
9 changes: 7 additions & 2 deletions mobile/lib/shared/agents/owned_agent_directory.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:convert';
import 'package:nostr/nostr.dart' as nostr;
import 'package:hooks_riverpod/hooks_riverpod.dart';
Expand Down Expand Up @@ -27,8 +28,12 @@ final ownedAgentDirectoryProvider =
ref.watch(relayConfigProvider);
final owner = ref.watch(myPubkeyProvider);
final session = ref.watch(relaySessionProvider);
if (owner == null || session.status != SessionStatus.connected) {
return const [];
if (owner == null) return const [];
// Stay loading until connected: an empty list would read as "no
// listed agents" and hide the owner's agents from mentions. The
// provider rebuilds when the session status changes.
if (session.status != SessionStatus.connected) {
return Completer<List<OwnedAgentDirectoryEntry>>().future;
}
final relay = ref.read(relaySessionProvider.notifier);
return loadOwnedAgentDirectory(
Expand Down
9 changes: 9 additions & 0 deletions mobile/test/features/channels/compose_bar_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import 'package:buzz/features/channels/voice_note_recording.dart';
import 'package:buzz/features/channels/voice_note_waveform.dart';
import 'package:buzz/shared/custom_emoji/custom_emoji.dart';
import 'package:buzz/shared/custom_emoji/custom_emoji_provider.dart';
import 'package:buzz/shared/agents/owned_agent_directory.dart';
import 'package:buzz/shared/mentions/agent_identity_provider.dart';
import 'package:buzz/shared/relay/relay.dart';
import 'package:buzz/shared/profile/user_cache_provider.dart';
Expand Down Expand Up @@ -207,9 +208,17 @@ Widget _buildComposeBar({
VoiceNoteRecorder Function()? voiceNoteRecorderFactory,
VoiceNotePlayerController Function()? voiceNotePlayerFactory,
Future<List<UserProfile>> Function(String query)? searchPeople,
List<OwnedAgentDirectoryEntry>? ownedAgents,
bool ownedAgentsUnknown = false,
}) {
return ProviderScope(
overrides: [
if (ownedAgents != null)
ownedAgentDirectoryProvider.overrideWith((ref) async => ownedAgents),
if (ownedAgentsUnknown)
ownedAgentDirectoryProvider.overrideWith(
(ref) => Completer<List<OwnedAgentDirectoryEntry>>().future,
),
// Directory people by exact query, found after the real typing pause.
if (searchPeople != null)
mentionUserSearchProvider.overrideWith((ref, query) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void exactMentionTests() {
List<ChannelMember> roster,
ComposeBarOnSend onSend, {
nostr.Keys? signer,
List<OwnedAgentDirectoryEntry>? ownedAgents,
bool ownedAgentsUnknown = false,
}) async {
await tester.pumpWidget(
_buildComposeBar(
Expand All @@ -35,6 +37,8 @@ void exactMentionTests() {
),
),
onSend: onSend,
ownedAgents: ownedAgents,
ownedAgentsUnknown: ownedAgentsUnknown,
),
);
if (find.byType(TextField).evaluate().isEmpty &&
Expand Down Expand Up @@ -79,6 +83,8 @@ void exactMentionTests() {
'non-member human',
'non-member denied agent',
'non-member unlisted own agent',
'non-member listed own agent',
'non-member own agent, list unknown',
]) {
testWidgets('persisted selection restore to signed send: $scenario', (
tester,
Expand All @@ -97,6 +103,16 @@ void exactMentionTests() {
mediaTags: mediaTags,
),
signer: signer,
// The Agents page lists the owned agent only in its own scenario.
ownedAgents: switch (scenario) {
'non-member unlisted own agent' => const [],
'non-member listed own agent' => [
OwnedAgentDirectoryEntry(pubkey: first),
],
_ => null,
},
// Still loading (or offline): nothing is known to be unlisted.
ownedAgentsUnknown: scenario == 'non-member own agent, list unknown',
);
final container = ProviderScope.containerOf(
tester.element(find.byType(ComposeBar)),
Expand Down Expand Up @@ -148,6 +164,8 @@ void exactMentionTests() {
'non-member human',
'non-member denied agent',
'non-member unlisted own agent',
'non-member listed own agent',
'non-member own agent, list unknown',
].contains(scenario))
ChannelMember(
pubkey: first,
Expand All @@ -164,11 +182,13 @@ void exactMentionTests() {
UserProfile(
pubkey: first,
displayName: 'Renamed',
// An agent only an earlier Buzz runs is the viewer's own,
// but the Agents page does not list it.
// The viewer's own agent. An earlier Buzz's agent is not on
// the Agents page; a listed one is.
ownerPubkey: switch (scenario) {
'non-member denied agent' => second,
'non-member unlisted own agent' => signer.public,
'non-member unlisted own agent' ||
'non-member listed own agent' ||
'non-member own agent, list unknown' => signer.public,
_ => null,
},
),
Expand Down Expand Up @@ -201,9 +221,15 @@ void exactMentionTests() {
}
}
}
// Admitted people and agents outside the channel are asked about.
final outsider = [
'non-member human',
'non-member listed own agent',
'non-member own agent, list unknown',
].contains(scenario);
await tester.tap(find.byIcon(BuzzIcons.arrowUp));
await tester.pumpAndSettle();
if (scenario == 'non-member human') {
if (outsider) {
expect(
find.textContaining('Renamed is not in this channel'),
findsOneWidget,
Expand All @@ -218,20 +244,22 @@ void exactMentionTests() {
'rename',
'legacy',
'non-member human',
'non-member listed own agent',
'non-member own agent, list unknown',
'map reset',
'map plain',
'map reselected',
].contains(scenario)) {
final event = messages.single;
expect(event['content'], expectedText.trim());
expect((event['tags'] as List).where((t) => t[0] == 'p').toList(), [
if (scenario != 'non-member human' && scenario != 'map plain')
if (!outsider && scenario != 'map plain')
[
'p',
['legacy', 'map reselected'].contains(scenario) ? second : first,
],
]);
if (scenario == 'non-member human') {
if (outsider) {
expect(
(event['tags'] as List).where((t) => t[0] == 'mention').toList(),
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,31 @@ void main() {
displayName: name,
ownerPubkey: userPubkey,
);
List<MentionCandidate> build({required bool offer}) =>
buildMentionCandidates(
members: [member(unlistedMember)],
relayAgents: [
AgentDirectoryEntry(
pubkey: unlisted,
respondTo: 'anyone',
channelIds: const ['chan-1'],
),
],
sharedChannelIds: const {'chan-1'},
userCache: {
unlisted: own(unlisted, 'old-app'),
unlistedMember: own(unlistedMember, 'old-member'),
},
ownerByAgentPubkey: const {},
searchResults: [own(listed, 'raccoon'), own(unlisted, 'old-app')],
currentPubkey: userPubkey,
ownedAgents: [
OwnedAgentDirectoryEntry(pubkey: listed, displayName: 'raccoon'),
],
offerOwnedAgents: offer,
);
List<MentionCandidate> build({
required bool offer,
bool known = true,
}) => buildMentionCandidates(
members: [member(unlistedMember)],
relayAgents: [
AgentDirectoryEntry(
pubkey: unlisted,
respondTo: 'anyone',
channelIds: const ['chan-1'],
),
],
sharedChannelIds: const {'chan-1'},
userCache: {
unlisted: own(unlisted, 'old-app'),
unlistedMember: own(unlistedMember, 'old-member'),
},
ownerByAgentPubkey: const {},
searchResults: [own(listed, 'raccoon'), own(unlisted, 'old-app')],
currentPubkey: userPubkey,
ownedAgents: known
? [OwnedAgentDirectoryEntry(pubkey: listed, displayName: 'raccoon')]
: null,
offerOwnedAgents: offer,
);

// Members always stay; an earlier Buzz's agent outside the channel is
// offered neither from the directory nor from search.
Expand All @@ -210,6 +212,13 @@ void main() {
expect(candidates.last.isMember, isFalse);
expect(candidates.last.ownerPubkey, userPubkey);
}
// While the list is unknown (loading, failed or offline), no owned
// agent is held back as unlisted.
expect(build(offer: true, known: false).map((c) => c.pubkey), [
unlistedMember,
unlisted,
listed,
]);
// Streams and forums offer listed agents before anyone searches.
final offered = buildMentionCandidates(
members: const [],
Expand Down
61 changes: 61 additions & 0 deletions mobile/test/shared/agents/owned_agent_directory_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:buzz/shared/agents/owned_agent_directory.dart';
import 'package:buzz/shared/relay/relay.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:nostr/nostr.dart' as nostr;
import '../../helpers/remote_agents_fixture.dart';

Expand All @@ -22,7 +23,67 @@ NostrEvent registration(
).toMap(),
);

class _Session extends RelaySessionNotifier {
_Session(this.registrations, this.profiles);
final List<NostrEvent> registrations;
final List<NostrEvent> profiles;

@override
SessionState build() =>
const SessionState(status: SessionStatus.disconnected);

void connect() => state = const SessionState(status: SessionStatus.connected);

@override
Future<List<NostrEvent>> queryRelay(
List<NostrFilter> filters, {
Duration timeout = const Duration(seconds: 8),
}) async {
final filter = filters.single;
if (filter.kinds.contains(30177)) {
return filter.extensions['page'] == 1 ? registrations : const [];
}
return profiles
.where((profile) => filter.authors!.contains(profile.pubkey))
.toList();
}
}

class _RelayConfig extends RelayConfigNotifier {
@override
RelayConfig build() =>
const RelayConfig(baseUrl: 'https://relay.example', nsec: null);
}

void main() {
test('stays unknown, not empty, until the session connects', () async {
final session = _Session(
[registration(fakeAgent)],
[signedAgentProfile(fakeAgentKeys, fakeOwner)],
);
final container = ProviderContainer(
overrides: [
relayConfigProvider.overrideWith(_RelayConfig.new),
myPubkeyProvider.overrideWithValue(fakeOwner.public),
relaySessionProvider.overrideWith(() => session),
],
);
addTearDown(container.dispose);
final subscription = container.listen(
ownedAgentDirectoryProvider,
(_, _) {},
);
addTearDown(subscription.close);

await Future<void>.delayed(Duration.zero);
expect(container.read(ownedAgentDirectoryProvider).isLoading, isTrue);
expect(container.read(ownedAgentDirectoryProvider).asData, isNull);

session.connect();
final found = await container.read(ownedAgentDirectoryProvider.future);
expect(found.map((entry) => entry.pubkey), [fakeAgent]);
});

test('lists owned agents as desktop does, without runtime directory '
'entries or account sign-in', () async {
final desktop = nostr.Keys('0' * 63 + '3');
Expand Down