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(tasks): smoke the sandbox agent on the go ai-gateway before approval (#105731)

Alessandro Pogliaghi4796ed5f25c2
diff --git a/.github/actions/sandbox-agent-gateway-smoke/action.yml b/.github/actions/sandbox-agent-gateway-smoke/action.yml
new file mode 100644
index 000000000000..8ced1d7038b4
--- /dev/null
+++ b/.github/actions/sandbox-agent-gateway-smoke/action.yml
@@ -0,0 +1,115 @@
+name: 'Sandbox agent gateway smoke'
+description: >-
+ Run one Claude turn and one Codex turn with the agent installed in a sandbox image,
+ through the production Go ai-gateway on the agent's default models and efforts.
+inputs:
+ image:
+ description: 'Sandbox base image to smoke'
+ required: true
+ mint-key:
+ description: 'Go ai-gateway credential that mints the scoped agent_smoke token'
+ required: true
+ registry-token:
+ description: 'Token that can pull the image from ghcr.io'
+ required: true
+ gateway-url:
+ description: 'Go ai-gateway base URL'
+ required: false
+ default: 'https://ai-gateway.us.posthog.com'
+outputs:
+ result:
+ description: >-
+ pass, broken (the release fails on the gateway), inconclusive (the provider
+ failed twice), infra (the smoke could not run), or unavailable (the image has
+ no agent-smoke bin).
+ value: ${{ steps.smoke.outputs.result }}
+ summary-file:
+ description: 'Markdown table with one row per runtime'
+ value: ${{ steps.smoke.outputs.summary-file }}
+runs:
+ using: composite
+ steps:
+ - id: smoke
+ shell: bash
+ env:
+ IMAGE: ${{ inputs.image }}
+ MINT_KEY: ${{ inputs.mint-key }}
+ REGISTRY_TOKEN: ${{ inputs.registry-token }}
+ AI_GATEWAY_URL: ${{ inputs.gateway-url }}
+ AI_GATEWAY_PRODUCT: agent_smoke
+ AI_GATEWAY_PRODUCTS: agent_smoke
+ run: |
+ set -uo pipefail
+ summary="$RUNNER_TEMP/gateway-smoke.md"
+ echo "summary-file=$summary" >> "$GITHUB_OUTPUT"
+ finish() {
+ echo "result=$1" >> "$GITHUB_OUTPUT"
+ cat "$summary" >> "$GITHUB_STEP_SUMMARY"
+ exit 0
+ }
+ printf '### Gateway smoke on `%s`\n\n' "$IMAGE" > "$summary"
+
+ if ! echo "$REGISTRY_TOKEN" | docker login ghcr.io -u "$GITHUB_ACTOR" --password-stdin >/dev/null \
+ || ! timeout 600 docker pull -q "$IMAGE" >/dev/null; then
+ echo "Could not pull the image." >> "$summary"
+ finish infra
+ fi
+ docker run --rm "$IMAGE" test -x /scripts/node_modules/.bin/agent-smoke
+ probe=$?
+ if [ "$probe" = 1 ]; then
+ echo "The image's @posthog/agent has no \`agent-smoke\` bin, so the gateway smoke did not run." >> "$summary"
+ finish unavailable
+ elif [ "$probe" != 0 ]; then
+ echo "Could not run the image." >> "$summary"
+ finish infra
+ fi
+ if [ -z "$MINT_KEY" ]; then
+ echo "No gateway mint key is configured." >> "$summary"
+ finish infra
+ fi
+
+ AI_GATEWAY_TOKEN=$(curl -sS --fail-with-body --retry 2 --max-time 30 -X POST "${AI_GATEWAY_URL%/}/v1/tokens" \
+ -H "Authorization: Bearer $MINT_KEY" -H 'Content-Type: application/json' \
+ -d '{"cap_usd":"10","ttl_seconds":1800,"product":"agent_smoke"}' | jq -r '.token // empty')
+ if [ -z "$AI_GATEWAY_TOKEN" ]; then
+ echo "The gateway did not mint an agent_smoke token." >> "$summary"
+ finish infra
+ fi
+ echo "::add-mask::$AI_GATEWAY_TOKEN"
+ export AI_GATEWAY_TOKEN
+
+ echo '| Runtime | Model | Result | Detail |' >> "$summary"
+ echo '| --- | --- | --- | --- |' >> "$summary"
+ overall=pass
+ for runtime in claude codex; do
+ for attempt in 1 2; do
+ timeout 300 docker run --rm \
+ -e AI_GATEWAY_URL -e AI_GATEWAY_TOKEN -e AI_GATEWAY_PRODUCT -e AI_GATEWAY_PRODUCTS \
+ "$IMAGE" /scripts/node_modules/.bin/agent-smoke --runtime "$runtime" --timeout 240 \
+ > "$RUNNER_TEMP/smoke-$runtime.out" 2> "$RUNNER_TEMP/smoke-$runtime.log"
+ status=$?
+ line=$(tail -n 1 "$RUNNER_TEMP/smoke-$runtime.out")
+ result=$(jq -r '.result // empty' <<< "$line" 2>/dev/null || true)
+ case "$result" in
+ pass) [ "$status" = 0 ] || result=infra ;;
+ broken | inconclusive | infra) ;;
+ *) result=infra ;;
+ esac
+ echo "$runtime attempt $attempt: $line"
+ if [ "$result" != inconclusive ]; then break; fi
+ done
+ if [ "$result" != pass ]; then
+ echo "::group::$runtime agent log"
+ tail -n 200 "$RUNNER_TEMP/smoke-$runtime.log"
+ echo "::endgroup::"
+ fi
+ model=$(jq -r '.model // "?"' <<< "$line" 2>/dev/null || echo '?')
+ detail=$(jq -r '.error // .reply // ""' <<< "$line" 2>/dev/null | tr '\n|' ' ' | cut -c1-300)
+ echo "| $runtime | \`$model\` | $result | $detail |" >> "$summary"
+ case "$result:$overall" in
+ broken:*) overall=broken ;;
+ infra:pass | infra:inconclusive) overall=infra ;;
+ inconclusive:pass) overall=inconclusive ;;
+ esac
+ done
+ finish "$overall"
diff --git a/.github/workflows/update-sandbox-agent-version.yml b/.github/workflows/update-sandbox-agent-version.yml
index 734d22451c20..732f84c02ca6 100644
--- a/.github/workflows/update-sandbox-agent-version.yml
+++ b/.github/workflows/update-sandbox-agent-version.yml
@@ -24,7 +24,10 @@ concurrency:
jobs:
update-sandbox-agent-version:
runs-on: ubuntu-24.04
- timeout-minutes: 100
+ timeout-minutes: 125
+ permissions:
+ contents: read
+ packages: read
env:
DOCKERFILE: products/tasks/backend/sandbox/images/Dockerfile.sandbox-base
@@ -58,6 +61,7 @@ jobs:
sparse-checkout: |
products/tasks/backend/sandbox/images/Dockerfile.sandbox-base
.github/actions/wait-for-check
+ .github/actions/sandbox-agent-gateway-smoke
sparse-checkout-cone-mode: false
- name: Resolve the published agent version
@@ -270,7 +274,7 @@ jobs:
- \`Dockerfile.sandbox-base\`: \`AGENT_VERSION\` \`${PINNED}\` to \`${LATEST}\`.
- The sandbox image workflow builds this image and smokes \`${LATEST}\` on both architectures. When that check passes, 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 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.
BODY
cat delta.md
@@ -278,7 +282,7 @@ jobs:
## How did you test this code?
- The sandbox image CD workflow builds this PR's image on both architectures, checks that the installed \`@posthog/agent\` matches the pin, and runs the \`agent-server\` entrypoint. That covers packaging and dependency resolution. The agent's own test suite ran before the release was published.
+ The sandbox image CD workflow builds this PR's image on both architectures, checks that the installed \`@posthog/agent\` matches the pin, and runs the \`agent-server\` entrypoint. That covers packaging and dependency resolution. This workflow then drives one Claude turn and one Codex turn from the image through the US Go ai-gateway, on the default models and efforts, and needs both to read a file with a tool. The agent's own test suite ran before the release was published.
BODY
} > body.md
pr_url=$(gh pr create \
@@ -362,6 +366,30 @@ jobs:
echo "::error::Sandbox Base Image Pass concluded $CONCLUSION on $SHA, so PR #$PR waits for a person"
exit 1
+ - name: Smoke the agent on the Go ai-gateway
+ id: gateway-smoke
+ if: steps.state.outputs.action == 'bump'
+ timeout-minutes: 25
+ uses: ./.github/actions/sandbox-agent-gateway-smoke
+ with:
+ image: ghcr.io/posthog/posthog-sandbox-base:${{ steps.commit.outputs.commit-hash }}
+ mint-key: ${{ secrets.AGENT_SMOKE_AI_GATEWAY_MINT_KEY }}
+ registry-token: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Stop when the gateway smoke did not pass
+ if: ${{ !cancelled() && steps.state.outputs.action == 'bump' && steps.gateway-smoke.outputs.result != 'pass' }}
+ env:
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
+ RESULT: ${{ steps.gateway-smoke.outputs.result }}
+ SUMMARY_FILE: ${{ steps.gateway-smoke.outputs.summary-file }}
+ PR: ${{ steps.pr.outputs.number }}
+ run: |
+ if [ -f "$SUMMARY_FILE" ]; then
+ gh pr comment "$PR" --body-file "$SUMMARY_FILE"
+ fi
+ echo "::error::The gateway smoke reported ${RESULT:-no result}, so PR #$PR waits for a person"
+ exit 1
+
- name: Get release approval token
id: releaser-token
if: steps.state.outputs.action == 'bump'
@@ -388,7 +416,7 @@ jobs:
gh api "repos/${REPO}/pulls/${PR}/reviews" \
-f event=APPROVE \
-f commit_id="$SHA" \
- -f body="Automated approval: the sandbox image built from this commit passed the agent smoke on both architectures." >/dev/null
+ -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/null
gh pr comment "$PR" --body '/trunk merge'
- name: Describe the outcome for Slack
@@ -398,6 +426,7 @@ jobs:
ACTION: ${{ steps.state.outputs.action }}
ENQUEUE: ${{ steps.enqueue.outcome }}
SMOKE: ${{ steps.smoke.outputs.conclusion }}
+ GATEWAY_SMOKE: ${{ steps.gateway-smoke.outputs.result }}
PR_URL: ${{ steps.pr.outputs.url }}
PR_NUMBER: ${{ steps.pr.outputs.number }}
LATEST: ${{ steps.resolve.outputs.latest }}
@@ -411,9 +440,11 @@ jobs:
case "$ACTION" in
bump)
if [ "$ENQUEUE" = "success" ]; then
- text=":white_check_mark: The image built from ${pr} passed the smoke on amd64 and arm64. Approved and added to the merge queue."
+ text=":white_check_mark: The image built from ${pr} passed the smoke on amd64 and arm64 and on the Go ai-gateway. Approved and added to the merge queue."
elif [ -n "$SMOKE" ] && [ "$SMOKE" != "success" ]; then
text=":red_circle: Sandbox Base Image Pass concluded \`${SMOKE}\` on ${pr}, so it waits for a person. <${RUN_URL}|View run>"
+ elif [ -n "$GATEWAY_SMOKE" ] && [ "$GATEWAY_SMOKE" != "pass" ]; then
+ text=":red_circle: The Go ai-gateway smoke reported \`${GATEWAY_SMOKE}\` on ${pr}, so it waits for a person. <${RUN_URL}|View run>"
elif [ -n "$PR_NUMBER" ]; then
text=":red_circle: The bump run failed before ${pr} reached the merge queue. <${RUN_URL}|View run>"
else
diff --git a/docs/published/handbook/engineering/ai/sandboxed-agents.md b/docs/published/handbook/engineering/ai/sandboxed-agents.md
index 82e4d2c2152e..fdb0b7cdf96e 100644
--- a/docs/published/handbook/engineering/ai/sandboxed-agents.md
+++ b/docs/published/handbook/engineering/ai/sandboxed-agents.md
@@ -669,6 +669,7 @@ These tests consume the published sandbox image, not the agent source in the che
The image pins the agent version in `Dockerfile.sandbox-base`.
An agent release opens a pull request that bumps that pin, and merging it rebuilds the shared image.
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.
Running backend tests against that image alone does not validate an unpublished agent change.
## Questions?