fix(core): resolve crash in ClearcutLogger when os.cpus() is empty#19555
fix(core): resolve crash in ClearcutLogger when os.cpus() is empty#19555
Conversation
Summary of ChangesHello @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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
|
Thank you for linking an issue! This pull request has been automatically reopened. |
|
Size Change: +74 B (0%) Total Size: 24.5 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
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.
| if (cpus && cpus.length > 0) { | ||
| data.push({ | ||
| gemini_cli_key: EventMetadataKey.GEMINI_CLI_CPU_INFO, | ||
| value: cpus[0].model, | ||
| }, | ||
| }); |
| { | ||
| gemini_cli_key: EventMetadataKey.GEMINI_CLI_CPU_CORES, | ||
| value: cpus.length.toString(), | ||
| value: os.availableParallelism().toString(), |
Summary
This PR fixes a critical crash in
ClearcutLogger.logStartSessionEventthat occurs on systems whereos.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 accesscpus[0].modelwithout checking if the array was empty, leading to aTypeError: Cannot read properties of undefined (reading 'model').This PR adds a safety check for
cpus.length > 0before accessingcpus[0].Additionally, as suggested during development, the core count logging has been updated to use
os.availableParallelism()instead ofos.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.tsThe new test case
handles empty os.cpus() gracefullyspecifically verifies this fix.Pre-Merge Checklist