Skip to content

fix(billing): fix overage strategy lifecycle and settings integration#21236

Merged
gsquared94 merged 3 commits intogoogle-gemini:mainfrom
gsquared94:fix/overage-strategy-reset
Mar 7, 2026
Merged

fix(billing): fix overage strategy lifecycle and settings integration#21236
gsquared94 merged 3 commits intogoogle-gemini:mainfrom
gsquared94:fix/overage-strategy-reset

Conversation

@gsquared94
Copy link
Copy Markdown
Contributor

@gsquared94 gsquared94 commented Mar 5, 2026

Summary

Fixes three issues with the AI credits billing feature:

  1. Overage strategy reset per turn: When overageStrategy is ask, accepting credits on one turn permanently mutated the strategy to always for the rest of the session. Now the strategy resets on each new user prompt.

  2. Billing settings not forwarded: billing.overageStrategy from settings.json was never passed to the Config constructor, so the setting had no effect. Fixed by passing settings.billing through.

  3. In-process setting changes ignored: configuredOverageStrategy was a stale snapshot from Config construction. Replaced with live settings read — resetBillingTurnState() now accepts the current value from settings.merged.billing.overageStrategy, so changes via /settings take effect on the next prompt.

Also includes two supporting commits: adding Flash model to the credits allowlist and deduplicating the "Using AI Credits" banner to show once per turn.

Changes

Commit 1: Add Flash model to credits allowlist

  • billing.ts — Add gemini-2.5-flash to OVERAGE_ELIGIBLE_MODELS

Commit 2: Deduplicate "Using AI Credits" banner

  • server.ts — Gate notification on Config.creditsNotificationShown
  • config.ts — Add creditsNotificationShown flag
  • creditsFlowHandler.ts — Remove dead initialOverageStrategy listener code

Commit 3: Fix overage strategy lifecycle

  • config.ts — Split billing resets from resetTurn() into resetBillingTurnState(overageStrategy?), removed stale configuredOverageStrategy field
  • config.ts (CLI) — Pass billing: settings.billing to Config constructor
  • useGeminiStream.ts — Call config.resetBillingTurnState(settings.merged.billing?.overageStrategy) in the !isContinuation guard; fixed pre-existing unnecessary config dep in useCallback
  • useQuotaAndFallback.ts — Remove dead initialOverageStrategy code
  • useGeminiStream.test.tsx — Add resetBillingTurnState mock
  • config.test.ts — Tests for resetTurn not resetting billing, resetBillingTurnState with/without args

How to Validate

Integration testing instructions at go/gemini-cli-x-ai-credits-integration-testing

Pre-Merge Checklist

  • Added/updated tests
  • npm run preflight passes
  • Validated on MacOS (npm run)

@gsquared94 gsquared94 requested a review from a team as a code owner March 5, 2026 09:09
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 billing experience by ensuring that the AI credit overage strategy correctly resets for each user turn when configured to 'ask', preventing unintended automatic credit usage. It also expands credit eligibility to include the Flash model and streamlines notifications by displaying the 'Using AI Credits' banner only once per turn. These changes collectively enhance the clarity and control users have over their AI credit consumption.

Highlights

  • Overage Strategy Reset: The billing overage strategy for 'ask' mode is now reset on each user turn. Previously, accepting credits would permanently set the strategy to 'always' for the session, preventing subsequent prompts for credit usage.
  • Flash Model Credit Eligibility: The Gemini Flash model has been added to the allowlist for AI credit usage, enabling users to utilize credits with this model.
  • Credits Banner Deduplication: The 'Using AI Credits' notification banner is now deduplicated to show only once per turn, improving user experience by preventing redundant messages.
  • Dead Code Removal: Unreachable code related to initialOverageStrategy in useQuotaAndFallback.ts has been removed, simplifying the codebase.
Changelog
  • packages/cli/src/ui/hooks/creditsFlowHandler.ts
    • Removed historyManager from the handleOverageMenu function arguments.
    • Removed the logic that added an 'Using AI Credits for this request.' info message to the history manager, as this is now handled centrally.
  • packages/cli/src/ui/hooks/useQuotaAndFallback.ts
    • Removed the initialOverageStrategy variable, as the config.getBillingSettings().overageStrategy is always defined.
    • Updated the overageStrategy assignment to directly use config.getBillingSettings().overageStrategy without a fallback.
    • Removed initialOverageStrategy from the useEffect dependency array to prevent unnecessary re-registrations.
  • packages/core/src/billing/billing.test.ts
    • Updated the test case for isOverageEligibleModel to correctly reflect that gemini-3-flash-preview is now eligible for overage.
  • packages/core/src/billing/billing.ts
    • Imported PREVIEW_GEMINI_FLASH_MODEL.
    • Added PREVIEW_GEMINI_FLASH_MODEL to the OVERAGE_ELIGIBLE_MODELS set, making it eligible for AI credit usage.
  • packages/core/src/code_assist/server.ts
    • Imported coreEvents for emitting feedback.
    • Implemented logic to check config.getCreditsNotificationShown() before emitting the 'Using AI Credits for this request.' info feedback, ensuring it's shown only once per turn.
  • packages/core/src/config/config.test.ts
    • Added a new test case to verify that resetTurn correctly resets the overageStrategy to its configured value.
    • Added a new test case to confirm that resetTurn preserves the overageStrategy when it is configured as 'always'.
    • Added a new test case to ensure resetTurn resets the creditsNotificationShown flag to false.
  • packages/core/src/config/config.ts
    • Added a private field creditsNotificationShown to track if the credits notification has been shown in the current turn.
    • Added a private readonly field configuredOverageStrategy to store the initial overage strategy.
    • Initialized configuredOverageStrategy with the billing overage strategy during configuration.
    • Modified resetTurn() to reset creditsNotificationShown to false and restore billing.overageStrategy to configuredOverageStrategy.
    • Added public methods setCreditsNotificationShown(value: boolean) and getCreditsNotificationShown(): boolean to manage the notification state.
Activity
  • Pull request created by gsquared94.
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
Copy Markdown
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 correctly addresses a bug where the billing overage strategy would permanently switch to 'always' for the session after a single use in 'ask' mode. The fix properly resets the strategy at the start of each user turn by storing and restoring the originally configured value. The implementation is robust and is well-covered by new unit tests that validate the reset logic.

Supporting changes further improve the billing functionality. The Flash model is now correctly included in the overage-eligible models list. The "Using AI Credits" notification has been refactored to prevent duplicates, showing only once per turn by centralizing its state in the Config object. Additionally, some unreachable code within the useQuotaAndFallback hook has been cleaned up, improving maintainability. Overall, these are high-quality changes that resolve the issue and enhance the codebase.

@gemini-cli gemini-cli bot added the status/need-issue Pull requests that need to have an associated issue. label Mar 5, 2026
Emit coreEvents.emitFeedback in CodeAssistServer when credits are
auto-attached to a request. Deduplicate by userPromptId so the
banner appears exactly once per user turn, not on agent sub-calls.
Remove the duplicate banner from creditsFlowHandler since the server
now handles it for all cases.
@gsquared94 gsquared94 force-pushed the fix/overage-strategy-reset branch 3 times, most recently from 6be1d36 to 42dda76 Compare March 5, 2026 15:57
Reset billing.overageStrategy back to the configured value in
resetTurn(), so 'ask' mode re-prompts the user on every turn instead
of permanently becoming 'always' after first acceptance.

Also removes dead initialOverageStrategy code from useQuotaAndFallback
and adds unit tests covering the resetTurn billing behaviour.
@gsquared94 gsquared94 force-pushed the fix/overage-strategy-reset branch from 42dda76 to 1e0f117 Compare March 6, 2026 06:34
@gsquared94 gsquared94 changed the title fix(billing): reset overage strategy on each user turn for ask mode fix(billing): fix overage strategy lifecycle and settings integration Mar 6, 2026
@gsquared94
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
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 several issues related to the AI credits billing feature. The changes correctly address the overage strategy lifecycle by resetting it on each new prompt and ensuring that live settings are used. The fix for forwarding billing settings from settings.json is also correctly implemented. The deduplication of the "Using AI Credits" banner and the addition of the Flash model to the allowlist are good enhancements. The new tests provide solid coverage for the updated logic. Overall, the changes are well-structured and improve the robustness and correctness of the billing functionality.

Note: Security Review did not run due to the size of the PR.

@gsquared94 gsquared94 added this pull request to the merge queue Mar 7, 2026
Merged via the queue into google-gemini:main with commit 9a74271 Mar 7, 2026
29 checks passed
@gsquared94 gsquared94 deleted the fix/overage-strategy-reset branch March 7, 2026 03:33
@gsquared94
Copy link
Copy Markdown
Contributor Author

/patch preview

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 9, 2026

Patch workflow(s) dispatched successfully!

📋 Details:

  • Channels: preview
  • Commit: 9a7427197bd2d8df9bf4cf5f723b4932557c5e0e
  • Workflows Created: 1

🔗 Track Progress:

github-actions bot pushed a commit that referenced this pull request Mar 9, 2026
…#21236)

# Conflicts:
#	packages/core/src/code_assist/server.ts
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 9, 2026

🚀 Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. ⚠️ Resolve conflicts in the hotfix PR first: #21714
  2. Test your changes after resolving conflicts
  3. Once merged, the patch release will automatically trigger
  4. You'll receive updates here when the release completes

🔗 Track Progress:

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 9, 2026

🚀 Patch Release Started!

📋 Release Details:

  • Environment: prod
  • Channel: preview → publishing to npm tag preview
  • Version: v0.33.0-preview.5
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.33.0-preview.5-pr-21236

⏳ Status: The patch release is now running. You'll receive another update when it completes.

🔗 Track Progress:

@jerop jerop added the release/patch-to-preview PR needs to be patch to preview release label Mar 9, 2026
@galz10
Copy link
Copy Markdown
Collaborator

galz10 commented Mar 9, 2026

/patch preview

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 9, 2026

Patch workflow(s) dispatched successfully!

📋 Details:

  • Channels: preview
  • Commit: 9a7427197bd2d8df9bf4cf5f723b4932557c5e0e
  • Workflows Created: 1

🔗 Track Progress:

github-actions bot pushed a commit that referenced this pull request Mar 9, 2026
…#21236)

# Conflicts:
#	packages/core/src/code_assist/server.ts
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 9, 2026

🚀 Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. ⚠️ Resolve conflicts in the hotfix PR first: #21788
  2. Test your changes after resolving conflicts
  3. Once merged, the patch release will automatically trigger
  4. You'll receive updates here when the release completes

🔗 Track Progress:

@github-actions
Copy link
Copy Markdown

🚀 Patch Release Started!

📋 Release Details:

  • Environment: prod
  • Channel: preview → publishing to npm tag preview
  • Version: v0.33.0-preview.8
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.33.0-preview.8-pr-21236

⏳ Status: The patch release is now running. You'll receive another update when it completes.

🔗 Track Progress:

@github-actions
Copy link
Copy Markdown

Patch Release Complete!

📦 Release Details:

🎉 Status: Your patch has been successfully released and published to npm!

📝 What's Available:

🔗 Links:

@jerop jerop removed the release/patch-to-preview PR needs to be patch to preview release label Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants