The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: coalesced approval followers wait the leader's captured timeout
kshitijk4poore776cdff1899
diff --git a/tests/tools/test_approval_gateway_wait_late_choice.py b/tests/tools/test_approval_gateway_wait_late_choice.pyindex eb279525bbd..8062fa2accd 100644--- a/tests/tools/test_approval_gateway_wait_late_choice.py+++ b/tests/tools/test_approval_gateway_wait_late_choice.py@@ -118,6 +118,22 @@ def test_gateway_approval_captures_routed_profiles_timeout(tmp_path, monkeypatchassert observed == [300, 300, 3600, 3600]+def test_coalesced_follower_waits_the_leaders_captured_timeout(monkeypatch):+ from tools.approval_gateway_wait import _ApprovalEntry++ _clear()+ monkeypatch.setattr(wait_mod._ctx, "_get_approval_timeout", lambda: 300) # edited since the leader prompted+ monkeypatch.setattr(wait_mod._ctx, "_fire_approval_hook", lambda name, **kw: None)+ seen = []+ monkeypatch.setattr(wait_mod, "_poll_event",+ lambda event, session_key, *, interrupt_log, timeout_s=None: seen.append(timeout_s) or "timeout")+ leader = _ApprovalEntry(dict(APPROVAL, request_id="leader", timeout_s=3600))++ wait_mod._await_coalesced_leader(SESSION_KEY, leader, {})++ assert seen == [3600]++def test_resolve_commits_the_choice_before_releasing_the_approval_lock(monkeypatch):"""``_drop_entry`` reads ``entry.result`` and leaves the queue in one ``_lock`` section, which onlycloses the race if ``resolve_gateway_approval`` commits ``result``/``event`` INSIDE the section thatdiff --git a/tools/approval_gateway_wait.py b/tools/approval_gateway_wait.pyindex 2cd716533e1..55802c14540 100644--- a/tools/approval_gateway_wait.py+++ b/tools/approval_gateway_wait.py@@ -115,7 +115,8 @@ def _await_coalesced_leader(session_key: str, leader, payload: dict):so the caller must issue a fresh prompt. Hooks fire with ``coalesced=True``so observers see the follower's lifecycle without a duplicate prompt."""_ctx._fire_approval_hook("pre_approval_request", **payload, coalesced=True)- state = _poll_event(leader.event, session_key,+ # The leader's captured timeout (when stamped), so a config edit mid-wait can't end the follower first.+ state = _poll_event(leader.event, session_key, timeout_s=leader.data.get("timeout_s"),interrupt_log="Coalesced approval wait interrupted — ""returning deny for session %s")if state == "set" and leader.result is None and leader.expired: