The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: recover mixed-clock sessions and compose runtime test listeners
Teknium9e747d7f1e43
diff --git a/gateway/session.py b/gateway/session.pyindex 9cdc8cf3d3a..73d8365f892 100644--- a/gateway/session.py+++ b/gateway/session.py@@ -1150,8 +1150,9 @@ class SessionStore(entries = list(self._entries.values())if active_minutes is not None:cutoff = _now() - timedelta(minutes=active_minutes)- entries = [e for e in entries if e.updated_at >= cutoff]- entries.sort(key=lambda e: e.updated_at, reverse=True)+ entries = [e for e in entries if e.updated_at.timestamp() >= cutoff.timestamp()]+ # Legacy local timestamps and canonical UTC timestamps can coexist after recovery.+ entries.sort(key=lambda e: e.updated_at.timestamp(), reverse=True)return entriesdef lookup_by_session_id(self, session_id: str) -> Optional[SessionEntry]:diff --git a/tests/gateway/test_runtime_bootstrap_lifecycle.py b/tests/gateway/test_runtime_bootstrap_lifecycle.pyindex 9d1aac78c26..ab49b29ebb1 100644--- a/tests/gateway/test_runtime_bootstrap_lifecycle.py+++ b/tests/gateway/test_runtime_bootstrap_lifecycle.py@@ -25,6 +25,9 @@ async def test_runtime_preserves_browser_ticket_gate(tmp_path):runner = GatewayRunner(GatewayConfig())try:await initialize_gateway_runtime(runner)+ from gateway.control_socket import GatewayControlServer+ runner.session_control_server = GatewayControlServer()+ assert await runner.session_control_server.start()await start_gateway_runtime_api(runner)assert await runner.start()publish_gateway_runtime_ready(runner)@@ -40,6 +43,7 @@ async def test_runtime_preserves_browser_ticket_gate(tmp_path):assert reply['result']['ok'] is Truefinally:await runner.stop()+ await runner.session_control_server.stop()process_ownership.close()clear_providers()diff --git a/tests/gateway/test_runtime_listener_supervision.py b/tests/gateway/test_runtime_listener_supervision.pyindex c8f3eea6c0f..3103536a207 100644--- a/tests/gateway/test_runtime_listener_supervision.py+++ b/tests/gateway/test_runtime_listener_supervision.py@@ -18,6 +18,9 @@ async def test_runtime_wait_observes_listener_exit(tmp_path, listener_failure):waiter = Nonetry:await run_runtime.initialize_gateway_runtime(runner)+ from gateway.control_socket import GatewayControlServer+ runner.session_control_server = GatewayControlServer()+ assert await runner.session_control_server.start()await run_runtime.start_gateway_runtime_api(runner)assert await runner.start()run_runtime.publish_gateway_runtime_ready(runner)@@ -37,6 +40,7 @@ async def test_runtime_wait_observes_listener_exit(tmp_path, listener_failure):waiter.cancel()await asyncio.gather(waiter, return_exceptions=True)await runner.stop()+ await runner.session_control_server.stop()process_ownership.close()diff --git a/tests/gateway/test_runtime_token_identity.py b/tests/gateway/test_runtime_token_identity.pyindex b3df6cb1f36..1f2fbc0aec5 100644--- a/tests/gateway/test_runtime_token_identity.py+++ b/tests/gateway/test_runtime_token_identity.py@@ -37,6 +37,9 @@ async def test_authenticated_token_can_create_without_identityless_permissions(trunner = GatewayRunner(GatewayConfig())try:await initialize_gateway_runtime(runner)+ from gateway.control_socket import GatewayControlServer+ runner.session_control_server = GatewayControlServer()+ assert await runner.session_control_server.start()await start_gateway_runtime_api(runner)assert await runner.start()publish_gateway_runtime_ready(runner)@@ -60,6 +63,7 @@ async def test_authenticated_token_can_create_without_identityless_permissions(tawait unbound.close()finally:await runner.stop()+ await runner.session_control_server.stop()process_ownership.close()diff --git a/tests/gateway/test_session_activity_ordering.py b/tests/gateway/test_session_activity_ordering.pynew file mode 100644index 00000000000..e7475262d9a--- /dev/null+++ b/tests/gateway/test_session_activity_ordering.py@@ -0,0 +1,16 @@+"""Recovered UTC routes coexist with legacy local-time routes."""+from datetime import datetime, timedelta, timezone++from gateway.config import GatewayConfig, Platform+from gateway.session import SessionSource, SessionStore+++def test_list_sessions_orders_and_filters_mixed_clock_routes(tmp_path):+ store = SessionStore(sessions_dir=tmp_path / 'sessions', config=GatewayConfig())+ recent = store.get_or_create_session(SessionSource(platform=Platform.TELEGRAM, chat_id='recent'))+ old = store.get_or_create_session(SessionSource(platform=Platform.TELEGRAM, chat_id='old'))+ recent.updated_at = datetime.now(timezone.utc)+ old.updated_at = datetime.now() - timedelta(hours=2)++ assert store.list_sessions() == [recent, old]+ assert store.list_sessions(active_minutes=60) == [recent]