Skip to content

feat: support pre-built base images for faster rebuilds - #2542

Merged
simonrosenberg merged 5 commits into
mainfrom
feat/prebuilt-base-support
Mar 25, 2026
Merged

simonrosenberg merged 5 commits into
mainfrom
feat/prebuilt-base-support

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Mar 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Add explicit Docker build targets that support phased benchmark image builds.

This PR adds support for building these stages directly from the SDK Dockerfile:

  • base-image-minimal
  • base-image
  • builder

It also keeps the base-only build path efficient by using an empty build context for targets that do not need the SDK source tree.

What This Enables

The benchmarks repo can use the SDK Dockerfile as the source of truth for the shared image components:

  1. build and push one shared builder image keyed by SDK SHA
  2. build and push per-instance base-image-minimal images keyed by SWE-bench instance tag
  3. assemble final benchmark images in the benchmarks repo from those prebuilt pieces

This keeps the SDK side focused on exposing the reusable build primitives, while the benchmarks repo owns orchestration.

Changes

  • Add builder, base-image-minimal, and base-image as valid build targets in build.py
  • Add the same targets to TargetType
  • Use an empty temp-dir build context for base-only targets instead of building an SDK sdist unnecessarily
  • Keep the normal image targets and default Dockerfile behavior unchanged

Backward Compatibility

Existing builds for the standard targets continue to work as before. This PR extends the target surface; it does not replace the normal build flow.

Dependency

Used by:

Validation

  • Python API breakage checks passed
  • REST API breakage checks passed
  • Type checks passed

Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22 Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:f3c8e24-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-f3c8e24-python \
  ghcr.io/openhands/agent-server:f3c8e24-python

All tags pushed for this build

ghcr.io/openhands/agent-server:f3c8e24-golang-amd64
ghcr.io/openhands/agent-server:f3c8e24-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:f3c8e24-golang-arm64
ghcr.io/openhands/agent-server:f3c8e24-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:f3c8e24-java-amd64
ghcr.io/openhands/agent-server:f3c8e24-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:f3c8e24-java-arm64
ghcr.io/openhands/agent-server:f3c8e24-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:f3c8e24-python-amd64
ghcr.io/openhands/agent-server:f3c8e24-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-amd64
ghcr.io/openhands/agent-server:f3c8e24-python-arm64
ghcr.io/openhands/agent-server:f3c8e24-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-arm64
ghcr.io/openhands/agent-server:f3c8e24-golang
ghcr.io/openhands/agent-server:f3c8e24-java
ghcr.io/openhands/agent-server:f3c8e24-python

About Multi-Architecture Support

  • Each variant tag (e.g., f3c8e24-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., f3c8e24-python-amd64) are also available if needed

simonrosenberg pushed a commit to OpenHands/benchmarks that referenced this pull request Mar 20, 2026
Add two-phase build support for SWE-bench images:

Phase 1: Build pre-built base images (base-image-minimal stage)
- New script: benchmarks/swebench/build_base_images.py
- Tags as ghcr.io/openhands/eval-base:{custom_tag}
- SDK-independent, only rebuilds when upstream SWE-bench image changes

Phase 2: Build agent images using pre-built bases
- New --use-prebuilt-bases flag in build_images.py
- Passes prebuilt_base through build_utils → SDK BuildOptions
- SDK Dockerfile's SOURCE_MINIMAL_BASE ARG skips base-image-minimal

Expected impact: new SDK with same instances goes from ~5-6h to ~30-45min.

Depends on: OpenHands/software-agent-sdk#2542

Closes #538

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@simonrosenberg
simonrosenberg force-pushed the feat/prebuilt-base-support branch from 82003c2 to b067387 Compare March 20, 2026 21:24
@github-actions

github-actions Bot commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Mar 20, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server/docker
   build.py51416268%81, 84–85, 99, 104, 108–110, 114, 119, 136–141, 144, 167, 169, 177, 179–180, 182–186, 188, 192, 195, 198–201, 203–205, 207, 209, 211, 213, 217–218, 303–304, 308–309, 313–314, 318–319, 332, 334–342, 422, 450–451, 453, 524, 538, 541, 545–546, 550–551, 555, 571–573, 576, 582–585, 595, 610, 631, 661, 680–681, 685–687, 741, 752–753, 777, 837, 847–848, 915–916, 921, 924, 931, 936, 941, 947, 952, 959–960, 965, 970, 976, 982, 987, 996, 999–1005, 1008–1010, 1013, 1027–1032, 1034–1035, 1037–1039, 1042–1043, 1047–1050, 1052, 1061, 1073, 1076, 1092–1097, 1099–1100, 1102–1106, 1108, 1115, 1119
TOTAL16333262583% 

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Acceptable - Pragmatic solution to a real problem (5-6h → 30-45min builds). Core design is solid with good backward compatibility. A couple of clarifications needed before merge.

@simonrosenberg

Copy link
Copy Markdown
Member Author

Addressed both review comments in 6e1b312:

  1. prebuilt_base validator: Added a model_validator that raises ValueError when prebuilt_base is set with a target other than source-minimal or source. Updated the field description to document this constraint.

  2. is_base_only excluding builder: Confirmed intentional — builder COPYs SDK source from the build context (Dockerfile lines 35-39), so it needs the full sdist context. Base-image targets only use FROM + RUN, so the empty temp dir is sufficient.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Good taste - Pragmatic solution that cuts build time from 5-6h to 30-45min. The empty context optimization for base-only targets is exactly right—skip expensive work when it's not needed. Clean, backward compatible, well-commented. LGTM!

Debug Agent and others added 5 commits March 24, 2026 17:36
Add Dockerfile ARGs (SOURCE_MINIMAL_BASE, SOURCE_BASE) that allow final
build targets to reference a pre-built base image instead of always
building base-image-minimal from scratch.  When the ARG is left at its
default the behaviour is identical to before; when overridden with an
image reference (e.g. ghcr.io/openhands/eval-base:tag) Docker pulls the
cached base and skips the base-image-minimal stage entirely.

Also adds:
- `prebuilt_base` field to BuildOptions
- Automatic --build-arg injection in build_with_telemetry() when
  prebuilt_base is set
- base-image-minimal / base-image as valid build targets (for building
  and pushing base images independently)
- Empty build context for base-only targets (skips uv build --sdist)

This enables a two-phase build workflow where base images are built once
and agent images are rebuilt in seconds on SDK changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Allows building and pushing just the builder stage independently, enabling
three-phase builds where the builder output is shared across all images.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Pydantic validator uses the Literal type, not VALID_TARGETS set.
Without this, BuildOptions(target="builder") fails validation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Raises ValueError when prebuilt_base is set with a target other than
source-minimal or source. Updated field description to document this.

Addresses review feedback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@simonrosenberg
simonrosenberg force-pushed the feat/prebuilt-base-support branch from 63b1336 to e8ddc72 Compare March 24, 2026 20:36
@simonrosenberg
simonrosenberg merged commit bf4e2dd into main Mar 25, 2026
28 checks passed
@simonrosenberg
simonrosenberg deleted the feat/prebuilt-base-support branch March 25, 2026 11:48
StressTestor pushed a commit to StressTestor/software-agent-sdk that referenced this pull request Jun 1, 2026
Co-authored-by: Debug Agent <debug@example.com>
pengzhang-create pushed a commit to Pyromind-Dynamics/software-agent-sdk that referenced this pull request Aug 13, 2026
Co-authored-by: Debug Agent <debug@example.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants