Ci workflow guide

From sgl-project/sglang · View interactive version

Ci workflow guide is an AI agent skill from the GitHub repository sgl-project/sglang. Guide to SGLang CI workflow orchestration — tiers and their workflows, stage ordering, fail-fast, gating, partitioning, execution modes, adding a runner to a tier, and debugging CI failures. Use when modifying CI workflows, adding stages or runners, debugging CI pipeline issues, or understanding how

How to use this skill

Skill file

SGLang CI Workflow Orchestration Guide

This skill covers the CI infrastructure layer — how tests are dispatched, gated, and aborted on failure across stages. For test authoring (templates, fixtures, registration, which tier a test belongs to), see the write-sglang-test skill. To run the tests a change touches on a PR, see rerun-test.

The workflow files settle any disagreement with this guide. Counts that change with the test tree (shard counts, job counts, suite lists) are left out on purpose; read them from the files named below.


Naming Conventions


Tiers

| Tier (stages) | Workflow | When it runs |

|---------------|----------|--------------|

| base (base-a, base-b, base-c) | pr-test.yml | Every PR with run-ci whose head commit carries a run-ci approval (not needed if its author can approve); on main twice daily (cron) |

| extra (extra-a, extra-b) | pr-test-extra.yml | PRs with run-ci, a run-ci approval of the head commit (as in base), and run-ci-nv-extra; on main from pr-test.yml's scheduled run (call-pr-test-extra) |

| nightly (nightly) | nightly-test-nvidia.yml | Every two days, 14:00 UTC |

| weekly (weekly) | weekly-test-nvidia.yml | Sunday 00:00 UTC |

pr-test-finish (base) and lint are the required checks for merging. Which tier a test belongs to is in write-sglang-test, Choosing a Tier. /rerun-test runs any registered test on a PR, whatever its tier.


Key Files

| File | Role |

|------|------|

| .github/workflows/pr-test.yml | Base tiers: stage jobs, wait jobs, pr-test-finish |

| .github/workflows/pr-test-extra.yml | Extra tier, gated by run-ci and run-ci-nv-extra |

| .github/workflows/nightly-test-nvidia.yml, weekly-test-nvidia.yml | Scheduled tiers: one matrix row per runner config |

| .github/workflows/_pr-test-stage.yml, _pr-test-stage-cpu.yml | Reusable stage: checkout, health check, install, run_suite.py per shard |

| .github/workflows/_diffusion-pr-test-stage.yml | Reusable diffusion lane, called by pr-test-multimodal-gen.yml: the same steps for one base-b-diffusion* stage and runner_config, one job per case partition |

| .github/workflows/_pr-test-check-changes.yml | Path filters, partitions, retry and continue-on-error flags |

| scripts/ci/utils/compute_partitions.py | Shard count and max_parallel per suite |

| scripts/ci/runner_configs.yml | runner_config -> runner label; stage kind -> install |

| test/run_suite.py | Suite lists (PER_COMMIT_SUITES, NIGHTLY_SUITES, OTHER_SUITES); collects, filters, partitions, executes tests |

| python/sglang/test/ci/ci_register.py | Test registration (AST-parsed markers), LPT auto-partition |

| python/sglang/test/ci/ci_utils.py | run_unittest_files(): execution, retry, continue-on-error |

| .github/workflows/pr-gate.yml | PR gating: draft check, run-ci label (with approval-mode: commit, also a run-ci approval of the head commit), per-user rate limiting |

| .github/actions/check-pr-test-health/action.yml | Cross-job fail-fast: queries API for any failed job |

| .github/actions/wait-for-jobs/action.yml | Stage gating: polls API until stage jobs complete |

| .github/scripts/ci-labels.cjs | Resolves the CI control labels into dispatch axes |

| scripts/ci/opt_in_ci_tiers.json | Opt-in CI selections: name -> workflow files and an optional label |

| scripts/ci/utils/slash_command_handler.py | Handles slash commands from PR comments |


Architecture Overview

pr-test.yml on a PR:

  1. detect-changes detects which packages changed (main_package, sgl_kernel, jit_kernel, multimodal_gen, ...) from the PR's file list, without a checkout; call-gate then runs pr-gate.yml (draft, run-ci and the run-ci approval of the head commit, rate limit), and is skipped when nothing relevant changed, which passes pr-test-finish. Only after the gate passes does check-changes check out the PR head and compute the partitions, from detect-changes' result. Kernel and rust-ext builds start after it.
  2. Base A (pre-flight): base-a-test (1-gpu-small, one shard) and base-a-test-cpu.
  3. wait-for-base-a, then Base B: the base-b-test matrix, one row per runner config.
  4. wait-for-base-b, then Base C: the base-c-test matrix and base-c-test-aarch64 (GB300 rows).
  5. Kernel, JIT kernel, and multimodal-gen tests run as called workflows beside the stages.
  6. pr-test-finish aggregates every job and fails on any failure or cancellation.

Each stage job is a matrix over { runner_config, run_timeout, timeout_per_file } rows that calls _pr-test-stage.yml; that job runs run_suite.py --suite {stage}-test-{runner_config} once per shard. Extra, nightly, and weekly reuse the same reusable stage.

Every stage job runs check-pr-test-health after checkout: if any job in the run has already failed, it fails fast with the root cause. Scheduled runs skip the wait-for-base-* jobs and the health check, and run all stages in parallel.


Fail-Fast Layers

4 layers of fail-fast, from fine to coarse:

| Layer | Mechanism | Granularity | Disabled on schedule? |

|-------|-----------|-------------|----------------------|

| 1. Test method → file | unittest -f (failfast) | One test method fails → entire test file stops immediately | Yes |

| 2. File → suite | run_unittest_files() default | One test file fails → entire suite stops (--continue-on-error off) | Yes |

| 3. Job → job | check-pr-test-health action | One job fails → jobs that have not started fail fast (red X) | Yes |

| 4. Stage → stage | wait-for-base-* + needs | Base A fails → base B/C jobs skip entirely (never get a runner) | Yes (wait jobs skipped) |

The control labels bypass-fail-fast, parallel-stages, max-concurrency, and highest-priority (all three) relax these limits for one PR; .github/scripts/ci-labels.cjs resolves them, and the contribution guide describes each.


Execution Modes

| Aspect | PR (pull_request_target) | Scheduled (cron, twice daily) | Manual dispatch (workflow_dispatch) |

|--------|---------------------|-------------------------------|--------------------------------------|

| Stage ordering | Sequential: A → B → C via wait-for-base-* | Parallel | Parallel (the wait jobs run only on PRs) |

| continue-on-error | No (stop at first failure within suite) | Yes (run all tests) | With force_continue_on_error or run_all_tests |

| Retry | Enabled | Enabled | Enabled |

| Shards at once | max_parallel (about a third of the shards); all with max-concurrency | All | All with run_all_tests; otherwise as on a PR |

| PR gate | Yes (draft, run-ci approval of the head commit, rate limit) | Skipped | Skipped with test_parallel_dispatch |

| Extra tier | Only with run-ci-nv-extra | Called from the same run | Called with run_all_tests or test_parallel_dispatch |

A single test, class, or method on a PR runs through /rerun-test, not a stage dispatch.

Testing workflow changes

pr-test.yml and pr-test-extra.yml run on pull_request_target, only for PRs into main and release/*, so a PR's CI runs the workflow files from its base branch, including every _pr-test-*.yml they call. Scripts, tests, and local composite actions (.github/actions/*, resolved from the PR checkout) come from the PR and are tested as usual; edits to the workflow files themselves are not exercised by the PR's own CI. To test them:

The run-ci approval is per commit; see .github/FOLDER_README.md for who approves and how.


Stage Gating (`wait-for-jobs` action)

wait-for-base-a and wait-for-base-b are lightweight ubuntu-latest jobs that poll the GitHub Actions API.

  1. Calls listJobsForWorkflowRun to list all jobs in the current run
  2. Matches jobs by name prefix (matrix shards are named like base-b-test-1-gpu-small (3)), so the stage jobs' name: is load-bearing
  3. If any matched job has conclusion === 'failure' → fail immediately
  4. If all matched jobs are completed and the count matches expected_count → success
  5. Otherwise → sleep and retry, up to max-wait-minutes (240 for base-a, 350 for base-b). Keep budgets under the 6h hard cap on GitHub-hosted runners: a wait killed by the cap ends cancelled, not timeout. The base-b wait sets fail-on-timeout: 'false', so a timeout lets base-c start; pr-test-finish still fails the run on any base-b failure

Each spec entry reads its expected_count from check-changes.outputs.partitions['<suite>'].size, so shard counts never need a hand edit. A new runner row in base-a or base-b still needs its own {"prefix": ..., "expected_count": ...} entry in the wait job.


Cross-Job Fail-Fast (`check-pr-test-health` action)

Composite action called after checkout in the reusable stage workflows and in the kernel and multimodal-gen workflows.

  1. Queries listJobsForWorkflowRun for the current workflow run
  2. Keeps root cause failures only — failed jobs whose failing step is not the health check itself (a job that failed fast is excluded)
  3. If any are found → core.setFailed() with their names; later steps skip through the default if: success()
  4. Otherwise the step succeeds

It checks every job in the run, not only the current stage. Error message example:

Fail-fast: skipping — root cause job(s): base-b-test-1-gpu-small (0), base-b-test-1-gpu-small (1)

Within-Suite Failure Handling

Controlled by run_unittest_files() in python/sglang/test/ci/ci_utils.py.

| Flag | PR default | Scheduled default | Effect |

|------|------------|-------------------|--------|

| --continue-on-error | Off | On | Off: stop at first failure. On: run all files, report all failures at end |

| --enable-retry | On | On | Retry retriable failures |

| --max-attempts | 2 | 2 | Max attempts per file including initial run |

Retry classification: a failure matching NON_RETRIABLE_PATTERNS (import, syntax, type errors, OOM, segfault, ...) is not retried; one matching RETRIABLE_PATTERNS (accuracy and performance assertions) or INFRA_RETRIABLE_PATTERNS is. An unknown AssertionError is retried; other unknown failures are not. The lists are in ci_utils.py.

check-changes sets continue_on_error (true for scheduled runs and run_all_tests), and _pr-test-stage.yml passes it to run_suite.py as --continue-on-error.


Test Partitioning

scripts/ci/utils/compute_partitions.py runs in check-changes and emits, per dispatched suite, {size, arr, max_parallel}:

Within a suite, ci_register.py:auto_partition() assigns files to shards with the LPT heuristic: sort by time descending (filename as tie-breaker), then give each file to the shard with the least total time.

The Compute partitions step summary lists every suite's size and max_parallel for that run. CUDA diffusion lanes also run test/run_suite.py (suites base-b-diffusion*-test-*), but partition the 1-gpu and 2-gpu lanes by case with compute_diffusion_partitions.py; AMD diffusion jobs call python/sglang/multimodal_gen/test/run_suite.py.


check-changes Job

| Trigger | Method |

|---------|--------|

| pull_request_target | dorny/paths-filter on the PR's file list from the API, in _pr-test-detect-changes.yml (no checkout) |

| workflow_dispatch / workflow_call with run_all_tests | Force all true |

| schedule | Force all true |

main_package gates the base stages; sgl_kernel builds the PR-local kernel wheel, runs the kernel suites, and switches B200 jobs to the kernel-build runner labels; jit_kernel and multimodal_gen gate their workflows. The full output list is in _pr-test-check-changes.yml.


Concurrency Control

pr-test.yml groups runs by pr-test-{event_name}-{PR number or ref name}-{git_ref or 'all'}:

cancel-in-progress is true except for workflow_call, so a new push cancels the old PR run.


How To: Add a Runner to a Tier

Adding a test to a runner that its tier already runs needs no workflow edit: stage= and runner_config= on the registration are enough. When the tier lacks that runner, add one row; never move the test to another runner to fit a tier.

  1. Add { runner_config: <key>, run_timeout: ..., ... } to the tier's matrix: the stage job in pr-test.yml (base-a-test, base-b-test, base-c-test, or base-c-test-aarch64 for aarch64 runners), the extra-test matrix in pr-test-extra.yml (with its stage and, for GB300, arch: aarch64), or the matrix in nightly-test-nvidia.yml / weekly-test-nvidia.yml.
  2. Add the suite name {stage}-test-{runner_config} to PER_COMMIT_SUITES or NIGHTLY_SUITES in test/run_suite.py; validate_all_suites rejects a registration whose suite is not listed.
  3. For a base-a or base-b row, add its prefix to the wait-for-base-* spec.
  4. A new runner config (a new machine type) also needs its entry in scripts/ci/runner_configs.yml.

A suite left with no tests makes its stage row fail (the partition lookup returns null): remove the row when moving the last test off a runner.


How To: Debug CI Failures

| Symptom | Likely cause | What to check |

|---------|-------------|---------------|

| Stage B/C jobs red with "Fail-fast: skipping" | An earlier job failed, check-pr-test-health triggered | The root cause job named in the annotation |

| wait-for-base-b waits until timeout | A stage job was renamed or a row lacks its spec entry | Job name: prefixes against the wait spec |

| pr-test-finish fails but all jobs green | A job was cancelled (counts as failure in finish) | Concurrency cancellation, or a wait-for-base-* job hit the 6h hosted-runner cap |

| Stage row fails before running tests | Its suite has no tests, so the partition is null | Registrations for {stage}-test-{runner_config} |

| Tests pass locally but fail in CI | Shard assignment, runner GPU type, or a timeout from the estimate | Which shard the file landed in, the runner label, the file's live estimate |

| Flaky test retried and passed | Retriable failure (accuracy/perf) | [CI Retry] markers in job logs |

| Flaky test NOT retried | Matched a non-retriable pattern | NON_RETRIABLE_PATTERNS in ci_utils.py |


Slash Commands

Handled by scripts/ci/utils/slash_command_handler.py → .github/workflows/slash-command-handler.yml. The commands, their permissions, and their limits are in the contribution guide.

Base CI covers only the core default paths; tests in the extra, nightly, and weekly tiers do not run on a normal PR. To cover what a change touches, run those tests with /rerun-test; the rerun-test skill describes how to pick them.

Opt-in CI tiers

An opt-in tier is a set of workflows a PR enters by carrying run-ci-<tier> on top of run-ci. NVIDIA and AMD have a Base selection (nv, amd, no label) and an Extra tier (nv-extra selects pr-test-extra.yml, amd-extra selects pr-test-amd-extra.yml). Every other hardware has only an Extra tier, <hw>-extra selecting pr-test-<hw>.yml (xeon, npu, xpu, musa, arm64, mlx, mlu, ppu). Each tier is one entry in scripts/ci/opt_in_ci_tiers.json; the slash handler reads it for the hardware arguments of /run-ci, /run-extra-ci, /run-full-ci and /tag-and-rerun-ci, so adding a tier needs no handler change. A tier's workflows follow one convention, enforced by scripts/lint/check_opt_in_ci_tiers.py (pre-commit):

  1. Gate through pr-gate.yml with require-label: run-ci-<tier>, and skip every job that needs the gate when needs.<gate>.outputs.opted-in == 'false'. The gate live-fetches labels; a missing opt-in passes the gate with opted-in=false, so the run is green with its tests skipped, and a full rerun after labeling runs them (/run-extra-ci <hw> reruns green runs). Keep this decision out of event-payload expressions, which do not refresh on rerun. A draft PR, a missing run-ci, or (pr-test.yml, pr-test-extra.yml) a head commit with no approval skips the same way in every workflow that uses the gate, so every job that needs the gate checks opted-in, finish jobs included, and a skipped run shows no passing check; only pr-test-finish, the required check, runs and fails then. The lint below enforces it.
  2. No labeled trigger. GitHub's rerun API reuses the original event payload, so a run started by an unrelated label event and skipped by an if on that payload stays skipped on rerun, and a label event joins the run's concurrency group and cancels the run in progress. Adding a label after a push takes a rerun instead (/run-extra-ci <hw>); for run-ci on pr-test.yml and pr-test-extra.yml, the approving slash command does that rerun.
  3. Every directly selectable workflow that accepts the label is listed in the tier, so /run-extra-ci <hw> re-runs all of them. Reusable jobs chained from a listed workflow stay part of that run.

The tier name extra is reserved: a tier name is also a slash-command hardware argument, and the bare extra argument is rejected as the retired shared tier.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.