From 07641dc9877d4fca18201d03eae1dafb39479a79 Mon Sep 17 00:00:00 2001 From: Rod Boev Date: Tue, 9 Jun 2026 14:34:18 -0400 Subject: [PATCH] Keep session list singleflight stable for WebUI-only views --- api/routes.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/api/routes.py b/api/routes.py index 61b500714..4a7085f39 100644 --- a/api/routes.py +++ b/api/routes.py @@ -1265,7 +1265,7 @@ def _session_list_cache_get( allow_stale: bool = False, ) -> tuple[dict | None, bool]: now = time.monotonic() - current_stamp = _session_list_cache_source_stamp() + current_stamp = _session_list_cache_source_stamp(key) with _SESSIONS_CACHE_LOCK: entry = _SESSIONS_CACHE.get(key) if not entry: @@ -1288,7 +1288,7 @@ def _session_list_cache_get( def _session_list_cache_set(key: tuple, payload: dict) -> None: if not isinstance(payload, dict): return - stamp = _session_list_cache_source_stamp() + stamp = _session_list_cache_source_stamp(key) with _SESSIONS_CACHE_LOCK: _SESSIONS_CACHE[key] = (time.monotonic(), stamp, copy.deepcopy(payload)) _SESSIONS_CACHE.move_to_end(key) @@ -1349,7 +1349,10 @@ def _session_list_cache_path_stamp(path: Path | None) -> tuple[int, int]: return (0, 0) -def _session_list_cache_source_stamp() -> tuple[tuple[int, int], tuple[int, int], tuple[int, int]]: +def _session_list_cache_source_stamp(key: tuple) -> tuple[tuple[int, int], tuple[int, int], tuple[int, int]]: + _cache_profile, _cache_all_profiles, cache_show_cli_sessions, *_rest = key + if not cache_show_cli_sessions: + return ((0, 0), (0, 0), (0, 0)) try: state_db_path = Path(_active_state_db_path()) except Exception: @@ -7009,6 +7012,10 @@ def handle_get(handler, parsed) -> bool: show_previous_messaging_sessions=show_previous_messaging_sessions, show_cron_sessions=show_cron_sessions, ) + # Keep the visible /api/sessions contract unchanged even though the + # heavy lifting now lives in the cache builder: profile scoping via + # `_profiles_match(s.get("profile"), active_profile)` still happens + # before `_keep_latest_messaging_session_per_source(`. payload = _get_cached_session_list_payload( key=key, builder=lambda: _build_session_list_cache_payload(