Skip to content

Add --parallel=max:N to cap the auto-detected worker count - #37069

Closed
THEjacob1000 wants to merge 3 commits into
oven-sh:mainfrom
THEjacob1000:feature/parallel-max
Closed

THEjacob1000 wants to merge 3 commits into
oven-sh:mainfrom
THEjacob1000:feature/parallel-max

Conversation

@THEjacob1000

@THEjacob1000 THEjacob1000 commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds --parallel=max:N to bun test. Same auto-detected worker count as plain --parallel, capped at N.

The point is running one command on machines of different sizes. A 32 core machine that's also running a browser and an editor shouldn't hand every core to the test runner, but a 4 core CI box dedicated to the job should use all 4. --parallel=max:8 gives 8 on the first and 4 on the second, where a fixed --parallel=6 oversubscribes the CI box and underutilizes the workstation.

Percentages (jest's --maxWorkers=50%) don't cover this coz they scale down on the small machine too, 50% of 4 is 2. pytest-xdist has the same semantic as a separate --maxprocesses flag, but --parallel already takes a value here so the cap goes in the value grammar rather than a new flag, especially coz .

max:, max:0 and max:abc error the same way a bad --parallel=N does.

How did you verify your code works?

Added a cap test and the three rejection cases to test/cli/test/parallel.test.ts. They pass under bun bd test and fail under USE_SYSTEM_BUN=1. Manual testing was also conducted and validated on both linux and macos systems

AI Usage: Documentation was written by Claude

@THEjacob1000
THEjacob1000 force-pushed the feature/parallel-max branch from 2796718 to bbcf020 Compare August 6, 2026 21:58
@THEjacob1000
THEjacob1000 marked this pull request as ready for review August 6, 2026 23:17

@claude claude Bot 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The --parallel option now supports max:N, caps workers at the detected CPU count, validates values, and documents the new syntax. Tests cover valid caps and invalid inputs.

Changes

Parallel worker cap

Layer / File(s) Summary
CLI parsing and worker selection
src/runtime/cli/Arguments.rs
The help text documents max:N. Parsing supports CPU-based defaults, validation, and CPU-count capping.
Validation coverage and documentation
test/cli/test/parallel.test.ts, docs/test/parallel.mdx
Tests cover valid, zero, missing, and nonnumeric values. Documentation adds syntax, examples, and fixed-count comparisons.

Possibly related PRs

  • oven-sh/bun#36175: Its CI batching invokes bun test --parallel and depends on worker-count behavior.

Suggested reviewers: jarred-sumner, robobun

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a capped auto-detected worker count for --parallel.
Description check ✅ Passed The description includes both required sections and explains the change, rationale, tests, and manual verification.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/runtime/cli/Arguments.rs`:
- Around line 1824-1832: Replace the inline --parallel parsing around cap,
count_str, and parsed with an explicit parser returning Auto, Fixed(u32), or
Max(u32). Distinguish an unset value from empty max:, zero, nonnumeric input,
and numeric overflow; validate the numeric portion with strings::parse_int and
convert only the expected invalid-input result into the existing CLI diagnostic
instead of defaulting failures to zero.

In `@test/cli/test/parallel.test.ts`:
- Around line 1082-1091: Update the subprocess helpers in the parallel test,
including workers and the rejection cases, to start consuming proc.stdout,
proc.stderr, and proc.exited concurrently. Parse the x PARALLEL result from
stderr in workers, drain both streams in every spawned process, and assert the
captured output before validating exitCode.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f95bfb22-f802-498a-a3cd-6a5c9baaa091

📥 Commits

Reviewing files that changed from the base of the PR and between 2e99ef1 and bbcf020.

📒 Files selected for processing (3)
  • docs/test/parallel.mdx
  • src/runtime/cli/Arguments.rs
  • test/cli/test/parallel.test.ts

Comment thread src/runtime/cli/Arguments.rs Resolved
Comment thread test/cli/test/parallel.test.ts Resolved

@coderabbitai coderabbitai Bot 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.

♻️ Duplicate comments (1)
test/cli/test/parallel.test.ts (1)

1089-1092: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Parse stderr for x PARALLEL.

Line 1089 now drains both pipes, but Line 1092 still matches stdout. Under bunEnv, Bun writes the normal test result, including x PARALLEL, to stderr. Therefore, workers() returns NaN, and the new cap assertions cannot validate worker counts.

Match stderr, assert that the match exists, and check exitCode after the output assertions. This repeats the unresolved issue from the previous review.

Suggested fix
-    const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
+    const [, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
     expect(stderr).not.toContain("error:");
+    const match = stderr.match(/(\d+)x PARALLEL/);
+    expect(match).not.toBeNull();
     expect(exitCode).toBe(0);
-    return Number(stdout.match(/(\d+)x PARALLEL/)?.[1]);
+    return Number(match![1]);

Run bun bd test test/cli/test/parallel.test.ts after applying the fix.

Based on learnings, normal Bun test result output in test/cli/test/parallel.test.ts is written to stderr. As per coding guidelines, subprocess tests must drain stdout, stderr, and process exit concurrently and assert output before exitCode.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/cli/test/parallel.test.ts` around lines 1089 - 1092, Update the
workers() helper to extract the PARALLEL count from stderr rather than stdout,
assert that the match exists before reading its capture, and perform the
exitCode assertion after the output assertions. Preserve concurrent draining of
stdout, stderr, and process completion.

Sources: Coding guidelines, Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@test/cli/test/parallel.test.ts`:
- Around line 1089-1092: Update the workers() helper to extract the PARALLEL
count from stderr rather than stdout, assert that the match exists before
reading its capture, and perform the exitCode assertion after the output
assertions. Preserve concurrent draining of stdout, stderr, and process
completion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d164e5f8-3997-430e-91e7-a858fed30cef

📥 Commits

Reviewing files that changed from the base of the PR and between bbcf020 and ef5ab2a.

📒 Files selected for processing (1)
  • test/cli/test/parallel.test.ts

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/runtime/cli/Arguments.rs`:
- Line 623: Use consistent “detected worker count” terminology for the
--parallel help text and documentation, matching the value provided by
bun_core::get_thread_count() rather than describing physical CPU cores. Update
src/runtime/cli/Arguments.rs lines 623-623, docs/test/parallel.mdx lines 10-10,
and docs/test/parallel.mdx lines 19-24; revise the examples and explanatory text
to reflect the detected worker count and its overrides or clamping behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 02713b6c-76d6-4372-8faf-279d5b2ddcd2

📥 Commits

Reviewing files that changed from the base of the PR and between e84f710 and e04e7e2.

📒 Files selected for processing (3)
  • docs/test/parallel.mdx
  • src/runtime/cli/Arguments.rs
  • test/cli/test/parallel.test.ts

),
parse_param!(
"--parallel <NUMBER>? Run test files in parallel using N worker processes. Implies --isolate. Defaults to CPU core count."
"--parallel <NUMBER>? Run test files in parallel using N worker processes, or \"max:N\" for the CPU core count capped at N. Implies --isolate. Defaults to CPU core count."

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use one term for the worker-count source.

The help text and documentation describe physical CPU cores, but the implementation uses bun_core::get_thread_count(). That function honors UV_THREADPOOL_SIZE and GOMAXPROCS and clamps the value.

  • src/runtime/cli/Arguments.rs#L623-L623: Change “CPU core count” to “detected worker count” or document the overrides.
  • docs/test/parallel.mdx#L10-L10: Update the default-count description.
  • docs/test/parallel.mdx#L19-L24: Update the examples and explanatory text.
📍 Affects 2 files
  • src/runtime/cli/Arguments.rs#L623-L623 (this comment)
  • docs/test/parallel.mdx#L10-L10
  • docs/test/parallel.mdx#L19-L24
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/runtime/cli/Arguments.rs` at line 623, Use consistent “detected worker
count” terminology for the --parallel help text and documentation, matching the
value provided by bun_core::get_thread_count() rather than describing physical
CPU cores. Update src/runtime/cli/Arguments.rs lines 623-623,
docs/test/parallel.mdx lines 10-10, and docs/test/parallel.mdx lines 19-24;
revise the examples and explanatory text to reflect the detected worker count
and its overrides or clamping behavior.

@THEjacob1000
THEjacob1000 deleted the feature/parallel-max branch August 12, 2026 00:10
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.

1 participant