The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(onboarding): Skip withdraws the card a compute-host child waits on
alt-glitch6b36cb6db4d4
diff --git a/tests/tui_gateway/test_compute_host_phase1.py b/tests/tui_gateway/test_compute_host_phase1.pyindex 125458ab90d..9e8b381fdb5 100644--- a/tests/tui_gateway/test_compute_host_phase1.py+++ b/tests/tui_gateway/test_compute_host_phase1.py@@ -79,6 +79,35 @@ def test_compute_host_routes_relayed_response_and_lock_to_its_open_request(monke+def test_compute_host_withdraws_its_open_request_when_the_parent_relays_a_cancel(monkeypatch):+ """Skip setup in the parent withdraws the card the child waits on: the wait returns and every+ renderer gets the ``request.cancel``."""+ from tui_gateway import server_requests+ out = io.StringIO()+ host = ComputeHost(stdout=out, heartbeat_secs=0)+ sid = "host-setup"+ server._sessions[sid] = {"history_lock": threading.Lock()}+ events = []+ monkeypatch.setattr(server_requests, "_emit", lambda kind, _sid, payload: events.append((kind, _sid, payload)))+ beat = server_requests.ServerRequest(sid, "setup_beat", {"beat": "theme"})+ other = server_requests.ServerRequest(sid, "clarify", {"question": "?"})+ with server_requests._lock:+ server_requests._open.update({beat.id: beat, other.id: other})++ try:+ host._handle_respond({"sid": sid, "request_id": "relay-cancel",+ "params": {"cancel": {"method": "setup_beat", "reason": "resolved"}}})+ assert beat.event.is_set() and not beat.answered+ assert not other.event.is_set()+ assert events == [("request.cancel", sid, {"id": beat.id, "method": "setup_beat", "reason": "resolved"})]+ frame = _json_lines(out)[-1]+ assert frame["type"] == "respond.ack" and frame["response"]["result"] == {"cancelled": 1}+ finally:+ server._sessions.pop(sid, None)+ server_requests.reset_for_tests()+ host.close()++def test_append_log_record_single_write_lines(tmp_path):path = tmp_path / "agent.log"diff --git a/tests/tui_gateway/test_onboarding_session.py b/tests/tui_gateway/test_onboarding_session.pyindex 373eb30a500..15be327f4b5 100644--- a/tests/tui_gateway/test_onboarding_session.py+++ b/tests/tui_gateway/test_onboarding_session.py@@ -179,6 +179,34 @@ def test_skip_setup_ends_the_run_and_closes_the_waiting_card(root, monkeypatch):assert onboarding["run"] is False and onboarding["seen"]["profile_build_offered"] is True+def test_skip_withdraws_the_card_a_compute_host_child_waits_on(root, monkeypatch):+ """dashboard.turn_isolation: the opening ran in the child, which owns the setup_beat wait; the+ parent holds only a mirror, so a local cancel never reaches it."""+ forwarded = []++ class _Supervisor:+ def respond(self, sid, params, *, timeout=15.0):+ forwarded.append((sid, dict(params)))+ return {"type": "respond.ack", "response": {"result": {"cancelled": 1}}}++ db = server._get_db()+ db.create_session("onb", "desktop")+ onboarding_record.start(db, "onb", FACTS)+ sid = "ui-onb"+ monkeypatch.setitem(server._sessions, sid, {"session_key": "onb", "agent": None, "source": "desktop",+ "agent_ready": threading.Event(), "_compute_host_active": True,+ "history_lock": threading.Lock()})+ monkeypatch.setattr(server, "_load_cfg", lambda: {"dashboard": {"turn_isolation": True}})+ monkeypatch.setattr(server, "_get_compute_host_supervisor", lambda _cfg=None: _Supervisor())+ monkeypatch.setattr(server, "write_json", lambda _message: True)+ server._relay_compute_host_rpc({"jsonrpc": "2.0", "id": "srq-host", "method": "setup_beat",+ "params": {"session_id": sid, "beat": "theme", "card": {"picker": "accent"}}})++ assert _call("onboarding.skip", {"session_id": sid})["result"] == {"skipped": True}+ assert forwarded == [(sid, {"cancel": {"method": "setup_beat", "reason": "resolved"}})]+ assert onboarding_record.load(db, "onb")["phase"] == "skipped"++def test_a_compression_rotation_carries_the_run_record(root):db = server._get_db()db.create_session("parent", "desktop")diff --git a/tui_gateway/compute_host.py b/tui_gateway/compute_host.pyindex c4ef50b1f07..2d26604a641 100644--- a/tui_gateway/compute_host.py+++ b/tui_gateway/compute_host.py@@ -203,7 +203,8 @@ class ComputeHost:def _handle_respond(self, frame: dict[str, Any]) -> None:"""Resolve a server→client request this host owns: ``params.frame`` is the client's JSON-RPC responseframe relayed by the parent; ``params.lock`` is one batch-clarify lock (answered with ``clarify.lock``'s- result so the parent can ack the client)."""+ result so the parent can ack the client); ``params.cancel`` withdraws this session's open requests of+ one ``method`` (the parent's own cancel never reaches a wait owned here)."""def body(server: Any, sid: str, request_id: Any) -> None:params = frame.get("params")error = ("session not found" if sid not in server._sessions@@ -214,6 +215,9 @@ class ComputeHost:from tui_gateway import server_requestsif isinstance(params.get("lock"), dict):response = server._methods["clarify.lock"](request_id, params["lock"])+ elif isinstance(cancel := params.get("cancel"), dict):+ withdrawn = server_requests.cancel(sid, str(cancel.get("reason") or "resolved"), method=str(cancel["method"]))+ response = {"jsonrpc": "2.0", "id": request_id, "result": {"cancelled": withdrawn}}else:response_frame = params.get("frame") if isinstance(params.get("frame"), dict) else paramsresolved = server_requests.resolve_response(response_frame)diff --git a/tui_gateway/compute_host_bridge.py b/tui_gateway/compute_host_bridge.pyindex ffff073d358..c39070ba70c 100644--- a/tui_gateway/compute_host_bridge.py+++ b/tui_gateway/compute_host_bridge.py@@ -194,6 +194,26 @@ def _relay_compute_host_response(frame: dict) -> bool:return True+def _cancel_session_requests(sid: str, reason: str, *, method: str) -> None:+ """Withdraw *sid*'s open *method* requests wherever they wait: in this process, or in the compute-host+ child that minted them (the parent holds only a mirror, so a local cancel never reaches that wait).+ The child's ``request.cancel`` comes back through ``_relay_compute_host_rpc``, which drops the mirror."""+ from tui_gateway import server_requests+ server_requests.cancel(sid, reason, method=method)+ session = _sessions.get(sid)+ if session is None:+ return+ with _history_lock(session):+ mirrored = session.get("_compute_host_open_request")+ hosted = isinstance(mirrored, dict) and mirrored.get("method") == method+ if not hosted or not _session_uses_compute_host(session):+ return+ try:+ _get_compute_host_supervisor().respond(sid, {"cancel": {"method": method, "reason": reason}})+ except Exception: # health: allow BLE001 -- the bridge raises transport-specific errors unknown here; the child's own deadline still ends the wait+ logger.warning("compute-host request cancel failed sid=%s method=%s", sid, method, exc_info=True)++def _lock_compute_host_clarify(rid: str, request_id: str, question_id: str, answer: str | None) -> dict | None:"""Proxy a batch-clarify lock into the child that owns the request; keeps the parent mirror's lockedanswers current for reconnect snapshots. None when the request is not host-owned."""diff --git a/tui_gateway/methods_onboarding.py b/tui_gateway/methods_onboarding.pyindex e6c55e5e7ad..ea28a1aff41 100644--- a/tui_gateway/methods_onboarding.py+++ b/tui_gateway/methods_onboarding.py@@ -153,22 +153,20 @@ def _(rid, params: dict) -> dict:if load(db, stored) is None:return _ok(rid, {"skipped": False})step = advance(db, stored, SkipAll())- from tui_gateway import server_requests# The card that waits returns to setup_beat, which reads the skipped record.- server_requests.cancel(params["session_id"], "resolved", method="setup_beat")+ _cancel_session_requests(params["session_id"], "resolved", method="setup_beat")return _ok(rid, {"skipped": bool(step.result.get("skipped_all"))})def _withdraw_setup_cards(stored_ids: list[str]) -> None:"""Close the card still waiting in a chat whose run just ended; its answer would be refused."""- from tui_gateway import server_requestsif not stored_ids:returnwith _sessions_lock:live = [sid for sid, sess in _sessions.items()if (getattr(sess.get("agent"), "session_id", None) or sess.get("session_key")) in stored_ids]for sid in live:- server_requests.cancel(sid, "resolved", method="setup_beat")+ _cancel_session_requests(sid, "resolved", method="setup_beat")def _setup_beat_request(sid: str, payload: dict) -> dict | None: