Skip to content

feat(run-docker-container): run a docker_image artifact without building - #574

Merged
earakely-scale merged 1 commit into
mainfrom
edgararakelyan/run-docker-container-image
Nov 9, 2026
Merged

earakely-scale merged 1 commit into
mainfrom
edgararakelyan/run-docker-container-image

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

run_docker_container always staged a build context and ran docker build, even when the image already existed. A task run many times, for example as RL episodes, paid a build for every episode. Pre-building a base and having each episode build only FROM <base> still means a build per episode, and under load that was 214 s for 16 episodes.

run_docker_container now also takes image_artifact_id / image_artifact_version: a docker_image artifact whose image it runs as it is. A step names exactly one of that, docker_context_artifact_id and docker_context_url.

  • The image goes onto the sandbox through load_docker_images, as install_agent puts an agent's image there. It's pulled by digest, loaded from a tar.gz, or built from its build context, only where the sandbox doesn't already hold it. Then docker run starts it, with nothing staged and nothing built.
  • On the local sandbox, a context-only image is built once per sources (host_images.build returns when this machine holds one built from the same sources). Later runs only inspect it, and a sandbox's teardown leaves it, since it doesn't carry the sandbox's label.
  • In a bundle, the step names an image folder, for example artifacts/task-image/ with a Dockerfile, or ref = "<image>" in its artifact.toml.
  • image_tag and build_args only apply to a build, so beside an image artifact they're a config problem, not silently ignored.

Tests

  • tst/unit/task_step/run_docker_container_test.py: the fields round-trip, two sources are refused, build options beside an image are a config problem, and a run loads the image and starts it with nothing staged or built.
  • tst/integration/task_step/test_run_docker_container_local.py: two runs of one context-only image artifact on the local sandbox. The first builds it, the second builds nothing, and teardown leaves the image.
  • tst/integration/cli/run_bundle_task_image_test.py (slow tier): agent-env run of a bundle task whose container comes from an image folder and is graded through a reward file. The first run builds once, and a rerun builds nothing.
  • On Linux (Ubuntu 24.04, Python 3.12, Docker 29.9): the new and existing run_docker_container integration tests and the bundle test pass (5). make unit-test passes apart from two MCP CLI codegen tests that also fail on main on that box; 14,164 passed, 9 skipped. ruff check is clean.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 4/5

The PR appears safe to merge, with a non-blocking cleanup issue in the new bundle test.

Fix All in CursorFindings

  1. P2 Test images accumulate ▶
Fix with agent prompt
### Issue 1
tst/integration/cli/run_bundle_task_image_test.py:61-69
This test leaves its Docker image behind. Its temporary bundle gets a new image name on each test run, and sandbox teardown deliberately keeps that image. Add a `finally` block that removes it after the reuse assertions, including when an assertion fails, so repeated test runs do not fill Docker storage.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

run_docker_container can now load a docker_image artifact instead of staging and building a context.

  • Task containers can start from a Docker image artifact.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Source{Container source} -->|Image artifact| Load[Load image through sandbox]
  Source -->|Context artifact or URL| Build[Stage context and build image]
  Load --> Run[Start labelled container]
  Build --> Run
  Run --> Record[Record container in task context]
Loading

Reviews (1) · Last reviewed commit: "feat(run-docker-container): run a docker..." · Reviewed by Greptile

run_docker_container always staged a build context and ran docker build, even
for an image that already existed, so a task run many times paid a build per
run. It now also takes image_artifact_id / image_artifact_version, a
docker_image artifact it runs as it is: the image is put on the sandbox with
load_docker_images, as install_agent puts an agent's there, and started with
nothing staged or built. On the local sandbox a context-only image is built
once per sources and kept across runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 9, 2026 21:00
Comment on lines +61 to +69
first = CliRunner().invoke(cli, ["run", str(root)])

assert first.exit_code == 0 and "tasks/grade.json v1: passed" in first.output, first.output
assert len(builds) == 1, (first.output, builds)

again = CliRunner().invoke(cli, ["run", str(root)])

assert again.exit_code == 0 and "tasks/grade.json v1: passed" in again.output, again.output
assert "building with docker" not in again.output and len(builds) == 1, (again.output, builds)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Test images accumulate

This test leaves its Docker image behind. Its temporary bundle gets a new image name on each test run, and sandbox teardown deliberately keeps that image. Add a finally block that removes it after the reuse assertions, including when an assertion fails, so repeated test runs do not fill Docker storage.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tst/integration/cli/run_bundle_task_image_test.py
Line: 61-69

Comment:
**Test images accumulate**

This test leaves its Docker image behind. Its temporary bundle gets a new image name on each test run, and sandbox teardown deliberately keeps that image. Add a `finally` block that removes it after the reuse assertions, including when an assertion fails, so repeated test runs do not fill Docker storage.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Cursor Fix in Claude Code Fix in Codex

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. This PR is merged, so the cleanup (removing the image in a finally) goes into the next PR.

@earakely-scale
earakely-scale merged commit 3e42df1 into main Nov 9, 2026
34 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/run-docker-container-image branch November 9, 2026 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant