The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(acp): a CLI that stops reading before the first request reports its exit text
Teknium129f205a0e85
diff --git a/agent/acp_client.py b/agent/acp_client.pyindex 2b00a9490f0..6caff6882ca 100644--- a/agent/acp_client.py+++ b/agent/acp_client.py@@ -451,8 +451,12 @@ class ACPClient:def _request(method: str, params: dict[str, Any], *, text_parts: list[str] | None = None,reasoning_parts: list[str] | None = None) -> Any:request_id = next(request_ids)- proc.stdin.write(json.dumps({"jsonrpc": "2.0", "id": request_id, "method": method, "params": params}) + "\n")- proc.stdin.flush()+ try:+ proc.stdin.write(json.dumps({"jsonrpc": "2.0", "id": request_id, "method": method, "params": params}) + "\n")+ proc.stdin.flush()+ except BrokenPipeError: # the CLI stopped reading (dying): report its exit text, not a bare EPIPE+ with contextlib.suppress(subprocess.TimeoutExpired):+ proc.wait(timeout=5)deadline = session_deadlinewhile time.monotonic() < deadline and proc.poll() is None:try:diff --git a/tests/agent/test_acp_client_invariants.py b/tests/agent/test_acp_client_invariants.pyindex 0ca1bbd8cf4..737328f6e4f 100644--- a/tests/agent/test_acp_client_invariants.py+++ b/tests/agent/test_acp_client_invariants.py@@ -14,6 +14,7 @@ import jsonimport osimport subprocessimport sys+import timefrom pathlib import Pathfrom unittest.mock import patch@@ -304,6 +305,36 @@ def test_cli_death_is_reported_as_a_crash_not_a_timeout(tmp_path):pass+_STDIN_CLOSING_ACP_CLI = """import os, sys, time+os.close(0) # stops reading: the client's first write hits a closed pipe+open(sys.argv[1], "w").close()+time.sleep(0.3)+print('fatal: agent cannot start', file=sys.stderr)+sys.exit(2)+"""+++def test_cli_that_stops_reading_is_reported_with_its_exit_text(tmp_path):+ """A CLI dying before it reads the first request: the write raised a bare BrokenPipeError, so the+ user never saw the CLI's own crash text (and the error read as a client bug)."""+ server = tmp_path / "stdin_closing_acp.py"+ server.write_text(_STDIN_CLOSING_ACP_CLI, encoding="utf-8")+ closed = tmp_path / "stdin-closed"+ client = _AcmeClient(command=sys.executable, args=[str(server), str(closed)], acp_cwd=str(tmp_path))+ real_spawn = client._spawn++ def spawn_then_wait_for_the_close():+ proc = real_spawn()+ deadline = time.monotonic() + 30+ while not closed.exists() and time.monotonic() < deadline:+ time.sleep(0.01)+ return proc++ client._spawn = spawn_then_wait_for_the_close+ with pytest.raises(RuntimeError, match="exited early: fatal: agent cannot start"):+ with client._session(30):+ pass+def test_model_discovery_does_not_allow_file_requests(tmp_path):"""``list_models`` opens a session only to read the catalog: an fs request on that path is refused."""target = tmp_path / "should-not-be-read.txt"