From 574f9cdb2ea7591cd617a5a20b3a1922a56d691c Mon Sep 17 00:00:00 2001 From: Shangming Cai Date: Wed, 21 Oct 2026 18:59:16 +1300 Subject: [PATCH] [CI] slash-command: Add /run-cpu-ci to run only the CPU unit suite (#45501) --- .agents/skills/ci-workflow-guide/SKILL.md | 1 + .github/FOLDER_README.md | 4 +- .github/workflows/_pr-test-stage-cpu.yml | 9 ++- .github/workflows/run-cpu-ci.yml | 69 ++++++++++++++++ .github/workflows/slash-command-handler.yml | 2 + .../developer_guide/contribution_guide.mdx | 3 +- scripts/ci/utils/slash_command_handler.py | 78 +++++++++++++++++++ 7 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/run-cpu-ci.yml diff --git a/.agents/skills/ci-workflow-guide/SKILL.md b/.agents/skills/ci-workflow-guide/SKILL.md index 27dcaf522c..30731fcc0f 100644 --- a/.agents/skills/ci-workflow-guide/SKILL.md +++ b/.agents/skills/ci-workflow-guide/SKILL.md @@ -398,6 +398,7 @@ group: pr-test-{event_name}-{branch}-{pr_sha}-{stage} | `/run-extra-ci` | Adds both labels + reruns **only** `PR Test Extra`, leaving baseline runs alone. Alias: `/rerun-extra-ci` | | `/rerun-test [ ...]` | Reruns specific test file(s) via `rerun-test.yml`. A file arg containing a glob metacharacter (`*`, `?`, `[...]`) expands against `test/registered/` and the multimodal test dir to every matching `test_*.py` (e.g. `/rerun-test test_*backend*.py` — wrap in backticks so GitHub doesn't italicize the `*`); matches are deduped, grouped by dispatch shape, and can't carry a `::test` selector. No match → single ⛔ reply, nothing dispatched. | | `/rerun-group [ ...]` | Expands registered test groups, then reuses `/rerun-test` | +| `/run-cpu-ci` | Dispatches `run-cpu-ci.yml` on main: only the `base-a-test-cpu` suite, at the PR head SHA, no caches saved. Same gate as `/rerun-test`. Alias: `/rerun-cpu-ci` | Handled by `scripts/ci/utils/slash_command_handler.py` → `.github/workflows/slash-command-handler.yml`. diff --git a/.github/FOLDER_README.md b/.github/FOLDER_README.md index f951adfa80..b170b074cc 100644 --- a/.github/FOLDER_README.md +++ b/.github/FOLDER_README.md @@ -14,9 +14,9 @@ Recognized permission keys: | --- | --- | | `can_tag_run_ci_label` | `/tag-run-ci-label`, `/tag-and-rerun-ci`, `/run-full-ci`, `/run-extra-ci` | | `can_rerun_failed_ci` | `/rerun-failed-ci`, `/tag-and-rerun-ci`, `/run-full-ci`, `/run-extra-ci` | -| `cooldown_interval_minutes` | rate limit in `pr-gate.yml`; `0` also grants `/rerun-test`, `/rerun-group` | +| `cooldown_interval_minutes` | rate limit in `pr-gate.yml`; `0` also grants `/rerun-test`, `/rerun-group`, `/run-cpu-ci` | -`/rerun-test` and `/rerun-group` are gated on the commenter alone: either +`/rerun-test`, `/rerun-group` and `/run-cpu-ci` are gated on the commenter alone: either `cooldown_interval_minutes: 0`, or `write`/`admin` permission on the repo. Where the PR comes from makes no difference, and authoring it grants nothing. diff --git a/.github/workflows/_pr-test-stage-cpu.yml b/.github/workflows/_pr-test-stage-cpu.yml index 57e0bffb7c..5f18ea70bd 100644 --- a/.github/workflows/_pr-test-stage-cpu.yml +++ b/.github/workflows/_pr-test-stage-cpu.yml @@ -17,7 +17,7 @@ on: type: string required: true caller_inputs: - description: 'toJson(inputs) from pr-test.yml. Read via fromJson(...).git_ref / skip_pr_test_health_check / test_parallel_dispatch / run_all_tests.' + description: 'toJson(inputs) from pr-test.yml. Read via fromJson(...).git_ref / skip_pr_test_health_check / test_parallel_dispatch / run_all_tests / skip_cache_save.' type: string required: true partitions: @@ -110,7 +110,7 @@ jobs: with: workspaces: rust shared-key: "sglang-grpc-cpu" - save-if: ${{ matrix.partition == 0 }} + save-if: ${{ matrix.partition == 0 && !fromJson(inputs.caller_inputs).skip_cache_save }} # uv pip targets a venv by default; setup-python has no venv — install into that interpreter (see UV_SYSTEM_PYTHON in https://docs.astral.sh/uv/guides/integration/github/) - name: Install dependencies @@ -156,9 +156,12 @@ jobs: python3 run_suite.py --hw cpu --suite ${{ inputs.self_name }} --auto-partition-id ${{ matrix.partition }} --auto-partition-size ${{ fromJson(inputs.partitions)[inputs.self_name].size }} --partition-model-file /tmp/partition-model.json --fork-worker-batch-size 20 $CONTINUE_ON_ERROR_FLAG # PRs save only what the base lacks; the implicit if: success() keeps a - # half-downloaded cache unpublished. + # half-downloaded cache unpublished. skip_cache_save is for callers that + # dispatch on main but test PR code (run-cpu-ci.yml): a save there would + # publish PR-written files under main's cache scope. - name: Decide whether to save the HF cache id: hf_cache_save + if: ${{ !fromJson(inputs.caller_inputs).skip_cache_save }} run: | size=$(du -sb "$HF_HOME" 2>/dev/null | cut -f1) after=${size:-0} diff --git a/.github/workflows/run-cpu-ci.yml b/.github/workflows/run-cpu-ci.yml new file mode 100644 index 0000000000..ee005afd28 --- /dev/null +++ b/.github/workflows/run-cpu-ci.yml @@ -0,0 +1,69 @@ +# Runs only the per-commit CPU unit suite (base-a-test-cpu) against a PR head, +# dispatched by the `/run-cpu-ci` slash command. A cheap check for small PRs: +# pair it with `/rerun-group ` instead of a full `run-ci` round. +# +# Always dispatched on main, so the workflow definition and every reusable +# workflow it calls are trusted; only the code under test comes from the PR. +# That code runs on hosted runners with a read-only token and no secrets +# (nothing here inherits them), the same exposure as `/rerun-test` cpu mode. +name: Run CPU CI +run-name: "[run-cpu-ci] ${{ inputs.git_ref }}" + +on: + workflow_dispatch: + inputs: + git_ref: + description: "PR head SHA to test" + required: true + type: string + pr_number: + description: "PR number (informational)" + required: false + type: string + default: "" + # Read by _pr-test-stage-cpu.yml via caller_inputs. Its fail-fast health + # check inspects sibling jobs of a pull_request run, which this is not. + skip_pr_test_health_check: + description: "Skip the PR test health check fail-fast" + required: false + type: boolean + default: true + # Also read via caller_inputs. This run is on main's ref, so a cache it + # saved would be restored by main and every PR, yet hold PR-written files. + skip_cache_save: + description: "Do not save the HF / Rust caches" + required: false + type: boolean + default: true + +concurrency: + group: run-cpu-ci-${{ inputs.git_ref }} + cancel-in-progress: true + +permissions: + contents: read + issues: read + pull-requests: read + +jobs: + # pr_test_yml stays pr-test.yml: compute_partitions.py reads it from the PR + # checkout, which may predate this file, and sizing shards off the per-commit + # stage's run_timeout_minutes keeps the split identical to PR CI. + check-changes: + uses: ./.github/workflows/_pr-test-check-changes.yml + with: + git_ref: ${{ inputs.git_ref }} + run_all_tests: true + + # self_name must be the suite name: the stage passes it to run_suite.py. + # No rust_ext_artifact: its compile job runs on a self-hosted build node, so + # the stage falls back to its cache and compiles on a miss. + base-a-test-cpu: + needs: check-changes + uses: ./.github/workflows/_pr-test-stage-cpu.yml + with: + self_name: base-a-test-cpu + check_changes: ${{ toJson(needs.check-changes.outputs) }} + caller_inputs: ${{ toJson(inputs) }} + partitions: ${{ needs.check-changes.outputs.partitions }} + run_timeout_minutes: '15' diff --git a/.github/workflows/slash-command-handler.yml b/.github/workflows/slash-command-handler.yml index beb3545e03..a8052f26a5 100644 --- a/.github/workflows/slash-command-handler.yml +++ b/.github/workflows/slash-command-handler.yml @@ -27,6 +27,8 @@ jobs: contains(github.event.comment.body, '/run-extra-ci') || contains(github.event.comment.body, '/rerun-full-ci') || contains(github.event.comment.body, '/rerun-extra-ci') || + contains(github.event.comment.body, '/run-cpu-ci') || + contains(github.event.comment.body, '/rerun-cpu-ci') || contains(github.event.comment.body, '/rerun-group') || contains(github.event.comment.body, '/rerun-test') || startsWith(github.event.comment.body, '/tag-') || diff --git a/docs/docs/developer_guide/contribution_guide.mdx b/docs/docs/developer_guide/contribution_guide.mdx index d0b25b1024..277d087cfa 100644 --- a/docs/docs/developer_guide/contribution_guide.mdx +++ b/docs/docs/developer_guide/contribution_guide.mdx @@ -149,6 +149,7 @@ For CI to run on a pull request, it must have the "run-ci" label. Authorized use - `/run-extra-ci`: Extra CI **only**. Applies both labels, then reruns just `PR Test Extra`, leaving baseline CI runs alone. Use it when baseline is already green and you only need the extra tier. - `/rerun-test [ ...]`: Reruns one or more specific tests directly. A spec may select a file, class, or method using `::[.]`. Multiple specs and file globs are supported. `--changed` (short form `-c`) adds every test file the PR itself adds or modifies (under `test/registered/` or the multimodal test directory), so a PR that touches several tests can rerun them all without listing them. Examples: `/rerun-test test_srt_endpoint.py`, `/rerun-test registered/core/test_srt_endpoint.py::TestSRTEndpoint.test_simple_decode`, `/rerun-test test_a.py test_b.py`, `/rerun-test test_*backend*.py`, `/rerun-test --changed`, or `/rerun-test -c`. - `/rerun-group [ ...]`: Expands one or more registered test groups (for example, `/rerun-group rust-server`) and dispatches their tests through the same selective-rerun workflow. Groups are defined in [`scripts/ci/rerun_test_groups.json`](https://github.com/sgl-project/sglang/blob/main/scripts/ci/rerun_test_groups.json). +- `/run-cpu-ci`: Runs only the CPU unit suite (`base-a-test-cpu`) against the PR head, partitioned the same way as in PR CI, without the `run-ci` label or any GPU stage. For a small PR, `/run-cpu-ci` plus `/rerun-group ` covers the unit tests and the affected module's tests. Alias: `/rerun-cpu-ci`. The rerun commands have the following permission rules: @@ -156,7 +157,7 @@ The rerun commands have the following permission rules: | --- | --- | --- | --- | | `/rerun-failed-ci` | Always allowed on their own PR | Must have `can_rerun_failed_ci` in `CI_PERMISSIONS.json` | None | | `/run-full-ci`, `/run-extra-ci` | Not auto-allowed -- these apply labels, which the PR-author allowance does not cover | Must have both `can_tag_run_ci_label` and `can_rerun_failed_ci` in `CI_PERMISSIONS.json` (every listed user has both) | None | -| `/rerun-test`, `/rerun-group` | No special allowance; judged as any other commenter | Must have `cooldown_interval_minutes: 0` in `CI_PERMISSIONS.json`, or `write`/`admin` repository permission | None -- the same rule applies wherever the PR comes from | +| `/rerun-test`, `/rerun-group`, `/run-cpu-ci` | No special allowance; judged as any other commenter | Must have `cooldown_interval_minutes: 0` in `CI_PERMISSIONS.json`, or `write`/`admin` repository permission | None -- the same rule applies wherever the PR comes from | Selective reruns do not build or install a PR-local `sglang-kernel` wheel. If a PR changes `python/sglang/kernels/aot/` or code that depends on that AOT change, use the normal/full PR CI workflow. A `/rerun-test` or `/rerun-group` result may use the pinned released kernel and does not validate the combined change. diff --git a/scripts/ci/utils/slash_command_handler.py b/scripts/ci/utils/slash_command_handler.py index d5cca48e47..a85507482c 100644 --- a/scripts/ci/utils/slash_command_handler.py +++ b/scripts/ci/utils/slash_command_handler.py @@ -1635,6 +1635,80 @@ def handle_rerun_group( ) +CPU_CI_WORKFLOW_FILE = "run-cpu-ci.yml" +CPU_CI_SUITE = "base-a-test-cpu" + + +def handle_run_cpu_ci(gh_repo, pr, comment, user_perms, token): + """ + Handles /run-cpu-ci: dispatch run-cpu-ci.yml, which runs only the CPU unit + suite (base-a-test-cpu) against the PR head, partitioned the way PR CI is. + + Always dispatched on main with the head SHA as an input, for forks and + in-repo PRs alike, so the workflow definition is main's. It runs PR code on + hosted runners with no secrets, so it takes the /rerun-test gate. + """ + if not _check_rerun_test_permissions( + gh_repo, pr, comment, user_perms, "run-cpu-ci" + ): + return False + + allowed, gate_msg = _check_rebase_gate(gh_repo, pr, token) + if not allowed: + comment.create_reaction("confused") + pr.create_issue_comment(gate_msg) + return False + + head_sha = pr.head.sha + ref = gh_repo.default_branch + try: + workflow = gh_repo.get_workflow(CPU_CI_WORKFLOW_FILE) + except Exception as e: + comment.create_reaction("confused") + pr.create_issue_comment(f"⛔ `{CPU_CI_WORKFLOW_FILE}` not found: {e}") + return False + + dispatch_time = time.time() + resp = requests.post( + f"https://api.github.com/repos/{gh_repo.full_name}/actions/workflows/{workflow.id}/dispatches", + json={ + "ref": ref, + "inputs": {"git_ref": head_sha, "pr_number": str(pr.number)}, + }, + headers={ + "Authorization": f"Bearer {token}", + "Accept": "application/vnd.github+json", + }, + ) + if resp.status_code not in (200, 204): + print(f"Dispatch failed: {resp.status_code} {resp.text}") + comment.create_reaction("confused") + pr.create_issue_comment( + f"⛔ Failed to dispatch `{CPU_CI_WORKFLOW_FILE}`: {resp.status_code}" + ) + return False + + run_url = find_workflow_run_url( + gh_repo, + workflow.id, + ref, + "run-cpu-ci", + token, + dispatch_time, + pr_head_sha=head_sha, + ) + target = f"`{CPU_CI_SUITE}` on `{head_sha[:12]}`" + if run_url: + pr.create_issue_comment(f"🚀 Running {target}: [View workflow run]({run_url})") + else: + pr.create_issue_comment( + f"🚀 Running {target}. Could not retrieve the run URL; check the " + f"[Actions tab](https://github.com/{gh_repo.full_name}/actions/workflows/{CPU_CI_WORKFLOW_FILE})." + ) + comment.create_reaction("+1") + return True + + # Namespaces this handler owns. Anything else reaching the script is a comment # that merely quoted a path, and is left alone. OWNED_COMMAND_PREFIXES = ("/tag-", "/rerun-", "/run-") @@ -1649,6 +1723,7 @@ KNOWN_COMMANDS = ( "/rerun-test", "/run-full-ci", "/run-extra-ci", + "/run-cpu-ci", ) # Removed commands, kept because they were documented long enough that muscle @@ -1767,6 +1842,9 @@ def main(): elif is_extra_ci: handle_run_extra_ci(repo, pr, comment, user_perms) + elif first_line.startswith(("/run-cpu-ci", "/rerun-cpu-ci")): + handle_run_cpu_ci(repo, pr, comment, user_perms, token) + elif first_line.startswith("/rerun-failed-ci"): handle_rerun_failed_ci(repo, pr, comment, user_perms)