Skip to content

Comments

fix(plan): time share by approval mode dashboard reporting negative time shares#19847

Merged
jerop merged 4 commits intomainfrom
adibakm/fix-plan-mode-telemetry-duration
Feb 22, 2026
Merged

fix(plan): time share by approval mode dashboard reporting negative time shares#19847
jerop merged 4 commits intomainfrom
adibakm/fix-plan-mode-telemetry-duration

Conversation

@Adib234
Copy link
Contributor

@Adib234 Adib234 commented Feb 21, 2026

Summary

This PR fixes negative telemetry durations by switching to a consistent use of performance.now() for tracking mode switches. It resolves a bug where lastModeSwitchTime was initialized with the system clock (Date.now()) but measured against the process timer (performance.now()).

Details

  • Consistent Monotonic Timing: Changed the initialization of lastModeSwitchTime to use performance.now(). This ensures that all duration calculations use the same monotonic time source, avoiding the massive offset between Unix epoch time and process uptime.
  • Improved State Management: Updated logCurrentModeDuration to refresh lastModeSwitchTime immediately after logging. This prevents "double-counting" time during multiple rapid mode switches or shutdown sequences.
  • Negative Duration Guard: Added a safety check to skip telemetry events if the calculated duration is non-positive, protecting against rare clock drift or edge cases.

Related Issues

Fixes #19846

How to Validate

Negative durations should never be logged going forward.

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
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@Adib234 Adib234 self-assigned this Feb 21, 2026
@Adib234 Adib234 requested a review from a team as a code owner February 21, 2026 18:30
@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 bug causing negative telemetry durations in approval mode dashboard reporting. It achieves this by standardizing the use of performance.now() for all time tracking related to mode switches, thereby resolving inconsistencies that arose from mixing Date.now() and performance.now(). The changes ensure accurate duration logging and prevent invalid data from being reported.

Highlights

  • Consistent Monotonic Timing: The initialization of lastModeSwitchTime now uses performance.now(), ensuring all duration calculations rely on a consistent monotonic time source and avoiding offsets between system and process timers.
  • Improved State Management: The logCurrentModeDuration method has been updated to refresh lastModeSwitchTime immediately after logging, preventing inaccurate time accumulation during rapid mode switches or shutdown sequences.
  • Negative Duration Guard: A safety check was added to skip telemetry events if the calculated duration is non-positive, which protects against logging erroneous data due to clock drift or edge cases.
Changelog
  • packages/core/src/config/config.ts
    • Imported logApprovalModeSwitch and logApprovalModeDuration for telemetry.
    • Consolidated type imports for UserTierId, RetrieveUserQuotaResponse, and AdminControlsSettings.
    • Initialized lastModeSwitchTime using performance.now() instead of Date.now().
    • Removed the redundant lastModeSwitchTime update from the setApprovalMode method.
    • Modified logCurrentModeDuration to use performance.now(), include a check for positive duration before logging, and update lastModeSwitchTime at the end of the method.
Activity
  • No specific activity has been recorded for this pull request yet, beyond its creation and the initial code changes.
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
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 effectively resolves a bug that caused negative durations in telemetry by standardizing on performance.now() for all duration calculations related to approval mode switches. This ensures the use of a monotonic clock, preventing issues from system time adjustments. The refactoring to centralize the timestamp update logic within logCurrentModeDuration is a good improvement for maintainability and correctness, particularly for handling shutdown sequences. The addition of a guard against non-positive durations is a solid defensive programming practice. The changes are well-implemented and I approve them.

@gemini-cli gemini-cli bot added the area/enterprise Issues related to Telemetry, Policy, Quota / Licensing label Feb 21, 2026
@github-actions
Copy link

github-actions bot commented Feb 21, 2026

Size Change: +39 B (0%)

Total Size: 25.2 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.2 MB +39 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

@jerop jerop added this pull request to the merge queue Feb 22, 2026
Merged via the queue into main with commit 84666e1 Feb 22, 2026
27 checks passed
@jerop jerop deleted the adibakm/fix-plan-mode-telemetry-duration branch February 22, 2026 00:44
SH20RAJ added a commit to SH20RAJ/gemini-cli that referenced 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/enterprise Issues related to Telemetry, Policy, Quota / Licensing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Metrics] Time shared by approval mode dashboard is reporting incorrect metrics

2 participants