Skip to content

fix(core): cache CLI version to ensure consistency during sessions#18793

Merged
sehoon38 merged 1 commit intomainfrom
fix/version-caching
Feb 11, 2026
Merged

fix(core): cache CLI version to ensure consistency during sessions#18793
sehoon38 merged 1 commit intomainfrom
fix/version-caching

Conversation

@sehoon38
Copy link
Contributor

Summary

Caches the CLI version string at startup to ensure consistent reporting throughout a session.

Details

Previously, getVersion() read package.json from disk on every call. If an auto-update occurred while a session was active, commands like /about would report the new version from disk even though the running process was still the older version. This PR introduces a cachedVersion variable to "freeze" the version at startup.

Related Issues

Fixes #18792

How to Validate

  1. Start CLI: npm start
  2. Run /about -> see version A.
  3. Edit packages/core/package.json -> set version to B.
  4. Run /about -> still see version A.
  5. Run unit tests: npm test -w @google/gemini-cli-core -- src/utils/version.test.ts

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

@sehoon38 sehoon38 requested a review from a team as a code owner February 11, 2026 04:33
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @sehoon38, 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 an issue where the CLI's reported version could become inconsistent if the package.json file was updated during an active session. By introducing a caching layer for the CLI version, the system now ensures that the version reported at startup remains consistent throughout the application's lifecycle, improving reliability and user experience.

Highlights

  • CLI Version Caching: Implemented a caching mechanism for the CLI version string at startup to ensure consistent version reporting throughout a session, preventing discrepancies if package.json changes mid-session.
  • Updated getVersion Function: Modified the getVersion function to first check for a cachedVersion before reading package.json from disk, improving performance and consistency.
  • Testability Enhancements: Introduced a resetVersionCache function, primarily for testing purposes, to clear the cached version between test runs.
  • New Test Case: Added a new unit test to verify that getVersion correctly caches the version and only calls getPackageJson once.
Changelog
  • packages/core/src/utils/version.test.ts
    • Imported resetVersionCache for testing purposes.
    • Added vi.clearAllMocks() and resetVersionCache() to the beforeEach hook to ensure a clean state for each test.
    • Included a new test case to validate the version caching behavior, asserting that getPackageJson is called only once and the cached version is returned.
  • packages/core/src/utils/version.ts
    • Declared a cachedVersion variable to store the CLI version.
    • Modified the getVersion function to return cachedVersion if already set, otherwise fetch it, store it, and then return it.
    • Exported a new function resetVersionCache to clear the cachedVersion, intended for testing.
Activity
  • The pull request author, sehoon38, has provided a detailed summary, validation steps, and a pre-merge checklist.
  • Tests have been added/updated and validated on MacOS.
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.

@github-actions
Copy link

github-actions bot commented Feb 11, 2026

Size Change: +240 B (0%)

Total Size: 24.3 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 24.3 MB +240 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./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-closed.sb 3.29 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

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

This pull request introduces caching for the CLI version to prevent inconsistencies during a session, which is a good improvement. The implementation correctly solves the problem for sequential calls. However, I've identified a potential race condition under concurrent calls to getVersion() and suggested a fix to make the caching more robust. The accompanying test changes are well-written and effectively validate the caching behavior.

@sehoon38 sehoon38 force-pushed the fix/version-caching branch from 617490d to 4ffcd1c Compare February 11, 2026 04:46
@sehoon38 sehoon38 enabled auto-merge February 11, 2026 04:48
@gemini-cli gemini-cli bot added the area/core Issues related to User Interface, OS Support, Core Functionality label Feb 11, 2026
@sehoon38 sehoon38 force-pushed the fix/version-caching branch from 4ffcd1c to ff8bdd1 Compare February 11, 2026 16:51
@sehoon38 sehoon38 added this pull request to the merge queue Feb 11, 2026
Merged via the queue into main with commit 34a47a5 Feb 11, 2026
27 checks passed
@sehoon38 sehoon38 deleted the fix/version-caching branch February 11, 2026 17:12
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(core): ensure consistent version reporting during active sessions

2 participants