Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/sandbox-executor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,49 @@ ENV PATH="/home/holon/.local/bin:/home/holon/.local/node_modules/.bin:${PATH}"
RUN mkdir -p /home/holon/.cache
# Build-time smoke check as the holon user: an image without a working uv fails to build
RUN uv --version
ARG SOURCE_COMMIT=unknown
LABEL org.holon.source-commit="${SOURCE_COMMIT}"

# --- Claude Agent Layer ---
FROM holon-base AS agent-claude
RUN --mount=type=cache,id=npm-claude,uid=1000,gid=1000,target=/home/holon/.npm \
echo "allow-scripts=@anthropic-ai/claude-code" > /home/holon/.npmrc && \
npm install --prefix /home/holon/.local --prefer-offline --no-audit --no-fund @anthropic-ai/claude-code@2.1.302
ARG SOURCE_COMMIT=unknown
LABEL org.holon.source-commit="${SOURCE_COMMIT}"

# --- OpenCode Agent Layer (opencode) ---
FROM holon-base AS agent-opencode
RUN --mount=type=cache,id=npm-opencode,uid=1000,gid=1000,target=/home/holon/.npm \
echo "allow-scripts=opencode-ai" > /home/holon/.npmrc && \
npm install --prefix /home/holon/.local --prefer-offline --no-audit --no-fund opencode-ai@1.19.3
ARG SOURCE_COMMIT=unknown
LABEL org.holon.source-commit="${SOURCE_COMMIT}"

# --- Pi Agent Layer ---
FROM holon-base AS agent-pi
RUN --mount=type=cache,id=npm-pi,uid=1000,gid=1000,target=/home/holon/.npm \
echo "allow-scripts=@google/genai,protobufjs" > /home/holon/.npmrc && \
npm install --prefix /home/holon/.local --prefer-offline --no-audit --no-fund @earendil-works/pi-coding-agent@1.3.0
ARG SOURCE_COMMIT=unknown
LABEL org.holon.source-commit="${SOURCE_COMMIT}"

# --- Codex Agent Layer ---
FROM holon-base AS agent-codex
RUN --mount=type=cache,id=npm-codex,uid=1000,gid=1000,target=/home/holon/.npm \
npm install --prefix /home/holon/.local --prefer-offline --no-audit --no-fund @openai/codex@0.163.0
ARG SOURCE_COMMIT=unknown
LABEL org.holon.source-commit="${SOURCE_COMMIT}"

# --- Antigravity Agent Layer ---
FROM holon-base AS agent-antigravity
RUN --mount=type=cache,id=uv-antigravity,uid=1000,gid=1000,target=/home/holon/.cache/uv \
--mount=type=cache,id=npm-antigravity,uid=1000,gid=1000,target=/home/holon/.npm \
curl --proto '=https' --tlsv1.2 -fsSL --compressed https://antigravity.google/cli/install.sh -o /tmp/install.sh && bash /tmp/install.sh && rm -f /tmp/install.sh
ARG SOURCE_COMMIT=unknown
LABEL org.holon.source-commit="${SOURCE_COMMIT}"

# --- Final Orchestrator Image ---
FROM holon-base AS holon-orchestrator
ARG SOURCE_COMMIT=unknown
LABEL org.holon.source-commit="${SOURCE_COMMIT}"
7 changes: 7 additions & 0 deletions apps/sandbox-executor/build_all_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ print_log_with_timestamps() {
done
}

resolve_source_commit() {
git -C "$REPO_ROOT" rev-parse --verify --quiet HEAD 2>/dev/null || echo "unknown"
}

if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo "Starting Docker Buildx Bake build for all Holon images..."
# why: the export overlays only the docker buildx bake child, whose SOURCE_COMMIT variable feeds each target's arg and label
export SOURCE_COMMIT="${SOURCE_COMMIT:-$(resolve_source_commit)}"
echo "Stamping org.holon.source-commit=${SOURCE_COMMIT} on every image"

# Build the bake arguments
BAKE_ARGS=("-f" "$SCRIPT_DIR/docker-bake.hcl" "--load")
Expand Down
10 changes: 10 additions & 0 deletions apps/sandbox-executor/docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ variable "CI" {
default = "false"
}

variable "SOURCE_COMMIT" {
default = "unknown"
}

target "common" {
context = "apps/sandbox-executor"
dockerfile = "Dockerfile"
cache-from = CI == "true" ? ["type=gha,scope=holon-sandbox-executor"] : []
cache-to = CI == "true" ? ["type=gha,mode=max,scope=holon-sandbox-executor"] : []
args = {
SOURCE_COMMIT = SOURCE_COMMIT
}
labels = {
"org.holon.source-commit" = SOURCE_COMMIT
}
}

target "base" {
Expand Down
24 changes: 19 additions & 5 deletions apps/sandbox-executor/src/sandbox_executor/preflight.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from dataclasses import dataclass
from typing import Any

from sandbox_executor import claude_token_migration, local_llm, preflight_cooldown
from sandbox_executor import claude_token_migration, local_llm, preflight_cooldown, preflight_image_commit
from sandbox_executor.agent_defaults import AGENT_IMAGE_MAPPING, normalise_agent_id
from sandbox_executor.claude_credential import pin_claude_credential, resolve_claude_credential_with_lookup
from sandbox_executor.preflight_model_error import is_model_error
Expand All @@ -36,6 +36,10 @@
_DOCKER_RUN_ENV_FILE_INSERT_INDEX = 2
_PROBE_CONTAINER_PREFIX = "holon-preflight-"
_PROBE_CONTAINER_ID_LENGTH = 12
_STALE_IMAGE_HINT = (
"Rebuild the Holon images from this checkout (make build-images) so the runner image matches the host engine, "
"or pass --skip-preflight (HOLON_SKIP_PREFLIGHT=1) to launch anyway."
)


_DECISIVE_TIMEOUT_STATUSES = (
Expand Down Expand Up @@ -251,6 +255,17 @@ def _early_probe_result(agent: str, agent_id: str, model: str, image: str) -> Pr
return preflight_cooldown.active_cooldown_result(agent, model, image)


def _real_docker_blocker(agent: str, model: str, image: str) -> PreflightResult | None:
if not shutil.which("docker"):
return _result(
PreflightStatus.UNKNOWN, agent, model, image, hint="'docker' CLI command not found. Please install Docker."
)
check = preflight_image_commit.check_image_source_commit(image)
if check is not None and check.stale:
return _result(PreflightStatus.UNKNOWN, agent, model, image, output=check.describe(), hint=_STALE_IMAGE_HINT)
return None


def run_preflight_probe(
agent: str,
model: str,
Expand All @@ -266,10 +281,9 @@ def run_preflight_probe(
if early := _early_probe_result(agent, agent_id, model, image):
return early

if runner_fn is None and not shutil.which("docker"):
return _result(
PreflightStatus.UNKNOWN, agent, model, image, hint="'docker' CLI command not found. Please install Docker."
)
# why: an injected runner has no real image to inspect, so the image commit check runs only against real docker
if runner_fn is None and (blocked := _real_docker_blocker(agent, model, image)):
return blocked

from sandbox_executor.launcher import env_files, mounts

Expand Down
122 changes: 122 additions & 0 deletions apps/sandbox-executor/src/sandbox_executor/preflight_image_commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
from __future__ import annotations

import json
import logging
import re
import subprocess
from collections.abc import Callable
from dataclasses import dataclass
from pathlib import Path

logger = logging.getLogger(__name__)

IMAGE_SOURCE_COMMIT_LABEL = "org.holon.source-commit"
FULL_COMMIT_SHA_RE = re.compile(r"^[0-9a-f]{40}$")
ENGINE_SOURCE_DIR = Path(__file__).resolve().parents[2]
IMAGE_BUILD_INPUTS = ("src", "entrypoint", "Dockerfile")
GIT_TIMEOUT_SECONDS = 10.0
INSPECT_TIMEOUT_SECONDS = 10.0

CommandRunner = Callable[..., subprocess.CompletedProcess[str]]


@dataclass(frozen=True)
class ImageCommitCheck:
image: str
image_commit: str
host_commit: str | None
build_inputs_changed: bool
image_commit_found: bool = True

@property
def stale(self) -> bool:
# why: inputs that cannot be compared are not known to match, so an unresolvable image commit still blocks
return self.build_inputs_changed or not self.image_commit_found

def describe(self) -> str:
inputs = ", ".join(IMAGE_BUILD_INPUTS)
if not self.image_commit_found:
verdict = "cannot be compared: the image commit is not in the host checkout's history"
else:
verdict = "differ" if self.build_inputs_changed else "match"
return (
f"image {self.image} built from {self.image_commit}; "
f"host engine at {self.host_commit or 'unresolved'}; build inputs ({inputs}) {verdict}"
)


def _run_quietly(run: CommandRunner, cmd: list[str], timeout: float) -> subprocess.CompletedProcess[str] | None:
try:
return run(cmd, capture_output=True, text=True, timeout=timeout, check=False)
except (OSError, subprocess.TimeoutExpired):
return None


def _full_sha_or_none(value: object) -> str | None:
if isinstance(value, str) and FULL_COMMIT_SHA_RE.match(value.strip()):
return value.strip()
return None


def read_image_source_commit(image: str, run: CommandRunner) -> str | None:
cmd = ["docker", "image", "inspect", "--format", "{{json .Config.Labels}}", image]
completed = _run_quietly(run, cmd, INSPECT_TIMEOUT_SECONDS)
if completed is None or completed.returncode != 0:
return None
try:
labels = json.loads(completed.stdout or "")
except json.JSONDecodeError:
return None
if not isinstance(labels, dict):
return None
return _full_sha_or_none(labels.get(IMAGE_SOURCE_COMMIT_LABEL))


def host_source_commit(run: CommandRunner, source_dir: Path) -> str | None:
completed = _run_quietly(run, ["git", "-C", str(source_dir), "rev-parse", "HEAD"], GIT_TIMEOUT_SECONDS)
if completed is None or completed.returncode != 0:
return None
return _full_sha_or_none(completed.stdout)


def commit_exists(run: CommandRunner, source_dir: Path, commit: str) -> bool:
cmd = ["git", "-C", str(source_dir), "cat-file", "-e", f"{commit}^{{commit}}"]
completed = _run_quietly(run, cmd, GIT_TIMEOUT_SECONDS)
return completed is not None and completed.returncode == 0


def build_inputs_changed_since(run: CommandRunner, source_dir: Path, image_commit: str) -> bool:
# why: diffing against the working tree, not HEAD, also catches uncommitted engine edits the image cannot contain
cmd = ["git", "-C", str(source_dir), "diff", "--quiet", image_commit, "--", *IMAGE_BUILD_INPUTS]
completed = _run_quietly(run, cmd, GIT_TIMEOUT_SECONDS)
return completed is None or completed.returncode != 0


def check_image_source_commit(
image: str, run: CommandRunner = subprocess.run, source_dir: Path = ENGINE_SOURCE_DIR
) -> ImageCommitCheck | None:
image_commit = read_image_source_commit(image, run)
if image_commit is None:
logger.warning("Image %s has no readable %s label; skipping the commit check", image, IMAGE_SOURCE_COMMIT_LABEL)
return None
host_commit = host_source_commit(run, source_dir)
if host_commit is None:
logger.warning("Host engine at %s is not a git checkout; skipping the image commit check.", source_dir)
return None
if not commit_exists(run, source_dir, image_commit):
return ImageCommitCheck(
image=image,
image_commit=image_commit,
host_commit=host_commit,
build_inputs_changed=False,
image_commit_found=False,
)
check = ImageCommitCheck(
image=image,
image_commit=image_commit,
host_commit=host_commit,
build_inputs_changed=build_inputs_changed_since(run, source_dir, image_commit),
)
if image_commit != host_commit and not check.stale:
logger.info("Image %s is from an older commit but its build inputs are unchanged: %s", image, check.describe())
return check
Loading
Loading