Skip to content

ci: apple-build-kunit: run only the touched KUnit suites until approval - #3675

Closed
RyanTheTide wants to merge 10 commits into
mainfrom
ci/kunit-tiering
Closed

RyanTheTide wants to merge 10 commits into
mainfrom
ci/kunit-tiering

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Every push to a PR that touches the Apple KUnit paths runs all 16 suites. That's 17 runner jobs per push, so the trusted queue on the shared runners is many hours deep: 23 queued "Apple build and KUnit" runs at noon, at 17 jobs each.

This adds a plan job ahead of the KUnit matrix. On same-repo PRs it reads the changed files through the API (pull-requests: read, no checkout, no PR code) and picks the suites to run:

  • Only the touched suites: the suites whose directories the PR changes, e.g. drivers/media/platform/apple/isp/ selects isp. Shared media files select all media suites.
  • All suites: shared code (include/, rust/, mm/, arm64 configs, any Kconfig* or Makefile, drivers/iommu, drivers/pci/controller, drivers/power, drivers/soc/apple outside clpc*, this workflow) and any other path outside the known-unrelated list (lib/, kernel/, drivers/base, the KUnit tooling, ...).
  • No suite (build only): drivers/nvme/host, drivers/thunderbolt, drivers/net/wireless/apple. apple-build compiles them, and it still runs on every PR.
  • Ignored: DT sources, Documentation/, MAINTAINERS, .github/ (except this workflow), and other workflows' tests and tools. Those can't change these suites.

The full matrix runs:

  • on pushes, dispatches and fork PRs (forks run on hosted runners, unchanged);
  • on a push to a PR that is already approved (GitHub's review decision, or an approval at the head);
  • when someone adds the kunit-full label;
  • when the API errors or truncates the file list.

Before merge. The merge train adds kunit-full with a maintainer token, so the label event starts the workflow; labels added with the bot's GITHUB_TOKEN don't. It then waits until all 16 suites have passed at the PR head; the train has a script that checks exactly that. kunit-full runs get their own concurrency group, so adding the label never cancels the PR's in-flight run. Other labels start nothing and cancel nothing.

An earlier revision of this PR also published a commit status as a merge gate and dispatched a full run on approval. That was dropped after review: linux has no required checks, so a status can't gate merges by itself, and its writers can't be serialized across runs.

What it would pick on open PRs (same planner, run against their live file lists):

PR changed files suites
#3483 (G16 TA ring) 4 asahi
#3340 (G16 compute) 17 asahi
#3217 (scaler) 2 scaler
#1489 (AVE + DT) 8 ave
#3616, #3609, #3405 (DCP) 5-9 dcp-fabric, dcp-topology
#3605, #3656 (thunderbolt) 1 none (build only)
#2633, #3603, #3660 (shared paths) 3-6 all 16

Tested: ran the plan job's script locally with the real API. Unapproved single-area PRs pick 1 suite (#3483, #3217, #1489); #2633 (shared path) picks 16; #2103 (approved) picks 16. A fork pull_request event, a push, and a bad token (with a warning) all pick 16. The workflow parses as YAML, with jobs apple-build, plan, and kunit (needs: plan, matrix from the plan output, skipped when the plan picks nothing). No runtime change: CI only.
Risk: two-way door (revert restores the full matrix on every push). Macs: none. Until approval or kunit-full, a PR's KUnit checks cover only its own suites, so a cross-suite break shows up at the full run before merge instead of on the first push.

The Apple KUnit matrix runs 16 suites for every push to every PR that
touches any of its paths, so one push costs 16 runner jobs and the
trusted queue on the shared runners is hours deep.

A new plan job reads the PR's changed files through the API (no
checkout) and picks the suites whose directories the PR changes.
Shared code (include/, rust/, mm/, arm64 configs, Kconfig or Makefile,
iommu, pci, power, drivers/soc/apple outside clpc, this workflow) and
any unknown path select all suites; nvme, thunderbolt and Apple Wi-Fi
are build-only (apple-build compiles them, no suite lives there);
files outside this workflow's paths are ignored. The full matrix runs
on pushes and dispatches, once the PR is approved (GitHub review
decision or an approval at the head), and when the kunit-full label is
added. API errors or a truncated file list select the full matrix.
apple-build always runs.

Labelled events start the workflow only for kunit-full; any other label
gets its own concurrency group, so it never cancels a running check.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at 2b721b5.

Blocker: The planner only observes approval when something else starts the workflow. The event list has no review event, so approving an already-green narrow run does not start full KUnit. The new code also does not make the full result a pre-merge gate. A PR armed for auto-merge can land on approval using the narrow result before anyone adds the label. Please wire a reliable full-run request and require its green result for the current head before arming or merging. Show the end-to-end case where a narrow pass followed by approval stays blocked until the full run passes, including a stale or cancelled full run.

Checked: Scope selection reads the API without executing PR code. Shared and uncertain paths select the full matrix, and rename handling includes both paths. The gap is the transition from a narrow result to merge eligibility.

Review: approving a PR started nothing, so a narrow pass stayed the
last KUnit result, and nothing required the full matrix before merge.

- The plan job sets the commit status "KUnit full matrix" to pending
  on the PR head for every same-repo run. A final job sets it to
  success only when a full-matrix run passed for that exact head; a
  narrow, cancelled or unfinished run leaves it pending, a failing
  suite sets failure. The readiness bot treats pending as not ready.
- An approval of a same-repo PR (pull_request_review) dispatches this
  workflow from main with the PR number. GITHUB_TOKEN dispatches do
  start workflows. The dispatch run reads the PR's current head through
  the API, refuses forks and closed PRs, checks out refs/pull/N/merge,
  verifies its second parent against that head, runs all suites and
  records the status.
- Fork PRs (the pull_request twin) always run the full matrix and get
  no gate. Dispatch concurrency groups are per PR, so two approvals do
  not cancel each other.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at 3e15f101.

Blockers: The new status needs a corresponding required gate or explicit merge-train predicate. The workflow writes it but does not enforce it before arming. Please show the effective policy and cover fork PRs and PRs outside the workflow path filters, where this job does not publish the status.

The narrow PR run and dispatched full run have different concurrency groups and can finish in either order. A slow narrow run can write pending after a full pass for the same SHA, leaving the approved PR blocked without another dispatch. Make narrow runs preserve an existing full pass, or serialize ownership of the result. Add a test for full success followed by late narrow completion.

Checked: Approval now has an explicit dispatch path, and the full run verifies the checked-out merge ref against the planned head.

Review: the narrow PR run and the dispatched full run are in different
concurrency groups and can finish in either order, so a slow narrow
run could write pending over a full pass for the same head.

Pending writes (the plan job's and the final job's) now read the
head's statuses first and keep an existing "KUnit full matrix"
success. Only a full run records failure; a narrow run's failing suite
shows in its own check and leaves the status pending.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at 550fe837.

Blockers: The current main rules do not require any status check, and the PR description confirms GitHub auto-merge does not wait for this status. Readiness labels and the train’s manual gate protect only the paths that consult them. Show that the affected PRs cannot be armed until a full pass exists at the current head, or make the status a required check with a covered path for forks and out-of-scope PRs.

The fake API test covers sequential completion. The GET and POST are separate operations across independent runs. A narrow writer can read pending, the full writer can post success, and the narrow writer can then post pending over it. Serialize status publication or give the terminal status a single writer. Include an interleaving test with full success between the narrow GET and POST.

@github-actions github-actions Bot added area:release Area from CODEOWNERS (bot) blast:none Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Merge readiness at bb701746: not ready yet

Check Detail
CI at head no failing: apple-build, host-tests, pr-text / pr-text, KUnit plan, KUnit ${{ matrix.suite }}
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok not needed: no runtime change
Conflicts ok not computed yet
PR text ok Risk: two-way · (revert restores the full matrix on every push). Macs: none. Until approval or kunit-full, a PR's KUnit checks cover only its own suites, so a cross-suite break shows up at the full run before merge instead of on the first push.

Areas: area:release

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

Review: a read-then-write across independent runs can interleave, so
a narrow run could read pending, a full run post success, and the
narrow run then post pending over it.

Full runs now own "KUnit full matrix": they write pending when they
start (keeping an existing pass) and their outcome when they finish.
A narrow run writes nothing at the end, and at the start only marks a
head that has no status yet. Any status means a full run has started,
and a full pass is always preceded by that run's own pending write, so
a full pass cannot land between a narrow run's read and its write.
Two full runs racing on one head can at worst leave pending until the
later one reports (fails closed).

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

On "make the status a required check": I'm not doing that in this PR. linux main has no required checks today (its rulesets require approvals only), so gh pr merge --auto already merges without waiting for any CI, including the existing KUnit, host-tests and dt-checks jobs. That is a repository setting, not something this workflow can fix.

A required KUnit full matrix would also block every PR that doesn't run this workflow, because nothing would ever report that context. That's most linux PRs (DT-only, docs, other drivers), plus fork PRs, which run the full matrix as plain checks. Making it required needs either a ruleset change by an owner or a companion workflow that reports success on every PR outside these paths. I'm raising that as a separate decision.

Within the current policy, the gates that do run before a merge both block on the pending status: the readiness label and the merge train's gate. The status itself now has a single owner per head (fourth commit).

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at c1360daf.

Removing the narrow final writer closes the late-completion case. The narrow planner still reads an absent status and then posts pending in a separate operation. If paused between those calls, it can publish pending after the full planner and recorder write success. The terminal full writer can also publish pending after cancellation. Please put status writes under one serialization boundary or use a dedicated required full-result context that narrow and cancelled runs cannot overwrite. The owner decision on enforcing the pre-arm gate is still open.

From an independent review of the gate:

- Only approvals by owners, members or collaborators dispatch the full
  matrix; anyone can submit an approving review on a public repository,
  which would have started self-hosted runs at will.
- Review-triggered runs get a per-run concurrency group, so a later
  review cannot cancel an approval's run before it dispatches.
- kunit-full label runs get their own group, so adding the label does
  not cancel the PR's in-flight run (a cancelled check reads as
  failing to the readiness bot).
- Dispatched runs are named after the PR (run-name and job names), so
  their checks on main's tip are not mistaken for main's own KUnit.
- Files outside the trigger paths now select all suites unless they
  are known to be unrelated (DT sources, Documentation, other
  workflows' tests and tools, .github), so shared code such as lib/,
  kernel/ or the KUnit tooling is not skipped.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
@RyanTheTide
RyanTheTide marked this pull request as draft November 30, 2026 02:28
@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Nov 30, 2026
… the full run

Decision on the gate: the full-matrix commit status, the approval
dispatch and the recorder job are removed. linux has no required
checks, so a status cannot gate merges by itself, and serializing its
writers across runs needs more machinery than it is worth.

Instead the merge train adds the kunit-full label with a maintainer
token before merging a linux PR and waits for all 16 KUnit suites to
pass at the head. kunit-full runs get their own concurrency group, so
the label does not cancel the PR's in-flight run. Unapproved same-repo
PRs still run only their suites; pushes, dispatches, fork PRs, pushes
to approved PRs and API doubt run the full matrix.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
@RyanTheTide
RyanTheTide marked this pull request as ready for review November 30, 2026 03:26

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: FINISH at 44654d59.

Removing the shared status writers resolves the status race. The train predicate still exits zero when no Apple check is present. That also occurs on an in-scope head before check creation or when the workflow did not start. Determine applicability from the files and trigger contract, then require positive full-run evidence for applicable heads. Wire that predicate into the actual pre-arm and landing path before tiering is enabled. Test in-scope with no checks, out-of-scope with no checks, and stale or cancelled runs.

The labeled event should force the full plan directly from its payload. Currently the planner re-reads the label through a bounded GraphQL list, so a label absent from that response can leave the requested full run narrow.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 30, 2026
Review: the planner re-read the label through a bounded GraphQL list,
so a kunit-full label missing from that response could leave the
requested full run narrow. The label name now comes from the event
payload, and a kunit-full label event runs every suite without asking
the API.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

On the predicate and its wiring:

  • The predicate. Applicability now comes from the PR's changed files matched against this workflow's pull_request_target paths, read from the base branch with GitHub's glob rules. It no longer depends on whether any check exists. For an applicable head it requires all 16 suites to have a SUCCESS check run at that head: a missing, queued, cancelled or failed suite means not proven, and an API error or truncated list means blocked. Tested cases: in scope with no checks (not proven), out of scope with no checks (not required), one suite cancelled (not proven), one suite queued (not proven), all green (proven), unreadable workflow (blocked).
  • The landing paths. The merge train's gate calls it before merging, and adds kunit-full when a PR isn't proven. The auto-merge path, pr-flow, gets the same check in pr-flow: linux needs the full KUnit matrix at the head before arming or merging .github#20: it won't arm or merge an unproven linux PR, it disarms one that is already armed, and it adds kunit-full once the PR is approved.
  • Order. This PR should merge after soc: apple: rtkit: retained ownership and adoption of a running co-processor (J700 ANS groundwork) #20 is deployed.

The label event now forces the full plan from its payload (latest commit).

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 30, 2026

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at 61cbf429

Blockers:

  • Ordering dependency: aurora-silicon/.github#20 (wiring the full-KUnit applicability and positive-evidence gate into pr-flow before arming/merging) is still open. Merge and deploy .github#20 before enabling tiering here, as noted in the PR discussion and prior review.
  • Hosted CI on 61cbf429 (apple-build, host-tests, readiness, and the 16 KUnit suites) is still queued (pr-text / pr-text passed).

Checked:

  • 61cbf429 passes LABEL directly from github.event.label.name on labeled events and bypasses the bounded GraphQL label query when LABEL == "kunit-full", forcing the full 16-suite matrix directly from the event payload.
  • plan.py TRIGGERS matches on.pull_request.paths 1-to-1; Kconfig*, Makefile, shared trigger paths (include/, rust/, mm/, arch/arm64/configs/, drivers/iommu/, drivers/pci/controller/, drivers/power/, non-CLPC drivers/soc/apple/, fs/splice.c, kernel/sys.c, this workflow), unknown non-UNRELATED paths, rename previous_filenames, API errors, and >= 3000-file lists all fail closed to the full 16-suite matrix.
  • concurrency isolates kunit-full (-full) and unrelated label events (-<run_id>), and if: guards prevent unrelated labels from running jobs or cancelling in-flight PR checks; kunit skips cleanly when needs.plan.outputs.count == '0' (build-only paths).
  • All commits carry human Signed-off-by: trailers and zero AI attribution.
Evidence
  • Diff audited: .github/workflows/apple-build-kunit.yml (+146/-26), head 61cbf4295fbd.
  • Checked aurora-silicon/.github#20 live state: OPEN (8bdf39cc, mergedAt: null).
  • Non-blocking nit: FILES=$(cat "$RUNNER_TEMP/files.txt") on line 179 passes the full file list through a single environment variable; on Linux x86_64 (MAX_ARG_STRLEN = 128 KiB), a very large PR (~2,000–3,000 files, below the 30-page truncation cap) could hit E2BIG instead of falling back to the full matrix. Reading $RUNNER_TEMP/files.txt inside plan.py directly avoids the envp ceiling.
  • Status checks at review time: pr-text / pr-text passed; apple-build, host-tests, readiness / readiness, and 16 KUnit suites queued (pull_request twin skipped as expected on same-repo PRs).

Review nit: the changed-file list went to the planner in one
environment variable, which a PR with a few thousand files could push
past the kernel's per-variable size limit (E2BIG) instead of falling
back to the full matrix. The planner now reads it from the runner's
temp file.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: HOLD at 008450ba.

The file-backed planner removes the environment-size limit and preserves the label-payload fix. Before enabling tiering, deploy the companion gate, which still needs to handle incomplete newer full attempts, and retain current hosted checks.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

The ordering condition is met. The auto-merge gate from aurora-silicon/.github#20 (approved by the review App at 2f51e44) is deployed to the running pr-flow, and its first scheduled run on the new code finished cleanly. pr-flow now arms or merges a linux PR that touches this workflow's paths only when the newest full attempt of this workflow at the head succeeded with all 16 suites. The only two linux PRs that were already armed (#3560, #3241) touch none of these paths, so no arm had to be cleared. The merge train's gate applies the same check. This PR still waits for its own CI.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 008450ba after hosted validation.

Checked: The label payload selects the full matrix and the file-backed planner avoids the environment-size limit. I verified the active pr-flow checkout at 8cdd9ab calls the full-attempt predicate before arming and that the latest scheduled service run succeeded. The owner checked the existing arms for applicability. This clears my deployment-order hold. Keep this PR’s own build, host tests and full KUnit results as landing prerequisites.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

code-owner ping <@422957901716652033> / @DjDeveloperr: merge train at 008450ba. App approved; workflow-only CI change from CI-RUNNERS. Merges under the 6-point rule 1 h from now once its own CI is green, unless you object.

Resolve the conflict with #3680: the three runs-on lines of
apple-build-kunit.yml (apple-build, plan, kunit) take main's routing,
so main pushes ask for aurora-buildbox-main and same-repo PR runs keep
aurora-buildbox.

Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com>

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: MERGE at 565e4482 after hosted validation.

Checked: The merge parents are the previously approved head and main at 42169a04. Against that base the PR changes only the Apple build and KUnit workflow. In that workflow the delta from the approved head is limited to the three runner selectors from #3680. PR-target jobs retain the PR buildbox label, while default-branch jobs use the main buildbox label. Full-label handling, planner output and matrix logic are unchanged. The companion pr-flow gate was already verified deployed.

Require the current-head build, host tests and full KUnit results before landing.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Local validation at 565e4482, the forward merge of main 42169a04 re-approved by the App. I'm posting it so this PR doesn't have to wait on the same queue that held #3680.

  • actionlint (rhysd/actionlint, with shellcheck), on apple-build-kunit.yml: 0 findings, and main's copy also has 0. That includes the plan job's inline scripts.
  • Merge resolution: the only conflict was the three runs-on lines (apple-build, plan, kunit). All three now use ci: run main pushes on the reserved buildbox runner label #3680's routing. Nothing else in the file changed against the approved 008450ba.
  • Planner dry run: I ran the plan job's own script from this head, with the real API.
case suites planned
#3483 (unapproved, asahi only) 1
#3217 (unapproved, scaler only) 1
#3217 with the kunit-full label event 16
#2633 (shared path) 16
fork pull_request event 16
push 16
bad token 16, with a warning
  • Landing gates, already live: pr-flow's full-attempt check (deployed 8cdd9ab) and the merge train's kunit-full-ok.py.

Revert: git revert -m 1 <merge> restores the full matrix on every push.

Main added the apple-sio KUnit suite to the static matrix. This branch
replaces that matrix with the planner, so the suite goes into the
planner's SUITES and TRIGGERS lists instead and the summary count becomes
17.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merged main in (bb70174, normal merge commit, no force push). The only conflict was main's new apple-sio suite in the static matrix. This branch replaces that matrix with the planner, so apple-sio is now in the planner's SUITES (prefix drivers/dma/apple-sio) and in TRIGGERS, and the summary count reads 17. Checked locally: the planner gives the same 17 suites as main's list, a drivers/dma/apple-sio.c change picks only apple-sio, lib/ picks the full matrix and DT-only picks none. The workflow still parses as YAML. A code owner still needs to approve.

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Closing: #3738 (merged as 75507ff) replaces this. It picks the KUnit suites per PR from the changed files, with apple-sio in the table, so this PR's touched-suites-only run is now how every linux PR runs.

@RyanTheTide RyanTheTide closed this Dec 1, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

linux#3738 (merged 75507ff) and #3739 (merged 19ee1b5) now plan the touched KUnit suites per PR and fold the single-suite workflows, so this tiering change looks superseded. Leaving it to you to close or rebase onto the new suite table in scripts/ci/apple-kunit.py.

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

Labels

area:release Area from CODEOWNERS (bot) blast:none Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant