Skip to content

feat(host-tools): add variables that are a share of the host's CPUs - #193

Merged
Mearman merged 1 commit into
mainfrom
feat/host-tools-cpu-share
Nov 3, 2026
Merged

Mearman merged 1 commit into
mainfrom
feat/host-tools-cpu-share

Conversation

@Mearman

@Mearman Mearman commented Nov 3, 2026

Copy link
Copy Markdown
Member

VITEST_MAX_WORKERS has to be half the host's logical CPUs, and vitest reads it with Number.parseInt, so a percentage would be read as a count. The play gathers no facts, so the count cannot come from the inventory either.

Two mappings of variable name to an integer divisor (at least 1): github_runner_host_tools_shell_env_cpu_share and github_runner_host_tools_mise_env_cpu_share. The value is the logical CPU count divided by the divisor, rounded down and never below 1, worked out when the shell or mise reads the file.

Shell: export V="$(n=$(getconf _NPROCESSORS_ONLN); n=$((n / 2)); echo $((n > 0 ? n : 1)))", same in sh, bash and zsh, no variable left in the user's shell. mise: a template over num_cpus(). The first form I tried, (num_cpus() | int / 8) | int, fails in mise for a count that does not divide evenly (Tera's int filter refuses a non-whole float), so the template divides the count less its remainder, and the floor is an if since Tera has no max filter.

The tests read the shell line back through real sh, bash and zsh with a stand-in getconf, and the template through a real mise env with a stand-in count, for 1 to 64 CPUs and divisors from 1 to 100, and check the two agree. Removing either floor fails them.

Both forms share the divisor check, and the check that a variable is given once across the plain, home-relative and CPU-share mappings (the wording of that error changed for the two earlier mappings).

@Mearman
Mearman force-pushed the feat/host-tools-cpu-share branch from deb1bcb to 5d7fd27 Compare November 3, 2026 13:41
…for the shell and for mise

A worker count has to follow the size of the host, and tools such as vitest read their
variable as an integer, so a percentage would be read as a count. The fleet cannot state the
count either: it has hosts of several sizes and the play gathers no facts.

github_runner_host_tools_shell_env_cpu_share and github_runner_host_tools_mise_env_cpu_share
map a variable name to an integer divisor of at least 1. The value is the logical CPU count
divided by it, rounded down and never below 1, worked out when the shell or mise reads the
file. The shell runs getconf _NPROCESSORS_ONLN in a subshell that leaves no variable behind,
and mise evaluates a template over its num_cpus(). The template divides the count less its
remainder, because Tera's int filter refuses a float that is not whole, and floors with an if,
because Tera has no max filter.

Both forms share the divisor check and the check that a variable is given once across the
plain, home-relative and CPU-share mappings. The tests read the shell line back through real
sh, bash and zsh with a stand-in getconf, and the template through a real mise with a stand-in
count, for counts and divisors including a single CPU, and check that the two agree.
@Mearman
Mearman force-pushed the feat/host-tools-cpu-share branch from 5d7fd27 to 50ba88b Compare November 3, 2026 13:58
@Mearman
Mearman marked this pull request as ready for review November 3, 2026 15:05
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ⚠️ Failed 2026-11-03T15:05:06.642600Z
We couldn’t complete this review. Comment @codex security review to try again.
50ba88b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

@Mearman
Mearman merged commit 359d4d3 into main Nov 3, 2026
29 checks passed
@Mearman
Mearman deleted the feat/host-tools-cpu-share branch November 3, 2026 15:05
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 2.27.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant