Skip to content

Payload scripts can exit before writing to disk #16381

Open

Description

@atimmer

Describe the Bug

We run all sorts of CI scripts related to Payload. We use Turborepo to cache the outputs. This all works fine, but we started to have issues where sometimes dependent scripts would fail.

We debugged it to Payload scripts sometimes not writing the relevant file in time for Turborepo to pick it up. It seems that the Node.js process can exit before the file is written.

Link to the code that reproduces this issue

https://github.com/atimmer/payload-cli-startup-repro/

Reproduction Steps

Run this in the repro repository:

corepack enable
pnpm install
pnpm repro

What the repro script does:

  1. Delete the output file in testing.
  2. Run the payload script to generate a db schema
  3. Verify whether the file is present immediately after

On my machine this reproduces cleanly every time, but as it is a timing issue, it might not reproduce always for other machines.

Which area(s) are affected?

area: core

Environment Info

❯ pnpm --filter=ucms payload info

> [email protected] payload /Users/anton/Code/Freave/MonoMisset/apps/ucms
> cross-env NODE_OPTIONS=--no-deprecation payload info

This project is configured to use pnpm because /Users/anton/Code/Freave/MonoMisset/package.json has a "packageManager" field

Binaries:
  Node: 22.17.1
  npm: 10.9.2
  Yarn: N/A
  pnpm: 10.33.0
Relevant Packages:
  payload: 3.82.1
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.6.0: Wed Nov  5 21:32:38 PST 2025; root:xnu-11417.140.69.705.2~1/RELEASE_ARM64_T6031
  Available memory (MB): 65536
  Available CPU cores: 16

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Apr 24, 2026
  2. added
    area: core
    and removed
    validate-reproduction
    on Apr 24, 2026
  3. albinronnkvist commented on May 19, 2026

    @albinronnkvist

    Not sure whether this is related, but we are seeing something that sounds very similar with Payload migration commands. In our case, commands like payload migrate:create and payload migrate will sometimes exit with status 0 and no output. The behavior appears to be flaky.

    We first started seeing this after upgrading Payload from 3.74.0 to 3.82.1. We have not been able to reproduce the issue on 3.78.0 or earlier, but it reproduces on every version from 3.79.0 onward (all the way up to current latest 3.84.1).

    Examples

    payload migrate:create

    When running pnpm payload migrate:create:

    Expected:

    > [email protected] payload /home/runner/work/cms/cms/app
    > cross-env NODE_OPTIONS=--no-deprecation PAYLOAD_CONFIG_PATH=src/payload.config.ts payload migrate:create --env production
    
    25l? No schema changes detected. Would you like to create a blank migration file? › (y/N)
    [13:17:09] INFO: Starting migration: generating UP statements...
    [13:17:09] INFO: Migration UP complete. Generating DOWN statements...
    [13:17:09] INFO: Migration DOWN statements generation complete.
    ✔ No schema changes detected. Would you like to create a blank migration file? … no
    

    Actual:

    > [email protected] payload /home/runner/work/cms/cms/app
    > cross-env NODE_OPTIONS=--no-deprecation PAYLOAD_CONFIG_PATH=src/payload.config.ts payload migrate:create --env production
    
    payload migrate

    When running pnpm run payload migrate:

    Expected:

    > [email protected] payload /home/runner/work/cms/cms/app
    > cross-env NODE_OPTIONS=--no-deprecation PAYLOAD_CONFIG_PATH=src/payload.config.ts payload migrate
    
    [13:58:28] INFO: Reading migration files from /home/runner/work/cms/cms/app/src/migrations
    [13:58:29] INFO: Done.
    

    Actual:

    > [email protected] payload /home/runner/work/cms/cms/app
    > cross-env NODE_OPTIONS=--no-deprecation PAYLOAD_CONFIG_PATH=src/payload.config.ts payload migrate
    

    Environments

    We have observed this behavior in:

    A local Ubuntu machine

    We ran this script in our project (based on the script in payload-cli-startup-repro):

    import { spawnSync } from 'node:child_process'
    
    const runs = Number(process.env.RUNS || 200)
    let reproduced = false
    
    for (let run = 1; run <= runs; run++) {
      const result = spawnSync(
        'bash',
        ['-c', 'printf "n\\n" | pnpm payload migrate:create --env production'],
        {
          stdio: 'pipe',
          encoding: 'utf8',
          env: {
            ...process.env,
            CI: 'true',
            GITHUB_ACTIONS: 'true',
          },
        },
      )
    
      const output = `${result.stdout || ''}\n${result.stderr || ''}`
      const missingPayloadOutput =
        result.status === 0 &&
        !output.includes('No schema changes detected') &&
        !output.includes('Migration created at') &&
        !output.includes('Starting migration:')
    
      if (missingPayloadOutput) {
        reproduced = true
        console.error(`Reproduced on run ${run}: exited 0 with no Payload migration output.`)
        console.error(output)
        process.exit(1)
      }
    
      console.log(`run ${run}: exit=${result.status}`)
      //console.error(output)
    }
    
    if (!reproduced) {
      console.log(`No silent exit after ${runs} runs.`)
    }

    Result: payload version 3.79.0 and later were reproduced on multiple runs (exited 0 with no Payload migration output). We were not able to reproduce it for payload version 3.78.0 and earlier. Example of a run using 3.82.1:

    RUNS=500 node scripts/repro-migrate-create.mjs
    run 1: exit=0
    run 2: exit=0
    run 3: exit=0
    run 4: exit=0
    run 5: exit=0
    run 6: exit=0
    run 7: exit=0
    run 8: exit=0
    run 9: exit=0
    run 10: exit=0
    run 11: exit=0
    run 12: exit=0
    run 13: exit=0
    run 14: exit=0
    run 15: exit=0
    run 16: exit=0
    run 17: exit=0
    run 18: exit=0
    run 19: exit=0
    run 20: exit=0
    run 21: exit=0
    run 22: exit=0
    run 23: exit=0
    run 24: exit=0
    run 25: exit=0
    run 26: exit=0
    run 27: exit=0
    Reproduced on run 28: exited 0 with no Payload migration output.
    
    > [email protected] payload /home/albin/Dev/cms/app
    > cross-env NODE_OPTIONS=--no-deprecation PAYLOAD_CONFIG_PATH=src/payload.config.ts payload migrate:create --env production
    

    Payload info:

    pnpm payload info
    
    > [email protected] payload /home/albin/Dev/cms/app
    > cross-env NODE_OPTIONS=--no-deprecation PAYLOAD_CONFIG_PATH=src/payload.config.ts payload info
    
    
    Binaries:
      Node: 22.17.0
      npm: 10.9.2
      Yarn: 1.22.22
      pnpm: 10.23.0
    Relevant Packages:
      payload: 3.82.1
      next: 16.2.3
      @payloadcms/db-postgres: 3.82.1
      @payloadcms/drizzle: 3.82.1
      @payloadcms/graphql: 3.82.1
      @payloadcms/live-preview: 3.82.1
      @payloadcms/live-preview-react: 3.82.1
      @payloadcms/next/utilities: 3.82.1
      @payloadcms/plugin-cloud-storage: 3.82.1
      @payloadcms/plugin-form-builder: 3.82.1
      @payloadcms/plugin-multi-tenant: 3.82.1
      @payloadcms/plugin-nested-docs: 3.82.1
      @payloadcms/plugin-redirects: 3.82.1
      @payloadcms/plugin-search: 3.82.1
      @payloadcms/plugin-seo: 3.82.1
      @payloadcms/richtext-lexical: 3.82.1
      @payloadcms/storage-azure: 3.82.1
      @payloadcms/translations: 3.82.1
      @payloadcms/ui/shared: 3.82.1
      react: 19.1.0
      react-dom: 19.1.0
    Operating System:
      Platform: linux
      Arch: x64
      Version: #23~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Apr 14 16:11:48 UTC 2
      Available memory (MB): 27702
      Available CPU cores: 16
    
    Hosted GitHub Actions runners using Ubuntu

    We first started seeing these issues in the workflows after upgrading Payload from 3.74.0 to 3.82.1.

    For example, this step is flaky as described in the examples above:

      - name: Apply Migrations
        run: pnpm run payload migrate
    

    We use bash:

    defaults:
      run:
        shell: bash
    

    Runner info:

    - Runner version: `2.334.0`
    - Operating system: `Ubuntu 24.04.4 LTS`
    - Runner image: `ubuntu-24.04`
    - Runner image version: `20260513.135.3`
    
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

    area: corecreated-by: Contributorstatus: needs-triagev3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions