From 7237466e8bbdd28e4be713dd6e5a336d83735c7f Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Mon, 9 Nov 2026 18:22:20 -0800 Subject: [PATCH] perf(proxy): compile the baked proxy's bytecode as the image is built Every fresh task container compiled the proxy's dependencies on first import, so 128 episodes starting at once spent their CPU compiling the same packages. bake.sh now installs the venv with --compile-bytecode. Co-Authored-By: Claude Opus 5.5 --- src/agent_env/agents/agents/proxy/bake.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/agent_env/agents/agents/proxy/bake.sh b/src/agent_env/agents/agents/proxy/bake.sh index 5d9b86479..c5917ee3f 100644 --- a/src/agent_env/agents/agents/proxy/bake.sh +++ b/src/agent_env/agents/agents/proxy/bake.sh @@ -1,7 +1,8 @@ #!/bin/sh # Bakes the proxy into an image as it's built, so an install into one of its containers only starts it: a private -# Python and a venv holding requirements.txt in /opt/agentenv-proxy, and a marker naming the requirements it holds, -# which install.sh checks. Plain sh, for images with no bash. A task image's Dockerfile ends with +# Python and a venv holding requirements.txt in /opt/agentenv-proxy, compiled to bytecode so each container doesn't +# compile it on first import, and a marker naming the requirements it holds, which install.sh checks. Plain sh, for +# images with no bash. A task image's Dockerfile ends with # # COPY --from=ghcr.io/astral-sh/uv:0.13.1@sha256:4a1f3666816dafadd20ceb71eac9a7d56d7ef30279f7d64048519ab901ada336 /uv /opt/agentenv-proxy/bin/uv # COPY agentenv-proxy /opt/agentenv-proxy/src @@ -15,7 +16,7 @@ here=$(cd "$(dirname "$0")" && pwd) export UV_PYTHON_PREFERENCE=only-managed UV_PYTHON_INSTALL_DIR="$BAKED/python" UV_CACHE_DIR="$BAKED/cache" "$BAKED/bin/uv" venv --quiet --python "$PYTHON_VERSION" "$BAKED/venv" -"$BAKED/bin/uv" pip install --quiet --python "$BAKED/venv/bin/python" -r "$here/requirements.txt" +"$BAKED/bin/uv" pip install --quiet --compile-bytecode --python "$BAKED/venv/bin/python" -r "$here/requirements.txt" rm -rf "$BAKED/cache" "$BAKED/venv/bin/python" -c 'import hashlib, sys; print(hashlib.sha256(open(sys.argv[1], "rb").read()).hexdigest())' \ "$here/requirements.txt" > "$BAKED/baked"