diff --git a/tui_gateway/server.py b/tui_gateway/server.py index 412c89aaf15..fb98f615fa3 100644 --- a/tui_gateway/server.py +++ b/tui_gateway/server.py @@ -8487,11 +8487,19 @@ def _notification_poller_loop( _emit("status.update", sid, {"kind": "process", "text": text}) _emitted.add(_dedup_key) + _requeued = False with session["history_lock"]: if session.get("running"): process_registry.completion_queue.put(evt) - continue - session["running"] = True + _requeued = True + else: + session["running"] = True + if _requeued: + # Back off before re-polling: the re-queued event keeps the queue + # non-empty, so without a sleep this loop spins at full speed + # (100% CPU, GIL churn) for as long as the session stays busy. + time.sleep(0.25) + continue rid = f"__notif__{int(time.time() * 1000)}" try: