Skip to content

: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.

chore(ci): install the sandbox agent from the release tarball (#106658)

Alessandro Pogliaghieee9f0ae0d37
diff --git a/.github/workflows/cd-sandbox-base-image.yml b/.github/workflows/cd-sandbox-base-image.yml
index 0f8f5c14e3f5..910633ff9136 100644
--- a/.github/workflows/cd-sandbox-base-image.yml
+++ b/.github/workflows/cd-sandbox-base-image.yml
@@ -90,7 +90,7 @@ jobs:
wait_for_agent:
needs: changes
- name: Wait for npm to serve the pinned agent
+ name: Wait for the pinned agent to be published
if: |
github.repository_owner == 'PostHog' &&
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && (
@@ -108,22 +108,28 @@ jobs:
sparse-checkout: products/tasks/backend/sandbox/images/Dockerfile.sandbox-base
sparse-checkout-cone-mode: false
- - name: Poll npm for the pinned version
+ - name: Poll GitHub and npm for the pinned version
run: |
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)
if [ -z "$pinned" ]; then
echo "::error::no ARG AGENT_VERSION line in Dockerfile.sandbox-base"
exit 1
fi
+ tarball="https://github.com/${GITHUB_REPOSITORY}/releases/download/agent-v${pinned}/posthog-agent-${pinned}.tgz"
for attempt in $(seq 1 120); do
+ if [ -n "$sha" ] && curl -fsIL --connect-timeout 10 -o /dev/null "$tarball"; then
+ echo "GitHub serves $tarball (attempt $attempt)"
+ exit 0
+ fi
if [ "$(npm view "@posthog/agent@${pinned}" version 2>/dev/null)" = "$pinned" ]; then
echo "npm serves @posthog/agent@${pinned} (attempt $attempt)"
exit 0
fi
- echo "npm does not serve @posthog/agent@${pinned} yet (attempt $attempt)"
+ echo "neither GitHub nor npm serves @posthog/agent@${pinned} yet (attempt $attempt)"
sleep 10
done
- echo "::error::npm did not serve @posthog/agent@${pinned} within 20 minutes"
+ echo "::error::@posthog/agent@${pinned} was not published within 20 minutes"
exit 1
build_skills:
diff --git a/.github/workflows/desktop-agent-release.yml b/.github/workflows/desktop-agent-release.yml
index 5755b7d79542..5f41e681921c 100644
--- a/.github/workflows/desktop-agent-release.yml
+++ b/.github/workflows/desktop-agent-release.yml
@@ -27,6 +27,7 @@ jobs:
id-token: write
outputs:
version: ${{ steps.version.outputs.version }}
+ tarball_sha256: ${{ steps.pack.outputs.tarball_sha256 }}
defaults:
run:
working-directory: products/desktop
@@ -67,6 +68,25 @@ jobs:
- name: Build and test agent release
uses: ./.github/actions/desktop-build-agent-release
+ - name: Pack the release tarball
+ id: pack
+ working-directory: products/desktop/packages/agent
+ env:
+ AGENT_VERSION: ${{ steps.version.outputs.version }}
+ run: |
+ pnpm pack --pack-destination "$RUNNER_TEMP"
+ cd "$RUNNER_TEMP"
+ sha256sum "posthog-agent-${AGENT_VERSION}.tgz" > "posthog-agent-${AGENT_VERSION}.tgz.sha256"
+ echo "tarball_sha256=$(cut -d' ' -f1 "posthog-agent-${AGENT_VERSION}.tgz.sha256")" >> "$GITHUB_OUTPUT"
+
+ - name: Upload the tarball for the release job
+ uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
+ with:
+ name: agent-tarball
+ path: ${{ runner.temp }}/posthog-agent-*.tgz*
+ if-no-files-found: error
+ retention-days: 1
+
- name: Publish the package to npm registry
working-directory: products/desktop/packages/agent
run: pnpm publish --access public --no-git-checks
@@ -146,9 +166,58 @@ jobs:
- type: "mrkdwn"
text: "*Run*\n<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Desktop Agent Release #${{ github.run_number }}>"
+ attach-tarball:
+ name: Attach the tarball to a GitHub release
+ needs: release
+ runs-on: ubuntu-24.04
+ timeout-minutes: 5
+ permissions:
+ contents: write
+ outputs:
+ tarball_sha256: ${{ steps.attach.outputs.tarball_sha256 }}
+ steps:
+ - name: Download the tarball
+ uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
+ with:
+ name: agent-tarball
+ path: ${{ runner.temp }}
+
+ - name: Create the release
+ id: attach
+ env:
+ GH_TOKEN: ${{ github.token }}
+ TAG: ${{ github.ref_name }}
+ AGENT_VERSION: ${{ needs.release.outputs.version }}
+ TARBALL_SHA256: ${{ needs.release.outputs.tarball_sha256 }}
+ run: |
+ tarball="$RUNNER_TEMP/posthog-agent-${AGENT_VERSION}.tgz"
+ checksum="${tarball}.sha256"
+ if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then
+ existing=$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name')
+ for asset in "$tarball" "$checksum"; do
+ name=$(basename "$asset")
+ if printf '%s\n' "$existing" | grep -qxF "$name"; then
+ gh release download "$TAG" --repo "$GITHUB_REPOSITORY" --pattern "$name" --output "$RUNNER_TEMP/existing-$name"
+ if ! cmp -s "$asset" "$RUNNER_TEMP/existing-$name"; then
+ echo "::error::$name on the $TAG release differs from the one this run built"
+ exit 1
+ fi
+ echo "$name is already attached to $TAG and matches this run's build"
+ else
+ gh release upload "$TAG" "$asset" --repo "$GITHUB_REPOSITORY"
+ fi
+ done
+ else
+ gh release create "$TAG" "$tarball" "$checksum" --repo "$GITHUB_REPOSITORY" \
+ --title "@posthog/agent ${AGENT_VERSION}" \
+ --notes "https://www.npmjs.com/package/@posthog/agent/v/${AGENT_VERSION}" \
+ --latest=false
+ fi
+ echo "tarball_sha256=$TARBALL_SHA256" >> "$GITHUB_OUTPUT"
+
bump-sandbox-agent-pin:
name: Open a PR bumping the sandbox agent pin
- needs: [release, notify-release]
+ needs: [release, notify-release, attach-tarball]
# notify-release runs on !cancelled(), so this job restates the release gate it used to inherit.
if: ${{ !cancelled() && needs.release.result == 'success' }}
runs-on: ubuntu-24.04
@@ -161,6 +230,7 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
AGENT_VERSION: ${{ needs.release.outputs.version }}
+ TARBALL_SHA256: ${{ needs.attach-tarball.outputs.tarball_sha256 }}
SLACK_THREAD_TS: ${{ needs.notify-release.outputs.thread_ts }}
run: |
echo "Dispatching sandbox agent pin bump to $AGENT_VERSION"
@@ -168,4 +238,5 @@ jobs:
--repo PostHog/posthog \
--ref master \
-f version="$AGENT_VERSION" \
+ -f tarball_sha256="$TARBALL_SHA256" \
-f slack_thread_ts="$SLACK_THREAD_TS"
diff --git a/.github/workflows/update-sandbox-agent-version.yml b/.github/workflows/update-sandbox-agent-version.yml
index e41940ecc51e..db6ef1913e4c 100644
--- a/.github/workflows/update-sandbox-agent-version.yml
+++ b/.github/workflows/update-sandbox-agent-version.yml
@@ -9,6 +9,10 @@ on:
description: 'Agent version to pin. Defaults to the npm "latest" dist-tag.'
required: false
type: string
+ tarball_sha256:
+ description: 'sha256 of the release tarball for that version. The release workflow sets it; leave it empty to install from npm.'
+ required: false
+ type: string
slack_thread_ts:
description: 'Slack thread of the release post to reply in. The release workflow sets it.'
required: false
@@ -69,6 +73,7 @@ jobs:
id: resolve
env:
REQUESTED_VERSION: ${{ inputs.version }}
+ REQUESTED_SHA256: ${{ inputs.tarball_sha256 }}
run: |
latest="$REQUESTED_VERSION"
for attempt in 1 2 3; do
@@ -85,6 +90,16 @@ jobs:
echo "latest=$latest" >> "$GITHUB_OUTPUT"
echo "BRANCH=${BRANCH_PREFIX}${latest}" >> "$GITHUB_ENV"
+ sha="$REQUESTED_SHA256"
+ if [ -n "$sha" ] && ! printf '%s' "$sha" | grep -qE '^[0-9a-f]{64}$'; then
+ echo "tarball_sha256 input '$sha' is not a sha256 digest" >&2
+ exit 1
+ fi
+ if [ -z "$sha" ]; then
+ echo "no tarball digest was passed, so the image installs from npm"
+ fi
+ echo "tarball_sha256=$sha" >> "$GITHUB_OUTPUT"
+
pinned=$(sed -n 's/^ARG AGENT_VERSION=//p' "$DOCKERFILE")
if [ -z "$pinned" ]; then
echo "no ARG AGENT_VERSION line in $DOCKERFILE" >&2
@@ -146,8 +161,10 @@ jobs:
if: 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"
if git diff --quiet "$DOCKERFILE"; then
echo "could not rewrite ARG AGENT_VERSION in $DOCKERFILE" >&2
exit 1
@@ -256,7 +273,13 @@ jobs:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
LATEST: ${{ steps.resolve.outputs.latest }}
PINNED: ${{ steps.resolve.outputs.pinned }}
+ TARBALL_SHA256: ${{ steps.resolve.outputs.tarball_sha256 }}
run: |
+ if [ -n "$TARBALL_SHA256" ]; then
+ digest_note="\`AGENT_TARBALL_SHA256\` set to the digest of the \`agent-v${LATEST}\` release tarball"
+ else
+ digest_note="\`AGENT_TARBALL_SHA256\` cleared, because no release tarball digest was passed for \`agent-v${LATEST}\`, so the image installs from npm"
+ fi
{
cat <<BODY
## Problem
@@ -265,9 +288,9 @@ jobs:
## Changes
- - \`Dockerfile.sandbox-base\`: \`AGENT_VERSION\` \`${PINNED}\` to \`${LATEST}\`.
+ - \`Dockerfile.sandbox-base\`: \`AGENT_VERSION\` \`${PINNED}\` to \`${LATEST}\`; ${digest_note}.
- The sandbox image workflow waits for npm to serve \`${LATEST}\`, builds this image and smokes it on both architectures. This workflow then runs one Claude turn and one Codex turn with that image through the production Go ai-gateway. When both checks pass, the release app approves this PR and adds it to the merge queue. Close it before the queue lands it to keep \`${PINNED}\`. A newer release opens its own PR and closes this one.
+ The sandbox image workflow waits for \`${LATEST}\` to be published, builds this image and smokes it on both architectures. This workflow then runs one Claude turn and one Codex turn with that image through the production Go ai-gateway. When both checks pass, the release app approves this PR and adds it to the merge queue. Close it before the queue lands it to keep \`${PINNED}\`. A newer release opens its own PR and closes this one.
BODY
cat delta.md
diff --git a/products/tasks/backend/sandbox/images/Dockerfile.sandbox-base b/products/tasks/backend/sandbox/images/Dockerfile.sandbox-base
index 81e83d89a4fb..225405291d67 100644
--- a/products/tasks/backend/sandbox/images/Dockerfile.sandbox-base
+++ b/products/tasks/backend/sandbox/images/Dockerfile.sandbox-base
@@ -162,11 +162,20 @@ 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_URL=https://github.com/PostHog/posthog/releases/download/agent-v${AGENT_VERSION}/posthog-agent-${AGENT_VERSION}.tgz
ARG COMMIT_HASH
RUN mkdir -p /scripts && \
cd /scripts && \
npm init -y && \
- CACHE_BUST=${COMMIT_HASH} npm install "@posthog/agent@${AGENT_VERSION}"
+ if [ -n "${AGENT_TARBALL_SHA256}" ] && curl -fsSL --retry 3 --retry-all-errors -o /tmp/posthog-agent.tgz "${AGENT_TARBALL_URL}"; then \
+ echo "${AGENT_TARBALL_SHA256} /tmp/posthog-agent.tgz" | sha256sum -c - && \
+ CACHE_BUST=${COMMIT_HASH} npm install /tmp/posthog-agent.tgz && \
+ rm /tmp/posthog-agent.tgz; \
+ else \
+ CACHE_BUST=${COMMIT_HASH} npm install "@posthog/agent@${AGENT_VERSION}"; \
+ fi && \
+ npm pkg set "dependencies.@posthog/agent=${AGENT_VERSION}"
# Install pre-built skills (PostHog + context-mill) into the plugin directory.
# The dist/skills/ directory is populated by the CD workflow's build_skills job.