The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: a crashed Copilot ACP CLI is reported as a crash, not a timeout (#121467)
teknium151d40c3016f5
diff --git a/agent/copilot_acp_client.py b/agent/copilot_acp_client.pyindex 647614c3044..4ad491d1c12 100644--- a/agent/copilot_acp_client.py+++ b/agent/copilot_acp_client.py@@ -398,7 +398,9 @@ class CopilotACPClient:sink(line)threading.Thread(target=_pump, args=(proc.stdout, lambda line: inbox.put(_decode(line))), daemon=True).start()- threading.Thread(target=_pump, args=(proc.stderr, lambda line: stderr_tail.append(line.rstrip("\n"))), daemon=True).start()+ stderr_pump = threading.Thread(+ target=_pump, args=(proc.stderr, lambda line: stderr_tail.append(line.rstrip("\n"))), daemon=True)+ stderr_pump.start()request_ids = iter(range(1, 1 << 62))# One budget for the WHOLE session (initialize + session/new + any prompt), not per# request: a hung CLI must not get 2x the caller's timeout on the foreground /model path.@@ -424,11 +426,14 @@ class CopilotACPClient:err = msg.get("error") or {}raise RuntimeError(f"Copilot ACP {method} failed: {err.get('message') or err}")return msg.get("result")- stderr_text = "\n".join(stderr_tail).strip()- if proc.poll() is not None and stderr_text:+ if proc.poll() is not None:+ # The pump can still hold the crash text when poll() first sees the exit; reading+ # it too early turned a dead CLI into a TimeoutError, which retries differently.+ stderr_pump.join(timeout=1.0)+ stderr_text = "\n".join(stderr_tail).strip()if _is_gh_copilot_deprecation_message(stderr_text):raise RuntimeError(_DEPRECATED_CLI_ERROR + stderr_text)- raise RuntimeError(f"Copilot ACP process exited early: {stderr_text}")+ raise RuntimeError(f"Copilot ACP process exited early: {stderr_text or f'exit code {proc.returncode}'}")raise TimeoutError(f"Timed out waiting for Copilot ACP response to {method}.")try:diff --git a/tests/agent/test_copilot_acp_client.py b/tests/agent/test_copilot_acp_client.pyindex ff008d93f97..5c114662039 100644--- a/tests/agent/test_copilot_acp_client.py+++ b/tests/agent/test_copilot_acp_client.py@@ -563,3 +563,28 @@ def test_close_terminates_every_live_session_process(tmp_path):client.close()assert all(proc.poll() is not None for proc in spawned)+++_CRASHING_ACP_CLI = """+import subprocess, sys+# Hand stderr to a straggler that writes the crash text after this process has exited, so+# poll() reports the exit before the client has read a single stderr line.+subprocess.Popen([sys.executable, "-c",+ "import sys, time; time.sleep(0.3); print('fatal: agent segfaulted', file=sys.stderr)"])+sys.exit(3)+"""+++def test_cli_death_is_reported_as_a_crash_not_a_timeout(tmp_path):+ """A CLI that dies must surface its crash text even when stderr lags the exit: the old path+ raised TimeoutError there, which the agent loop retries on a different (larger) budget."""+ server = tmp_path / "crashing_acp.py"+ server.write_text(_CRASHING_ACP_CLI, encoding="utf-8")+ client = CopilotACPClient(command=sys.executable, args=[str(server)], acp_cwd=str(tmp_path))+ try:+ with client._session(30):+ pass+ except RuntimeError as exc:+ assert "exited early: fatal: agent segfaulted" in str(exc)+ else:+ raise AssertionError("session on a dead CLI must raise")