Skip to content

Comments

fix(core): resolve crash in ClearcutLogger when os.cpus() is empty#19555

Merged
Adib234 merged 1 commit intomainfrom
fix/clearcut-logger-crash-empty-cpus
Feb 19, 2026
Merged

fix(core): resolve crash in ClearcutLogger when os.cpus() is empty#19555
Adib234 merged 1 commit intomainfrom
fix/clearcut-logger-crash-empty-cpus

Conversation

@Adib234
Copy link
Contributor

@Adib234 Adib234 commented Feb 19, 2026

Summary

This PR fixes a critical crash in ClearcutLogger.logStartSessionEvent that occurs on systems where os.cpus() returns an empty array.

Details

On some environments, such as Android/Termux, os.cpus() can return an empty array. The previous implementation attempted to access cpus[0].model without checking if the array was empty, leading to a TypeError: Cannot read properties of undefined (reading 'model').

This PR adds a safety check for cpus.length > 0 before accessing cpus[0].

Additionally, as suggested during development, the core count logging has been updated to use os.availableParallelism() instead of os.cpus().length, which is the modern and more reliable way to determine parallelism in Node.js (available since v18.14.0/v19.4.0, and this project requires >= v20.0.0).

Related Issues

Fixes #18527

How to Validate

Run the updated unit tests in @google/gemini-cli-core:

npm test -w @google/gemini-cli-core -- src/telemetry/clearcut-logger/clearcut-logger.test.ts

The new test case handles empty os.cpus() gracefully specifically verifies this fix.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run

@Adib234 Adib234 requested a review from a team as a code owner February 19, 2026 19:51
@gemini-cli gemini-cli bot closed this Feb 19, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Adib234, 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 addresses a critical runtime error in the ClearcutLogger that manifested on systems where CPU information was unavailable or empty. The changes enhance the stability of the logging mechanism by preventing crashes and improve the accuracy of hardware reporting by adopting a more reliable Node.js API for determining CPU parallelism.

Highlights

  • Crash Resolution: Resolved a critical TypeError in ClearcutLogger.logStartSessionEvent that occurred when os.cpus() returned an empty array, by adding a safety check before accessing CPU model information.
  • Core Count Logging Improvement: Updated the logging of CPU core count to use os.availableParallelism() instead of os.cpus().length, aligning with modern Node.js practices for determining parallelism.
  • Test Coverage: Introduced a new unit test case, handles empty os.cpus() gracefully, to specifically verify the fix and ensure robustness against empty CPU information.
Changelog
  • packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts
    • Imported the node:os module for testing purposes.
    • Mocked os.availableParallelism() to return a default value in tests.
    • Added a new test case to verify graceful handling when os.cpus() returns an empty array.
  • packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts
    • Implemented a conditional check for cpus.length > 0 before attempting to access cpus[0].model to prevent TypeError.
    • Replaced cpus.length with os.availableParallelism() for logging the CPU core count.
Activity
  • Added/updated tests to cover the new functionality and fix.
  • Validated the changes on MacOS using npm run.
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.

@gemini-cli gemini-cli bot reopened this Feb 19, 2026
@gemini-cli
Copy link
Contributor

gemini-cli bot commented Feb 19, 2026

Thank you for linking an issue! This pull request has been automatically reopened.

@google-gemini google-gemini deleted a comment from gemini-cli bot Feb 19, 2026
@google-gemini google-gemini deleted a comment from gemini-cli bot Feb 19, 2026
@Adib234 Adib234 self-assigned this Feb 19, 2026
@github-actions
Copy link

Size Change: +74 B (0%)

Total Size: 24.5 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 24.5 MB +74 B (0%)
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

Copy link
Contributor

@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

The pull request effectively addresses a critical crash by adding a safety check for os.cpus() returning an empty array and updates the core count logging to use os.availableParallelism(), which is a more modern and reliable approach in Node.js. The changes are well-tested with a new unit test case specifically for the os.cpus() empty array scenario. The code changes align with the project's technical stack and conventions.

Comment on lines +618 to +622
if (cpus && cpus.length > 0) {
data.push({
gemini_cli_key: EventMetadataKey.GEMINI_CLI_CPU_INFO,
value: cpus[0].model,
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The conditional check if (cpus && cpus.length > 0) is good for preventing crashes when os.cpus() returns an empty array. This directly addresses the critical crash described in the PR summary.

{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_CPU_CORES,
value: cpus.length.toString(),
value: os.availableParallelism().toString(),
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Using os.availableParallelism() instead of cpus.length is a good improvement for determining the number of CPU cores. It's a more modern and reliable API, especially since the project requires Node.js >= v20.0.0, where this function is available.

@gemini-cli gemini-cli bot added priority/p1 Important and should be addressed in the near term. area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 19, 2026
@Adib234 Adib234 added this pull request to the merge queue Feb 19, 2026
Merged via the queue into main with commit 264c7ac Feb 19, 2026
35 of 53 checks passed
@Adib234 Adib234 deleted the fix/clearcut-logger-crash-empty-cpus branch February 19, 2026 20:29
@MohammadGhorayeb MohammadGhorayeb mentioned this pull request Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG

2 participants