The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): ignore secondary local adapters for idle exit
David Dudok de Witcf3e2374ce2e
diff --git a/gateway/run_idle_exit.py b/gateway/run_idle_exit.pyindex 0bec7e04134..7e5e941e4d8 100644--- a/gateway/run_idle_exit.py+++ b/gateway/run_idle_exit.py@@ -75,10 +75,10 @@ def _messaging_busy(runner) -> str | None:local = {Platform.LOCAL}live = [p for p in (getattr(runner, "adapters", None) or {}) if p not in local]for adapters in (getattr(runner, "_profile_adapters", None) or {}).values():- live.extend(adapters)+ live.extend(p for p in adapters if p not in local)for pending in (getattr(runner, "_profile_failed_platforms", None) or {}).values():- live.extend(pending or {})- live.extend(getattr(runner, "_failed_platforms", None) or {})+ live.extend(p for p in (pending or {}) if p not in local)+ live.extend(p for p in (getattr(runner, "_failed_platforms", None) or {}) if p not in local)config = getattr(runner, "config", None)if config is not None:live.extend(p for p, cfg in config.platforms.items() if p not in local and getattr(cfg, "enabled", False))diff --git a/tests/gateway/test_unmanaged_idle_exit.py b/tests/gateway/test_unmanaged_idle_exit.pyindex 61e10f76068..575f5526336 100644--- a/tests/gateway/test_unmanaged_idle_exit.py+++ b/tests/gateway/test_unmanaged_idle_exit.py@@ -89,3 +89,22 @@ async def test_queued_work_clients_adapters_and_cron_each_keep_it_up(tmp_path, massert "idle probe failed" in run_idle_exit.busy_reason(runner, window=0.2)finally:db.close()+++def test_secondary_local_session_adapter_does_not_count_as_messaging(tmp_path, monkeypatch):+ """A secondary local session leaves an adapter map behind after the client disconnects."""+ runner, _home, db, _stops = _runner(tmp_path, monkeypatch)+ secondary_home = tmp_path / "secondary"+ secondary_home.mkdir()+ secondary_db = SessionDB(db_path=secondary_home / "state.db")+ runner.session_authorities.add(+ secondary_home, SimpleNamespace(profile_id=str(secondary_home), db=secondary_db), name="secondary")+ try:+ runner._profile_adapters["secondary"] = {Platform.LOCAL: object()}+ assert run_idle_exit.busy_reason(runner, window=0.2) is None++ runner._profile_adapters["secondary"][Platform.TELEGRAM] = object()+ assert "telegram" in run_idle_exit.busy_reason(runner, window=0.2)+ finally:+ secondary_db.close()+ db.close()