Title: mcpx testing: shard the suite by measured time, and a rule for when to stop splitting · Issue #1994 · developing-today/code · GitHub
Open Graph Title: mcpx testing: shard the suite by measured time, and a rule for when to stop splitting · Issue #1994 · developing-today/code
X Title: mcpx testing: shard the suite by measured time, and a rule for when to stop splitting · Issue #1994 · developing-today/code
Description: Relocated from dezren39/darwin-nix#139 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/ni...
Open Graph Description: Relocated from dezren39/darwin-nix#139 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue referenc...
X Description: Relocated from dezren39/darwin-nix#139 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue refe...
Opengraph URL: https://github.com/developing-today/code/issues/1994
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mcpx testing: shard the suite by measured time, and a rule for when to stop splitting","articleBody":"Relocated from dezren39/nix#139 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue references inside it are historical (dezren39/nix numbering).\n\nParent: #95\n\n## Summary\n\nDecide how the suite is split across matrix legs and how the split is kept balanced as tests are added. Today the whole suite is one job, and one package (`internal/e2e`, 100.7 s, strictly serial) is three quarters of it. The notes propose: split unit from integration, shard the longer one into logical groups, repeat on the longest shard, then fall back to alphabetical ranges balanced by time, and stop when setup/teardown dominates. This issue makes that concrete, gives the stop rule as arithmetic, and recommends a **timing-file-driven splitter** over hand-tuned alphabetical ranges -- while keeping the one real advantage of the alphabetical idea (a shard you can reproduce locally with one `-run`).\n\n## Original notes\n\n> - testing\n> - make a comprehensive github action ci.yaml workflow (or test.yaml) that is as fast as possible,\n> - splitting sets of tests into as small groups as practical, eg split out unit/integration tests into 2 jobs, whichever one takes longer: shard it into 4 logical groups (or however many) based on an appropriate category, then find the longest job at that point and repeat (you dont want to iterate on this forever, at some point start splitting logical units by like, e.g. maybe a-f/g-s/t-z, balance number of letters by time.\n\n> - testing\n> - make a comprehensive github action ci.yaml workflow (or test.yaml) that is as fast as possible,\n> - continue until the jobs can't get much faster considering setup/teardown and then set a ci testing budget which is a hardcoded default input. after the test matrix have a time budget job when subtracts github workflow request time from now. (this catches if the jobs are impacted by matrix size, could lessen by taking initial job end or matrix start time.)\n\n> - testing\n> - make a comprehensive github action ci.yaml workflow (or test.yaml) that is as fast as possible,\n> - repeat this process whenever testing exceeds some time budget. make setup faster, rebalance alpha splits, split groups of tests on the longest shard. maybe flag that never tears down because just killing the box after. anything downloaded should be cached, shallow clone a partial path to mcpx dir, if there's unexplainable job start delays, try to keep all job times balanced, 10 ultrafast ones can give you quick signals but may put pressure on runner infra and cause the longest jobs to last a little longer. all that matters is how long the longest jobs take. job runners have 2 or 4 cores, consider if theres lengthy tests which are '1' test but re-exec N times 'in parallel': they will only run 1-3 at a time and so 30 cases _could_ take up to 10 tests worth of time even in parallel and may need to be examined. we're using go so im not too worried about time budget but its best to get this early. main focus is strong tests as each step of the lifecycle.\n\n## Current state\n\nFrom run 36673523537 (see #135 for the full step table); the post-#182 run 36693030957 at 05c78b2 is in brackets:\n\n| Package | Time | Tests |\n| --- | --- | --- |\n| `internal/e2e` | **100.7 s** [108.9 s] | 199 [209] |\n| `internal/tui` | 8.6 s | 15 |\n| `internal/pool` | 1.5 s | |\n| `internal/events`, `internal/mcpserver` | ~1 s each | |\n| every other package | \u003c 0.5 s | |\n| compile (no working cache) | ~31 s [~39 s incl. module download; #182 fixed the cache key, but this run was a miss by construction -- first warm figure is #143's] | |\n\n`internal/e2e` by file (`rg -c '^func Test'`; at 05c78b2 in brackets):\n\n| File | Tests | Share |\n| --- | --- | --- |\n| `e2e_test.go` | 128 [129] | 64 % [62 %] |\n| `consumer_test.go` | 17 | 9 % |\n| `exec_test.go`, `proto_test.go`, `v1ops_test.go` | 11 each | 17 % |\n| `settings_test.go` | 10 | 5 % |\n| `unread_test.go` | [9, new in #171] | [4 %] |\n| `logs_test.go` | 5 | |\n| `multiconfig_test.go` | 4 | |\n| `runtime_test.go` | 2 | (loops deno/bun/node inside) |\n\nPer-test timings do not exist yet: the log has package totals only (no `-v`, no `-json`). 199 tests in 100.7 s is ~0.5 s each on average (209 in 108.9 s at 05c78b2, the same rate); the distribution is unknown. For contrast, the ~520 unit tests take ~15 s together, ~0.03 s each -- a 17x gap (from #166). 62 of the e2e tests start a JavaScript runtime (53 `\"exec\"` calls in `e2e_test.go`, 9 in `exec_test.go`, 3 in `runtime_test.go`; unchanged at 05c78b2), so one e2e test is commonly 3-4 processes: the CLI, a daemon, a fake MCP server and deno/bun/node.\n\nParallelism today:\n- **No `t.Parallel()` anywhere** in the module. `go help testflag`: `-parallel n` \"Allow[s] parallel execution of test functions that call t.Parallel ... By default, -parallel is set to the value of GOMAXPROCS\" -- so it currently does nothing.\n- `go help build`: `-p n` is \"the number of programs, such as build commands or test binaries, that can be run in parallel. The default is GOMAXPROCS\". So `go test ./...` runs up to 4 *package* binaries at once on the runner, which is why every unit package finished inside e2e's 100 s -- but e2e itself is one binary running 199 tests one after another.\n- Runner: this repo is public, so `ubuntu-latest` = **4 vCPU / 16 GB**; a private repo gets **2 vCPU / 8 GB**; `ubuntu-slim` is a 1 vCPU container; `macos-latest` is 3 vCPU M1 ([runner reference](https://docs.github.com/en/actions/reference/runners/github-hosted-runners)). The notes' \"2 or 4 cores\" is right; which one depends on repo visibility.\n- Account limits on the Free plan: **20 concurrent standard-runner jobs** (5 macOS), shared by every workflow in the account; 256 jobs per matrix ([limits](https://docs.github.com/en/actions/reference/limits)).\n\nTests that fan out internally (\"1 test that re-execs N times in parallel\"):\n\n| Test | Fan-out | Where |\n| --- | --- | --- |\n| `TestConcurrentRunsGetIsolatedInstances` | 4 concurrent `mcpx run`, each a runtime process + daemon traffic | `internal/e2e/e2e_test.go:319` (func, 05c78b2) |\n| `TestConcurrentRunsOfOneScriptKeepTheirOwnLauncher` | 6 concurrent `mcpx run --launcher` | `internal/e2e/e2e_test.go:2938` |\n| `TestTwoConfigurationsDoNotShareAGeneratedClient` | 2 | `internal/e2e/e2e_test.go:2826` |\n| five pool tests (`TestSharedModeHandlesConcurrentCalls`, `TestSessionModeRespectsMaxAndQueues`, ...) | goroutine fan-out over fakemcp | `internal/pool/pool_test.go:92-475` |\n\nEach `mcpx run` starts Deno/Bun/Node, which is CPU-heavy at startup, so on 4 vCPU a 6-way fan-out runs roughly 3-4 at a time and on 2 vCPU roughly 2 -- the notes' \"30 cases could take up to 10 tests worth of time\" is the right intuition. These are also the tests that will contend worst once other tests run in parallel. There are also 7 fixed `time.Sleep` waits in e2e (100-500 ms each, e.g. `e2e_test.go:149,403`) that cost wall time regardless of cores.\n\n## The procedure, made concrete\n\n1. **Measure.** Every CI run of e2e uses `go test -json` (keep human output via `gotestsum` or a `jq` filter) and uploads per-test `Elapsed` as an artifact. The final job (#140) merges them into one timing file per main run.\n2. **Unit vs integration.** One `unit` job (`go test $(go list ./... | grep -v /internal/e2e)`), and e2e separately. The unit job's test time is ~9 s (tui); it will never be the long pole unless something changes drastically.\n3. **Shard e2e** (the approaches below).\n4. **Repeat on the longest job** -- which after step 3 will likely be the `nix` job, not a test shard (#143 predicts this). That is the runbook in #140.\n5. **Stop** by the rule below.\n\n### Stop rule\n\nPer-leg fixed cost today, from the step table: queue 2-3 s (occasionally ~40 s) + set up 3.4 s + checkout ~2 s + toolchains ~18-26 s (setup-go 10.9 s alone) + compile and binary build (part of the ~31 s, less with a cache) + post 2 s + completion ~3 s ≈ **30-45 s**. With T = 100 s of e2e test time and N equal shards, the longest leg is ≈ fixed + T/N:\n\n| N | T/N | longest leg (fixed ≈ 35 s) |\n| --- | --- | --- |\n| 1 | 100 s | 135 s |\n| 2 | 50 s | 85 s |\n| 3 | 33 s | 68 s |\n| 4 | 25 s | 60 s |\n| 8 | 12.5 s | 48 s |\n\nEach extra shard saves T/N - T/(N+1) and costs one more runner (and more pressure on the 20-job limit). **Stop when T/N is below the fixed cost** (going from 4 to 8 legs saves 12 s for 4 more runners), or when the leg is no longer the longest job. Today that means N ≈ 3-4. Reducing the fixed cost (the working Go cache, shipping a compiled `e2e.test`, #135 decision 7) moves the optimum up; `t.Parallel` (below) moves T down.\n\n\"Many tiny jobs\" vs \"all that matters is the longest job\": more legs are free until they queue. With lint (~3 legs), unit, nix, plugin, docs-examples and #97's environment legs, a 4-shard e2e already puts ~12 jobs in one run; two concurrent runs (a PR and a main push) reach 20 and the 21st waits. Queue time is invisible in the per-job durations and only shows in the run's wall clock -- the budget job reports it separately (#140).\n\n## Approaches\n\n### A -- hand-tuned alphabetical ranges (the notes' fallback), least recommended as the end state\n\n`-run '^Test[A-F]'`, `'^Test[G-S]'`, `'^Test[T-Z]'`, with boundaries moved by hand when the budget is exceeded.\n- Pro: no tooling; anyone can reproduce a shard locally from its name; stable membership.\n- Con: every test starts with `Test` and the next letter follows English, not runtime -- clusters like `TestRun...`, `TestExec...`, `TestConcurrent...` cannot be split by a range boundary without going to two letters (`^TestC[a-n]`), and after a few rebalances the regexes are unreadable. Balance drifts with every added test, and each rebalance is a workflow edit and a PR -- exactly the \"iterate on this forever\" the notes warn about. Balancing \"number of letters by time\" requires the per-test timings anyway, and once you have them, bin-packing uses them better than contiguous ranges can.\n\n### B -- logical shards by feature (file), a static list\n\nOne shard per feature file: exec, consumer, v1ops, proto, settings, logs, runtime, multiconfig, plus the rest.\n- Pro: a red leg names a feature; stable; readable.\n- Con: badly unbalanced by construction -- `e2e_test.go` holds 64 % of the tests, so the \"rest\" shard is roughly two thirds of the time and needs splitting again. Go cannot select tests by file, so each shard's `-run` regex is a generated list of names (`grep '^func Test' file`). To make B balance, `e2e_test.go` would have to be broken into feature files first -- a worthwhile readability refactor on its own (one file of 2,977 lines and 129 tests at 05c78b2), but not something to do *for* CI balance.\n- Variant (from #166): split `internal/e2e` into **subpackages** (`internal/e2e/exec`, `.../proto`, `.../v1ops`, ... with `newEnv` and the fixtures lifted into a shared helper package). Each subpackage is its own test binary, so shards need no regex, survive renames, cannot silently select zero tests, and compile in parallel; `go test ./internal/e2e/...` still means \"all e2e\". Same arithmetic limit as B: on today's file boundaries the largest shard is still `e2e_test.go`.\n\n### C -- timing-file-driven splitter (recommended)\n\nA small Go program in the repo (e.g. `pkgs/mcpx/internal/ci/shard` or `scripts/ci/shard.go`, run with `go run`; the toolchain is already there):\n1. lists tests (`grep '^func Test'` over `internal/e2e/*_test.go` is free; `go test -list .` is exact but compiles the test binary first);\n2. reads the latest timing file -- the artifact of the last successful main run (via `gh run download` / `actions/download-artifact` with `run-id`), falling back to a committed `timings.json`, falling back to equal weights;\n3. gives tests without a timing the median;\n4. computes N = clamp(ceil(total / target_leg_seconds), 1, max_shards), and assigns tests to shards by **longest-processing-time greedy** bin-packing (sort descending, put each into the currently lightest shard);\n5. emits the matrix JSON: `[{\"name\":\"e2e-1\",\"run\":\"^(TestA|TestB|...)$\"}, ...]`, and each leg prints its exact `go test -run '...'` line into the job summary.\n6. makes each leg assert it ran the number of tests it was assigned. A `-run` regex that matches nothing makes `go test` print \"testing: warning: no tests to run\" and exit **0** -- a shard that ran nothing is green (from #166).\n7. records subtests as their own units: `TestGeneratedClientWorksOnEveryRuntime` and `TestSessionIsolationHoldsOnEveryRuntime` (`internal/e2e/runtime_test.go:13,45`) are one `func Test` each but three runtimes' worth of time, so a packer that weighs by `func Test` under-counts them 3x (from #166 / #168).\n\nWhy it beats A: balance within a few percent regardless of naming, rebalancing is automatic on every run (no workflow edits), and \"split the longest shard\" becomes changing one number (`target_leg_seconds`). The alphabetical idea's real benefit -- a shard you can reproduce locally -- is kept by printing the regex, and the #99 policy can say \"rerun the failing leg with the line in its summary\". Honest costs: ~100-150 lines to own; shard membership changes between runs (fine, since the summary names the tests); timings are noisy (use the median of the last few main runs, not the last one); a very long `-run` regex is ugly but Go handles thousands of alternatives fine.\n\nExisting tools considered: `gotesplit` splits by test **count**, not time; CircleCI's `tests split --split-by=timings` is CircleCI-only; `gotestsum` records `-json` but does not split. Nothing off the shelf does LPT from Go JSON timings on GitHub Actions without adopting a larger framework, so a small in-repo program is the honest choice.\n\nHybrid worth considering: keep the `-run` names meaningful by packing whole *files* first (B's readability) and only splitting `e2e_test.go` by LPT. Adds complexity for readability only; decide after the first timings.\n\n### Beyond sharding: `t.Parallel` in e2e (the biggest single win; #52 no longer blocks it)\n\n199 (now 209) serial tests that mostly wait on process start, sockets and runtime startup are the textbook case for `t.Parallel`: on one 4 vCPU runner it could plausibly cut e2e 2-3x with **zero** extra setup cost, and it composes with sharding (fewer legs needed). What stood in the way, and what still does:\n- ~~#52: leaked daemons multiply under parallel runs, and the cleanup error is discarded.~~ **Fixed in #182**: cleanup runs `mcpx stop --all` through the info files and logs its error (`internal/e2e/e2e_test.go:71-85`), and every test daemon idles out after 60 s (`:68`, `:92`).\n- #138: `newEnv` still starts from `os.Environ()` (`e2e_test.go:52`), so an exported `MCPX_DAEMON_ENDPOINT` or `MCPX_SOCKET` sends every test -- every *parallel* test at once -- to one outside daemon. Fix before parallelising.\n- Shared state audit: no `t.Setenv`/`os.Setenv` in e2e (good -- `t.Setenv` forbids `t.Parallel`), and each `newEnv` isolates state/cache/config dirs (`internal/e2e/e2e_test.go:35-87`). Unknown: fixed ports, the stub registry, anything in `$HOME`, and whether a long `t.TempDir()` path pushes two tests' sockets into the shared private runtime dir (`internal/daemon/paths.go:103-133`; hashed per state dir, so a collision is unlikely but the directory is shared -- #88).\n- Process count, not test count, is the unit of contention: each parallel test is 3-4 processes (above), so `-parallel 8` on 4 vCPU is 24-32 processes and the 90 s per-command timeout (`e2e_test.go:113`) stops being generous. Measure `-parallel` at 2, 4, 6, 8 and record the chosen value with its reason, rather than taking GOMAXPROCS (from #166 / #168).\n- The fan-out tests above should stay serial (or get their own leg) so they do not starve the rest.\n- #79 (faster CLI/exec, no self-socket) reduces per-test time directly; every e2e test pays process start.\n\nRecommended order: #143 (unit/e2e split, first static shards, timing capture; the cache line already landed in #182) -> C with N = 3-4 -> #138's allowlist, then `t.Parallel` in e2e at a measured `-parallel`, re-measure, reduce N.\n\n### Unexplained job-start delays\n\nMeasure, do not guess: the jobs API gives `created_at` (queued), `started_at`, and per-step times for every job (#140 reports max and sum of queue delay per run). Observed so far: 2-3 s in 9 of the last 10 runs, 37 s once (run 36663358199). If queue delay grows with leg count, merge the smallest legs (lint legs are the obvious candidates) before adding shards.\n\n## Open questions\n\n1. Per-test time distribution of e2e: is it flat (~0.5 s each) or dominated by a few slow tests? Decides whether LPT or \"fix the ten slowest tests\" comes first. (#143 captures it.)\n2. Timing source: last main run's artifact (fresh, no commits) vs a committed file (reviewable, deterministic, needs a bot or manual refresh). Recommendation: artifact with committed fallback.\n3. `target_leg_seconds` default: tie to the budget (#140) or set independently?\n4. Should unit packages join the packer (as package-granularity items) or stay one leg? Probably one leg until units exceed ~30 s.\n5. Split `e2e_test.go` into feature files regardless of CI? (Readability win; separate issue if wanted.)\n6. ~~Does `t.Parallel` in e2e need a per-test daemon idle-exit (#52 fix 1) first, or only the stop-error fix?~~ Answered by #182, which landed both. The remaining precondition is #138.\n7. A per-shard `-timeout`? A hung shard currently burns the default 10 minutes and #140 would report it as a budget breach rather than a hang (from #166).\n8. `internal/tui` (8.6 s) stays in the unit leg: it is the second-largest package but does not justify a leg's fixed cost (from #166).\n\n## Ease · Impact · Related\n\n**Ease** M · **Impact** high · **Depends on / related**: #95, #135 (matrix from `init`), #140 (timing merge, runbook), #143 (first measurements), #138 (environment allowlist -- the remaining precondition for `t.Parallel`), #52 (closed, fixed in #182 -- no longer blocks `t.Parallel`), #88 (shared socket fallback dir), #79 (faster CLI/exec shortens every e2e test), #97 / #134 (environment legs share runner capacity), #130 (the changed-tests `-race -shuffle -count=N` PR job runs beside the matrix and must not become the longest leg), #99 / #127 (agents rerun one shard from its printed `-run` line, not the suite), #93 (seed; `-shuffle` interacts with ordering, not with membership).\n\nSecurity/auth deferred; see tracker.\n\n## Acceptance criteria\n\n- The suite is sharded by measured time per the body's rule, shard timings are recorded on this issue, and the stop-splitting rule is documented in the workflow/repo.\n- The work described in the Summary/Scope above is delivered via a branch + PR (no direct push to main); verification runs in GitHub Actions CI, not on the sandbox.\n- Evidence (CI links, timings, or probe output as applicable) is recorded on this issue before it is closed.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-28T22:59:17Z","url":"https://github.com/developing-today/code/issues/1994"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d964a162-6ac1-c348-343a-d20f77d990d8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E192:1A09C8:20CAAA:2AF2F3:6B0612AC |
| html-safe-nonce | 29aec7ca1c4895cc8db76be22f820ee14b7a90f21bb420b2bde43c2e7a0ca4a5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTkyOjFBMDlDODoyMENBQUE6MkFGMkYzOjZCMDYxMkFDIiwidmlzaXRvcl9pZCI6IjE0MTA4MjQ3ODM0Njk2MTM3NDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b87bfe3aa1838b1190acba6a86b7ec559d5b594b72a3ccb7d23a78c05eea2e1a |
| hovercard-subject-tag | issue:6089061995 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/1994/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9877b0f52a28b4a712983ccbbcb0d4e00a21192a0755bafb24e9ca946b334cb6/developing-today/code/issues/1994 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9877b0f52a28b4a712983ccbbcb0d4e00a21192a0755bafb24e9ca946b334cb6/developing-today/code/issues/1994 |
| og:image:alt | Relocated from dezren39/darwin-nix#139 on 2026-10-28 (placement audit): mcpx's single source lives in developing-today/code (pkgs/mcpx); re-home tracked at #309. Original body below; issue referenc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | e58943f0186bb8d97b217393c2724a49ab47e4aefefc43595a90fa04699066c9 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 23517473abc6d5da019b4958bd421644e98a418b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width