:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(tasks): quote the sandbox agent tarball digest default (#107642)
Alessandro Pogliaghi4203a7a364d2
diff --git a/.github/scripts/test_sandbox_agent_release.py b/.github/scripts/test_sandbox_agent_release.pyindex 6171121a7c2b..17a53bd5898c 100644--- a/.github/scripts/test_sandbox_agent_release.py+++ b/.github/scripts/test_sandbox_agent_release.py@@ -198,3 +198,35 @@ docker() {PLATFORMS=platforms,)assert (result.returncode == 0) == ok, result.stderr++[email protected]("digest", ["c" * 64, ""])+def test_bump_quotes_the_tarball_digest_default(tmp_path: Path, digest: str) -> None:+ dockerfile = tmp_path / "Dockerfile"+ dockerfile.write_text(f'ARG AGENT_VERSION=1.0.0\nARG AGENT_TARBALL_SHA256="{"a" * 64}"\n')+ subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True)+ subprocess.run(["git", "add", "Dockerfile"], cwd=tmp_path, check=True)+ result = run(+ tmp_path,+ script(UPDATE, "bump"),+ HOME=str(tmp_path),+ DOCKERFILE="Dockerfile",+ LATEST="2.0.0",+ TARBALL_SHA256=digest,+ )+ assert result.returncode == 0, result.stderr+ assert dockerfile.read_text() == f'ARG AGENT_VERSION=2.0.0\nARG AGENT_TARBALL_SHA256="{digest}"\n'++[email protected]("default,source", [(f'"{"c" * 64}"', "GitHub"), ('""', "npm")])+def test_wait_polls_the_tarball_only_when_the_pin_carries_a_digest(tmp_path: Path, default: str, source: str) -> None:+ dockerfile = tmp_path / "products/tasks/backend/sandbox/images/Dockerfile.sandbox-base"+ dockerfile.parent.mkdir(parents=True)+ dockerfile.write_text(f"ARG AGENT_VERSION=1.0.0\nARG AGENT_TARBALL_SHA256={default}\n")+ stubs = """+curl() { return 0; }+npm() { printf '1.0.0\\n'; }+"""+ result = run(tmp_path, stubs + script(BUILD, "wait", "wait_for_agent"))+ assert result.returncode == 0, result.stderr+ assert f"{source} serves" in result.stdoutdiff --git a/.github/workflows/cd-sandbox-base-image.yml b/.github/workflows/cd-sandbox-base-image.ymlindex 910633ff9136..7a1d3cede996 100644--- a/.github/workflows/cd-sandbox-base-image.yml+++ b/.github/workflows/cd-sandbox-base-image.yml@@ -109,9 +109,10 @@ jobs:sparse-checkout-cone-mode: false- name: Poll GitHub and npm for the pinned version+ id: waitrun: |pinned=$(sed -n 's/^ARG AGENT_VERSION=//p' products/tasks/backend/sandbox/images/Dockerfile.sandbox-base)- sha=$(sed -n 's/^ARG AGENT_TARBALL_SHA256=//p' products/tasks/backend/sandbox/images/Dockerfile.sandbox-base)+ sha=$(sed -n 's/^ARG AGENT_TARBALL_SHA256=//p' products/tasks/backend/sandbox/images/Dockerfile.sandbox-base | tr -d '"')if [ -z "$pinned" ]; thenecho "::error::no ARG AGENT_VERSION line in Dockerfile.sandbox-base"exit 1diff --git a/.github/workflows/update-sandbox-agent-version.yml b/.github/workflows/update-sandbox-agent-version.ymlindex db6ef1913e4c..1c8c7eeac518 100644--- a/.github/workflows/update-sandbox-agent-version.yml+++ b/.github/workflows/update-sandbox-agent-version.yml@@ -158,13 +158,14 @@ jobs:} >> "$GITHUB_OUTPUT"- name: Bump the pin+ id: bumpif: steps.state.outputs.action == 'bump'env:LATEST: ${{ steps.resolve.outputs.latest }}TARBALL_SHA256: ${{ steps.resolve.outputs.tarball_sha256 }}run: |sed -i "s/^ARG AGENT_VERSION=.*/ARG AGENT_VERSION=${LATEST}/" "$DOCKERFILE"- sed -i "s/^ARG AGENT_TARBALL_SHA256=.*/ARG AGENT_TARBALL_SHA256=${TARBALL_SHA256}/" "$DOCKERFILE"+ sed -i "s/^ARG AGENT_TARBALL_SHA256=.*/ARG AGENT_TARBALL_SHA256=\"${TARBALL_SHA256}\"/" "$DOCKERFILE"if git diff --quiet "$DOCKERFILE"; thenecho "could not rewrite ARG AGENT_VERSION in $DOCKERFILE" >&2exit 1diff --git a/products/tasks/backend/logic/services/test_modal_sandbox.py b/products/tasks/backend/logic/services/test_modal_sandbox.pyindex 806dded6d22d..53aeb7150527 100644--- a/products/tasks/backend/logic/services/test_modal_sandbox.py+++ b/products/tasks/backend/logic/services/test_modal_sandbox.py@@ -1,9 +1,12 @@+import reimport shutilfrom pathlib import Pathimport pytestfrom unittest.mock import MagicMock, patch+from django.conf import settings+from modal.exception import TimeoutError as ModalTimeoutErrorfrom products.tasks.backend.constants import (@@ -15,6 +18,7 @@ from products.tasks.backend.exceptions import SandboxExecutionErrorfrom products.tasks.backend.logic.services.modal_sandbox import (DEFAULT_MODAL_APP_NAME,LOCAL_MODAL_AGENT_SHADOW_DIR,+ LOCAL_MODAL_DOCKERFILES,LOCAL_MODAL_HOGLI_SHIM_SCRIPT,LOCAL_MODAL_NOTEBOOK_KERNEL_DIR,LOCAL_MODAL_NOTEBOOK_KERNEL_MODULE,@@ -402,6 +406,15 @@ class TestLocalModalBuildContext:shutil.rmtree(context_dir, ignore_errors=True)_prepare_local_modal_build_context.cache_clear()+ @pytest.mark.parametrize("dockerfile", sorted(LOCAL_MODAL_DOCKERFILES.values()), ids=lambda path: path.name)+ def test_dockerfile_has_no_empty_unquoted_arg_default(self, dockerfile: Path):+ lines = (Path(settings.BASE_DIR) / dockerfile).read_text().splitlines()+ bare = [line for line in lines if re.fullmatch(r"ARG\s+\w+=\s*", line)]+ assert bare == [], (+ f"{dockerfile} declares an ARG with an empty unquoted default. Modal's Dockerfile parser rejects it "+ 'in DEBUG builds, although BuildKit accepts it. Write ARG NAME="" instead.'+ )+def test_notebook_context_carries_the_baked_kernel_package(self):# DEBUG builds the notebook image from this trimmed context, not the repo root, so a# Dockerfile COPY whose source is missing here fails the build and no notebookdiff --git a/products/tasks/backend/sandbox/images/Dockerfile.sandbox-base b/products/tasks/backend/sandbox/images/Dockerfile.sandbox-baseindex 225405291d67..4b003b8443ad 100644--- a/products/tasks/backend/sandbox/images/Dockerfile.sandbox-base+++ b/products/tasks/backend/sandbox/images/Dockerfile.sandbox-base@@ -162,7 +162,7 @@ RUN set -eux; \# in a reviewed PR when picking up a new agent release. COMMIT_HASH invalidates# the layer for PostHog-side image changes that keep the agent version unchanged.ARG AGENT_VERSION=2.4.230-ARG AGENT_TARBALL_SHA256=+ARG AGENT_TARBALL_SHA256=""ARG AGENT_TARBALL_URL=https://github.com/PostHog/posthog/releases/download/agent-v${AGENT_VERSION}/posthog-agent-${AGENT_VERSION}.tgzARG COMMIT_HASHRUN mkdir -p /scripts && \diff --git a/products/tasks/turbo.json b/products/tasks/turbo.jsonindex 62b2ba312b23..dfa3816275d7 100644--- a/products/tasks/turbo.json+++ b/products/tasks/turbo.json@@ -3,7 +3,7 @@"tasks": {"backend:test": {// backend/tests/test_constants.py reads the MCP manifest from disk.- "inputs": ["$TURBO_EXTENDS$", "mcp/tools.yaml"]+ "inputs": ["$TURBO_EXTENDS$", "mcp/tools.yaml", "backend/sandbox/images/Dockerfile.*"]}}}