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.

fix(ci): stop superseded runs promptly with !cancelled() (#73956)

Raúl Negrón-Otero7840c05c1e47
diff --git a/.github/workflows/ci-ai.yml b/.github/workflows/ci-ai.yml
index b13fdf88404b..85998ea78340 100644
--- a/.github/workflows/ci-ai.yml
+++ b/.github/workflows/ci-ai.yml
@@ -150,7 +150,10 @@ jobs:
name: AI evals / summary
runs-on: ubuntu-latest
needs: eval
- if: always() && needs.eval.result != 'skipped'
+ # A status function is required to summarize even when some eval groups errored.
+ # !cancelled() rather than always() so a superseded run does not post an eval
+ # summary comment for a commit that is no longer HEAD.
+ if: ${{ !cancelled() && needs.eval.result != 'skipped' }}
permissions:
contents: read
diff --git a/.github/workflows/ci-e2e-playwright.yml b/.github/workflows/ci-e2e-playwright.yml
index cfd89c95a788..ab8ce97166cf 100644
--- a/.github/workflows/ci-e2e-playwright.yml
+++ b/.github/workflows/ci-e2e-playwright.yml
@@ -1049,10 +1049,10 @@ jobs:
timeout-minutes: 5
needs: [changes, select-specs, playwright, playwright_tests]
if: # Run on pull requests to PostHog/posthog + on PostHog/posthog outside of PRs - but never on forks or Dependabot (no secrets access)
- always() && github.actor != 'dependabot[bot]' &&
+ ${{ !cancelled() && github.actor != 'dependabot[bot]' &&
needs.changes.outputs.shouldRun == 'true' && (
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog') ||
- (github.event_name != 'pull_request' && github.repository == 'PostHog/posthog'))
+ (github.event_name != 'pull_request' && github.repository == 'PostHog/posthog')) }}
steps:
- name: Get telemetry app token
id: telemetry-app-token
diff --git a/.github/workflows/ci-frontend.yml b/.github/workflows/ci-frontend.yml
index 0285f096007d..f314b8ce2978 100644
--- a/.github/workflows/ci-frontend.yml
+++ b/.github/workflows/ci-frontend.yml
@@ -182,7 +182,7 @@ jobs:
timeout-minutes: 5
needs: changes
if: |
- always() && needs.changes.outputs.frontend_code == 'true'
+ !cancelled() && needs.changes.outputs.frontend_code == 'true'
&& github.event_name == 'pull_request'
&& github.event.pull_request.draft == true
&& !contains(github.event.pull_request.labels.*.name, 'run-ci-frontend')
@@ -641,8 +641,11 @@ jobs:
# the ready-for-review fanout shards well below either limit.
timeout-minutes: 20
needs: [changes, select-jest-tests]
+ # A status function is required because select-jest-tests is skipped on ready
+ # PRs and master pushes, and a skipped need would otherwise cascade a skip here.
+ # !cancelled() rather than always() so a superseded run's shards stop promptly.
if: |
- always() && needs.changes.outputs.frontend_code == 'true'
+ !cancelled() && needs.changes.outputs.frontend_code == 'true'
&& needs.select-jest-tests.outputs.should_run != 'false'
name: Jest test (${{ matrix.segment }} - ${{ matrix.chunk }})
strategy:
@@ -891,10 +894,10 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
if: # Run on pull requests to PostHog/posthog + on PostHog/posthog outside of PRs - but never on forks or Dependabot (no secrets access)
- always() && github.actor != 'dependabot[bot]' &&
+ ${{ !cancelled() && github.actor != 'dependabot[bot]' &&
needs.changes.outputs.frontend_code == 'true' && (
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog') ||
- (github.event_name != 'pull_request' && github.repository == 'PostHog/posthog'))
+ (github.event_name != 'pull_request' && github.repository == 'PostHog/posthog')) }}
steps:
- name: Get telemetry app token
id: telemetry-app-token
diff --git a/.github/workflows/ci-hobby.yml b/.github/workflows/ci-hobby.yml
index f978e71f73fe..3fd45c4782b9 100644
--- a/.github/workflows/ci-hobby.yml
+++ b/.github/workflows/ci-hobby.yml
@@ -227,7 +227,10 @@ jobs:
timeout-minutes: 90
name: Setup DO Hobby Instance and test
needs: [wait-for-docker-image, changes]
- if: always() && ((needs.changes.outputs.should_run == 'true' && needs.wait-for-docker-image.outputs.conclusion == 'success') || github.event_name == 'push')
+ # A status function is required to read wait-for-docker-image's conclusion after it
+ # failed or was skipped. !cancelled() rather than always() so a superseded PR run stops
+ # this 90-minute job promptly; the explicit conclusion/push checks preserve when it runs.
+ if: ${{ !cancelled() && ((needs.changes.outputs.should_run == 'true' && needs.wait-for-docker-image.outputs.conclusion == 'success') || github.event_name == 'push') }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
diff --git a/.github/workflows/ci-mcp.yml b/.github/workflows/ci-mcp.yml
index cbbd4f453766..dbe453001d70 100644
--- a/.github/workflows/ci-mcp.yml
+++ b/.github/workflows/ci-mcp.yml
@@ -628,7 +628,10 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [changes, unit-tests]
- if: ${{ always() && needs.changes.outputs.mcp == 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && !contains(github.actor, '[bot]') && github.actor != 'posthog-bot' && !contains(github.actor, 'github-actions') }}
+ # A status function is required to commit regenerated snapshots even when unit-tests
+ # failed (a snapshot mismatch fails that job). !cancelled() rather than always() so a
+ # superseded run does not push a stale snapshot commit to the branch.
+ if: ${{ !cancelled() && needs.changes.outputs.mcp == 'true' && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && !contains(github.actor, '[bot]') && github.actor != 'posthog-bot' && !contains(github.actor, 'github-actions') }}
permissions:
contents: write
pull-requests: write
diff --git a/.github/workflows/ci-storybook.yml b/.github/workflows/ci-storybook.yml
index f1309c58ecf9..5aacc226919c 100644
--- a/.github/workflows/ci-storybook.yml
+++ b/.github/workflows/ci-storybook.yml
@@ -272,11 +272,12 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: [changes, build-storybook, select-stories]
- # always() so vr-setup still runs when select-stories is skipped (ready PRs
- # and master pushes). Without it, GitHub treats a skipped need as a
- # skip-cascade and vr-setup wouldn't run when we still want it to.
+ # A status function is required because select-stories is skipped on ready PRs
+ # and master pushes, and GitHub would otherwise cascade that skip to this job.
+ # !cancelled() rather than always() so a superseded run stops here instead of
+ # creating a Visual Review run that its cancelled matrix will never complete.
if: |
- always()
+ !cancelled()
&& needs.changes.outputs.frontend == 'true'
&& needs.build-storybook.result == 'success'
&& needs.select-stories.outputs.should_run != 'false'
@@ -351,8 +352,11 @@ jobs:
name: Visual regression tests - ${{ matrix.browser }} (${{ matrix.shard }}/${{ matrix.shard_count }})
runs-on: ${{ matrix.browser == 'webkit' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
needs: [changes, build-storybook, vr-setup, select-stories]
+ # A status function is required because select-stories is skipped on ready PRs
+ # and master pushes. !cancelled() rather than always() so a superseded run's
+ # browser shards stop promptly instead of running the full 30-minute matrix.
if: >-
- always()
+ !cancelled()
&& needs.changes.outputs.frontend == 'true'
&& needs.build-storybook.result == 'success'
&& needs.select-stories.outputs.should_run != 'false'
@@ -662,11 +666,12 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 15
needs: [visual-regression, vr-setup]
- # always() so the skipped select-stories job (transitively in the needs
- # chain on ready PRs) doesn't skip-propagate past the always() jobs above
- # and leave the VR run uncompleted with its commit status stuck pending.
- # Legit skips still work: no-VR cases leave run_id empty, and a failed or
- # cancelled matrix fails the result == 'success' check.
+ # Intentional always(), not !cancelled(): this job finalizes external state,
+ # so a run cancelled after the matrix succeeded must still complete the VR
+ # run rather than leave its commit status stuck pending. It also stops the
+ # skipped select-stories job (transitively in the needs chain on ready PRs)
+ # from skip-propagating here. Legit skips still work: no-VR cases leave
+ # run_id empty, and a failed or cancelled matrix fails the result check.
if: |
always()
&& needs.vr-setup.outputs.run_id != ''
@@ -724,10 +729,10 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
if: # Run on pull requests to PostHog/posthog + on PostHog/posthog outside of PRs - but never on forks or Dependabot (no secrets access)
- always() && github.actor != 'dependabot[bot]' &&
+ ${{ !cancelled() && github.actor != 'dependabot[bot]' &&
needs.changes.outputs.frontend == 'true' && (
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'PostHog/posthog') ||
- (github.event_name != 'pull_request' && github.repository == 'PostHog/posthog'))
+ (github.event_name != 'pull_request' && github.repository == 'PostHog/posthog')) }}
steps:
- name: Get telemetry app token
id: telemetry-app-token
@@ -767,7 +772,7 @@ jobs:
# select-stories only runs on internal draft PRs; fire only when it produced a
# decision. DevEx project only; continue-on-error so telemetry never reds CI.
if: |
- always() && github.run_attempt == '1'
+ !cancelled() && github.run_attempt == '1'
&& github.actor != 'dependabot[bot]'
&& github.event.pull_request.head.repo.full_name == 'PostHog/posthog'
&& needs.select-stories.result == 'success'
@@ -806,7 +811,7 @@ jobs:
timeout-minutes: 5
needs: [changes, build-storybook]
if: |
- always() && needs.changes.outputs.frontend == 'true'
+ !cancelled() && needs.changes.outputs.frontend == 'true'
&& github.event_name == 'pull_request'
&& github.event.pull_request.draft == true
&& !contains(github.event.pull_request.labels.*.name, 'run-ci-frontend')
diff --git a/.github/workflows/pr-approval-agent.yml b/.github/workflows/pr-approval-agent.yml
index 0957cdf049d9..a7807dabe452 100644
--- a/.github/workflows/pr-approval-agent.yml
+++ b/.github/workflows/pr-approval-agent.yml
@@ -22,8 +22,11 @@ jobs:
# label already present, or `synchronize` where decide-delta
# asked for re-review (or itself failed — fail closed for safety).
needs: [decide-delta, dismiss]
+ # !cancelled() rather than always() so a push that supersedes this run stops the
+ # LLM review instead of posting a stamphog approval for a commit that is no longer
+ # HEAD. The explicit decide-delta checks below keep the fail-closed re-review paths.
if: >-
- always()
+ !cancelled()
&& !github.event.pull_request.draft
&& github.event.pull_request.user.type != 'Bot'
&& !contains(github.event.pull_request.user.login, '[bot]')
diff --git a/.github/workflows/rust-docker-build.yml b/.github/workflows/rust-docker-build.yml
index 01276a479d1d..4a96c9c79656 100644
--- a/.github/workflows/rust-docker-build.yml
+++ b/.github/workflows/rust-docker-build.yml
@@ -74,12 +74,12 @@ jobs:
build-images:
needs: affected
- # always() is required because 'affected' may be skipped (workflow_dispatch),
- # and GitHub Actions treats skipped dependencies as failures by default.
- # !cancelled() prevents running after manual workflow cancellation.
+ # A status function is required because 'affected' may be skipped (workflow_dispatch)
+ # and a skipped need would otherwise cascade a skip here. !cancelled() covers that
+ # while still stopping the build after manual workflow cancellation.
# Run unless affected explicitly found zero images ('none') or failed.
if: |
- always() && !cancelled() &&
+ !cancelled() &&
(github.event_name != 'pull_request' ||
github.event.pull_request.head.repo.full_name == github.repository) &&
needs.affected.result != 'failure' &&