From 0f6cbc87062833efc38f3991a85f5930d88abbfb Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 24 Jul 2026 09:42:00 +0000 Subject: [PATCH 1/2] Use non-blocking file reads in host agy daemon Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com> --- scripts/host_agy_daemon.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/scripts/host_agy_daemon.py b/scripts/host_agy_daemon.py index 5948b74c..0317c00d 100755 --- a/scripts/host_agy_daemon.py +++ b/scripts/host_agy_daemon.py @@ -180,18 +180,17 @@ async def run(): except Exception: returncode = -1 - # Read output from the temporary files - try: - with open(stdout_path, "r", encoding="utf-8", errors="replace") as f: - stdout = f.read().strip() - except Exception: - stdout = "" - - try: - with open(stderr_path, "r", encoding="utf-8", errors="replace") as f: - stderr = f.read().strip() - except Exception: - stderr = "" + # Read output from the temporary files without blocking the event loop + def read_file_sync(path): + try: + with open(path, "r", encoding="utf-8", errors="replace") as f: + return f.read().strip() + except Exception: + return "" + + loop_ref = asyncio.get_running_loop() + stdout = await loop_ref.run_in_executor(None, read_file_sync, stdout_path) + stderr = await loop_ref.run_in_executor(None, read_file_sync, stderr_path) # Clean up temporary files for path in [stdout_path, stderr_path]: From 711cc9ac7dfd901427e201b807111ad70eab9b10 Mon Sep 17 00:00:00 2001 From: boy Date: Fri, 24 Jul 2026 12:37:51 +0200 Subject: [PATCH 2/2] refactor(daemon): hoist read_file_sync and run stdout/stderr reads concurrently via asyncio.gather --- scripts/host_agy_daemon.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/host_agy_daemon.py b/scripts/host_agy_daemon.py index 0317c00d..07571e57 100755 --- a/scripts/host_agy_daemon.py +++ b/scripts/host_agy_daemon.py @@ -23,6 +23,14 @@ def get_last_conversation_id(): pass return None +def read_file_sync(path): + """Synchronously read and return content from a file, returning empty string on error.""" + try: + with open(path, "r", encoding="utf-8", errors="replace") as f: + return f.read().strip() + except Exception: + return "" + class AgyDaemonHandler(BaseHTTPRequestHandler): """HTTP request handler for agy execution requests.""" def do_POST(self): @@ -180,17 +188,12 @@ async def run(): except Exception: returncode = -1 - # Read output from the temporary files without blocking the event loop - def read_file_sync(path): - try: - with open(path, "r", encoding="utf-8", errors="replace") as f: - return f.read().strip() - except Exception: - return "" - + # Read output from the temporary files without blocking the event loop concurrently loop_ref = asyncio.get_running_loop() - stdout = await loop_ref.run_in_executor(None, read_file_sync, stdout_path) - stderr = await loop_ref.run_in_executor(None, read_file_sync, stderr_path) + stdout, stderr = await asyncio.gather( + loop_ref.run_in_executor(None, read_file_sync, stdout_path), + loop_ref.run_in_executor(None, read_file_sync, stderr_path), + ) # Clean up temporary files for path in [stdout_path, stderr_path]: