The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): unserving one bot keeps the rest of its group talking
Tekniumf70d055aa769
diff --git a/gateway/session_hosted_service.py b/gateway/session_hosted_service.pyindex e0bd13e23a2..aee215434ad 100644--- a/gateway/session_hosted_service.py+++ b/gateway/session_hosted_service.py@@ -30,6 +30,15 @@ class CanonicalHostedRoomService(HostedControls, HostedRoomService):def local_profiles(self):return tuple(self.profile_homes())+ def room_profiles(self, room):+ """A saved room keeps every local member it seated: unserving one bot must not stop the+ others. That member's own turns still fail (``_resolve_member_transport`` and ``attest``+ need a live home), and a new group cannot seat it (``local_profiles``)."""+ seated = {m.get('profile') for m in room.get('members') or ()+ if isinstance(m, dict) and isinstance(m.get('profile'), str)+ and (m.get('target') or {}).get('kind', 'local') == 'local'}+ return tuple(sorted(set(self.local_profiles()) | seated))+def attest(self, selector, operation, params):from dataclasses import asdictfrom gateway.hosted_room_driver import list_tasksdiff --git a/tests/gateway/test_hosted_group_members.py b/tests/gateway/test_hosted_group_members.pyindex 2c78060f7f4..7e154dcd5ae 100644--- a/tests/gateway/test_hosted_group_members.py+++ b/tests/gateway/test_hosted_group_members.py@@ -143,6 +143,49 @@ def test_desktop_group_of_served_bots_is_created_and_runs(tmp_path, monkeypatch)e['payload'] for e in hosted_rooms.read_events(db_path, room_id='crew')['events']]+def test_unserving_one_bot_keeps_the_rest_of_its_group_talking(tmp_path, monkeypatch):+ """Greptile on #140187: unserving alpha must not stop a saved default/alpha/beta group; a turn+ for beta still runs, a turn for alpha fails as that member's own turn, and no new group seats it."""+ from gateway import hosted_rooms, session_finite+ from gateway.run_runtime import unserve_profile_runtime++ ran = []++ async def execute(authority, ref, row):+ ran.append(authority.profile_id)+ return 'member reply'+ monkeypatch.setattr(session_finite, 'execute_finite_admission', execute)+ with _gateway(tmp_path, monkeypatch, served=('alpha', 'beta')) as (runner, homes, call):+ desktop = _desktop(runner, call)+ assert 'result' in desktop('default', 'groups.create', room_id='crew', name='Crew',+ members=_members('default', 'alpha', 'beta'))+ assert call(unserve_profile_runtime(runner, homes['alpha']))+ assert runner.session_authorities.for_home(homes['alpha']) is None+ db_path = runner.session_authority.db.db_path++ def settled(count):+ return sum(e['kind'] == 'room.activity' and e['payload'].get('status') == 'settled'+ for e in hosted_rooms.read_events(db_path, room_id='crew')['events']) >= count+ sent = desktop('default', 'groups.send', room_id='crew', event_id='hello',+ payload={'text': '@beta hello', 'thread_id': 'thread'})+ assert 'result' in sent, sent+ wait_until(lambda: settled(1), what='the room settled after beta answered')+ assert ran == [str(homes['beta'])], [+ e['payload'] for e in hosted_rooms.read_events(db_path, room_id='crew')['events']]+ # A turn for alpha fails as alpha's own turn, without wedging the room for beta.+ assert 'result' in desktop('default', 'groups.send', room_id='crew', event_id='to-alpha',+ payload={'text': '@alpha hello', 'thread_id': 'thread'})+ wait_until(lambda: settled(2), what="the room settled after alpha's turn failed")+ assert 'result' in desktop('default', 'groups.send', room_id='crew', event_id='again',+ payload={'text': '@beta again', 'thread_id': 'thread'})+ wait_until(lambda: settled(3), what='the room settled after beta answered again')+ assert ran == [str(homes['beta'])] * 2, ran+ # A new group cannot seat the unserved bot.+ refused = desktop('default', 'groups.create', room_id='again', name='Crew',+ members=_members('default', 'alpha'))+ assert "profile 'alpha' is not local to this gateway" in refused['error']['data']['detail'], refused++def test_a_bot_this_gateway_does_not_serve_is_refused_by_name(tmp_path, monkeypatch, caplog):caplog.set_level(logging.WARNING, logger='gateway.session_controls')# gamma is a real profile on disk, but this gateway does not serve it; ghost does not exist.diff --git a/tui_gateway/hosted_room_driver.py b/tui_gateway/hosted_room_driver.pyindex eb2b9176cc6..202b3ca9e89 100644--- a/tui_gateway/hosted_room_driver.py+++ b/tui_gateway/hosted_room_driver.py@@ -589,10 +589,12 @@ class HostedRoomRuntime:) -> None:profile, submit_attempted = task["payload"]["target_profile"], Falseattachments = task["payload"].get("attachments")- transport = self._transport_for(binding, task)with self._status_lock:self._current_tasks[binding.room_id] = attempt.identitytry:+ # Inside the try: a member whose destination is gone (an unserved bot) fails its own+ # turn before submit instead of leaving the task running and the room wedged.+ transport = self._transport_for(binding, task)if attachments and not getattr(transport, "accepts_attachments", False):# A route that cannot carry the files would answer without them, and a# retry cannot change the route: settle a proven failure before submit.diff --git a/tui_gateway/hosted_room_service.py b/tui_gateway/hosted_room_service.pyindex 442738cb9cb..e8ae53d6c77 100644--- a/tui_gateway/hosted_room_service.py+++ b/tui_gateway/hosted_room_service.py@@ -140,6 +140,11 @@ class HostedRoomService:and named_profile_has_identity(path) and not named_profile_is_deleted(path))return tuple(sorted(profiles))+ def room_profiles(self, room: Mapping[str, Any]) -> tuple[str, ...]:+ """Profiles a SAVED room's roster is checked against. New groups use ``local_profiles``;+ a subclass may keep a seated member valid after it stops being eligible for new groups."""+ return self.local_profiles()+def bindings(self) -> tuple[HostedRoomBinding, ...]:local_gateway_id = hosted_rooms.local_authority_gateway_id()return tuple(@@ -374,7 +379,7 @@ class HostedRoomService:room_id=str(room["room_id"]), latest_seq=int(room["latest_seq"]))def _publish_terminal_tasks(self, room: Mapping[str, Any]) -> bool:- changed, room_id, local_profiles = False, str(room["room_id"]), self.local_profiles()+ changed, room_id, local_profiles = False, str(room["room_id"]), self.room_profiles(room)cursor = int(room["latest_seq"])for task in self._list_tasks(room_id, _TERMINAL_STATUSES):status, execution_generation = task["status"], int(task["execution_generation"])@@ -436,7 +441,7 @@ class HostedRoomService:if next(iter(self._list_tasks(binding.room_id, _LIVE_STATUSES)), None) is not None:returndecision = discussion.plan_next_task(- room, list(snapshot.events), local_profiles=self.local_profiles(),+ room, list(snapshot.events), local_profiles=self.room_profiles(room),initial_watermarks=snapshot.watermarks, freeze_input_context=True)if decision.status == "task" and decision.task is not None:existing = driver.get_task_for_turn(self.db_path, decision.task.identity)@@ -448,11 +453,11 @@ class HostedRoomService:prior_events = self.policy_checkpoint.events_for_task(room_id=binding.room_id, source_event_seq=existing["payload"]["source_event_seq"],input_context=existing["payload"]["input_context"], task_id=existing["identity"].task_id)- discussion.reconstruct_task_plan(room, prior_events, existing, local_profiles=self.local_profiles())+ discussion.reconstruct_task_plan(room, prior_events, existing, local_profiles=self.room_profiles(room))admitted = existingelif existing is not None and existing["payload"] == legacy_payload:discussion.reconstruct_task_plan(room, list(snapshot.events), existing,- local_profiles=self.local_profiles())+ local_profiles=self.room_profiles(room))admitted = existingelse:admitted = driver.admit_task(