Skip to content

CI gets a fifth shard: test_108*/test_109* leave shard 3 - #997

Merged
lmoresi merged 4 commits into
developmentfrom
bugfix/fifth-shard
Nov 7, 2026
Merged

lmoresi merged 4 commits into
developmentfrom
bugfix/fifth-shard

Conversation

@lmoresi

@lmoresi lmoresi commented Nov 7, 2026

Copy link
Copy Markdown
Member

CI gets a fifth shard, which takes shard 3's longest batch off the 60-minute budget. Shard 4 stays where it is until #911's fix.

What was wrong

On development 37aa2a1, run 42412307017, shards 3 and 4 ran 56:28 and 55:40 against the 60-minute budget (hard limit 70); shards 1 and 2 ran 43:11 and 33:11. Shard 3's test_108*/test_109* batch took 25:47 of that. Shard 4's test_00[0-4]* took 27:29, which #985 and #911 put nearly all on test_0022.

The fix

That batch becomes batch 5, and --print-shards gives [1,2,3,4,5], so the CI matrix grows a fifth job. By subtraction, shard 3 falls to about 31 minutes and shard 5 runs about 31 with install and build. Shard 5 starts with a cold JIT and mesh cache that the batch shared on shard 3, so this is an estimate to re-measure on this PR's run. test_0022 is held for #911, as the hub asked; the PR wall-clock stays near 56 minutes until then.

Tests

  • Every batch N glob expanded at both commits maps 404 paths, each to exactly one shard. The only change is 12 files from shard 3 to 5: test_1080 to 1085, 1087, 1091, 1092, 1094, 1096 and 1098. The tier filter is unchanged.
  • check_test_coverage.py: OK, 394 files reachable. It runs on every shard, including 5.
  • --shard 4/4 is now refused for the mismatch, as designed.
  • No required check names a shard, so the rename from "shard K/4" to "shard K/5" blocks nothing.

To check on this PR's first run: five shard jobs, shard 5 reporting 38 passed for its batch, and the shard 3 and 5 times against the estimates.

Refs #985, #911

Underworld development team with AI support from Claude Code

On development 37aa2a1 shards 3 and 4 ran at 56:28 and 55:40 of the 60-minute
cap. Shard 3's test_108*/test_109* batch was 25:47 of that; it moves to shard 5,
which --print-shards adds to the CI matrix. Shard 4's test_0022 stays until
#911's fix (#985).

Underworld development team with AI support from Claude Code
… caveat, from review

Underworld development team with AI support from Claude Code
Copilot AI balanced review requested due to automatic review settings November 7, 2026 22:11

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@lmoresi

lmoresi commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Adversarial review record

Independent review at daeef09; its wording fixes are applied at 3f10dc0 (usage example, budget wording, the cold-cache caveat, "running it four times").

Mergeable. We found no defects that block it. The change moves exactly 12 files from shard 3 to shard 5. Nothing goes unrun, nothing runs twice, and the tier filter is unchanged. Each header number we could check matches run 42412307017. All remaining findings are low or nits.

Findings

Low: the shard-5 estimate assumes a warm disk cache that shard 5 won't have.

  • The JIT and mesh caches are kept on disk for the whole job (src/underworld3/utilities/_jit_cache.py:11, src/underworld3/meshing/_mesh_files.py:36).
  • On shard 3 the test_108*/109* batch ran after test_08* and the tests/parallel serial files, so it may have reused their cached kernels and meshes.
  • On shard 5 it starts with an empty cache. test_110* may also lose kernels that it used to pick up from 108/109.
  • So the "shard 3 near 31, shard 5 near 31" figures are a subtraction, not a measurement. Re-measure them on the PR's first run.

Low: the slowest shard is unchanged.

Nit: the header says "the 60-minute cap", but the job cap is 70. The 60 is the budget the workflow comment gives (build_uw3_and_test.yaml, timeout comment, #954).

Nit: scripts/test.sh:21 still gives --shard 1/4 as its usage example. That command is now refused, loudly. This is not a coverage risk, but the line should be fixed.

Nit: some comments still describe four shards.

  • scripts/test.sh:124 ("the four shards") and :399-401 ("running it four times") describe four shards.
  • The CHANGELOG ("four-way shard matrix") is historical, so it is acceptable to leave.

Attacks that failed

  • Coverage equivalence. We expanded every batch N glob at both commits.
    • Both versions map 404 paths, each to exactly one shard.
    • The only difference is 12 files changing from 3 to 5: test_1080 to 1085, 1087, 1091, 1092, 1094, 1096 and 1098.
    • No file is claimed by two shards. tests/parallel/test_1088 and test_1090 stay on shard 3, and the tests/test_108* glob does not match them.
  • Tier filter. -m "not tier_c" is in the shared PYTEST array, so batch 5 gets the same filter as batch 3 did. test_1081 and test_1084 stay excluded as tier C.
  • Coverage check. check_test_coverage.py reports "OK: all 394 test files are reachable (0 deferred)". It parses batch \d+ lines without regard to the shard number. It also runs unconditionally in the serial phase, so it runs on every shard, shard 5 included.
  • Shard-count refusal.
    • --print-shards prints [1,2,3,4,5].
    • --shard 4/4 is refused: "asked for shard 4 of 4, but ... assigned to 5 shards".
    • 5/4, 6/5 and 0/5 are each refused as out of range.
  • Workflow.
    • The matrix comes from plan / --print-shards. The job name and the --shard argument both use strategy.job-total.
    • Shard 5 runs the same steps as the others: checkout, pixi install, build, import smoke test, gdb, then tests.
    • Artifacts are named hang-stacks-shard-${{ matrix.shard }}, so they are unique.
    • There is no concurrency: block.
    • The aggregate test job uses needs: shards plus if: always(), and fails on any result other than success.
    • No other workflow under .github/ mentions shards.
  • Phases that one shard owns.
    • shard_owns 4 (the mpirun phase) is the only call site, and it remains valid with N=5. Shard 5 logs "Parallel tests belong to shard 4".
    • No "ptest" phase and no shard-2-owned phase exist in scripts/test.sh, so that premise does not apply.
    • Nothing is keyed to shard 1 or to the last shard.
  • Required checks.
    • gh api .../branches/{development,main}/protection/required_status_checks returns empty contexts and checks.
    • .../rules/branches/* holds only the deletion, pull_request (1 approval) and copilot_code_review rules.
    • So no check name like "shard 4/4" is required, and the rename to "shard K/5" cannot block a merge.
    • The flip side, which predates this change: no CI check is required at all, so a red test does not block a merge either.
    • scripts/triage.py reads statusCheckRollup conclusions without regard to job names.
  • Header numbers against run 42412307017 (development push of 37aa2a1, success):
    • Shard 3 log span is 20:42:17 to 21:38:45, which is 56:28.
    • Shard 4 span is 55:40.
    • The jobs API gives 43:13 for shard 1 and 33:13 for shard 2, consistent with 43:11 and 33:11 to within the API's roughly 2 s of extra time.
    • Shard 3's test_108*/109* batch: "38 passed ... in 1547.43s (0:25:47)", with test_1094 and test_1082 among them.
    • test_110*: 608.60 s (10:08).
    • Shard 4's test_00[0-4]*: 1649.04 s (27:29).
    • Arithmetic: 56:28 - 25:47 = 30:41. Shard 3's setup before tests was about 4:25, plus about 0:18 of startup, which puts shard 5 at about 30:30 with a warm cache.

Merge conditions

  • Fix scripts/test.sh:21 to read --shard 1/5, or a form that does not name N. Optionally fix the "60-minute cap" wording.
  • On the PR's first run, confirm five jobs named "shard K/5", each running the coverage check. Confirm shard 5 reports "38 passed" for the 108/109 batch. Record shard 3 and shard 5 times against the 31-minute estimates. A cold-cache shard 5 well over 31 minutes would mean the header needs correcting.

Not checked

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Adversarial review of #997 at 3f10dc0

We checked the change independently first, then the review record already on the PR. This record adds only what that one misses or gets wrong. We read the branch and also refs/pull/997/merge (653fda6 = development 7274187 + 3f10dc0). CI tests the merge ref, and the merge ref is what lands.

Must fix

None.

Should fix

1. Low. The header's shard times come from one run, and that run spread the shards over runner CPUs that differ by about 2x. The CPU is not recorded. scripts/test.sh:138-147.

Every number in the new header comes from run 42412307017. In that run shard 3 ran on an Intel Xeon 8370C and shard 4 on an AMD EPYC 7763. Run 42412968302 is development at f31edcb, this PR's own merge base. It started eight minutes later and ran the same batches on faster AMD hosts. Every batch took about half as long:

batch (shard) 42412307017 42412968302 42412949155 (#958)
shard 3 total 56:30, Xeon 8370C (SkylakeX) 30:08, EPYC 9V45 (Cooperlake) 42:04, EPYC 9V74
test_08* 11:43 5:11
test_108*/109* 25:47 13:57 20:05
test_110* 10:08 5:30
shard 4 total 55:43, EPYC 7763 (Zen) 27:27, EPYC 9V45
test_00[0-4]* 27:29 8:21
shard 1 total 43:13, EPYC 7763 43:58, EPYC 7763

Evidence: gh run view <run> --json jobs; gh api repos/underworldcode/underworld3/actions/jobs/<id>/logs, grepping each log for the Model name: and Core: lines from the "Report the CPU and the BLAS kernel" step and for each batch's pytest summary line.

What goes wrong: the header's merge condition says to "re-measure both on the first five-shard run". If shard 3 of that run lands on a 9V45, it reports about 17 minutes. That would read as the move saving 39 minutes and as confirming the 31-minute estimate, when it confirms neither. The opposite also happens: a shard 5 on an 8370C can look like a cold-cache penalty when it is the host. The variance by CPU (2x, and 3.3x for test_00[0-4]*, the #985 kernel class) is larger than the effect being measured.

The same table bears on the premise. On the base run, shard 3 was at 30:08, nowhere near the cap, and the long pole was shard 1 at 43:58. So this change relieves shard 3 when it lands on a slow host. That is still worth doing, and the subtraction is right for the slow host (56:28 - 25:47 = 30:41).

Fix: put the CPU next to every quoted time (for example "56:28 on a Xeon 8370C"). In the merge condition, compare times on the same CPU, or across several runs.

2. Low. On the merge result, the comment this PR rewrote is contradicted by the block that follows it. The review record's "no ptest phase" check was run on the branch only. scripts/test.sh:402-405 of 653fda6.

#958 merged into development at 21:42. It adds an mpirun phase for the named ptest_* files, owned by shard 2 (shard_owns 2, line 433 of the merged file). It sits directly below the paragraph this PR reworded. After the merge, line 402 says "The whole mpirun phase belongs to ONE shard (4)", and line 407 says the ptest files are "owned by shard 2". The review record says "No 'ptest' phase and no shard-2-owned phase exist in scripts/test.sh". That is true at 3f10dc0 and false on the ref CI runs and merges.

Evidence: with fake pytest, python and mpirun on PATH, we ran the merged script as test.sh --p 2 --shard K/5:

shard 2 ; mpi launches: 3   "Parallel ptest_* files (2 ranks), on shard 2"
                            "Parallel tests belong to shard 4; this is shard 2."
shard 4 ; mpi launches: 13
shard 1, 3, 5 ; mpi launches: 0

Shard 2's log already prints both lines on run 42412949155 (lines 1610 and 1880). The header's "shard 2 at 33:11" also predates that phase. It took 1:41 on that run (21:14:30 to 21:16:12, EPYC 9V74).

Fix: merge development into the branch. Make lines 402-405 say that shard 4 owns the tests/parallel/test_* enumeration and shard 2 the named ptest_* files. The echo at line 538 comes from #958 (see Note 6).

Notes

1. Nit. scripts/test.sh:155-158 still says "add a batch 5 ... line and CI grows a fifth shard on the next run". After this change it describes something that has already happened. It should say batch 6, or not name a number.

2. Nit. The workflow's own comments still count four shards. .github/workflows/build_uw3_and_test.yaml:169-170 ("having to AND four shard results together"), :193-194 ("cost its ~42 minutes four times over") and :90-93 ("The slowest shard is ~33 min of tests ... A hung batch costs shard 4 about 5 minutes more"). The record says "No other workflow under .github/ mentions shards". That is true of other workflows, but this one's comments are stale. The matrix logic itself does not depend on the count. plan builds the matrix from --print-shards. The job name and --shard use strategy.job-total. test aggregates needs.shards.result. hang-stacks-shard-${{ matrix.shard }} is unique per shard. Run 42419419706 on this PR started five jobs named "shard K/5".

3. The only cache shard 5 loses is the JIT cache. Meshes are not reused. The record says the batch "may have reused their cached kernels and meshes". src/underworld3/meshing/_mesh_files.py:5-6: "It is not a cache: every construction regenerates both, and nothing checks whether they already exist". tests/conftest.py:45-47 also gives each xdist worker its own UW_MESH_CACHE_DIR=.meshes/gwN. The JIT disk cache (src/underworld3/utilities/_jit_cache.py:39-49, ~/.cache/underworld3/jit) does persist across the batches of one job, and nothing carries it between jobs (setup-pixi cache: true caches the pixi environment only). So the cold start costs compile time only. It cannot change a result.

4. Cross-file assumptions: we found none. This is the question the author asked about. What we checked:

  • Grouping. The PR does not change which files share a pytest process. With a fake pytest recording every call, the 32 pytest invocations, taken as file lists, are identical at f31edcb and 3f10dc0, and also at development 7274187 and the merge ref (diff of the sorted lists: no output). The test_108*/109* batch was one invocation on shard 3 and is the same invocation on shard 5: --config-file=tests/pytest.ini --dist loadfile -n 4 -m not tier_c tests/test_1080_... tests/test_1098_....
  • Ordering. The only ordering that changes is across processes. On shard 3 the batch ran after test_08* and the ten tests/parallel serial files, and test_110*, test_1141 and test_1142 ran after it. Across processes only the JIT disk cache carries over.
  • Shared files and imports. None of the 12 moved files reads a file another test writes. None imports another test module or _mg_ladder. None calls os.environ or PETSc.Options at module level. The only module-scope fixtures are test_1087:23 and test_1098:21, each private to its file. No test outside them names them, apart from a docstring at test_0010:11.
  • Timeouts. pytest-timeout is installed on CI (plugins: ... timeout-2.4.0), but tests/pytest.ini sets no timeout and none of the 12 files has a timeout mark or a wall-clock check. A slower cold JIT cannot turn into a failure.
  • test_1092 and test_1094. Each builds its own mesh: SphericalManifold (with add_fault in the third test) and UnstructuredSimplexBox(regular=False). Each reads only its own solver's _rotated_freeslip_info or uw.function.evaluate, and asserts against closed forms. Nothing in them depends on an earlier file.
  • The stayers. The files left on shard 3 (test_110*, 1141, 1142) read nothing that 108/109 wrote. test_1142:116 reads s._rotated_linear_cache, which is the solver's in-process cache.

5. Coverage on the merge result as well as the branch. With the fake pytest, each shard's script expands to 407 paths at development 7274187 and at 653fda6, none of them in two shards. Between the two, exactly the same 12 files move from 3 to 5, and nothing else changes. Among the files named explicitly elsewhere, tests/parallel/test_1088 and test_1090 stay on shard 3. check_test_coverage.py on the merged tree, from every shard: "OK: all 397 test files are reachable from scripts/test.sh (0 deferred by decision); 17 of 39 ptest files run (22 deferred with a reason)". The batch collects 38 items locally (pytest --co -m "not tier_c" tests/test_108*py tests/test_109*py: "38/43 tests collected (5 deselected)"), which matches the PR body.

6. Outside this diff, on development (#958): shard 2 prints "Parallel tests belong to shard 4; this is shard 2." right after its own three mpirun batches (scripts/test.sh:538 of the merge ref). A reader of shard 2's log is told no parallel tests ran there.

7. The batch's internal tail is unknown. The log shows xdist dots only, so it has no per-file durations. With --dist loadfile the batch cannot finish before its slowest file, so splitting the batch further could only help if that file is short. test_1092's tide test (192 time steps) and test_1094 are likely candidates. This does not change the verdict; it is the input any further split would need.

8. Next to the cap, not in this diff: on run 42412307017 the tier C job ran 83:04 (20:42:07 to 22:05:11) against its timeout-minutes: 90.

9. CI on 3f10dc0 (run 42419419706): plan passed and started five jobs, "shard 1/5" to "shard 5/5". All five were pending when we wrote this, so the re-measurement the header asks for is not in this record.

Issue verdicts

Not checked

  • We did not time each file inside the test_108*/109* batch. That needs a run with --durations or a lower worker count.
  • We did not measure the cost of the cold JIT cache separately from the runner CPU. One run cannot separate them. Several runs, or one run with the cache cleared, could.
  • We ran nothing under MPI. The MPI phases were traced with fake python and mpirun only.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

Both cross-review Lows are addressed at 1227d1c.

  1. The header now gives shard times by runner CPU, from 9 successful four-shard runs on 37aa2a1 and the PRs just after it. On an EPYC 7763, shard 3 runs 54:37 to 54:49 and shard 4 54:57 to 56:53. On an EPYC 9V45 they run 31:11 and 25:17 to 27:13. Run 42412307017's shard 3 was on a Xeon 8370C. The case for the fifth shard rests on the slow runners, which is where shards 3 and 4 sit within 5 minutes of the budget.
  2. Development is merged in, including CI runs the ptest_* files that pass; the rest are listed with their reason #958. The paragraph now says the test_* mpirun phase belongs to shard 4 and the ptest_* loop to shard 2.

--print-shards gives [1,2,3,4,5], and check_test_coverage.py is OK on 397 files.

Underworld development team with AI support from Claude Code

@lmoresi

lmoresi commented Nov 7, 2026

Copy link
Copy Markdown
Member Author

First five-shard run, 42419419706 at 3f10dc0, all green:

shard time CPU
1 30:33 EPYC 9V74
2 35:48 EPYC 7763
3 21:18 EPYC 9V74
4 55:00 EPYC 7763
5 24:21 EPYC 9V74

Shard 5's batch reports 38 passed in 20:13 on a 9V74. Shard 3 on a 9V74 ran 41:34 to 51:59 before this change, so it fell by roughly 20 to 30 minutes. Shard 4 on a 7763 is unchanged at 55:00, as expected until #911. A slow-runner (7763) time for shards 3 and 5 is still to come from a later run.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit cb1772f into development Nov 7, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants