diff --git a/mobile/lib/features/channels/agent_activity/working_bots_provider.dart b/mobile/lib/features/channels/agent_activity/working_bots_provider.dart index fc34f9677..cebceddca 100644 --- a/mobile/lib/features/channels/agent_activity/working_bots_provider.dart +++ b/mobile/lib/features/channels/agent_activity/working_bots_provider.dart @@ -123,7 +123,7 @@ final composerActivityStateProvider = Provider.autoDispose humans.add(entry); continue; } - if (signals.containsKey(pubkey)) continue; + if (signals[pubkey]?.isWorking == true) continue; final turn = activeByAgent[pubkey]; final liveTurn = turn?.isWorking == true ? turn : null; signals[pubkey] = WorkingAgentSignal( diff --git a/mobile/test/features/channels/agent_activity/working_bots_provider_test.dart b/mobile/test/features/channels/agent_activity/working_bots_provider_test.dart index af5c1fc38..23d85d0f7 100644 --- a/mobile/test/features/channels/agent_activity/working_bots_provider_test.dart +++ b/mobile/test/features/channels/agent_activity/working_bots_provider_test.dart @@ -114,55 +114,68 @@ void main() { }, ); - test('thread typing does not inherit a retained terminal turn', () { - final failedTurn = _turn('agent-a', phase: AgentTurnPhase.error); - final container = ProviderContainer( - overrides: [ - currentPubkeyProvider.overrideWith((ref) => 'owner'), - channelMembersProvider( - _channelId, - ).overrideWith((ref) async => const []), - channelTypingProvider(_channelId).overrideWith( - () => _FakeTypingNotifier(const [ - TypingEntry( - pubkey: 'agent-a', - threadHeadId: 'thread-1', - expiresAtMs: 9999999999999, + for (final retainedThreadHeadId in [null, 'thread-1']) { + test( + 'thread typing replaces a retained terminal turn ' + '${retainedThreadHeadId == null ? 'from another scope' : 'in the same scope'}', + () { + final failedTurn = _turn( + 'agent-a', + phase: AgentTurnPhase.error, + threadHeadId: retainedThreadHeadId, + ); + final container = ProviderContainer( + overrides: [ + currentPubkeyProvider.overrideWith((ref) => 'owner'), + channelMembersProvider( + _channelId, + ).overrideWith((ref) async => const []), + channelTypingProvider(_channelId).overrideWith( + () => _FakeTypingNotifier(const [ + TypingEntry( + pubkey: 'agent-a', + threadHeadId: 'thread-1', + expiresAtMs: 9999999999999, + ), + ]), ), - ]), - ), - agentMentionPubkeysProvider( - _channelId, - ).overrideWith((ref) => const {'agent-a'}), - agentOwnersProvider.overrideWithValue( - const AsyncData({'agent-a': 'owner'}), - ), - userCacheProvider.overrideWith(_FakeUserCacheNotifier.new), - observerRelayProvider.overrideWith( - () => _FakeObserverRelayNotifier({ - 'agent-a': [_observerFrame('agent-a')], - }), - ), - composerAgentTurnStatesProvider.overrideWithValue([failedTurn]), - ], + agentMentionPubkeysProvider( + _channelId, + ).overrideWith((ref) => const {'agent-a'}), + agentOwnersProvider.overrideWithValue( + const AsyncData({'agent-a': 'owner'}), + ), + userCacheProvider.overrideWith(_FakeUserCacheNotifier.new), + observerRelayProvider.overrideWith( + () => _FakeObserverRelayNotifier({ + 'agent-a': [_observerFrame('agent-a')], + }), + ), + composerAgentTurnStatesProvider.overrideWithValue([failedTurn]), + ], + ); + addTearDown(container.dispose); + + final signal = container + .read( + composerActivityStateProvider(( + channelId: _channelId, + threadHeadId: 'thread-1', + )), + ) + .agents + .single; + + expect(signal.source, AgentWorkingSource.typing); + expect(signal.isWorking, isTrue); + expect(signal.turnId, isNull); + expect(signal.startedAt, isNull); + expect(container.read(workingBotPubkeysProvider(_channelId)), { + 'agent-a', + }); + }, ); - addTearDown(container.dispose); - - final signal = container - .read( - composerActivityStateProvider(( - channelId: _channelId, - threadHeadId: 'thread-1', - )), - ) - .agents - .single; - - expect(signal.source, AgentWorkingSource.typing); - expect(signal.isWorking, isTrue); - expect(signal.turnId, isNull); - expect(signal.startedAt, isNull); - }); + } test( 'keeps a scoped terminal outcome reachable after thread typing stops',