Skip to content

fix(cli): detect macOS logical CPU count via sysctl, not just nproc - #5642

Merged
gabsprogrammer merged 1 commit into
Osmantic:public-betafrom
roshangupta00750:fix/ods-cli-macos-cpu-count
Sep 19, 2026
Merged

gabsprogrammer merged 1 commit into
Osmantic:public-betafrom
roshangupta00750:fix/ods-cli-macos-cpu-count

Conversation

@roshangupta00750

Copy link
Copy Markdown

Problem

ods-cli's _get_host_logical_cpus() reports 1 logical CPU on macOS:

cores=$(nproc 2>/dev/null || grep -c '^processor' /proc/cpuinfo 2>/dev/null || echo "1")

nproc and /proc/cpuinfo are Linux-only; on macOS both fail and the chain falls through to echo "1". That value backs _get_docker_available_cpus()'s fallback (used when docker info --format {{.NCPU}} is unavailable), and the result caps the per-service CPU budget — so an Apple-silicon host provisions llama-server and the bundled services for a single core.

Reproduced on macOS:

( set -- version; source ./ods-cli >/dev/null 2>&1; _get_host_logical_cpus )  # 1
sysctl -n hw.logicalcpu                                                       # 12

Fix

Probe sysctl -n hw.logicalcpu (macOS/BSD) between the two Linux sources. Order is preserved on Linux — nproc still wins first — so only the previously-broken macOS path changes.

Sibling of the same nproc-only gap being fixed for installers/lib/detection.sh in #5564 / #2827; those PRs do not touch ods-cli.

Validation

Adds tests/test-ods-cli-host-cpu-fallback.sh (wired into make test).

  • Before: on macOS _get_host_logical_cpus1; the new test's stubbed case (nproc unavailable, sysctl→7) returns the Linux /proc/cpuinfo count instead of 7 → FAIL.
  • After: macOS returns its true count (12 on the test host); the stubbed sysctl case returns 7 on both macOS and the Linux VM.
  • No Linux change: with nproc present the result is unchanged (VM: 4 = nproc).
  • Teeth: reverting the ods-cli change makes the test fail again on both platforms.
  • bash -n and shellcheck -S error ods-cli clean.

Closes 5641

_get_host_logical_cpus() probes `nproc` then `/proc/cpuinfo`, both of
which are Linux-only. On macOS neither exists, so the chain always fell
through to the degenerate `echo "1"`. That value backs
_get_docker_available_cpus()'s fallback, so whenever Docker's own NCPU is
unavailable an Apple-silicon host computes its llama-server / bundled-
service CPU budget as a single core and throttles the stack.

Probe `sysctl -n hw.logicalcpu` (macOS/BSD) between the two Linux sources.
Order is preserved on Linux (nproc still wins first), so this only changes
the previously-broken macOS path.

This is the ods-cli sibling of the same nproc-only gap being fixed for
installers/lib/detection.sh in Osmantic#5564 / Osmantic#2827; those PRs do not touch
ods-cli.

Adds tests/test-ods-cli-host-cpu-fallback.sh (wired into `make test`),
which proves the sysctl fallback deterministically by stubbing nproc
unavailable, and asserts the true count on a real macOS host.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@gabsprogrammer
gabsprogrammer merged commit 4ce6be5 into Osmantic:public-beta Sep 19, 2026
43 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.

2 participants