: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
chore(ci): verify a sandbox agent bump reaches the master image (#108191)
Alessandro Pogliaghi3cb94d96e8f6
diff --git a/.github/workflows/update-sandbox-agent-version.yml b/.github/workflows/update-sandbox-agent-version.ymlindex 1c8c7eeac518..0b94bb97ad61 100644--- a/.github/workflows/update-sandbox-agent-version.yml+++ b/.github/workflows/update-sandbox-agent-version.yml@@ -21,18 +21,23 @@ on:permissions:contents: read-concurrency:- group: update-sandbox-agent-version- cancel-in-progress: false-jobs:update-sandbox-agent-version:runs-on: ubuntu-24.04timeout-minutes: 125+ concurrency:+ group: update-sandbox-agent-version+ cancel-in-progress: falsepermissions:actions: readcontents: readpackages: read+ outputs:+ action: ${{ steps.state.outputs.action }}+ pr_number: ${{ steps.pr.outputs.number }}+ latest: ${{ steps.resolve.outputs.latest }}+ thread_ts: ${{ steps.thread.outputs.ts }}+ enqueued: ${{ steps.enqueue.outputs.enqueued }}env:DOCKERFILE: products/tasks/backend/sandbox/images/Dockerfile.sandbox-base@@ -499,6 +504,7 @@ jobs:-f commit_id="$SHA" \-f body="Automated approval: the sandbox image built from this commit passed the agent smoke on both architectures and one Claude and one Codex turn on the Go ai-gateway." >/dev/nullgh pr comment "$PR" --body '/trunk merge'+ echo "enqueued=true" >> "$GITHUB_OUTPUT"- name: Describe the outcome for Slackid: outcome@@ -560,3 +566,238 @@ jobs:thread_ts: "${{ steps.thread.outputs.ts }}"unfurl_links: falsetext: "${{ steps.outcome.outputs.text }}"++ verify_rollout:+ needs: update-sandbox-agent-version+ name: Verify the bump reaches the master image+ if: ${{ !cancelled() && github.repository_owner == 'PostHog' && vars.CD_DEPLOY_ENABLED == 'true' && needs.update-sandbox-agent-version.outputs.action == 'bump' && needs.update-sandbox-agent-version.outputs.enqueued == 'true' }}+ runs-on: ubuntu-24.04+ timeout-minutes: 160+ concurrency:+ group: update-sandbox-agent-version-verify+ cancel-in-progress: true+ permissions:+ actions: write+ contents: read+ packages: read+ pull-requests: read++ env:+ IMAGE: ghcr.io/posthog/posthog-sandbox-base:master+ LABEL_JQ: '[if has("config") then . else .[] end | .config.Labels["com.posthog.sandbox.agent-version"] // empty] | unique | if length == 1 then .[0] else empty end'+ SLACK_CHANNEL: 'C0C3FBES5ST'+ GH_REPO: ${{ github.repository }}+ PR: ${{ needs.update-sandbox-agent-version.outputs.pr_number }}+ LATEST: ${{ needs.update-sandbox-agent-version.outputs.latest }}++ steps:+ - name: Wait for the bump to merge+ id: merge+ env:+ GH_TOKEN: ${{ github.token }}+ run: |+ deadline=$(( $(date +%s) + 75 * 60 ))+ while :; do+ if pr=$(gh pr view "$PR" --json state,mergeCommit); then+ state=$(jq -r .state <<< "$pr")+ sha=$(jq -r '.mergeCommit.oid // empty' <<< "$pr")+ if [ "$state" = MERGED ] && [ -n "$sha" ]; then+ echo "PR #$PR merged as $sha"+ { echo "state=merged"; echo "sha=$sha"; } >> "$GITHUB_OUTPUT"+ exit 0+ fi+ if [ "$state" = CLOSED ]; then+ closer=$(gh api "repos/$GH_REPO/issues/$PR/events" --paginate \+ --jq '.[] | select(.event == "closed") | .actor.type' | tail -1 || true)+ if [ "$closer" = Bot ]; then+ echo "A newer bump closed PR #$PR, so its own run reports the rollout"+ echo "state=superseded" >> "$GITHUB_OUTPUT"+ else+ echo "PR #$PR was closed without merging"+ echo "state=declined" >> "$GITHUB_OUTPUT"+ fi+ exit 0+ fi+ fi+ if [ "$(date +%s)" -ge "$deadline" ]; then+ echo "::error::PR #$PR did not merge within 75 minutes"+ echo "state=not_merged" >> "$GITHUB_OUTPUT"+ exit 0+ fi+ sleep 60+ done++ - name: Login to ghcr.io+ if: steps.merge.outputs.state == 'merged'+ uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0+ with:+ registry: ghcr.io+ username: ${{ github.actor }}+ password: ${{ github.token }}++ - name: Wait for the master image to carry the version+ id: master+ if: steps.merge.outputs.state == 'merged'+ run: |+ read_label() {+ for attempt in 1 2 3; do+ if image=$(docker buildx imagetools inspect "$IMAGE" --format '{{json .Image}}'); then+ jq -r "$LABEL_JQ" <<< "$image"+ return 0+ fi+ sleep $((attempt * 5))+ done+ return 1+ }+ deadline=$(( $(date +%s) + 30 * 60 ))+ while :; do+ label=$(read_label || true)+ echo "$IMAGE carries agent version '${label}'"+ if [ "$label" = "$LATEST" ]; then+ echo "live=true" >> "$GITHUB_OUTPUT"+ exit 0+ fi+ if [ "$(date +%s)" -ge "$deadline" ]; then+ echo "::warning::$IMAGE did not carry $LATEST within 30 minutes of the merge"+ echo "live=false" >> "$GITHUB_OUTPUT"+ exit 0+ fi+ sleep 60+ done++ - name: Rebuild the master image+ id: repair+ if: steps.merge.outputs.state == 'merged' && steps.master.outputs.live != 'true'+ env:+ GH_TOKEN: ${{ github.token }}+ run: |+ read_label() {+ for attempt in 1 2 3; do+ if image=$(docker buildx imagetools inspect "$IMAGE" --format '{{json .Image}}'); then+ jq -r "$LABEL_JQ" <<< "$image"+ return 0+ fi+ sleep $((attempt * 5))+ done+ return 1+ }+ dispatched_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)+ if ! gh workflow run cd-sandbox-base-image.yml --ref master; then+ echo "::error::Could not dispatch cd-sandbox-base-image.yml on master"+ echo "outcome=failed" >> "$GITHUB_OUTPUT"+ exit 0+ fi+ run_id=""+ rebuilt=false+ for attempt in 1 2 3 4 5 6; do+ sleep 10+ run_id=$(gh run list --workflow cd-sandbox-base-image.yml --event workflow_dispatch --branch master \+ --json databaseId,createdAt --limit 5 \+ --jq "[.[] | select(.createdAt >= \"$dispatched_at\")] | sort_by(.createdAt) | last | .databaseId // empty" || true)+ if [ -n "$run_id" ]; then break; fi+ done+ if [ -n "$run_id" ]; then+ echo "run_url=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${run_id}" >> "$GITHUB_OUTPUT"+ if timeout 40m gh run watch "$run_id" --exit-status --interval 30 >/dev/null; then+ rebuilt=true+ else+ echo "::warning::The rebuild run $run_id did not succeed within 40 minutes"+ fi+ else+ echo "::warning::Could not find the dispatched cd-sandbox-base-image.yml run"+ fi+ deadline=$(( $(date +%s) + 5 * 60 ))+ while :; do+ label=$(read_label || true)+ echo "$IMAGE carries agent version '${label}'"+ if [ "$label" = "$LATEST" ]; then+ if [ "$rebuilt" = true ]; then+ echo "outcome=repaired" >> "$GITHUB_OUTPUT"+ else+ echo "outcome=live" >> "$GITHUB_OUTPUT"+ fi+ exit 0+ fi+ if [ "$(date +%s)" -ge "$deadline" ]; then+ echo "::error::$IMAGE still does not carry $LATEST after the rebuild"+ echo "outcome=failed" >> "$GITHUB_OUTPUT"+ exit 0+ fi+ sleep 60+ done++ - name: Describe the rollout for Slack+ id: outcome+ if: ${{ !cancelled() }}+ env:+ MERGE_STATE: ${{ steps.merge.outputs.state }}+ MERGE_SHA: ${{ steps.merge.outputs.sha }}+ LIVE: ${{ steps.master.outputs.live }}+ REPAIR: ${{ steps.repair.outputs.outcome }}+ REPAIR_URL: ${{ steps.repair.outputs.run_url }}+ THREAD_TS: ${{ needs.update-sandbox-agent-version.outputs.thread_ts }}+ RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}+ REPO_URL: ${{ github.server_url }}/${{ github.repository }}+ run: |+ pr="<${REPO_URL}/pull/${PR}|#${PR}>"+ commit="<${REPO_URL}/commit/${MERGE_SHA}|${MERGE_SHA:0:7}>"+ if [ "$MERGE_STATE" = superseded ]; then+ exit 0+ elif [ "$MERGE_STATE" = declined ]; then+ outcome=declined+ text=":information_source: ${pr} was closed without merging, so the sandbox pin stays where it was."+ elif [ "$MERGE_STATE" != merged ]; then+ outcome=not_merged+ text=":red_circle: ${pr} did not merge within 75 minutes, so \`posthog-sandbox-base:master\` still runs the previous agent. <${RUN_URL}|View run>"+ elif [ "$LIVE" = true ] || [ "$REPAIR" = live ]; then+ outcome=live+ text=":rocket: \`posthog-sandbox-base:master\` now runs @posthog/agent ${LATEST} (merged in ${commit})."+ elif [ "$REPAIR" = repaired ]; then+ outcome=repaired+ text=":rocket: \`posthog-sandbox-base:master\` now runs @posthog/agent ${LATEST} (merged in ${commit}) after a manual rebuild, because the merge run did not build it. <${REPAIR_URL:-$RUN_URL}|View rebuild>"+ else+ outcome=failed+ text=":red_circle: \`posthog-sandbox-base:master\` still does not run @posthog/agent ${LATEST} after ${commit} merged, and a manual rebuild did not fix it. <${RUN_URL}|View run>"+ fi+ if [ -z "$THREAD_TS" ]; then+ text="*@posthog/agent ${LATEST}*: ${text}"+ fi+ {+ echo "outcome=$outcome"+ echo "text=$text"+ } >> "$GITHUB_OUTPUT"++ - name: Post the rollout in the release thread+ if: ${{ !cancelled() && steps.outcome.outputs.text != '' && needs.update-sandbox-agent-version.outputs.thread_ts != '' }}+ continue-on-error: true+ uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1+ with:+ method: chat.postMessage+ token: ${{ secrets.SLACK_DEVEX_BOT_TOKEN }}+ errors: true+ payload: |+ channel: "${{ env.SLACK_CHANNEL }}"+ thread_ts: "${{ needs.update-sandbox-agent-version.outputs.thread_ts }}"+ unfurl_links: false+ text: "${{ steps.outcome.outputs.text }}"++ - name: Post the rollout as a new thread+ if: ${{ !cancelled() && steps.outcome.outputs.text != '' && needs.update-sandbox-agent-version.outputs.thread_ts == '' }}+ continue-on-error: true+ uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1+ with:+ method: chat.postMessage+ token: ${{ secrets.SLACK_DEVEX_BOT_TOKEN }}+ errors: true+ payload: |+ channel: "${{ env.SLACK_CHANNEL }}"+ unfurl_links: false+ text: "${{ steps.outcome.outputs.text }}"++ - name: Fail when the version did not reach the master image+ if: ${{ !cancelled() && contains(fromJSON('["failed", "not_merged"]'), steps.outcome.outputs.outcome) }}+ env:+ OUTCOME: ${{ steps.outcome.outputs.outcome }}+ run: |+ echo "::error::The @posthog/agent $LATEST rollout ended as $OUTCOME"+ exit 1diff --git a/docs/published/handbook/engineering/ai/sandboxed-agents.md b/docs/published/handbook/engineering/ai/sandboxed-agents.mdindex e37508ae21bc..a06ccfe2f322 100644--- a/docs/published/handbook/engineering/ai/sandboxed-agents.md+++ b/docs/published/handbook/engineering/ai/sandboxed-agents.md@@ -713,6 +713,7 @@ An agent release opens a pull request that bumps that pin.Every master push, a half-hourly schedule, and a manual dispatch compare the pin and the image inputs on master with the labels on the published images, and rebuild when they differ.That build checks the installed agent against the pin and starts the `agent-server` entrypoint on both architectures before the image is promoted.Before the pull request is approved, the bump workflow runs one Claude turn and one Codex turn from that image through the production Go ai-gateway, on the agent's default models and efforts.+After the pull request merges, the bump workflow waits until `posthog-sandbox-base:master` reports the new version, dispatches a rebuild when it does not, and posts the outcome in the release thread.Running backend tests against that image alone does not validate an unpublished agent change.## Questions?