The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(tui_gateway): evaluate the quiescence predicate outside _sessions_lock
kshitijk4poor4626656c744f
diff --git a/tui_gateway/session_reaper.py b/tui_gateway/session_reaper.pyindex 1aba5061a82..081f0cf6c9c 100644--- a/tui_gateway/session_reaper.py+++ b/tui_gateway/session_reaper.py@@ -164,9 +164,12 @@ def _sessions_quiescent(exclude: str | None = None) -> bool:"""No session but ``exclude`` is mid-turn, building, awaiting input, holding live delegations, or on a livetransport. A non-forced memory trim holds the GIL (gc.collect) and every glibc arena lock (malloc_trim) forits whole duration — 20-50 s on multi-GB heaps — which stalls the event loop, drops WS clients past the- write deadline and interrupts their turns (#58576); this is the only moment it costs nobody."""+ write deadline and interrupts their turns (#58576); this is the moment it costs no other session. The+ predicate is advisory (a turn can start right after), so the per-session checks — one may read state.db —+ run outside ``_sessions_lock``."""with _sessions_lock:- return all(_session_is_lru_evictable(sid, s) for sid, s in _sessions.items() if sid != exclude)+ others = [(sid, s) for sid, s in _sessions.items() if sid != exclude]+ return all(_session_is_lru_evictable(sid, s) for sid, s in others)def _session_is_evictable(sid: str, session: dict, now: float) -> bool: