Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
325e95b
ci(review): require code-owner approvals on gitlab merge requests
kajalj22 Nov 24, 2026
a3b2aa9
ci(review): document the MR-local rule limitation and test the child job
kajalj22 Nov 24, 2026
97b8018
ci(review): state when required pools are absent and tighten the pin …
kajalj22 Nov 24, 2026
18844f1
ci(review): repin the shared adapter
kajalj22 Nov 24, 2026
2c31fa3
ci(review): repin the shared adapter
kajalj22 Nov 25, 2026
cf09f99
Repin review-pool adapter to gitignore-semantics fix
kajalj22 Nov 25, 2026
1b4dbc4
fix: repin review-pool adapter to advisory-problem routing fix
kajalj22 Nov 25, 2026
5cc3afa
refactor: repin review-pool adapter to plan_sides extraction
kajalj22 Nov 25, 2026
4122bf2
fix: repin review-pool adapter; assert adapter argv instead of script…
kajalj22 Nov 25, 2026
5e1ba33
fix: repin review-pool adapter; ignore shell comments when checking a…
kajalj22 Nov 25, 2026
79c507d
fix: repin review-pool adapter to exact-globstar fix
kajalj22 Nov 27, 2026
92bb6e2
refactor: repin review-pool adapter to resolve_sides extraction
kajalj22 Nov 27, 2026
74510f7
fix: repin review-pool adapter to rename-aware required review
kajalj22 Nov 27, 2026
5b7dba3
fix: repin review-pool adapter to voided-rule and decode-error handling
kajalj22 Nov 27, 2026
14bfce1
refactor: repin review-pool adapter to apply_sides extraction
kajalj22 Nov 27, 2026
3956254
fix: repin review-pool adapter to required-only approver guard
kajalj22 Nov 27, 2026
3537ac2
fix: repin review-pool adapter to anchored-star fix
kajalj22 Nov 30, 2026
744d876
fix: repin review-pool adapter to fallback-argument validation
kajalj22 Nov 30, 2026
2e7b45e
fix: repin review-pool adapter to per-side inheritance preflight
kajalj22 Nov 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 36 additions & 17 deletions .gitlab/ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ Focused validation runs with:
uv run pytest tests/unit_tests/tooling/test_collect_downstream_junit.py
```

## Advisory review pools
## Review pools

Today MR webhooks run the shared adapter on protected `nv-internal-main` and
create optional approval rules with zero required approvals. These rules expose
eligible approvers; they do not assign the MR's Reviewers field.
MR webhooks run the shared adapter on protected `nv-internal-main`. It creates
optional approval rules with zero required approvals for `# suggest:` lines and
required approval rules for enforced `.github/CODEOWNERS` lines (see below).

From deployment of this configuration, a lightweight preparation job will validate
`TRIGGER_PAYLOAD` and generate a child pipeline. Each child will lock only
Expand All @@ -52,17 +52,18 @@ flowchart LR
Lock --> Adapter[Pinned shared adapter]
Rules[GitHub suggestion rules and team membership] --> Adapter
Adapter --> Pools[Optional GitLab approval pools]
Adapter --> Required[Required code-owner pools]
```

The GitLab adapter pin will move to
`f6e8ed5837b263566534bf0dff0d83a7c653ca8b`
([FW-CI-templates PR 631](https://github.com/NVIDIA-NeMo/FW-CI-templates/pull/631)).
The adapter will skip mapped users without active Developer-or-higher project
membership and report them in `warnings`. Missing identity mappings, empty pools,
and attempts to replace required approval rules will still block writes. The MR
author is excluded. The adapter will always reconcile the optional approval pools.
When the MR has no reviewers, the adapter will additionally assign eligible pool
members as reviewers. If reviewers already exist, their list will stay unchanged.
The GitLab adapter is pinned to
`79a9ef871b7d56692a9598392e75101be3a18c26`
([FW-CI-templates PR 632](https://github.com/NVIDIA-NeMo/FW-CI-templates/pull/632),
which adds `--require-codeowners`). The adapter skips mapped users without active
Developer-or-higher project membership and reports them in `warnings`. It manages
only the rules it names (`github-review-pool:` and `github-codeowners:`) and never
touches other required rules. The MR author is excluded. The adapter always
reconciles the optional approval pools. When the MR has no reviewers, it also
assigns eligible pool members as reviewers; an existing reviewer list stays unchanged.
The adapter rechecks the reviewer list immediately before assignment and checks
the current MR state and head before writes. GitLab has no atomic assign-if-empty
operation, so a manual assignment in the remaining read/write window can race.
Expand All @@ -80,22 +81,40 @@ Both credentials are protected, masked, hidden, raw CI variables scoped to the
| Variable | Purpose |
| --- | --- |
| `GH_SSO_MANAGMENT_PAT` | Read audited SSO identities, GitHub rules, and team membership. |
| `GITLAB_REVIEW_POOLS_TOKEN` | Read project members and manage optional MR approval rules. |
| `GITLAB_REVIEW_POOLS_TOKEN` | Read project members and manage the adapter's optional and required MR approval rules. |

The protected environment permits dedicated project bot `160783`, which owns
trigger `3236`. Webhook `283184` sends merge request events to that trigger on
protected `nv-internal-main`. The child inherits the triggering identity and reads
the project variables in its own `review-pools` environment; the bridge forwards
neither pipeline nor YAML variables. CPU CI continues to select MR pipelines only.

Failures remain advisory through `allow_failure: true`; inspect the child job
status and trace rather than relying on the parent pipeline's success status.

GitLab switches to MR-local approval rules when the first optional pool is
created. Future project-level regular or any-approver rules will not automatically
apply to those MRs. Before introducing or changing project approval requirements,
maintainers must migrate rules on existing MRs as part of that policy change.

## Required code-owner pools

The same child job runs the adapter with `--require-codeowners`, so enforced
`.github/CODEOWNERS` lines on GitHub `main` also gate GitLab MRs: for each changed
file the last matching enforced line wins, and each distinct owner set becomes a
`github-codeowners: <owners>` approval rule requiring one approval from the live
members of those GitHub teams. `--codeowners-fallback @nvidia-nemo/gym_maintainers`
keeps the MR gated by the maintainers when an identity or eligibility problem
prevents resolving the exact pools; the job then fails with the problems listed and
converges on a later run. All three review-pool jobs use `allow_failure: false`
so a failed reconciliation is visible in the trigger pipeline.

Limitations: the rules are MR-local, so the MR author and Maintainers can edit them
and no webhook reports that edit; the adapter restores them on the next MR update.
The rules exist only after the adapter has run: if the trigger pipeline fails before
the adapter writes (package install, adapter fetch, expired credentials, provider
outage), the MR has no required rule and only the red trigger pipeline shows it.
A project-level backstop rule is not configured today.
Keep "Prevent editing approval rules in merge requests" disabled on the project:
that setting also removes the adapter's permission to manage MR approval rules.

Validate the dispatcher tests, shared adapter tests, pre-commit hooks, and expanded
parent/child configurations with GitLab CI lint. After deployment, trigger two
different MRs and verify different resource-group keys, inspect missing-member
Expand Down
6 changes: 4 additions & 2 deletions .gitlab/ci/review-pools-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
name: review-pools
action: access
timeout: 15m
allow_failure: true
allow_failure: false
variables:
GIT_STRATEGY: empty
script:
- apt-get update
- apt-get install -y --no-install-recommends ca-certificates git nodejs npm gh glab
- git init ci-templates
- git -C ci-templates remote add origin https://github.com/NVIDIA-NeMo/FW-CI-templates.git
- git -C ci-templates fetch --depth=1 origin f6e8ed5837b263566534bf0dff0d83a7c653ca8b
- git -C ci-templates fetch --depth=1 origin 79a9ef871b7d56692a9598392e75101be3a18c26
- git -C ci-templates checkout --detach FETCH_HEAD
- npm ci --prefix ci-templates/.github/scripts/review-matcher --ignore-scripts --no-audit --no-fund
- export GH_TOKEN="$GH_SSO_MANAGMENT_PAT"
Expand All @@ -29,5 +29,7 @@
--github-repository NVIDIA-NeMo/Gym
--github-ref main
--gitlab-username-from-email
--require-codeowners
--codeowners-fallback @nvidia-nemo/gym_maintainers
--mr "$GYM_REVIEW_MR_IID"
--apply
4 changes: 2 additions & 2 deletions .gitlab/ci/review-pools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
gym-review-pools-prepare:
extends: .review-pools-trigger
stage: test
allow_failure: true
allow_failure: false
image: python:3.12-slim-trixie@sha256:5e2bdb1b0d542d5039cffb8181c65930093949194a65c365dfb1b0fe13a4fa5b
variables:
GIT_DEPTH: "1"
Expand All @@ -28,7 +28,7 @@ gym-review-pools:
extends: .review-pools-trigger
stage: report
needs: [gym-review-pools-prepare]
allow_failure: true
allow_failure: false

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.

RISK: Required-owner enforcement can fail open before the adapter writes.

allow_failure: false makes the protected-branch trigger pipeline red, but the review-pool rules select a different pipeline from MR CPU CI. There is no dependency between them. On a new MR, an install/fetch/credential failure can therefore leave a green MR pipeline with no required owner rule. The README explicitly confirms the missing rule and absence of a backstop. My routing probe confirmed the disjoint job sets, and a failing package-manager stub stopped the real child script before adapter execution.

The pipeline separation predates this PR, but it becomes an enforcement gap when these pools become required policy. Could you add a required reconciliation result bound to the MR's current SHA, or an equivalent provider-enforced backstop, so missing reconciliation blocks merge? Keep credentialed execution on trusted code rather than moving it into the untrusted MR job.

Acceptance: create an MR touching an enforced owner path, fail setup before the adapter runs, and verify it cannot merge even when CPU CI passes. After successful reconciliation, verify an eligible owner approval is still required. Repeat after a push so a stale reconciliation result cannot satisfy the requirement.

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.

RISK: Required-owner enforcement can still fail open before the adapter writes.

This is unchanged from the prior review. allow_failure: false makes the protected-branch trigger pipeline red, but the review-pool predicates select a different pipeline from MR CPU CI, with no reconciliation dependency between them. Under the documented configuration, a setup failure on a new MR can therefore leave green CPU CI without a required owner rule. The README explicitly confirms the missing-rule window and absence of a backstop.

probe_routing.py confirmed the disjoint job sets. Full-script probes under both shells confirmed that package, fetch and npm failures stop before adapter execution. These are local boundary checks, not a live mergeability test.

Could you require a successful reconciliation result bound to the MR's current SHA, or an equivalent provider-enforced backstop, before merge? Keep credentialed execution on protected, trusted code and preserve the eligible-owner approval requirement after reconciliation.

Acceptance: open an MR touching an enforced path, fail setup before the adapter, and verify merge stays blocked even with green CPU CI. Restore setup and verify an eligible owner approval is required. Push again and verify an earlier reconciliation cannot satisfy the new head.

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.

RISK: Required-owner enforcement can still fail open before the adapter writes.

This is unchanged from the prior review. allow_failure: false propagates failure within the protected-branch trigger pipeline, but the review-pool predicates select a different pipeline from MR CPU CI, with no reconciliation dependency between them. The README confirms that a pre-write failure leaves no required rule and that no project-level backstop is configured.

Under that documented configuration, a new MR touching an enforced path can therefore have green CPU CI without an owner rule. PYTHONDONTWRITEBYTECODE=1 /opt/nemo_gym_venv/bin/python /workspace/review-probes/pipeline-enforcement-1/probe.py confirmed the disjoint job sets and reproduced package, fetch and npm failures stopping before the adapter under both sh and bash. These are local boundary checks, not a live mergeability test.

Could you require successful reconciliation bound to the MR's current SHA, or an equivalent provider-enforced backstop, before merge? Keep credentialed execution on protected trusted code and preserve the eligible-owner approval requirement after reconciliation.

Acceptance: open an MR touching an enforced path, fail setup before adapter execution, and verify merging stays blocked despite green CPU CI. Restore setup and verify an eligible owner approval is required. Push again and verify an earlier reconciliation cannot satisfy the new head.

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.

RISK: Required-owner enforcement can still fail open before the adapter writes.

This is the unresolved prior finding. allow_failure: false makes failure visible within the protected-branch trigger pipeline, but the review-pool predicates select a different pipeline from MR CPU CI, with no reconciliation dependency between them. The README confirms that a pre-write failure leaves no required rule and that no project-level backstop is configured.

Under that documented configuration, a new MR touching an enforced path can have green CPU CI without an owner-approval rule. PYTHONDONTWRITEBYTECODE=1 /opt/nemo_gym_venv/bin/python /workspace/review-probes/r6731-dispatch-1/probe.py passed six routing contexts and 12 shell/failure cases. Package, fetch and npm failures stopped before adapter execution under both sh and bash, so --codeowners-fallback could not run. These are local boundary checks, not a live mergeability test. Repinning the adapter cannot repair paths that never execute it.

Could you require successful reconciliation bound to the MR's current SHA, or an equivalent provider-enforced backstop, before merge? Keep credentialed execution on trusted protected-branch code and preserve the eligible-owner approval requirement after reconciliation.

Acceptance checks:

  1. Open an MR touching an enforced path, fail setup before adapter execution, and verify merging stays blocked despite green CPU CI.
  2. Restore setup and verify an eligible owner approval is required.
  3. Push a new head and verify an earlier successful reconciliation cannot satisfy its requirement.

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.

RISK: Required-owner enforcement can still fail open before the adapter writes.

This is the unresolved baseline finding. allow_failure: false propagates failure within the protected-branch trigger pipeline, but the review-pool predicates select a different pipeline from MR CPU CI, with no reconciliation dependency between them. The documented deployment has no project-level backstop and can have no required rule after a pre-write failure.

Under that configuration, a new MR touching an enforced path can have green CPU CI without an owner-approval rule. PYTHONDONTWRITEBYTECODE=1 /opt/nemo_gym_venv/bin/python /workspace/review-probes/current-dispatch-1/probe.py passed six routing contexts, six webhook CLI cases and fourteen shell cases. Under both sh and bash, injected package, fetch, checkout and npm failures stopped the actual YAML script before adapter execution. These were local stub checks, not a live mergeability test. Repinning cannot fix paths that never execute the adapter.

Could you require successful reconciliation bound to the MR's current SHA, or an equivalent provider-enforced backstop, before merge? Keep credentialed execution on trusted protected-branch code and preserve the eligible-owner approval requirement after reconciliation.

Acceptance checks:

  1. Fail setup before adapter execution on a new MR touching an enforced path, and verify merging stays blocked despite green CPU CI.
  2. Restore setup and verify an eligible owner approval is required.
  3. Push a new head and verify an earlier successful reconciliation cannot satisfy its requirement.

trigger:
include:
- artifact: review-pools-child.yml
Expand Down
25 changes: 21 additions & 4 deletions tests/unit_tests/tooling/test_review_pool_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import importlib.util
import json
import re
import shlex
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -39,11 +41,26 @@ def event(iid: object = 1355) -> dict:
class ReviewPoolDispatchTests(unittest.TestCase):
"""Exercise the boundary between untrusted webhooks and child CI config."""

def test_invalid_payload_cannot_create_child_and_failure_is_advisory(self) -> None:
def test_review_pool_jobs_block_on_failure_and_require_code_owners(self) -> None:
"""Every review-pool job blocks, and the child runs the pinned adapter in enforcing mode."""
parent = yaml.safe_load((ROOT / ".gitlab/ci/review-pools.yml").read_text())
child = yaml.safe_load((ROOT / ".gitlab/ci/review-pools-run.yml").read_text())
self.assertFalse(parent["gym-review-pools-prepare"]["allow_failure"])
self.assertFalse(parent["gym-review-pools"]["allow_failure"])
self.assertFalse(child[".gym-review-pools"]["allow_failure"])
script = child[".gym-review-pools"]["script"]
adapter = next(shlex.split(line, comments=True) for line in script if "gitlab_review_pools.py" in line)
self.assertIn("--require-codeowners", adapter)
self.assertEqual(adapter[adapter.index("--codeowners-fallback") + 1], "@nvidia-nemo/gym_maintainers")
pin = re.search(r"fetch --depth=1 origin ([0-9a-f]{40})", "\n".join(script))
self.assertIsNotNone(pin, "child job must fetch the adapter by full commit SHA")
readme = (ROOT / ".gitlab/ci/README.md").read_text()
self.assertIn(
f"The GitLab adapter is pinned to\n`{pin.group(1)}`", readme, "README pin differs from the job pin"
)

def test_invalid_payload_cannot_create_child(self) -> None:
"""Reject malformed payloads without producing runnable child configuration."""
config = yaml.safe_load((ROOT / ".gitlab/ci/review-pools.yml").read_text())
self.assertTrue(config["gym-review-pools-prepare"]["allow_failure"])
self.assertTrue(config["gym-review-pools"]["allow_failure"])
with tempfile.TemporaryDirectory() as directory:
payload = Path(directory) / "event.json"
output = Path(directory) / "child.json"
Expand Down
Loading