Skip to content

fix(core): respect --parallel limit for discrete task concurrency#34721

Merged
AgentEnder merged 1 commit intomasterfrom
gh-34117
Mar 21, 2026
Merged

fix(core): respect --parallel limit for discrete task concurrency#34721
AgentEnder merged 1 commit intomasterfrom
gh-34117

Conversation

@leosvelperez
Copy link
Copy Markdown
Member

@leosvelperez leosvelperez commented Mar 5, 2026

Current Behavior

--parallel=N doesn't cap discrete task concurrency when continuous tasks exist. getThreadCount inflates the thread count to N + continuousCount, and all threads are fungible — any thread picks up any task. With --parallel=1 and 2 continuous tasks, 3 threads run, allowing up to 3 discrete tasks concurrently.

Expected Behavior

--parallel=N caps discrete task concurrency to N. Continuous tasks get dedicated threads that don't inflate the discrete limit.

Changes

  • Two-pool thread model: Split the unified thread pool into discrete and continuous pools. Each pool runs its own loop and only picks up matching tasks.
  • getThreadPoolSize (renamed from getThreadCount): Returns { discrete, continuous, total }. Discrete pool = options.parallel, continuous pool = number of continuous tasks.
  • executeDiscreteTaskLoop: Handles batches + discrete tasks only. Uses slot-based groupIds via closeGroup/openGroup.
  • executeContinuousTaskLoop: Handles continuous tasks only. Uses counter-based groupIds (parallel + n++). Exits once all continuous tasks have been started.
  • nextTask(filter?) on TasksSchedule: Optional filter param to dequeue only matching tasks. Scheduler stays unaware of pools/limits.

Related Issue(s)

Fixes #34117
Fixes #31494

@leosvelperez leosvelperez self-assigned this Mar 5, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 5, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 53ed28a
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69aa90523532830008cbce1b
😎 Deploy Preview https://deploy-preview-34721--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 5, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 53ed28a
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69aa90522aad49000871d22e
😎 Deploy Preview https://deploy-preview-34721--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Mar 5, 2026

View your CI Pipeline Execution ↗ for commit 53ed28a

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 56m 14s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 3m 24s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-06 09:30:00 UTC

…s tasks exist

Split the unified thread pool into discrete and continuous pools so that
--parallel only caps discrete task concurrency. Continuous tasks get
dedicated threads that don't inflate the discrete limit.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

🐳 We have a release for that!

This PR has a release associated with it. You can try it out using this command:

npx create-nx-workspace@22.6.0-pr.34721.53ed28a my-workspace

Or just copy this version and use it in your own command:

22.6.0-pr.34721.53ed28a
Release details 📑
Published version 22.6.0-pr.34721.53ed28a
Triggered by @leosvelperez
Branch gh-34117
Commit 53ed28a
Workflow run 22757606337

To request a new release for this pull request, mention someone from the Nx team or the @nrwl/nx-pipelines-reviewers.

@AgentEnder AgentEnder merged commit e0b7f12 into master Mar 21, 2026
24 checks passed
@AgentEnder AgentEnder deleted the gh-34117 branch March 21, 2026 02:23
FrozenPandaz pushed a commit that referenced this pull request Mar 26, 2026
…4721)

## Current Behavior

`--parallel=N` doesn't cap discrete task concurrency when continuous
tasks exist. `getThreadCount` inflates the thread count to `N +
continuousCount`, and all threads are fungible — any thread picks up any
task. With `--parallel=1` and 2 continuous tasks, 3 threads run,
allowing up to 3 discrete tasks concurrently.

## Expected Behavior

`--parallel=N` caps discrete task concurrency to N. Continuous tasks get
dedicated threads that don't inflate the discrete limit.

### Changes

- **Two-pool thread model**: Split the unified thread pool into discrete
and continuous pools. Each pool runs its own loop and only picks up
matching tasks.
- **`getThreadPoolSize`** (renamed from `getThreadCount`): Returns `{
discrete, continuous, total }`. Discrete pool = `options.parallel`,
continuous pool = number of continuous tasks.
- **`executeDiscreteTaskLoop`**: Handles batches + discrete tasks only.
Uses slot-based groupIds via `closeGroup`/`openGroup`.
- **`executeContinuousTaskLoop`**: Handles continuous tasks only. Uses
counter-based groupIds (`parallel + n++`). Exits once all continuous
tasks have been started.
- **`nextTask(filter?)`** on `TasksSchedule`: Optional filter param to
dequeue only matching tasks. Scheduler stays unaware of pools/limits.

## Related Issue(s)

Fixes #34117
Fixes #31494

(cherry picked from commit e0b7f12)
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

2 participants