The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): require live consumer for restored delegations
KoNit-K41337290801f
diff --git a/tests/tui_gateway/test_launch_db_home_override_race.py b/tests/tui_gateway/test_launch_db_home_override_race.pyindex 0f7f71e5b00..ea64134880e 100644--- a/tests/tui_gateway/test_launch_db_home_override_race.py+++ b/tests/tui_gateway/test_launch_db_home_override_race.py@@ -186,6 +186,17 @@ def test_notification_owner_gate_resolves_rotated_key_in_the_session_profile_stoassert server._get_db().get_session("parent") is None # never looked up through the launch store+def test_restored_delegation_requires_a_live_notification_consumer():+ """Regression for #138343: a persisted completion cannot wake a detached runtime."""+ session = {"session_key": "chat", "transport": None}+ event = {"type": "async_delegation", "session_key": "chat", "restored": True}++ assert server._session_owns_notification_event("ui1", session, event) is False++ session["transport"] = object()+ assert server._session_owns_notification_event("ui1", session, event) is True++def test_foreign_profile_poller_requeues_event_owned_through_another_profiles_lineage(launch_db_env, tmp_path):"""Two profiles share one completion queue. Profile B's poller dequeues an event keyed on profileA's compressed parent: B cannot resolve A's lineage in its own store, so both of B's ownershipdiff --git a/tui_gateway/session_notifications.py b/tui_gateway/session_notifications.pyindex d6ba781d128..5f140bab1b1 100644--- a/tui_gateway/session_notifications.py+++ b/tui_gateway/session_notifications.py@@ -96,6 +96,12 @@ def _session_owns_notification_event(sid: str, session: dict, evt: dict) -> boolresolved matches) — the fail-closed gate for addressed notifications, without the orphan-adoption fallback."""if session.get("_finalized"):return False+ # A completion restored after process restart has no in-process owner. A matching+ # persisted key alone can belong to a detached runtime whose old lease survived;+ # requiring a current client prevents it from spending a full model turn unseen.+ if (evt.get("type") == "async_delegation" and evt.get("restored")+ and not _session_has_live_transport(session)):+ return Falseif str(evt.get("origin_ui_session_id") or "") == str(sid or ""):return Trueevt_key = str(evt.get("session_key") or "")