Skip to content

ci: fan flake checks out into a parallel matrix - #1293

Merged
kalbasit merged 3 commits into
mainfrom
user/wnasreddine/further-improvement
May 29, 2026
Merged

kalbasit merged 3 commits into
mainfrom
user/wnasreddine/further-improvement

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

Why

After compile-once (#1292) CI is ~10m, bottlenecked by a single nix flake check building ~13 check derivations on one contended 4-core runner. They're logically parallel but CPU-starved; the remaining costs (backend-cohort test execution, golangci's own analysis) aren't cacheable — they need more cores in parallel.

What

Replace the monolithic check with a CI matrix:

  • check-matrix job enumerates checks: nix eval .#checks.x86_64-linux --apply builtins.attrNames --json.
  • checks job runs each as its own parallel runner: nix build .#checks.x86_64-linux.<name> (fail-fast: false), pulling the shared _ncps-test-cache/_ncps-base from Cachix instead of rebuilding.
  • coverage job (needs: checks) merges per-cohort profiles → Codecov.
  • The shared build job sets run_flake_check: false (feat(ci): add run_flake_check to skip inline checks for fan-out consumers gh-actions#9) so it only builds/pushes the OCI image.

Wall-clock collapses from sum-under-contention (~10m) to slowest-single-check + nix setup (~3–4m) — the path to the ~5m target. The per-job times on this run also give us the first clean per-check breakdown.

⚠️ Merge order

Depends on kalbasit/gh-actions#9 (adds run_flake_check). The caller is temporarily pinned to the gh-actions branch to validate now; revert to @main before merging once #9 lands.

OpenSpec: flake-check-topology gains "CI runs each check as an independent parallel job" + "Coverage is produced by a job consuming the fanned-out cohorts".

The single `nix flake check` built ~13 check derivations on one contended
4-core runner. Replace it with a matrix: enumerate the checks via
`nix eval .#checks.x86_64-linux --apply builtins.attrNames` and run each as
its own parallel job (`nix build .#checks.x86_64-linux.<name>`), pulling the
shared compile cache from Cachix. Wall-clock collapses to slowest-single-check
+ nix setup instead of the sum under core contention.

Coverage moves to a dedicated `coverage` job (needs: checks) that merges the
per-cohort profiles and uploads to Codecov. The shared build job sets
run_flake_check: false so it only builds/pushes the OCI image.

TEMP: caller pinned to the gh-actions feature branch to validate before
kalbasit/gh-actions#9 merges; revert to @main before merging.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit

kalbasit commented May 29, 2026 •

Copy link
Copy Markdown
Owner Author

This change is part of the following stack:

Change managed by git-spice.

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 29, 2026
@coderabbitai

coderabbitai Bot commented May 29, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 63bf137e-4c73-4830-ab0a-c1d9ac91fecc

📥 Commits

Reviewing files that changed from the base of the PR and between 34295d0 and 209315c.

📒 Files selected for processing (5)
  • .github/workflows/ci.yml
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/design.md
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/proposal.md
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/specs/flake-check-topology/spec.md
  • openspec/specs/flake-check-topology/spec.md
✅ Files skipped from review due to trivial changes (3)
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/design.md
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/proposal.md
  • openspec/specs/flake-check-topology/spec.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/specs/flake-check-topology/spec.md
  • .github/workflows/ci.yml

📝 Walkthrough

Summary by CodeRabbit

  • Chores

    • CI now runs flake checks as parallel, per-check jobs for faster feedback and aggregates results so any failing check fails the gate.
    • Coverage is produced in a dedicated post-check job and no longer blocks the CI gate.
  • Documentation

    • Added design, proposal, spec, task checklist, and metadata documenting the new parallel CI topology, rollout plan, and coverage behavior.

Walkthrough

This PR disables the upstream monolithic nix flake check, adds check-matrix to enumerate per-check attrs, runs checks as a parallel matrix (one job per flake check), adds a coverage job that builds and uploads merged coverage, and wires these jobs into the final ci gate.

Changes

CI fan-out workflow and topology

Layer / File(s) Summary
Workflow input metadata
openspec/changes/archive/2026-05-29-fan-out-flake-check/.openspec.yaml
Adds .openspec.yaml declaring the spec-driven change with creation date.
Specification, proposal, and design documents
openspec/changes/archive/2026-05-29-fan-out-flake-check/{proposal.md,design.md,specs/flake-check-topology/spec.md,tasks.md}, openspec/specs/flake-check-topology/spec.md
Adds proposal, design, task checklist, and formal spec describing: dynamic enumeration of checks attrs, per-check parallel jobs on x86_64-linux, a post-check .#ncps.coverage job that uploads merged Codecov once (upload failures are informational), and Cachix caching guidance.
CI workflow changes
.github/workflows/ci.yml
Disables monolithic flake checking via run_flake_check: false, introduces check-matrix to enumerate checks, checks matrix to run each nix build .#checks.<system>.<name>, and coverage to build/upload merged coverage; updates the final ci gate to depend on and aggregate results from these jobs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • kalbasit/ncps#1235: Related reusable-workflow integration and previous rewiring of the final CI gate used by this fan-out change.
  • kalbasit/ncps#1221: Adds per-check flake entries that will be enumerated and executed by the new fan-out matrix.
  • kalbasit/ncps#1249: Introduces flake outputs and coverage artifacts consumed by the fan-out checks and coverage jobs.

Suggested labels

enhancement, size:M

Poem

🐰 I counted checks from far and near,
I spawned them wide so tests run clear,
Each hop a job, each run a cheer,
Coverage gathers, tidy and dear.
The gate awaits — hop in, no fear!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: converting a monolithic flake check into a parallel matrix structure.
Description check ✅ Passed The description is well-organized and directly related to the changeset, explaining the motivation, proposed solution, expected improvements, and merge dependencies.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request proposes and documents a transition from a monolithic nix flake check to a fanned-out parallel CI matrix to improve wall-clock times. The review feedback identifies that nix eval does not realize derivations and thus cannot warm Cachix as intended, suggesting an explicit build instead. Additionally, the reviewer noted multiple instances in the documentation and specifications where the --json flag was omitted from the nix eval command, which is required for GitHub Actions to parse the output.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
.github/workflows/ci.yml (1)

75-78: ⚡ Quick win

Fail fast if nix eval errors instead of emitting an empty matrix.

echo "checks=$(nix eval ...)" swallows a failing nix eval (the failure is inside a command substitution used as an argument, so set -e won't trip). On failure you get checks= empty, and the checks job then fails opaquely at fromJson. Capture into a variable first so the step fails at the real cause.

♻️ Proposed fix
       - name: Enumerate checks
         id: list
         run: |
-          echo "checks=$(nix eval .#checks.x86_64-linux --apply builtins.attrNames --json)" >> "$GITHUB_OUTPUT"
+          checks="$(nix eval .#checks.x86_64-linux --apply builtins.attrNames --json)"
+          echo "checks=$checks" >> "$GITHUB_OUTPUT"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yml around lines 75 - 78, The step "Enumerate checks"
(id: list) currently uses command substitution directly in echo which hides nix
eval failures; instead run the nix eval command and capture its output into a
shell variable (e.g., result=$(nix eval ... --json 2>&1)), check the command
exit status and fail the step if non-zero, then write the successful JSON to
GITHUB_OUTPUT with echo "checks=$result" >> "$GITHUB_OUTPUT"; update the step's
run block to perform the capture, explicit exit-on-error check, and only emit to
GITHUB_OUTPUT when the eval succeeded so failures surface at the real cause
instead of producing an empty matrix consumed by fromJson.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/ci.yml:
- Around line 23-26: The workflow is pinned to a mutable branch ref in the uses
line ("uses:
kalbasit/gh-actions/.github/workflows/ci.yml@user/wnasreddine/further-improvement")
which triggers the unpinned-uses warning; change that ref back to `@main` or a
specific immutable tag/SHA and update the header comment that currently reads
"Pinned to `@main`" so it accurately reflects the chosen ref, and ensure this
revert is applied before merging.
- Around line 95-96: The workflow is vulnerable because it expands ${{
matrix.check }} directly into the shell; change the step that runs `nix build
".#checks.x86_64-linux.${{ matrix.check }}" -L` to pass the matrix value through
an environment variable (e.g., set env CHECK: ${{ matrix.check }}) and then
reference that variable quoted in the run command (use the string
".#checks.x86_64-linux.${CHECK}" or equivalent) so the matrix value is treated
as data, not as shell code; update the step that currently uses `matrix.check`
in the `run:` line to use the env var (CHECK) instead and keep the build
argument quoted.

---

Nitpick comments:
In @.github/workflows/ci.yml:
- Around line 75-78: The step "Enumerate checks" (id: list) currently uses
command substitution directly in echo which hides nix eval failures; instead run
the nix eval command and capture its output into a shell variable (e.g.,
result=$(nix eval ... --json 2>&1)), check the command exit status and fail the
step if non-zero, then write the successful JSON to GITHUB_OUTPUT with echo
"checks=$result" >> "$GITHUB_OUTPUT"; update the step's run block to perform the
capture, explicit exit-on-error check, and only emit to GITHUB_OUTPUT when the
eval succeeded so failures surface at the real cause instead of producing an
empty matrix consumed by fromJson.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ce9577b8-31b5-4280-a78f-176f5c0dc6b2

📥 Commits

Reviewing files that changed from the base of the PR and between b5fd1e4 and f7ce87b.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/.openspec.yaml
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/design.md
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/proposal.md
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/specs/flake-check-topology/spec.md
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/tasks.md
  • openspec/specs/flake-check-topology/spec.md

Comment thread .github/workflows/ci.yml Resolved
Comment thread .github/workflows/ci.yml Resolved
run_flake_check is on @main; drop the temporary gh-actions feature-branch
pin used to validate the fan-out end-to-end (validated: CI green at 5.1m).

Co-Authored-By: Claude Opus 4.8 <[email protected]>

@coderabbitai coderabbitai 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.

♻️ Duplicate comments (1)
.github/workflows/ci.yml (1)

92-93: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Template injection: ${{ matrix.check }} is still expanded directly into the shell.

The matrix values come from builtins.attrNames over the PR-head flake, which is attacker-controlled on fork PRs. The previously proposed fix (pass the value via an env var and reference it quoted) has not been applied.

🔒 Proposed fix
       - name: Build check
-        run: nix build ".#checks.x86_64-linux.${{ matrix.check }}" -L
+        env:
+          CHECK: ${{ matrix.check }}
+        run: nix build ".#checks.x86_64-linux.$CHECK" -L
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/ci.yml around lines 92 - 93, The workflow step named
"Build check" currently expands the template value `${{ matrix.check }}`
directly into the shell command (run: nix build ".#checks.x86_64-linux.${{
matrix.check }}" -L), which allows template injection; change the step to pass
the matrix value via an environment variable (e.g. set env: CHECK: ${{
matrix.check }}) and update the run line to reference the env var instead (use
the shell-safe quoted variable, e.g. nix build ".#checks.x86_64-linux.$CHECK"
-L), ensuring the matrix value is not directly injected into the run string but
read from $CHECK at runtime and properly quoted.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In @.github/workflows/ci.yml:
- Around line 92-93: The workflow step named "Build check" currently expands the
template value `${{ matrix.check }}` directly into the shell command (run: nix
build ".#checks.x86_64-linux.${{ matrix.check }}" -L), which allows template
injection; change the step to pass the matrix value via an environment variable
(e.g. set env: CHECK: ${{ matrix.check }}) and update the run line to reference
the env var instead (use the shell-safe quoted variable, e.g. nix build
".#checks.x86_64-linux.$CHECK" -L), ensuring the matrix value is not directly
injected into the run string but read from $CHECK at runtime and properly
quoted.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6a5e8ecf-8ad2-414a-b227-687fbac09c91

📥 Commits

Reviewing files that changed from the base of the PR and between f7ce87b and 34295d0.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/tasks.md
✅ Files skipped from review due to trivial changes (1)
  • openspec/changes/archive/2026-05-29-fan-out-flake-check/tasks.md

@kalbasit kalbasit mentioned this pull request May 29, 2026
2 of 3 tasks
Address review feedback on #1293:
- Security (CodeRabbit/zizmor): pass matrix.check via an env var and
  reference it quoted in `run:`, instead of expanding `${{ matrix.check }}`
  directly into the shell. On fork PRs the check names come from
  builtins.attrNames over the attacker-controlled flake, so direct
  interpolation was a template-injection vector.
- Docs (Gemini): add the required `--json` flag to the prose `nix eval`
  references in the proposal/spec (the workflow already used it).
- Docs: correct the design.md cold-cache note — `nix eval` does NOT realize
  derivations, so check-matrix doesn't warm Cachix; warm Cachix is the
  steady state from prior merged runs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit merged commit da70a1c into main May 29, 2026
38 of 51 checks passed
@kalbasit
kalbasit deleted the user/wnasreddine/further-improvement branch May 29, 2026 23:17
kalbasit added a commit that referenced this pull request May 29, 2026
## Summary

The release workflow (`v*.*.*` tag builds) called `build.yml`
**without** `test_systems`, so it re-ran the full `nix flake check` +
coverage on **both** x86_64 and aarch64 — including the slower, flaky
aarch64 Postgres path that the CI workflow (#1291) already learned to
avoid.

- `releases.yml`: pass `test_systems: '["x86_64-linux"]'` to the shared
build workflow. The integration suite + coverage now run on x86_64 only;
the aarch64 leg still **builds and pushes** its OCI image, so the
multi-arch manifest is unchanged. `run_flake_check` stays at its default
(`true`) so releases still gate on the full suite.
- Mirrors the CI workflow's scoping.
- `flake-check-topology` spec: the "Integration cohorts validated on a
single CI architecture" requirement now covers **both** `ci.yml` and
`releases.yml`, with a new release-tag scenario.

Independent of the fan-out PR (#1293); branched off `main`. Relies on
the `test_systems` input already on `kalbasit/gh-actions@main` (merged
in #8).

## Test plan

- [x] `actionlint .github/workflows/releases.yml` — exit 0
- [x] `task fmt` clean; pre-commit hooks pass
- [ ] Confirm on the next release tag that the aarch64 leg builds the
image but skips `nix flake check`

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant