The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui_gateway): withdraw an approval that ends before its settle hook attaches
teknium101217c5fc239
diff --git a/tests/tui_gateway/test_protocol.py b/tests/tui_gateway/test_protocol.pyindex 6ec0eb7bd98..84cbe7f2756 100644--- a/tests/tui_gateway/test_protocol.py+++ b/tests/tui_gateway/test_protocol.py@@ -1522,6 +1522,34 @@ def test_approval_for_a_ws_client_that_never_advertised_settles_the_queue_entry(assert "ws-old-approval" not in approval_mod._gateway_queues+def test_approval_that_ends_before_its_settle_hook_attaches_is_still_withdrawn(server):+ """The client can answer (``approval.respond`` RPC, or another surface) between the frame going out and+ the settle hook attaching; ``register_gateway_settle`` then reports the entry gone. The sent request must+ still be withdrawn, or every later ``session.resume`` replays a prompt nobody is waiting on."""+ from tui_gateway import server_requests+ from tui_gateway.transport import bind_transport, reset_transport++ peer = _silent_ws()+ _ws_session(server, "ws-raced", peer)+ token = bind_transport(peer)+ try:+ server.handle_request({"id": 1, "method": "client.capabilities", "params": {"server_requests": True}})+ finally:+ reset_transport(token)+ try:+ # No queue entry carries this request id: the wait already ended when the hook tries to attach.+ server._emit_approval_request("ws-raced", {"command": "rm -rf build", "description": "",+ "request_id": "appr-already-resolved"})+ assert len(peer.frames) == 2, f"the sent approval was never withdrawn: {peer.frames}"+ sent, cancel = peer.frames+ assert sent["method"] == "approval"+ assert cancel["params"]["type"] == "request.cancel"+ assert cancel["params"]["payload"]["id"] == sent["id"]+ assert server_requests.open_requests("ws-raced") == []+ finally:+ server.unregister_live_transport(peer)++def test_peerless_global_broadcast_never_reaches_stdout_in_ws_backend(capture, monkeypatch):"""`hermes serve` / dashboard speak JSON-RPC over WS only; Desktop captures their stdoutinto desktop.log. After the last WS client leaves, the change watcher keeps ticking —diff --git a/tui_gateway/server.py b/tui_gateway/server.pyindex bd812679a8e..6f294f3f81d 100644--- a/tui_gateway/server.py+++ b/tui_gateway/server.py@@ -792,8 +792,10 @@ def _emit_approval_request(sid: str, data: dict | None) -> None:request_id=request_id or None)settle = server_requests.send_async("approval", sid, payload, on_result)- if request_id:- _approval.register_gateway_settle(session_key, request_id, settle)+ # The wait can end between the frame going out and the hook attaching (the client answered by RPC, another+ # surface resolved it): withdraw now, or the request stays in ``open_requests`` for every later resume.+ if request_id and not _approval.register_gateway_settle(session_key, request_id, settle):+ settle("resolved")def _status_update(sid: str, kind: str, text: str | None = None):