Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
fix(ci): multi-stage manylinux build for e2e dockerfiles + release workflow test
chopratejasb31a34b4ac00
diff --git a/e2e/init/Dockerfile b/e2e/init/Dockerfileindex 1ef1240e3..d51fa20dd 100644--- a/e2e/init/Dockerfile+++ b/e2e/init/Dockerfile@@ -1,50 +1,68 @@+# ─── Stage 1: build the headroom-ai wheel in manylinux ─────────────────────+# See e2e/wrap/Dockerfile for the full rationale. tl;dr: building from+# source inside `node:22-bookworm` produced a `_core.so` referencing+# `__isoc23_strtoll` (glibc 2.38+) that the same image's runtime libc+# couldn't resolve. Building inside manylinux_2_28 (AlmaLinux 8, glibc+# 2.28 baseline) yields a wheel portable to any glibc 2.28+ runtime.+FROM quay.io/pypa/manylinux_2_28_x86_64 AS builder++RUN yum install -y openssl-devel pkgconfig perl-IPC-Cmd++ENV CARGO_HOME=/usr/local/cargo \+ RUSTUP_HOME=/usr/local/rustup \+ PATH=/usr/local/cargo/bin:/opt/python/cp311-cp311/bin:${PATH}+RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \+ | sh -s -- -y --no-modify-path --profile minimal -c rustfmt -c clippy --default-toolchain 1.95.0++WORKDIR /build++COPY pyproject.toml uv.lock README.md ./+COPY Cargo.toml Cargo.lock rust-toolchain.toml ./+COPY crates/ crates/+COPY headroom/ headroom/++ENV PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1+RUN /opt/python/cp311-cp311/bin/pip install 'maturin>=1.5,<2.0' && \+ /opt/python/cp311-cp311/bin/maturin build --release --out /dist --interpreter python3.11++# ─── Stage 2: node-based init e2e runtime ──────────────────────────────────FROM node:22-bookwormENV DEBIAN_FRONTEND=noninteractive \- PATH="/root/.cargo/bin:/opt/headroom-venv/bin:${PATH}" \- CARGO_HOME=/root/.cargo \- RUSTUP_HOME=/root/.rustup \+ PATH="/opt/headroom-venv/bin:${PATH}" \PIP_DISABLE_PIP_VERSION_CHECK=1 \PIP_NO_CACHE_DIR=1 \PYTHONUNBUFFERED=1 \PYTHONDONTWRITEBYTECODE=1-# Single wheel architecture: `pip install -e .` invokes maturin (declared in-# pyproject.toml's build-system) which calls cargo to compile the Rust-# extension. The image needs python + rust + maturin at build time.RUN apt-get update && \apt-get install -y --no-install-recommends \ca-certificates \- curl \git \- pkg-config \- libssl-dev \python3 \python3-pip \python3-venv && \ln -sf /usr/bin/python3 /usr/local/bin/python && \- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.95.0 --profile minimal -c rustfmt -c clippy && \rm -rf /var/lib/apt/lists/*WORKDIR /workspace-COPY pyproject.toml README.md uv.lock ./-COPY Cargo.toml Cargo.lock rust-toolchain.toml ./-COPY headroom ./headroom-COPY crates ./crates+COPY --from=builder /dist/*.whl /tmp/wheels/++# Init e2e harness imports from e2e._lib + .claude-plugin assets.+# DO NOT copy `headroom/` or `pyproject.toml` from the workspace —+# the installed wheel must be authoritative. The harness packages+# (e2e/_lib/, .claude-plugin/, plugins/) don't shadow `headroom`.COPY .claude-plugin ./.claude-pluginCOPY .github/plugin ./.github/pluginCOPY plugins/headroom-agent-hooks ./plugins/headroom-agent-hooks-# The init e2e harness imports from e2e._lib; both directories must be-# present and each must contain an __init__.py so Python sees them as-# packages rooted at /workspace.COPY e2e/__init__.py ./e2e/__init__.pyCOPY e2e/_lib ./e2e/_libCOPY e2e/init ./e2e/initRUN python -m venv /opt/headroom-venv && \/opt/headroom-venv/bin/python -m pip install --upgrade "pip<25" && \- /opt/headroom-venv/bin/python -m pip install -e ".[proxy]" && \+ /opt/headroom-venv/bin/python -m pip install "$(ls /tmp/wheels/headroom_ai-*.whl)[proxy]" && \/opt/headroom-venv/bin/python -c "from headroom._core import DiffCompressor; print('headroom._core OK')"CMD ["python", "e2e/init/run.py"]diff --git a/e2e/wrap/Dockerfile b/e2e/wrap/Dockerfileindex bd4ad687a..e974f7010 100644--- a/e2e/wrap/Dockerfile+++ b/e2e/wrap/Dockerfile@@ -1,47 +1,89 @@+# ─── Stage 1: build the headroom-ai wheel in manylinux ─────────────────────+# Building from source inside `node:22-bookworm` produced a `_core.so` that+# referenced `__isoc23_strtoll` (a glibc 2.38+ symbol). The runtime in the+# same image couldn't resolve it at import time because something in the+# build chain — gcc version, libc6-dev backport, or cc-rs compiling+# transitive C deps against newer headers — emitted C23-era symbols that+# the runtime libc.so.6 doesn't have. Building inside the manylinux_2_28+# container (AlmaLinux 8, glibc 2.28 baseline) guarantees the wheel works+# on any glibc 2.28+ runtime, including bookworm.+FROM quay.io/pypa/manylinux_2_28_x86_64 AS builder++# `openssl-sys` (transitive via fastembed/hf-hub/ureq → native-tls) needs+# OpenSSL dev headers. perl-IPC-Cmd is required by openssl-sys's autotools+# probe.+RUN yum install -y openssl-devel pkgconfig perl-IPC-Cmd++# Install rust toolchain into the manylinux container. Match the+# rust-toolchain.toml at repo root (1.95.0 + rustfmt + clippy) so cargo+# doesn't try to mutate the toolchain on first invocation.+ENV CARGO_HOME=/usr/local/cargo \+ RUSTUP_HOME=/usr/local/rustup \+ PATH=/usr/local/cargo/bin:/opt/python/cp311-cp311/bin:${PATH}+RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \+ | sh -s -- -y --no-modify-path --profile minimal -c rustfmt -c clippy --default-toolchain 1.95.0++WORKDIR /build++COPY pyproject.toml uv.lock README.md ./+COPY Cargo.toml Cargo.lock rust-toolchain.toml ./+COPY crates/ crates/+COPY headroom/ headroom/++# Build the wheel with maturin. PYO3_USE_ABI3_FORWARD_COMPATIBILITY allows+# building against Python 3.14+ until we bump pyo3 past 0.22.+ENV PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1+RUN /opt/python/cp311-cp311/bin/pip install 'maturin>=1.5,<2.0' && \+ /opt/python/cp311-cp311/bin/maturin build --release --out /dist --interpreter python3.11++# ─── Stage 2: node-based e2e runtime ────────────────────────────────────────+# Wraps Aider, Codex, OpenClaw on top of the prebuilt headroom-ai wheel.+# No rust/maturin needed at this stage — we just `pip install` the wheel+# from stage 1.FROM node:22-bookwormENV DEBIAN_FRONTEND=noninteractive \AIDER_CHAT_VERSION=0.86.2 \CODEX_VERSION=0.118.0 \OPENCLAW_VERSION=2026.4.7 \- PATH="/root/.cargo/bin:/opt/headroom-venv/bin:/opt/aider-venv/bin:${PATH}" \- CARGO_HOME=/root/.cargo \- RUSTUP_HOME=/root/.rustup \+ PATH="/opt/headroom-venv/bin:/opt/aider-venv/bin:${PATH}" \PIP_DISABLE_PIP_VERSION_CHECK=1 \PIP_NO_CACHE_DIR=1 \PYTHONUNBUFFERED=1 \PYTHONDONTWRITEBYTECODE=1-# Single wheel architecture: `pip install -e .` invokes maturin under the-# hood which compiles the Rust extension. With rust + maturin available at-# build time, the image now ships the full Rust core — no-# `HEADROOM_REQUIRE_RUST_CORE=false` opt-out needed.RUN apt-get update && \apt-get install -y --no-install-recommends \ca-certificates \curl \git \- pkg-config \- libssl-dev \python3 \python3-pip \python3-venv && \ln -sf /usr/bin/python3 /usr/local/bin/python && \- curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.95.0 --profile minimal -c rustfmt -c clippy && \rm -rf /var/lib/apt/lists/*WORKDIR /workspace-COPY pyproject.toml README.md uv.lock ./-COPY Cargo.toml Cargo.lock rust-toolchain.toml ./-COPY headroom ./headroom-COPY crates ./crates+# Bring in the prebuilt manylinux wheel from stage 1.+COPY --from=builder /dist/*.whl /tmp/wheels/++# `sdk/typescript` and `plugins/openclaw` are wired into the wrap-e2e+# harness (e2e/wrap/run.py invokes `npx openclaw`). DO NOT copy+# `headroom/` or `pyproject.toml` from the workspace — they would shadow+# the installed wheel's `headroom/` package via cwd and Python would+# import the source-only `headroom/` (which has no `_core.so`),+# triggering the same `ModuleNotFoundError` the wheel install fixes.COPY sdk/typescript ./sdk/typescriptCOPY plugins/openclaw ./plugins/openclaw+# Install the prebuilt manylinux wheel with [proxy] extras. Pip resolves+# extras from the wheel's metadata and pulls deps from public PyPI. The+# wheel's `_core.so` was compiled against glibc 2.28, so it loads cleanly+# against bookworm's glibc 2.36 at runtime.RUN python -m venv /opt/headroom-venv && \/opt/headroom-venv/bin/python -m pip install --upgrade pip && \- /opt/headroom-venv/bin/python -m pip install -e ".[proxy]" && \+ /opt/headroom-venv/bin/python -m pip install "$(ls /tmp/wheels/headroom_ai-*.whl)[proxy]" && \/opt/headroom-venv/bin/python -c "from headroom._core import DiffCompressor; print('headroom._core OK')" && \python -m venv /opt/aider-venv && \/opt/aider-venv/bin/python -m pip install --upgrade pip && \diff --git a/tests/test_release_workflows.py b/tests/test_release_workflows.pyindex 6cf067e7f..12d74d39b 100644--- a/tests/test_release_workflows.py+++ b/tests/test_release_workflows.py@@ -41,12 +41,19 @@ def test_release_workflow_publishes_python_distributions_to_github_release() ->def test_create_release_runs_after_successful_build_even_if_other_publishes_fail() -> None:content = (ROOT / ".github" / "workflows" / "release.yml").read_text(encoding="utf-8")+ # Single-wheel maturin refactor (PR #360) added `build-wheels` (the+ # cross-platform matrix that produces the linux/macos/aarch64 wheels)+ # and `collect-dist` (aggregator that merges wheel artifacts + npm+ # release-assets) between `build` and the publish jobs. create-release+ # must wait for all of them.assert (- "needs: [detect-version, build, publish-pypi, publish-npm, publish-github-packages, publish-docker]"+ "needs: [detect-version, build, build-wheels, collect-dist, publish-pypi, publish-npm, publish-github-packages, publish-docker]"in content)assert "always()" in contentassert "needs.build.result == 'success'" in content+ assert "needs.build-wheels.result == 'success'" in content+ assert "needs.collect-dist.result == 'success'" in contentdef test_macos_native_wrapper_dependency_install_retries_pypi_downloads() -> None: