: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): self-cancel depot backend runs on deterministic failures (#103125)
Raúl Negrón-Otero46a69c90a608
diff --git a/.depot/workflows/ci-backend.yml b/.depot/workflows/ci-backend.ymlindex 3e4b69235fd7..661b620a2c30 100644--- a/.depot/workflows/ci-backend.yml+++ b/.depot/workflows/ci-backend.yml@@ -54,11 +54,11 @@# secrets and cannot authenticate to Depot Cache) prime instead of migrating from scratch.# The shadow routes cache writes to Depot Cache, so it must not fill the GitHub# cache. This job and the mig_schema_key output that feeds it remain depot-exempt.-# - Deterministic-failure self-cancel remains omitted: the injected Depot job token-# cannot authorize the CLI's run lookup. Workflow-name expressions also remain-# literal, so the role cannot switch names through a variable; the cutover renames-# the workflow in a plain edit. The gate's hand-off `&&` is safe only while its-# status remains optional.+# - Deterministic-failure self-cancel: `depot ci cancel` with DEPOT_CI_CANCEL_TOKEN replaces+# `gh run cancel` with github.token, which only reaches GitHub Actions runs.+# - Workflow-name expressions remain literal, so the role cannot switch names through a+# variable; the cutover renames the workflow in a plain edit. The gate's hand-off `&&`+# is safe only while its status remains optional.# - events_json variants: gated on the test-new-events-schema label only; canonical also# doubles the matrices on workflow_dispatch, but shadow dispatches stay legacy-only so# trial runs do the same work as handed-off PR runs@@ -1493,6 +1493,8 @@ jobs:# product_yamls: ownership-only PRs still need the owners.yaml lint below.if: (needs.changes.outputs.backend == 'true' || needs.changes.outputs.product_yamls == 'true' || needs.changes.outputs.repo_invariants == 'true') && github.event_name != 'push'timeout-minutes: 10+ outputs:+ deterministic_failure: ${{ steps.deterministic-failure.outputs.deterministic_failure || 'false' }}permissions:contents: readpull-requests: read # list PR files for the deleted-migration check@@ -1523,6 +1525,8 @@ jobs:# Block deleting historical migration files (see safe-django-migrations.md).# Two steps, so a failed PR-files read fails the job instead of handing the# check an empty list. The read uses the ambient token, which only reads here.+ # Above the boundary: a gh-api flake here is retryable setup, not a+ # run-cancelling deterministic failure. The classifier runs below.- name: Fetch deleted migration pathsid: fetch-deleted-migrationsif: github.event_name == 'pull_request' && needs.changes.outputs.migrations_any == 'true'@@ -1531,6 +1535,12 @@ jobs:REPO: ${{ github.repository }}PR_NUMBER: ${{ github.event.pull_request.number }}run: .github/scripts/list-removed-renamed-paths.sh > "$RUNNER_TEMP/deleted-migration-paths.txt"+ # Boundary between network-dependent setup and the deterministic+ # checks below. The "Flag deterministic failure" step keys off this+ # step's outcome so a transient setup failure doesn't cancel the run.+ - name: Mark setup complete+ id: setup-complete+ run: echo "Setup complete — any failure below is a deterministic check failure"- name: Check deleted migrationsif: steps.fetch-deleted-migrations.outcome == 'success'run: ./bin/hogli lint:migration-deletions < "$RUNNER_TEMP/deleted-migration-paths.txt"@@ -1578,6 +1588,38 @@ jobs:elsepytest -p no:cacheprovider posthog/test/test_startup_import_budget.py posthog/test/test_dataclass_defaults.pyfi+ # Deterministic = a static check above failed after setup completed.+ # A retry can't fix it, so this signals the cancellation gate to stop the run.+ - name: Flag deterministic failure+ id: deterministic-failure+ if: failure() && steps.setup-complete.outcome == 'success'+ run: echo "deterministic_failure=true" >> "$GITHUB_OUTPUT"++ cancel-backend-on-repo-check-failure:+ needs: [repo-checks]+ if: >+ always() &&+ needs.repo-checks.outputs.deterministic_failure == 'true' &&+ github.event_name == 'pull_request' &&+ github.event.pull_request.head.repo.full_name == github.repository+ timeout-minutes: 5+ permissions:+ contents: read+ name: Cancel Backend CI after repo check failure+ runs-on: depot-ubuntu-24.04+ steps:+ - uses: depot/setup-action@15c09a5f77a0840ad4bce955686522a257853461 # v1.7.1+ - name: Cancel run+ env:+ DEPOT_TOKEN: ${{ secrets.DEPOT_CI_CANCEL_TOKEN }}+ REPO: ${{ github.repository }}+ PR_NUMBER: ${{ github.event.pull_request.number }}+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}+ run: |+ echo "::notice title=Repo checks failed deterministically::Canceling remaining Backend CI jobs. A retry cannot fix this failure; push a fix to start a new run."+ depot ci workflow list --repo "$REPO" --pr "$PR_NUMBER" --status running -o json \+ | jq -r --arg sha "$HEAD_SHA" '.[] | select(.workflow_path == "ci-backend.yml" and .head_sha == $sha) | "\(.run_id) \(.workflow_id)"' \+ | while read -r run workflow; do depot ci cancel "$run" --workflow "$workflow"; donevalidate-product-yamls:needs: [changes]@@ -2108,6 +2150,8 @@ jobs:# Not on master push: master only primes the schema cache.if: (needs.changes.outputs.backend == 'true' || needs.changes.outputs.openapi_types == 'true') && github.event_name != 'push'timeout-minutes: 20+ outputs:+ deterministic_failure: ${{ steps.deterministic-failure.outputs.deterministic_failure || 'false' }}name: Validate OpenAPI typesruns-on: depot-ubuntu-24.04steps:@@ -2254,6 +2298,13 @@ jobs:echo "drifted-files=$DRIFTED_FILES" >> $GITHUB_OUTPUTecho "needs-commit=true" >> $GITHUB_OUTPUT+ # Deterministic = the OpenAPI check step itself failed (not a transient+ # setup or commit-step failure), so a retry can't fix it. Mirrors repo-checks.+ - name: Flag deterministic failure+ id: deterministic-failure+ if: failure() && steps.openapi-check.outcome == 'failure'+ run: echo "deterministic_failure=true" >> "$GITHUB_OUTPUT"+- name: Get app token for OpenAPI type commitsif: steps.openapi-check.outputs.needs-commit == 'true'id: openapi-app-token@@ -2279,6 +2330,33 @@ jobs:file_pattern: ${{ steps.openapi-check.outputs.drifted-files }}env:GITHUB_TOKEN: ${{ steps.openapi-app-token.outputs.token }}++ cancel-backend-on-openapi-check-failure:+ needs: [check-openapi-types]+ if: >+ always() &&+ needs.check-openapi-types.outputs.deterministic_failure == 'true' &&+ github.event_name == 'pull_request' &&+ github.event.pull_request.head.repo.full_name == github.repository+ timeout-minutes: 5+ permissions:+ contents: read+ name: Cancel Backend CI after OpenAPI check failure+ runs-on: depot-ubuntu-24.04+ steps:+ - uses: depot/setup-action@15c09a5f77a0840ad4bce955686522a257853461 # v1.7.1+ - name: Cancel run+ env:+ DEPOT_TOKEN: ${{ secrets.DEPOT_CI_CANCEL_TOKEN }}+ REPO: ${{ github.repository }}+ PR_NUMBER: ${{ github.event.pull_request.number }}+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}+ run: |+ echo "::notice title=OpenAPI check failed deterministically::Canceling remaining Backend CI jobs. A retry cannot fix this failure; push a fix to start a new run."+ depot ci workflow list --repo "$REPO" --pr "$PR_NUMBER" --status running -o json \+ | jq -r --arg sha "$HEAD_SHA" '.[] | select(.workflow_path == "ci-backend.yml" and .head_sha == $sha) | "\(.run_id) \(.workflow_id)"' \+ | while read -r run workflow; do depot ci cancel "$run" --workflow "$workflow"; done+build_django_matrix:name: Build Django matrixneeds: [changes, get_clickhouse_versions, turbo-discover, prime-schema-cache]@@ -3618,7 +3696,11 @@ jobs:# !cancelled() collates skipped/failed matrix jobs without reporting failure on a# superseded run (mirrors canonical); gated on the hand-off so it doesn't# spin up a lone runner when GitHub Actions kept this event.- if: ${{ !cancelled() && needs.wait-for-handoff.outputs.handed_off == 'true' }}+ if: >+ (!cancelled()+ || needs.repo-checks.outputs.deterministic_failure == 'true'+ || needs.check-openapi-types.outputs.deterministic_failure == 'true')+ && needs.wait-for-handoff.outputs.handed_off == 'true'steps:- name: Summarize dependency resultsrun: |@@ -3637,6 +3719,14 @@ jobs:echo "| build-product-test-matrix | ${{ needs.build-product-test-matrix.result }} |"echo "| turbo-tests | ${{ needs.turbo-tests.result }} |"echo "| handle-snapshots | ${{ needs.handle-snapshots.result }} |"+ if [[ "${{ needs.repo-checks.outputs.deterministic_failure }}" == "true" ]]; then+ echo ""+ echo "**Root cause:** Repo checks failed deterministically. Open the repo checks job logs; downstream cancelled jobs are expected."+ fi+ if [[ "${{ needs.check-openapi-types.outputs.deterministic_failure }}" == "true" ]]; then+ echo ""+ echo "**Root cause:** OpenAPI type checks failed deterministically. Open the OpenAPI type check job logs; downstream cancelled jobs are expected."+ fi} | tee -a "$GITHUB_STEP_SUMMARY"- name: Download shard JUnit results@@ -3725,6 +3815,14 @@ jobs:print(f"::error {loc}title={title}::{body}")PY+ if [[ "${{ needs.repo-checks.outputs.deterministic_failure }}" == "true" ]]; then+ echo "::error title=Repo checks failed deterministically::Open the repo checks job for the root failure. Backend CI cancelled downstream jobs to save runners; retrying will not fix this."+ fi++ if [[ "${{ needs.check-openapi-types.outputs.deterministic_failure }}" == "true" ]]; then+ echo "::error title=OpenAPI type checks failed deterministically::Open the OpenAPI type check job for the root failure. Backend CI cancelled downstream jobs to save runners; retrying will not fix this."+ fi+check_required_result() {local label="$1"local result="$2"