Skip to content

GitHub integration: overlapping production deploy runs race, so an older commit's Edge Functions can overwrite a newer commit's #52048

Open

Description

@luizfneves404

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

With the GitHub integration's Deploy to production enabled, every push to the production branch starts a deployment workflow run. Runs for consecutive pushes are not serialized or cancelled, so they overlap whenever pushes arrive less than one run apart (about 7 minutes for 146 Edge Functions in our case). Each run deploys every function in a different order, so for any one function, the run that deploys it last wins. That is often the run for the older commit. The result is that a function keeps serving the previous commit's code while both Supabase Preview checks are green. It stays that way until a later push happens to redeploy it.

Example, from the project's workflow_run_logs (Cloning git repo... git_ref=main, then Deploying Function... slug=<fn>):

function run for commit N (started 21:19:50) run for commit N-1 (started 21:16:11) served after both green
fn-a 21:21:19 21:17:51 N ✅
fn-b 21:20:14 21:23:13 N-1 ❌
fn-c 21:22:17 21:23:16 N-1 ❌

Over 24 hours on a busy day, about 80 runs had at least one function overwritten by an older, still-running run. For about 50 of those overwrites, the function's own import graph differed between the two commits, meaning stale runtime code was served. Those windows lasted from under a minute to 44 minutes. The integration gives no signal at all: both checks are green, and the function's version and updated_at both advance.

To Reproduce

  1. Connect a repo with many Edge Functions to the GitHub integration, with Deploy to production on.
  2. Push commit A to the production branch, then push commit B (which changes a module imported by several functions) about 2–3 minutes later, while A's run is still deploying.
  3. Once both checks are green, read the functions back (GET /v1/projects/{ref}/functions/{slug}/body or the MCP get_edge_function). Some of the functions that import the module serve A's code.
  4. Logs Explorer: select timestamp, log_attributes['workflow_run'], event_message from logs where source='workflow_run_logs' and event_message like '%Deploying Function%slug=<fn>%' order by timestamp shows A's run deploying the function after B's run did.

Expected behavior

The newest pushed commit's code is what ends up deployed. For example, runs for the same production branch could be queued, or a superseded run could be cancelled before its deploy step, as GitHub Actions concurrency groups do. The Branching docs say "the same deployment workflow will be run on every commit pushed to your git branch", with nothing about ordering.

System information

  • Hosted project with Branching via GitHub, Deploy to production on (no preview branches)
  • Functions are deployed by the integration (not the CLI); about 146 functions, one shared _shared/ directory

Additional context

Related but different: #51535 (git-triggered branch-action redeploys). The dashboard's "Resync branch" (#46723) repairs the state by hand, if someone knows to press it.

Activity

  1. added
    external-issue
    on Oct 20, 2026
  2. yogiwaran2003 commented on Oct 21, 2026

    @yogiwaran2003

    @luizfneves404 I would like to solve this issue

  3. efekanbahceci commented on Oct 21, 2026

    @efekanbahceci
    Contributor

    I looked into the root cause of this race across the branching workflow runner and the CLI function deployment path. This is a backend orchestration issue in the platform workflow runner rather than something that lives in the supabase/supabase frontend/docs monorepo.

    Why this happens

    1. No per-branch concurrency control on action_runs:
      When Deploy to production is enabled, each push to the production branch triggers a separate workflow run (/v1/projects/{ref}/actions/{run_id}) executing the clone -> pull -> health -> configure -> migrate -> seed -> deploy DAG. The runner currently starts overlapping runs for the same branch_id / project_ref concurrently rather than serializing them in a per-branch queue or canceling superseded in-progress runs.

    2. Non-deterministic per-run function deployment order:
      During the deploy step, the Go CLI (pkg/function/deploy.go and pkg/function/batch.go) iterates over config.FunctionConfig (map[string]config.Function) using for slug, function := range functionConfig and dispatches uploads through a worker queue (queue.NewJobQueue(s.maxJobs)). Because Go randomizes map iteration order on each execution—and individual bundle/upload timings vary under concurrency—two overlapping runs with 100+ functions traverse and upload the function set in different orders.

    3. Last-writer-wins on function updates:
      Both individual function uploads (POST /v1/projects/{ref}/functions/deploy / PUT /v1/projects/{ref}/functions/{slug}) and the final PUT /v1/projects/{ref}/functions (v1-bulk-update-functions) call apply unconditionally without checking whether the calling workflow_run_id has been superseded by a newer run for the same branch. Whenever run N-1 reaches a given function slug after run N has already deployed it, run N-1 overwrites the bundle with the older commit's artifact and increments version / updated_at, while both runs exit 0 and report green check runs.

    Where the fix needs to happen

    Since the workflow orchestrator and /v1/projects/{ref}/actions execution engine live in the internal platform backend (outside this repository), this needs to be addressed server-side by the Supabase team:

    • Per-branch serialization / coalescing: Runs targeting the same branch_id (especially the production branch) should be serialized per branch, or queued runs should coalesce so that if commits B and C arrive while A is running, A finishes safely and only C runs next (or A's deploy step is skipped/canceled once superseded).
    • Run fencing on deploy: The deploy step and function update endpoints should reject writes from a workflow_run_id when a newer workflow run has already been created or started deploying for the same branch_id.
  4. added
    integrations
    and removed on Oct 21, 2026
  5. SahilArate commented on Oct 24, 2026

    @SahilArate

    Hi @Hallidayo @luizfneves404 here i went through the issue and investigated on my machine please assign it to me i would like to raise PR with the root solution once you assign it to me.
    Thank you!

  6. solvionholdings commented on Oct 30, 2026

    @solvionholdings

    Until the runner serializes runs, you can get "newest commit wins" by moving production deploys into a GitHub Actions workflow with a concurrency group.

    1. Turn off Deploy to production in the GitHub integration (it covers new migrations, Edge Functions and Storage buckets from config.toml). Preview branches keep working.
    2. Deploy from Actions:
    on:
      push:
        branches: [main]
    concurrency:
      group: supabase-production
      cancel-in-progress: false
    jobs:
      deploy:
        runs-on: ubuntu-latest
        env:
          SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
          SUPABASE_DB_PASSWORD: ${{ secrets.PRODUCTION_DB_PASSWORD }}
          SUPABASE_PROJECT_ID: ${{ secrets.PRODUCTION_PROJECT_ID }}
        steps:
          - uses: actions/checkout@v4
          - uses: supabase/setup-cli@v1
          - run: supabase link --project-ref $SUPABASE_PROJECT_ID
          - run: supabase db push
          - run: supabase functions deploy --project-ref $SUPABASE_PROJECT_ID

    With cancel-in-progress: false only one run executes at a time, and a newer queued run replaces an older pending one, so the last deploy is always the newest queued commit. true would cancel mid-deploy and leave a mixed set.

    Verify after a burst of pushes: supabase functions download <slug> and diff against the commit, or the /functions/{slug}/body check you already use.

    This matters for security too: a fix to an auth check can be silently reverted for as long as the windows you measured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    edge functionsexternal-issueintegrations

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions