Skip to content

ci(tests): run four workers per test shard - #5608

Merged
ko3n1g merged 5 commits into
mainfrom
ko3n1g/ci/four-test-workers
Nov 4, 2026
Merged

ko3n1g merged 5 commits into
mainfrom
ko3n1g/ci/four-test-workers

Conversation

@ko3n1g

@ko3n1g ko3n1g commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Background

The four core shards introduced in #5498 still run pytest serially, and each of the eight server shards tests its components serially. In run 41859920268, the core test steps took roughly 12–17 minutes and server test steps took 7–14 minutes.

Use four workers directly on the existing four-CPU runners. No separate issue is needed for this focused CI follow-up.

What changed

  • Run core pytest with -n 4 --dist=loadfile, preserving file-scoped fixtures and the existing shard assignment.
  • Run four concurrent component processes per full server shard. Original shard s of N becomes slices s, s+N, s+2N, and s+3N of 4N, preserving exactly the original selection.
  • Limit OpenMP, OpenBLAS, MKL, and NumExpr to one thread per process. Apply the same settings to the manual full-suite workflow.
  • Preserve every worker's failure status, terminate owned process groups on cancellation, and upload separate worker logs even when tests fail. Observe worker exit with waitid(WNOWAIT) so unreaped leader PIDs reserve group IDs until cleanup finishes. Check live group members independently of leader completion, use one shared ten-second TERM grace period, then KILL and verify termination before reaping leaders.
  • Fix related concurrency failures: exclude installation metadata from component discovery, wait for SciCodePile's grandchild readiness before testing cleanup, isolate a warn-once public getter test, and allow five seconds for the cancellation test's scheduling guards.

Details

The shard counts, completeness checks, test selection, sandbox jobs, and coverage threshold remain unchanged. The cancellation test retains #4028's exact sampling/count assertions. Component metadata created by editable installs must not change ownership while other workers are discovering components.

flowchart LR
    C[4 core jobs] --> CW[4 pytest workers per job]
    CW --> CC[Combined coverage per job]
    CC --> CG[Existing 95 percent coverage gate]
    S[8 server jobs] --> SW[4 component workers per job]
    SW --> SR[Aggregate every worker result]
    SR --> SG[Existing server gate]
Loading

There are no user-facing configuration, migration, verifier, or benchmark-result changes. A matched CI speed comparison is pending; local timings below are validation evidence.

Tested

  • Latest-main merge (9dffde9602e32e751c0818ff2eb70d2495a9bf94): incorporate test: mirror nemo_gym packages in the unit test tree #5589's package-aligned test tree, including moving the new worker test into tooling/ and updating its root lookup. 402 passed in 27.02 seconds; full pre-commit run --all-files passed.

    source scripts/ci/test_worker_env.sh
    PYTEST_ADDOPTS='' taskset -c 0-3 python -m pytest -q -n 4 --dist=loadfile -o addopts='' --tb=short \
      tests/unit_tests/tooling/test_server_test_workers.py \
      tests/unit_tests/tooling/test_ci_environment.py tests/unit_tests/tooling/test_core_test_shards.py \
      tests/unit_tests/cli/test_cli.py tests/unit_tests/models/test_token_capture_renames.py \
      tests/unit_tests/server_runtime/test_base_server.py
  • Review correction for review 5772528498, after merging origin/main at d56eeb5590:

    • PYTEST_ADDOPTS='' python -m pytest -q -o addopts='' --tb=short tests/unit_tests/test_server_test_workers.py — 6 passed in 22.15 seconds. Both new cases launch four TERM-ignoring children, cover an active leader and an already-exited leader, require exit 143 within 15 seconds, and verify no live worker or child survives. The same cases fail against reviewed head 7dd149d586ddfae11c0266d0bc12a5e47659a940 because children remain alive.
    • source scripts/ci/test_worker_env.sh; PYTEST_ADDOPTS='' taskset -c 0-3 python -m pytest -q -n 4 --dist=loadfile -o addopts='' --tb=short tests/unit_tests/test_server_test_workers.py tests/unit_tests/test_ci_environment.py tests/unit_tests/test_core_test_shards.py tests/unit_tests/test_cli.py — 283 passed in 29.46 seconds.
    • pre-commit run --all-files and focused uv --no-config tool run --from mypy==1.17.1 mypy scripts/ci/server_test_workers.py — passed.
  • Previous-head CI run 41871937982: all four core shards, all eight server shards, sandbox tests, combined coverage, and Nemo_CICD_Test passed. Fresh CI and a full review are requested for the correction.

  • Initial integration check after merging origin/main at b520fed283f5663f2c7d4c42dd27ac356598888c:

    source .venv/bin/activate
    source scripts/ci/test_worker_env.sh
    PYTEST_ADDOPTS='' taskset -c 0-3 python -m pytest -q -n 4 --dist=loadfile -o addopts='' --tb=short \
      tests/unit_tests/server_runtime/test_base_server.py \
      tests/unit_tests/test_core_test_shards.py tests/unit_tests/test_server_test_workers.py \
      tests/unit_tests/test_cli.py tests/unit_tests/test_ci_environment.py \
      tests/unit_tests/models/test_token_capture_renames.py \
      tests/unit_tests/artifacts/test_live_export_receipt.py \
      tests/unit_tests/rollouts/test_batch_status.py tests/unit_tests/rollouts/test_rollout_collection.py \
      tests/unit_tests/test_cli_main.py tests/unit_tests/test_rerun_masked_without_artifact.py

    1,626 passed in 36.84 seconds on four CPU cores.

  • Real server shard: python scripts/ci/server_test_workers.py 3 8 +fail_on_total_and_test_mismatch=true +delete_venvs_after_each_test=true — all four workers exited zero; all 31 components and their data validations passed.

  • Changed component: gym env test +entrypoint=resources_servers/scicodepile +delete_venvs_after_each_test=true +should_validate_data=true — 86 passed; data validation passed.

  • Full non-sandbox core run on four CPU cores, with native thread limits and --cov=. --cov-report= --cov-fail-under=0: 18,290 passed, 101 skipped, 343 subtests passed in 659.95 seconds. Its sole failure was the one-second cancellation-test startup timeout addressed here; the affected module then passed with the final guard. This workstation required process-local hostname resolution and unsigned synthetic Git fixture configuration; no repository or global configuration was changed. This was before the final guard change and the latest main merge, so it is not a claim of a final full-suite pass.

  • Regression tests exercise actual xdist/coverage combination, whole-file ownership, concurrent subprocess overlap, exact server shard membership, failure propagation, raw logs, and cancellation. Synthetic coverage reached 100%; the real full run produced a combined coverage database with 568 measured files and no absolute paths.

  • pre-commit run --all-files; shellcheck -x scripts/ci/core_unit_tests.sh scripts/ci/server_tests.sh scripts/ci/test_worker_env.sh; actionlint -shellcheck='' -ignore 'label ".+" is unknown' .github/workflows/unit-tests.yml .github/workflows/full-test-suite.yml; uv --no-config tool run --from mypy==1.17.1 mypy scripts/ci/server_test_workers.py — passed. Actionlint ignores the repository's custom runner labels and disables shell lint for existing workflow snippets; the changed scripts are checked separately.

  • Model rollouts: N/A; this changes CI scheduling, component discovery, and test fixtures. The other seven full server shards and sandbox checks are left to CI.

@ko3n1g
ko3n1g requested a review from a team as a code owner November 4, 2026 16:52
@ko3n1g ko3n1g added ci CI, automation, test queue, or workflow infrastructure work area:ci CI workflows, test routing, and repository automation needs-review PR is ready for code review and waiting on a reviewer labels Nov 4, 2026
@nemo-automation-bot
nemo-automation-bot Bot requested review from a team November 4, 2026 16:53

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP WITH CARE

One RISK: cancellation cleanup can leave worker descendants running after their group leader exits. The inline finding describes the failure and required checks.

I completed the review of all 14 changed files and their directly affected paths, including shard selection, coverage aggregation, environment propagation, component discovery, and the changed fixtures. This was a static review; I didn't execute tests.

Review generated by codex. This was a full review. Request a full review with /review reset=true.

Comment thread scripts/ci/server_test_workers.py Outdated
deadline = monotonic() + 10
for process in active:
try:
process.wait(timeout=max(0, deadline - monotonic()))

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 — Check process-group termination independently of worker exit

Could you make cleanup check the process group rather than only its leader? A minimal trigger is a fake ng_test_all that starts a same-group child which ignores SIGTERM, waits for the child's readiness marker, then waits itself. When the launcher receives SIGTERM, stop_workers signals the group. The leader exits, so process.wait() succeeds and the SIGKILL branch never runs. The child survives the launcher. The initial poll() filter also skips surviving groups whose leaders have already exited.

Cancelled server shards can therefore leave descendants consuming runner resources or modifying installation state. The real worker creates nested processes through _test_single, run_command, and the installer wrapper.

Correction: Decouple group cleanup from leader completion in stop_workers. Retain ownership of each launched group, send SIGTERM, enforce the shared grace deadline against group liveness, then send SIGKILL to remaining groups and reap the direct workers. The invariant is that cleanup leaves no live member of an owned worker group, even when its leader exits first. Don't simply remove the poll() guard without considering reused group IDs. I haven't established a safe drop-in patch for that ownership boundary.

Preservation and acceptance: Extend the cancellation test with a ready child that ignores SIGTERM. Cover both an active leader and a leader that exits while its child remains; cancellation must return 143 within the cleanup bound and leave no live descendant. Retain the ordinary-run assertions: all four workers overlap and finish, statuses 1 and 5 make the launcher exit 1, shard membership stays unchanged, and invalid output bytes remain in raw logs while console decoding replaces them. These are proposed checks, not executed results.

@ko3n1g

ko3n1g commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/review reset=true

@ko3n1g

ko3n1g commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/review reset=true

@ko3n1g

ko3n1g commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/review reset=true approve=true

@ko3n1g

ko3n1g commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/review reset=true approve=true

@ko3n1g

ko3n1g commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/review reset=true approve=true model=claude

1 similar comment
@ko3n1g

ko3n1g commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

/review reset=true approve=true model=claude

@svcnvidia-nemo-ci svcnvidia-nemo-ci 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.

SHIP

I found one NOTE and nothing at BLOCKER or RISK level. The earlier RISK from review 5772528498 is fixed at this head.

The earlier RISK is fixed. The concern was that cancellation cleanup could leave worker descendants running after their group leader exited. The new stop_workers fixes this:

  • worker_exit_status checks for worker exit with waitid(WNOWAIT). It doesn't collect (reap) the exited leaders, so their PIDs keep each group ID reserved until cleanup finishes.
  • live_groups reads the process-group field of /proc/<pid>/stat and skips zombies, so it checks whether a group is alive without relying on its leader.
  • All groups share one 10-second SIGTERM grace period. Any group still alive then gets SIGKILL, and cleanup confirms the groups are gone before it collects the leaders.
  • The nested _test_single → run_command processes stay in the worker's group because they don't start a new session (server_venv.py).
  • test_cancellation_kills_term_ignoring_children_after_leader_exit covers both the active-leader case and the exited-leader case.

What else I checked (all 14 changed files):

  • Server shard split: each original shard s of N still runs exactly the same components. Splitting it into slices s, s+N, s+2N and s+3N of 4N selects the same modules, because _select_shard takes every num_shards-th entry of a sorted list.
  • Core tests on four workers: pytest-xdist is in the dev extra. The core-shard plugin loads from tests/conftest.py and drops the same tests on every worker. Each worker's coverage still lands in the COVERAGE_FILE that combine_core_coverage.py expects. New test files get the median duration weight.
  • Shared state across the four server workers:
    • setup_dev.sh creates and activates the driver venv before the launcher starts.
    • Each server gets its own venv under uv_venv_dir, guarded by its own lock.
    • JUnit files are named per entrypoint.
    • Log artifacts are named per shard and don't match the coverage download pattern.
  • Discovery fix: the .egg-info/.dist-info exclusion protects the module-count check (fail_on_total_and_test_mismatch). The new metadata_present case in test_server_suite_exit_status would fail without it.
  • Test fixes: the SciCodePile readiness change closes the pidfile before it signals readiness. The fresh public getter in the token-capture test is needed because lazy_exports keeps its warn-once record inside the getter. The longer wait_for timeouts leave the #4028 count assertions unchanged.

This was a static review; I didn't run any tests. I split the review into three parts and gave each to a separate reviewer. Only one of them returned a report: the one covering the CI wiring. I inspected the launcher lifecycle and the discovery and test-fixture changes myself.


NOTE — The CI contract README still says the shard entrypoints behave as before

I couldn't anchor this inline because scripts/ci/README.md isn't in this diff.

What's out of date:

  • L116 says "The eight server shards and the separate on-demand full-test-suite.yml keep their existing behavior." That's no longer true:
    • server_tests.sh now starts four ng_test_all workers and writes their logs to results/server-workers/shard-<s>.
    • core_unit_tests.sh always runs -n 4 --dist=loadfile, including the no-argument run the internal adapter uses.
    • full-test-suite.yml does the same.
    • Both entrypoints now limit OpenMP, OpenBLAS, MKL and NumExpr to one thread per process.
  • The entrypoint descriptions at L7–L10 don't mention any of this.

Who is affected: the internal NeMo CI adapter runs these same entrypoints under contract version 3 on the cpu_short Slurm partition (.gitlab-ci.yml). Its jobs now run four concurrent pytest or component processes whatever their allocation is, and the README doesn't tell providers. This PR already had to raise a scheduling timeout from 1 s to 5 s because of CPU contention.

Suggested fix:

  • Replace L116 with a sentence like this: "Each server shard runs four disjoint ng_test_all workers (slices s, s+N, s+2N, s+3N of 4N) and writes per-worker logs to results/server-workers/shard-<s>. The core and server entrypoints start four workers and limit native thread pools to one thread per process."
  • Add the expected per-job CPU allocation to the provider contract.
  • Could you confirm that cpu_short jobs get four CPUs? If the adapter should opt in explicitly, a contract-version bump may be appropriate; that's your call.

Keep: the color and JUnit statements (L12–L20), the sharding description (L98–L101), and "Tests within a file stay serial" (L102). The last one is still true with --dist=loadfile.

How to check: this is a static check. After the edit, the README's entrypoint descriptions should match core_unit_tests.sh L39, server_tests.sh L67 and L76, and full-test-suite.yml L80 and L131–L133.

Review generated by claude. This was a full review. Request a full review with /review reset=true.

@ko3n1g
ko3n1g removed the request for review from a team November 4, 2026 19:03
@ko3n1g
ko3n1g removed request for a team November 4, 2026 19:03
@ko3n1g
ko3n1g added this pull request to the merge queue Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/41893255371

Merged via the queue into main with commit 6c29535 Nov 4, 2026
66 of 69 checks passed
@ko3n1g
ko3n1g deleted the ko3n1g/ci/four-test-workers branch November 4, 2026 19:19

This branch was previously deployed

1 inactive deployment
public — 9dffde96 Deployed Nov 4, 2026 by copy-pr-bot[bot] via release / finalize / notify #10083
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI workflows, test routing, and repository automation ci CI, automation, test queue, or workflow infrastructure work needs-review PR is ready for code review and waiting on a reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants