Repository navigation
Conversation
265 test files run one process at a time, in series, on a 2-vCPU runner: about 16 minutes and the longest job in this repo. Nothing about that is inherently serial -- the loop already isolates each file in its own process precisely because bun shares module mocks across files -- but there was no way to ask for a subset. `--shard INDEX/TOTAL` (or SHARD_INDEX/SHARD_TOTAL) deals the sorted file list round-robin across N shards. Every file lands in exactly one shard: no duplicates, no gaps, and sizes differ by at most one file. Round-robin rather than duration packing on purpose. Packing is better, but it needs per-file timings that nothing collects yet, and a made-up weight table produces an uneven split that looks considered while being wrong. Round-robin is exact and honest about being approximate; pack it properly once real timings exist. Unsharded invocation is unchanged: no argument and no env means one shard holding everything. `--list` is byte-identical, which the registration test in scripts/test-consensus.registration.test.ts asserts. Also fixes an existing bug that sharding exposes: under `set -u`, bash below 4.4 treats an empty `failed[]` as unbound and aborts the script even when every test passed. Bash 5 on the runner accepts the plain form, so it never showed there -- but it makes any no-failure run impossible to reproduce on macOS, which is exactly what a shard does routinely.
Consensus Tests is 67% of this repo's CI compute and, at ~987s, the critical path every PR waits on. It is now four shards of ~66 files each. Modelled from the measured 987s: the slowest shard lands near 250s, so wall clock drops to roughly 4-5 minutes and Rehearsal Drill Checks (~279s) becomes the new critical path. Compute is close to flat -- four checkouts and four bun installs replace one -- so this buys feedback time, not minutes. On a public repo on hosted runners that is the right thing to optimise. 4 shards is conservative because the slowest single file sets the floor. Raise it once real per-shard timings are visible; do not guess. The two shell guards (launcher-wipe-guard, launcher-external-db) are not partitioned and run in every shard. They are stubs, measured at ~2s, so repeating them is cheaper than adding a mode flag to skip them.
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Round-robin splits by file count, but file durations differ by two orders of magnitude -- the slowest measured file is 48s and the median is 4s. That left shard 1 running 262s of tests against 208s for shard 4. scripts/consensus-weights.tsv carries the per-file seconds measured from this branch's own sharded run (parsed from the ::group:: markers in the Actions log), and shard_files now packs with LPT when that table covers the suite. Measured effect at 4 shards: max shard 262s -> 229s, which is the theoretical lower bound for an even split, and the spread drops from 54s to 1s. Exactness is preserved -- every file in exactly one shard, no duplicates, no gaps -- verified across totals 1, 2, 3, 4, 6 and 8. The weights are counted work, not wall clock: they are missing per-file process spawn and teardown, so they predict the ratio between files well and absolute shard duration less well. That is fine for a packing decision and wrong to quote as a prediction. Falls back to round-robin when the table is absent, partially covering the suite, or unparseable. Packing on a stale or partial table would silently skew the split, and a file with no weight would be placed as if it were free.
launcher-wipe-guard measures 40s per shard (I had assumed ~2s and said so in the previous commit's comment, which this corrects). On four shards that is 160s of duplicated wall clock per run -- more than the sharding itself saved. Both stub guards move to their own job, beside the shards rather than repeated inside them. Nothing about coverage changes: the guards still run on every commit, still fail CI on failure, and this workflow has no aggregate gate, so each job stands as its own check. Runs in parallel with the shards, so it costs no wall clock. Roughly 160s of duplicated work removed per run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Measured result
CIwall clock: 17.3–18.1 min → 4.9 min. A 72% cut. All 18 checks pass, zero failures.Three changes, three commits
1. Shard the suite (
--shard INDEX/TOTAL)Consensus Testswas the longest job here and 67% of CI compute. Measured: 987s, of which setup is only 12s — the rest isscripts/test-consensus.shrunning 265 test files one process at a time, in series, on a 2-vCPU runner.Not inherently serial: the script already gives each file its own process because bun shares module mocks across files. There was simply no way to ask for a subset.
2. Pack shards by measured duration, not file count
Round-robin is even by file count, but file durations differ by two orders of magnitude — slowest measured file 48s, median 4s. That left shard 1 at 262s of test time against 208s for shard 4.
scripts/consensus-weights.tsvcarries per-file seconds measured from this branch's own sharded run (parsed from::group::markers in the Actions log), andshard_filesnow packs with LPT.At 4 shards: max shard 262s → 229s, the theoretical lower bound for an even split; spread 54s → 1s. Exact partition preserved — every file in exactly one shard, no gaps, no duplicates — verified at totals 1, 2, 3, 4, 6, 8.
3. Run the launcher guards once, not once per shard
launcher-wipe-guardmeasures 40s per shard. I had assumed ~2s and said so in commit 2's comment; commit 4 corrects it. On four shards that was ~160s of duplicated wall clock — more than sharding saved. Both stub guards moved to their own parallel job (measured 53s standalone).Where my modelling was wrong, twice
I want these on the record because both shaped the result:
Rehearsal Drill Checks(279s) as the new critical path. Shards actually landed at 4m22s–5m23s. Round-robin's evenness-by-count was the reason.That distinction is in the weights file's own comment. The ratio is what a packing decision needs; the absolute number is not something to quote as a prediction, and I am not quoting one.
What actually bounds this now
Rehearsal Drill Checksran 4m48s, and 254s of it is a single step (lockstep-stub.test.sh). Sharding the consensus suite can't go below that. Further gains need that step looked at — which is a separate change, not part of this PR, and I have not attempted it.Verified before each push
--listbyte-identical (sha256 8a658ede…) with and without shard env →test-consensus.registration.test.tsstill passes--shard 1,abc/2,0/4,5/4,1/0actionlintcleanAlso fixes an existing bug
Under
set -u, bash below 4.4 treats an emptyfailed[]as unbound and aborts even when every test passed. Bash 5 on the runner accepts the plain form, so it never surfaced there — but it makes a no-failure run impossible to reproduce on macOS, which is exactly what a shard does routinely. Fixed with${failed[@]:-}.On compute
Still close to flat: four checkouts and bun installs replace one, and the hoisted guards remove 160s of duplication, so it is slightly better than flat. This is a feedback-time win, not a cost win. On a public repo with hosted runners that is the right thing to optimise, and I would rather label it correctly than inflate it.
Draft for review — no merge implied.