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): open the sandbox bump PR before npm serves the agent (#106657)

Alessandro Pogliaghiea9048ff95c1
diff --git a/.github/workflows/cd-sandbox-base-image.yml b/.github/workflows/cd-sandbox-base-image.yml
index bd3a6e97e537..0f8f5c14e3f5 100644
--- a/.github/workflows/cd-sandbox-base-image.yml
+++ b/.github/workflows/cd-sandbox-base-image.yml
@@ -88,6 +88,44 @@ jobs:
- 'services/mcp/schema/**'
- '!products/posthog_ai/frontend/**'
+ wait_for_agent:
+ needs: changes
+ name: Wait for npm to serve the pinned agent
+ if: |
+ github.repository_owner == 'PostHog' &&
+ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) && (
+ needs.changes.outputs.sandbox_image == 'true' ||
+ github.event_name == 'workflow_dispatch' ||
+ contains(github.event.pull_request.labels.*.name, 'build-tasks-sandbox-image')
+ )
+ runs-on: ubuntu-24.04
+ timeout-minutes: 25
+ permissions:
+ contents: read
+ steps:
+ - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
+ with:
+ sparse-checkout: products/tasks/backend/sandbox/images/Dockerfile.sandbox-base
+ sparse-checkout-cone-mode: false
+
+ - name: Poll npm for the pinned version
+ run: |
+ pinned=$(sed -n 's/^ARG AGENT_VERSION=//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
+ for attempt in $(seq 1 120); do
+ 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)"
+ sleep 10
+ done
+ echo "::error::npm did not serve @posthog/agent@${pinned} within 20 minutes"
+ exit 1
+
build_skills:
needs: changes
name: Build agent skills from source
@@ -352,13 +390,14 @@ jobs:
retention-days: 1
sandbox_base_build:
- needs: [changes, build_skills, fetch_skills]
+ needs: [changes, build_skills, fetch_skills, wait_for_agent]
name: Build and push Tasks Sandbox container image
if: |
!cancelled() &&
github.repository_owner == 'PostHog' &&
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) &&
- (needs.build_skills.result == 'success' || needs.fetch_skills.result == 'success') && (
+ (needs.build_skills.result == 'success' || needs.fetch_skills.result == 'success') &&
+ needs.wait_for_agent.result == 'success' && (
needs.changes.outputs.sandbox_image == 'true' ||
github.event_name == 'workflow_dispatch' ||
contains(github.event.pull_request.labels.*.name, 'build-tasks-sandbox-image')
@@ -681,11 +720,11 @@ jobs:
text: "${{ steps.message.outputs.text }}"
sandbox_base_smoke_check:
- needs: [build_skills, fetch_skills, sandbox_base_build]
+ needs: [build_skills, fetch_skills, wait_for_agent, sandbox_base_build]
name: Sandbox Base Image Smoke
runs-on: ubuntu-24.04
timeout-minutes: 5
- if: ${{ !cancelled() && (needs.build_skills.result != 'skipped' || needs.fetch_skills.result != 'skipped' || needs.sandbox_base_build.result != 'skipped') && (github.event_name == 'pull_request' || vars.CD_DEPLOY_ENABLED == 'true') }}
+ if: ${{ !cancelled() && (needs.build_skills.result != 'skipped' || needs.fetch_skills.result != 'skipped' || needs.wait_for_agent.result != 'skipped' || needs.sandbox_base_build.result != 'skipped') && (github.event_name == 'pull_request' || vars.CD_DEPLOY_ENABLED == 'true') }}
permissions: {}
steps:
- name: Check the base image build and agent smoke
@@ -705,7 +744,7 @@ jobs:
# paths, and a required check that never reports blocks merging forever.
# Before registering it in the ruleset, remove that paths filter.
sandbox_base_image_check:
- needs: [changes, build_skills, fetch_skills, sandbox_base_build, sandbox_derived_build]
+ needs: [changes, build_skills, fetch_skills, wait_for_agent, sandbox_base_build, sandbox_derived_build]
name: Sandbox Base Image Pass
runs-on: ubuntu-24.04
timeout-minutes: 5
@@ -720,8 +759,13 @@ jobs:
exit 1
fi
+ if [[ "${{ needs.wait_for_agent.result }}" != "success" && "${{ needs.wait_for_agent.result }}" != "skipped" ]]; then
+ echo "Agent version wait failed."
+ exit 1
+ fi
+
# Pass if build wasn't required (no relevant changes, no dispatch, no label)
- if [[ "${{ needs.build_skills.result }}" == "skipped" && "${{ needs.fetch_skills.result }}" == "skipped" && "${{ needs.sandbox_base_build.result }}" == "skipped" ]]; then
+ if [[ "${{ needs.build_skills.result }}" == "skipped" && "${{ needs.fetch_skills.result }}" == "skipped" && "${{ needs.wait_for_agent.result }}" == "skipped" && "${{ needs.sandbox_base_build.result }}" == "skipped" ]]; then
echo "Sandbox image build was skipped (no relevant changes)."
exit 0
fi
diff --git a/.github/workflows/update-sandbox-agent-version.yml b/.github/workflows/update-sandbox-agent-version.yml
index 4a5813159da9..e41940ecc51e 100644
--- a/.github/workflows/update-sandbox-agent-version.yml
+++ b/.github/workflows/update-sandbox-agent-version.yml
@@ -142,22 +142,6 @@ jobs:
echo "declined_by=${declined_by:-}"
} >> "$GITHUB_OUTPUT"
- - name: Wait for npm to serve the version
- if: steps.state.outputs.action == 'bump'
- env:
- LATEST: ${{ steps.resolve.outputs.latest }}
- run: |
- for attempt in $(seq 1 45); do
- if [ "$(npm view "@posthog/agent@${LATEST}" version 2>/dev/null)" = "$LATEST" ]; then
- echo "npm serves @posthog/agent@${LATEST}"
- exit 0
- fi
- echo "npm does not serve @posthog/agent@${LATEST} yet (attempt $attempt)"
- sleep 20
- done
- echo "npm did not serve @posthog/agent@${LATEST} within 15 minutes" >&2
- exit 1
-
- name: Bump the pin
if: steps.state.outputs.action == 'bump'
env:
@@ -198,18 +182,26 @@ jobs:
printf '%s\n' "$commits" | sed -E 's/^([0-9a-f]{40}) (.*)$/- \2 \1/'
fi
echo
- echo "### Dependency changes in the published package"
+ echo "### Dependency changes"
echo
deps_ok=true
- for v in "$PINNED" "$LATEST"; do
- if ! npm view "@posthog/agent@${v}" dependencies --json > "deps-${v}.json" 2>/dev/null; then
+ for tag in "$from_tag" "$to_tag"; do
+ catalog=$(gh api "repos/${REPO}/contents/products/desktop/pnpm-workspace.yaml?ref=${tag}" --jq '.content' 2>/dev/null \
+ | base64 -d | yq -o=json '{"default": (.catalog // {}), "named": (.catalogs // {})}' 2>/dev/null \
+ || echo '{"default": {}, "named": {}}')
+ if ! (set -o pipefail; gh api "repos/${REPO}/contents/products/desktop/packages/agent/package.json?ref=${tag}" --jq '.content' 2>/dev/null \
+ | base64 -d | jq -r --argjson catalog "$catalog" '
+ .dependencies // {} | to_entries[] | .value as $spec
+ | (if $spec == "catalog:" or $spec == "catalog:default" then ($catalog.default[.key] // $spec)
+ elif ($spec | startswith("catalog:")) then ($catalog.named[$spec[8:]][.key] // $spec)
+ else $spec end) as $resolved
+ | "\(.key) \($resolved)"' | sort > "deps-${tag}.txt"); then
deps_ok=false
fi
- jq -r 'to_entries[] | "\(.key) \(.value)"' "deps-${v}.json" 2>/dev/null | sort > "deps-${v}.txt" || deps_ok=false
done
if [ "$deps_ok" != true ]; then
- echo "_Unavailable: npm did not return the dependencies for both versions._"
- elif changed=$(diff "deps-${PINNED}.txt" "deps-${LATEST}.txt" | grep -E '^[<>]'); then
+ echo "_Unavailable: could not read package.json at both tags._"
+ elif changed=$(diff "deps-${from_tag}.txt" "deps-${to_tag}.txt" | grep -E '^[<>]'); then
echo '```diff'
printf '%s\n' "$changed" | sed -E 's/^< /- /; s/^> /+ /'
echo '```'
@@ -269,13 +261,13 @@ jobs:
cat <<BODY
## Problem
- The sandbox base image pins \`@posthog/agent\` so a published release reaches production sandboxes only through a commit on \`master\`. That pin is at \`${PINNED}\`; npm now serves \`${LATEST}\`.
+ The sandbox base image pins \`@posthog/agent\` so a published release reaches production sandboxes only through a commit on \`master\`. That pin is at \`${PINNED}\`; the release published \`${LATEST}\`.
## Changes
- \`Dockerfile.sandbox-base\`: \`AGENT_VERSION\` \`${PINNED}\` to \`${LATEST}\`.
- The sandbox image workflow builds this image and smokes \`${LATEST}\` 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 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.
BODY
cat delta.md
@@ -355,7 +347,7 @@ jobs:
checkName: Sandbox Base Image Smoke
ref: ${{ steps.commit.outputs.commit-hash }}
timeoutSeconds: '4500'
- intervalSeconds: '30'
+ intervalSeconds: '10'
- name: Stop when the smoke did not pass
if: steps.state.outputs.action == 'bump' && steps.smoke.outputs.conclusion != 'success'