The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): keep first clarify resolution
deacon-botdoctor28b62b069ad8
diff --git a/tests/gateway/test_clarify_thread_followup_not_swallowed.py b/tests/gateway/test_clarify_thread_followup_not_swallowed.pyindex 00cc75fa79f..7f476579019 100644--- a/tests/gateway/test_clarify_thread_followup_not_swallowed.py+++ b/tests/gateway/test_clarify_thread_followup_not_swallowed.py@@ -133,6 +133,30 @@ async def test_thread_prose_not_swallowed_by_native_multi_choice_clarify():_clear_clarify_state()+async def test_thread_prose_does_not_overwrite_concurrent_button_choice():+ """A button result that wins the race remains the clarify response."""+ _clear_clarify_state()+ from tools import clarify_gateway as cm++ adapter = _StubAdapter()+ runner = _make_runner(adapter)+ entry = cm.register(+ "cl-button-race",+ SESSION_KEY,+ "Pick a UI variant",+ ["buttons", "dropdown"],+ )+ assert cm.resolve_gateway_clarify("cl-button-race", "buttons") is True++ with pytest.raises(_FellThroughIntercept):+ await _dispatch(runner, _event("one more unrelated thought"))++ assert entry.event.is_set()+ assert entry.response == "buttons"+ _clear_clarify_state()++@pytest.mark.asyncioasync def test_prose_still_accepted_after_other_flips_text_capture():"""After the user taps 'Other', free text IS the answer — must resolve."""@@ -154,4 +178,3 @@ async def test_prose_still_accepted_after_other_flips_text_capture():assert entry.response == "a carousel actually"_clear_clarify_state()-diff --git a/tests/tools/test_clarify_gateway.py b/tests/tools/test_clarify_gateway.pyindex e9d410fb573..3a164d0c6cc 100644--- a/tests/tools/test_clarify_gateway.py+++ b/tests/tools/test_clarify_gateway.py@@ -42,6 +42,16 @@ class TestClarifyPrimitive:result = cm.wait_for_response("id1", timeout=10.0)assert result == "B"+ def test_first_resolution_wins(self):+ """A late cancellation must not overwrite an already-selected choice."""+ from tools import clarify_gateway as cm++ entry = cm.register("id-race", "sk-race", "Pick one", ["A", "B"])++ assert cm.resolve_gateway_clarify("id-race", "A") is True+ assert cm.resolve_gateway_clarify("id-race", "") is False+ assert entry.response == "A"+def test_open_ended_auto_awaits_text(self):"""Clarify with no choices is in text-capture mode immediately."""from tools import clarify_gateway as cmdiff --git a/tools/clarify_gateway.py b/tools/clarify_gateway.pyindex 6bee2214bce..212cb0b4446 100644--- a/tools/clarify_gateway.py+++ b/tools/clarify_gateway.py@@ -169,11 +169,11 @@ def resolve_gateway_clarify(clarify_id: str, response: str) -> bool:"""with _lock:entry = _entries.get(clarify_id)- if entry is None:+ if entry is None or entry.event.is_set():return False- entry.response = str(response) if response is not None else ""- entry.event.set()- return True+ entry.response = str(response) if response is not None else ""+ entry.event.set()+ return Truedef get_pending_for_session(