Build and run agents you can see, understand and trust.
Python agentchatbotlarge-language-modelsllmllm-agentmcpmulti-agentmulti-modalreact-agentrealtime-agentvoice-agentvoice-assistant
fix(channel): show a channel that is starting as connecting, not stopped (#2487)
DavdGao61cdeae4ffe6
diff --git a/src/agentscope/app/_service/_channel.py b/src/agentscope/app/_service/_channel.pyindex dd2c57c69..d6ef2ad80 100644--- a/src/agentscope/app/_service/_channel.py+++ b/src/agentscope/app/_service/_channel.py@@ -160,6 +160,9 @@ class ChannelService:reporting can leave its last entry behind indefinitely while asuccessor keeps the namespace alive.+ With no report at all, the enabled flag decides: an enabled+ channel is starting, a disabled one is stopped.+Args:channel_id (`str`): The channel to report on."""@@ -180,7 +183,17 @@ class ChannelService:return beat.statusif best is None or best.state == "stopped":best = beat.status- return best or ChannelStatus(state="stopped")+ if best is not None:+ return best++ # Nobody has reported yet. For an enabled channel that means it+ # has not been picked up *yet* — a freshly created one is on its+ # way — and calling that "stopped" sends the operator looking+ # for something to start that is already starting.+ record = await self._storage.get_channel(channel_id)+ if record is not None and record.enabled:+ return ChannelStatus(state="connecting")+ return ChannelStatus(state="stopped")async def list_seen_chat_ids(self, channel_id: str) -> list[str]:"""Chat_ids passively recorded from inbound messages.diff --git a/tests/channel_clients_test.py b/tests/channel_clients_test.pyindex cb9c43d34..d28f006aa 100644--- a/tests/channel_clients_test.py+++ b/tests/channel_clients_test.py@@ -278,9 +278,13 @@ class ChannelDeliveryTest(IsolatedAsyncioTestCase):class ChannelStatusTest(IsolatedAsyncioTestCase):"""Status is read from the heartbeat, not from local instances."""- def _service(self, bus: InMemoryMessageBus) -> ChannelService:+ def _service(+ self,+ bus: InMemoryMessageBus,+ enabled: bool = True,+ ) -> ChannelService:return ChannelService(- storage=_Storage(_record()),+ storage=_Storage(_record(enabled=enabled)),message_bus=bus,type_registry=ChannelTypeRegistry([_FakeChannel]),)@@ -303,11 +307,25 @@ class ChannelStatusTest(IsolatedAsyncioTestCase):ttl_secs=LIVENESS_TTL_SECS,)- async def test_no_heartbeat_reads_as_stopped(self) -> None:- """Nothing is holding the channel, so nothing reports it."""+ async def test_an_enabled_channel_with_no_report_is_connecting(+ self,+ ) -> None:+ """A channel just created has not been picked up yet. Calling+ that stopped sends the operator looking for something to start+ that is already starting."""bus = InMemoryMessageBus()self.assertEqual(await self._service(bus).get_status("chan-1"),+ ChannelStatus(state="connecting"),+ )++ async def test_a_disabled_channel_with_no_report_is_stopped(+ self,+ ) -> None:+ """Nothing is holding it, and nothing is meant to."""+ bus = InMemoryMessageBus()+ self.assertEqual(+ await self._service(bus, enabled=False).get_status("chan-1"),ChannelStatus(state="stopped"),)@@ -339,8 +357,11 @@ class ChannelStatusTest(IsolatedAsyncioTestCase):ChannelStatus(state="connecting"),)- async def test_only_stale_reports_read_as_stopped(self) -> None:- """Every holder went away; nothing fresh is left to believe."""+ async def test_only_stale_reports_fall_back_to_the_enabled_flag(+ self,+ ) -> None:+ """Every holder went away; nothing fresh is left to believe, so+ this reads like never having been reported at all."""bus = InMemoryMessageBus()await self._beat(bus,@@ -351,6 +372,10 @@ class ChannelStatusTest(IsolatedAsyncioTestCase):self.assertEqual(await self._service(bus).get_status("chan-1"),+ ChannelStatus(state="connecting"),+ )+ self.assertEqual(+ await self._service(bus, enabled=False).get_status("chan-1"),ChannelStatus(state="stopped"),)