From 706a6052f18d70cc628f778f814b4b0845344ec1 Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Sun, 15 Nov 2026 15:17:02 -0800 Subject: [PATCH] fix(mobile): skip the Huddle record read when one person remains (#9547) --- .../features/channels/mobile_huddle_controller.dart | 6 ++++++ .../channels/huddle_agents_provider_test.dart | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/mobile/lib/features/channels/mobile_huddle_controller.dart b/mobile/lib/features/channels/mobile_huddle_controller.dart index 45b89fdae4..abf4f8d3b7 100644 --- a/mobile/lib/features/channels/mobile_huddle_controller.dart +++ b/mobile/lib/features/channels/mobile_huddle_controller.dart @@ -67,6 +67,12 @@ final huddleHumanCountProvider = Provider((ref) { } if (events.isEmpty) return 0; final members = membersFromEvent(events.first); + final nonBotCount = members.where((member) => member.role != 'bot').length; + // A managed-agent record can only lower this count. With at most one + // non-bot member the answer is final, so skip the record read: a slow or + // failed read must not keep a bot-only Huddle open after its last person + // leaves, as it did before records were consulted. + if (nonBotCount <= 1) return nonBotCount; // An agent without NIP-OA has role `member`. A failed record read throws, // so leave keeps the Huddle open rather than count an agent as a person. final recordAgents = await fetchTrustedManagedAgentPubkeys( diff --git a/mobile/test/features/channels/huddle_agents_provider_test.dart b/mobile/test/features/channels/huddle_agents_provider_test.dart index e8a0f0d7ce..8984e7e6c7 100644 --- a/mobile/test/features/channels/huddle_agents_provider_test.dart +++ b/mobile/test/features/channels/huddle_agents_provider_test.dart @@ -173,6 +173,19 @@ void main() { expect(await container.read(huddleHumanCountProvider)(_channelId), 3); }); + test('last-human count skips the record read for a lone person', () async { + final relay = _HuddleRelaySession( + members: {_owner.public: 'owner', _botAgent: 'bot'}, + recordError: Exception('relay timeout'), + ); + final container = _container(relay); + + // Records can only lower the count, so a failed read must not keep a + // bot-only Huddle open after its last person leaves. + expect(await container.read(huddleHumanCountProvider)(_channelId), 1); + expect(relay.recordFilters, isEmpty); + }); + test('last-human count fails when the records cannot be read', () async { final relay = _HuddleRelaySession( members: {_owner.public: 'owner', _ownerAgent: 'member'},