Skip to content

Conversation

@xusd320
Copy link

@xusd320 xusd320 commented Dec 17, 2025

This pull request refactors the worker creation and tracking logic in the Node.js pool, with a focus on simplifying how pending worker creations are managed and improving the robustness of worker statistics updates. The main changes are grouped into two themes: improvements to statistics handling and simplification of the worker creation queue.

Improvements to statistics handling:

  • Replaced direct subtraction with saturating_sub in the NodeJsPoolStats methods to prevent underflow when decrementing counters such as booting_workers, workers, and queued_tasks. [1] [2]

Simplification of the worker creation queue:

  • Refactored PENDING_CREATIONS to store only the oneshot::Sender<u32> instead of a tuple with WorkerOptions, reducing unnecessary data storage.
  • Updated the logic in create_worker and worker_created to match the new structure of PENDING_CREATIONS, simplifying the push and pop operations and removing redundant code related to WorkerOptions. [1] [2]
  • Added a conversion of WorkerOptions to napi_options early in create_worker for cleaner code and more explicit handling of options.

@gemini-code-assist
Copy link

Summary of Changes

Hello @xusd320, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the worker management system within turbopack-node by addressing two key areas: improving the reliability of worker pool statistics and simplifying the worker creation process. The changes prevent statistical underflow and streamline the internal handling of pending worker creations, resulting in a more robust and maintainable codebase.

Highlights

  • Robust Statistics Handling: Replaced direct decrements with saturating_sub for worker and task counters in NodeJsPoolStats to prevent potential underflow issues and ensure accurate statistics.
  • Simplified Worker Creation Queue: Streamlined the PENDING_CREATIONS queue to store only oneshot::Sender<u32>, removing redundant WorkerOptions storage and simplifying the logic for adding and retrieving pending worker creation requests.
  • Cleaner Worker Creation Logic: Introduced an early conversion of WorkerOptions to napi_options in create_worker and simplified the worker_created function by removing unnecessary worker pool recording logic, focusing solely on sending the worker ID.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively improves the robustness of worker statistics by using saturating_sub to prevent underflow errors, and it simplifies the worker creation logic by refactoring PENDING_CREATIONS. However, the simplification in worker_created introduces a potential resource leak. When a task waiting for a worker is cancelled, the newly created worker can become orphaned. I have provided a specific comment with a suggested fix to handle this scenario by terminating the orphaned worker.

@xusd320 xusd320 merged commit 1c892ad into utoo Dec 17, 2025
12 of 25 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.

4 participants